forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Impeller] libImpeller: Add support for Metal and Vulkan rendering.
The tests were already parameterized. This enables the remaining backends. Fixes flutter/flutter#159512
- Loading branch information
1 parent
05fdaa6
commit 43ea25f
Showing
27 changed files
with
618 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2013 The Flutter Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//flutter/impeller/tools/impeller.gni") | ||
|
||
group("backend") { | ||
public_deps = [] | ||
|
||
if (impeller_enable_metal) { | ||
public_deps += [ "metal" ] | ||
} | ||
|
||
if (impeller_enable_opengles) { | ||
public_deps += [ "gles" ] | ||
} | ||
|
||
if (impeller_enable_vulkan) { | ||
public_deps += [ "vulkan" ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2013 The Flutter Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//flutter/impeller/tools/impeller.gni") | ||
|
||
impeller_component("gles") { | ||
public_deps = [ "../../:interop_base" ] | ||
sources = [ | ||
"context_gles.cc", | ||
"context_gles.h", | ||
"reactor_worker_gles.cc", | ||
"reactor_worker_gles.h", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "impeller/toolkit/interop/backend/gles/context_gles.h" | ||
|
||
#include "impeller/base/validation.h" | ||
#include "impeller/entity/gles/entity_shaders_gles.h" | ||
#include "impeller/entity/gles/framebuffer_blend_shaders_gles.h" | ||
#include "impeller/renderer/backend/gles/context_gles.h" | ||
|
||
namespace impeller::interop { | ||
|
||
ScopedObject<Context> ContextGLES::Create( | ||
std::function<void*(const char* gl_proc_name)> proc_address_callback) { | ||
auto proc_table = std::make_unique<ProcTableGLES>( | ||
impeller::ProcTableGLES(std::move(proc_address_callback))); | ||
if (!proc_table || !proc_table->IsValid()) { | ||
VALIDATION_LOG << "Could not create valid OpenGL ES proc. table."; | ||
return {}; | ||
} | ||
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = { | ||
std::make_shared<fml::NonOwnedMapping>( | ||
impeller_entity_shaders_gles_data, | ||
impeller_entity_shaders_gles_length), | ||
std::make_shared<fml::NonOwnedMapping>( | ||
impeller_framebuffer_blend_shaders_gles_data, | ||
impeller_framebuffer_blend_shaders_gles_length), | ||
}; | ||
auto impeller_context = impeller::ContextGLES::Create(std::move(proc_table), | ||
shader_mappings, false); | ||
if (!impeller_context) { | ||
VALIDATION_LOG << "Could not create Impeller context."; | ||
return {}; | ||
} | ||
auto reactor_worker = std::make_shared<ReactorWorkerGLES>(); | ||
auto worker_id = impeller_context->AddReactorWorker(reactor_worker); | ||
if (!worker_id.has_value()) { | ||
VALIDATION_LOG << "Could not add reactor worker."; | ||
return {}; | ||
} | ||
|
||
// Can't call Create because of private constructor. Adopt the raw pointer | ||
// instead. | ||
auto context = Adopt<Context>( | ||
new ContextGLES(std::move(impeller_context), std::move(reactor_worker))); | ||
|
||
if (!context->IsValid()) { | ||
VALIDATION_LOG << "Could not create valid context."; | ||
return {}; | ||
} | ||
return context; | ||
} | ||
|
||
ContextGLES::ContextGLES(std::shared_ptr<impeller::Context> context, | ||
std::shared_ptr<ReactorWorkerGLES> worker) | ||
: Context(std::move(context)), worker_(std::move(worker)) {} | ||
|
||
ContextGLES::~ContextGLES() = default; | ||
|
||
} // namespace impeller::interop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_CONTEXT_GLES_H_ | ||
#define FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_CONTEXT_GLES_H_ | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
#include "impeller/toolkit/interop/backend/gles/reactor_worker_gles.h" | ||
#include "impeller/toolkit/interop/context.h" | ||
|
||
namespace impeller::interop { | ||
|
||
class ContextGLES final : public Context { | ||
public: | ||
static ScopedObject<Context> Create( | ||
std::function<void*(const char* gl_proc_name)> proc_address_callback); | ||
|
||
ContextGLES(); | ||
|
||
// |Context| | ||
~ContextGLES() override; | ||
|
||
ContextGLES(const ContextGLES&) = delete; | ||
|
||
ContextGLES& operator=(const ContextGLES&) = delete; | ||
|
||
private: | ||
std::shared_ptr<ReactorWorkerGLES> worker_; | ||
|
||
ContextGLES(std::shared_ptr<impeller::Context> context, | ||
std::shared_ptr<ReactorWorkerGLES> worker); | ||
}; | ||
|
||
} // namespace impeller::interop | ||
|
||
#endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_CONTEXT_GLES_H_ |
19 changes: 19 additions & 0 deletions
19
impeller/toolkit/interop/backend/gles/reactor_worker_gles.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "impeller/toolkit/interop/backend/gles/reactor_worker_gles.h" | ||
|
||
namespace impeller::interop { | ||
|
||
ReactorWorkerGLES::ReactorWorkerGLES() | ||
: thread_id_(std::this_thread::get_id()) {} | ||
|
||
ReactorWorkerGLES::~ReactorWorkerGLES() = default; | ||
|
||
bool ReactorWorkerGLES::CanReactorReactOnCurrentThreadNow( | ||
const ReactorGLES& reactor) const { | ||
return thread_id_ == std::this_thread::get_id(); | ||
} | ||
|
||
} // namespace impeller::interop |
33 changes: 33 additions & 0 deletions
33
impeller/toolkit/interop/backend/gles/reactor_worker_gles.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_REACTOR_WORKER_GLES_H_ | ||
#define FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_REACTOR_WORKER_GLES_H_ | ||
|
||
#include "impeller/renderer/backend/gles/reactor_gles.h" | ||
|
||
namespace impeller::interop { | ||
|
||
class ReactorWorkerGLES final : public ReactorGLES::Worker { | ||
public: | ||
ReactorWorkerGLES(); | ||
|
||
// |ReactorGLES::Worker| | ||
~ReactorWorkerGLES() override; | ||
|
||
// |ReactorGLES::Worker| | ||
bool CanReactorReactOnCurrentThreadNow( | ||
const ReactorGLES& reactor) const override; | ||
|
||
private: | ||
std::thread::id thread_id_; | ||
|
||
ReactorWorkerGLES(const ReactorWorkerGLES&) = delete; | ||
|
||
ReactorWorkerGLES& operator=(const ReactorWorkerGLES&) = delete; | ||
}; | ||
|
||
} // namespace impeller::interop | ||
|
||
#endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_GLES_REACTOR_WORKER_GLES_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2013 The Flutter Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//flutter/impeller/tools/impeller.gni") | ||
|
||
impeller_component("metal") { | ||
public_deps = [ "../../:interop_base" ] | ||
sources = [ | ||
"context_mtl.h", | ||
"context_mtl.mm", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_METAL_CONTEXT_MTL_H_ | ||
#define FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_METAL_CONTEXT_MTL_H_ | ||
|
||
#include "impeller/toolkit/interop/context.h" | ||
|
||
namespace impeller::interop { | ||
|
||
class ContextMTL final : public Context { | ||
public: | ||
static ScopedObject<Context> Create(); | ||
|
||
// |Context| | ||
~ContextMTL() override; | ||
|
||
ContextMTL(const ContextMTL&) = delete; | ||
|
||
ContextMTL& operator=(const ContextMTL&) = delete; | ||
|
||
private: | ||
explicit ContextMTL(std::shared_ptr<impeller::Context> context); | ||
}; | ||
|
||
} // namespace impeller::interop | ||
|
||
#endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_BACKEND_METAL_CONTEXT_MTL_H_ |
Oops, something went wrong.