| Flutter Impeller |

context_gles.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/gles/context_gles.h"
6 #include <memory>
7
8 #include "impeller/base/config.h"
9 #include "impeller/base/validation.h"
10 #include "impeller/base/version.h"
11 #include "impeller/core/runtime_types.h"
12 #include "impeller/renderer/backend/gles/command_buffer_gles.h"
13 #include "impeller/renderer/backend/gles/gpu_tracer_gles.h"
14 #include "impeller/renderer/backend/gles/handle_gles.h"
15 #include "impeller/renderer/backend/gles/render_pass_gles.h"
16 #include "impeller/renderer/backend/gles/texture_gles.h"
17 #include "impeller/renderer/command_queue.h"
18
19 namespace impeller {
20
21 std::shared_ptr<ContextGLES> ContextGLES::Create(
22 const Flags& flags,
23 std::unique_ptr<ProcTableGLES> gl,
24 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries,
25 bool enable_gpu_tracing) {
26 return std::shared_ptr<ContextGLES>(new ContextGLES(
27 flags, std::move(gl), shader_libraries, enable_gpu_tracing));
28 }
29
30 ContextGLES::ContextGLES(
31 const Flags& flags,
32 std::unique_ptr<ProcTableGLES> gl,
33 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
34 bool enable_gpu_tracing)
35 : Context(flags) {
36 reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
37 if (!reactor_->IsValid()) {
38 VALIDATION_LOG << "Could not create valid reactor.";
39 return;
40 }
41
42 // Create the shader library.
43 {
44 auto library = std::shared_ptr<ShaderLibraryGLES>(
45 new ShaderLibraryGLES(shader_libraries_mappings));
46 if (!library->IsValid()) {
47 VALIDATION_LOG << "Could not create valid shader library.";
48 return;
49 }
50 shader_library_ = std::move(library);
51 }
52
53 // Create the pipeline library.
54 {
55 pipeline_library_ =
56 std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
57 }
58
59 // Create allocators.
60 {
61 resource_allocator_ =
62 std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
63 if (!resource_allocator_->IsValid()) {
64 VALIDATION_LOG << "Could not create a resource allocator.";
65 return;
66 }
67 }
68
69 device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
70
71 // Create the sampler library.
72 {
73 sampler_library_ =
74 std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
75 device_capabilities_->SupportsDecalSamplerAddressMode()));
76 }
77 gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
78 enable_gpu_tracing);
79 command_queue_ = std::make_shared<CommandQueue>();
80 is_valid_ = true;
81 }
82
83 ContextGLES::~ContextGLES() = default;
84
85 Context::BackendType ContextGLES::GetBackendType() const {
86 return Context::BackendType::kOpenGLES;
87 }
88
89 const std::shared_ptr<ReactorGLES>& ContextGLES::GetReactor() const {
90 return reactor_;
91 }
92
93 std::optional<ReactorGLES::WorkerID> ContextGLES::AddReactorWorker(
94 const std::shared_ptr<ReactorGLES::Worker>& worker) {
95 if (!IsValid()) {
96 return std::nullopt;
97 }
98 return reactor_->AddWorker(worker);
99 }
100
101 bool ContextGLES::RemoveReactorWorker(ReactorGLES::WorkerID id) {
102 if (!IsValid()) {
103 return false;
104 }
105 return reactor_->RemoveWorker(id);
106 }
107
108 bool ContextGLES::IsValid() const {
109 return is_valid_;
110 }
111
112 void ContextGLES::Shutdown() {}
113
114 // |Context|
115 std::string ContextGLES::DescribeGpuModel() const {
116 return reactor_->GetProcTable().GetDescription()->GetString();
117 }
118
119 // |Context|
120 std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
121 return resource_allocator_;
122 }
123
124 // |Context|
125 std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
126 return shader_library_;
127 }
128
129 // |Context|
130 std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
131 return sampler_library_;
132 }
133
134 // |Context|
135 std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
136 return pipeline_library_;
137 }
138
139 // |Context|
140 std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
141 return std::shared_ptr<CommandBufferGLES>(
142 new CommandBufferGLES(weak_from_this(), reactor_));
143 }
144
145 // |Context|
146 const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
147 const {
148 return device_capabilities_;
149 }
150
151 // |Context|
152 std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
153 return command_queue_;
154 }
155
156 // |Context|
157 void ContextGLES::ResetThreadLocalState() const {
158 if (!IsValid()) {
159 return;
160 }
161 [[maybe_unused]] auto result =
162 reactor_->AddOperation([](const ReactorGLES& reactor) {
163 RenderPassGLES::ResetGLState(reactor.GetProcTable());
164 });
165 }
166
167 bool ContextGLES::EnqueueCommandBuffer(
168 std::shared_ptr<CommandBuffer> command_buffer) {
169 return true;
170 }
171
172 // |Context|
173 [[nodiscard]] bool ContextGLES::FlushCommandBuffers() {
174 return reactor_->React();
175 }
176
177 // |Context|
178 bool ContextGLES::AddTrackingFence(
179 const std::shared_ptr<Texture>& texture) const {
180 if (!reactor_->GetProcTable().FenceSync.IsAvailable()) {
181 return false;
182 }
183 HandleGLES fence = reactor_->CreateHandle(HandleType::kFence);
184 TextureGLES::Cast(*texture).SetFence(fence);
185 return true;
186 }
187
188 // |Context|
189 RuntimeStageBackend ContextGLES::GetRuntimeStageBackend() const {
190 if (GetReactor()->GetProcTable().GetDescription()->GetGlVersion().IsAtLeast(
191 Version{3, 0, 0})) {
192 return RuntimeStageBackend::kOpenGLES3;
193 }
194 return RuntimeStageBackend::kOpenGLES;
195 }
196
197 } // namespace impeller
config.h
impeller::BackendCast< TextureGLES, Texture >::Cast
static TextureGLES & Cast(Texture &base)
Definition: backend_cast.h:13
impeller::ContextGLES
Definition: context_gles.h:25
impeller::ContextGLES::~ContextGLES
~ContextGLES() override
impeller::ContextGLES::GetBackendType
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
Definition: context_gles.cc:85
impeller::ContextGLES::RemoveReactorWorker
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
Definition: context_gles.cc:101
impeller::ContextGLES::GetReactor
const std::shared_ptr< ReactorGLES > & GetReactor() const
Definition: context_gles.cc:89
impeller::ContextGLES::Create
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping >> &shader_libraries, bool enable_gpu_tracing)
Definition: context_gles.cc:21
impeller::ContextGLES::AddReactorWorker
std::optional< ReactorGLES::WorkerID > AddReactorWorker(const std::shared_ptr< ReactorGLES::Worker > &worker)
Definition: context_gles.cc:93
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:65
impeller::Context::BackendType
BackendType
Definition: context.h:67
impeller::Context::BackendType::kOpenGLES
@ kOpenGLES
impeller::RenderPassGLES::ResetGLState
static void ResetGLState(const ProcTableGLES &gl)
Definition: render_pass_gles.cc:179
impeller::TextureGLES::SetFence
void SetFence(HandleGLES fence)
Attach a sync fence to this texture that will be waited on before encoding a rendering operation that...
Definition: texture_gles.cc:678
command_buffer_gles.h
command_queue.h
gpu_tracer_gles.h
handle_gles.h
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
impeller
Definition: allocation.cc:12
impeller::RuntimeStageBackend
RuntimeStageBackend
Definition: runtime_types.h:16
impeller::RuntimeStageBackend::kOpenGLES
@ kOpenGLES
impeller::RuntimeStageBackend::kOpenGLES3
@ kOpenGLES3
impeller::HandleType::kFence
@ kFence
render_pass_gles.h
context_gles.h
runtime_types.h
impeller::Flags
Definition: flags.h:9
impeller::UniqueID
Definition: comparable.h:16
texture_gles.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
version.h