| 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 std::unique_ptr<ProcTableGLES> gl,
23 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries,
24 bool enable_gpu_tracing) {
25 return std::shared_ptr<ContextGLES>(
26 new ContextGLES(std::move(gl), shader_libraries, enable_gpu_tracing));
27 }
28
29 ContextGLES::ContextGLES(
30 std::unique_ptr<ProcTableGLES> gl,
31 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
32 bool enable_gpu_tracing) {
33 reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
34 if (!reactor_->IsValid()) {
35 VALIDATION_LOG << "Could not create valid reactor.";
36 return;
37 }
38
39 // Create the shader library.
40 {
41 auto library = std::shared_ptr<ShaderLibraryGLES>(
42 new ShaderLibraryGLES(shader_libraries_mappings));
43 if (!library->IsValid()) {
44 VALIDATION_LOG << "Could not create valid shader library.";
45 return;
46 }
47 shader_library_ = std::move(library);
48 }
49
50 // Create the pipeline library.
51 {
52 pipeline_library_ =
53 std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
54 }
55
56 // Create allocators.
57 {
58 resource_allocator_ =
59 std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
60 if (!resource_allocator_->IsValid()) {
61 VALIDATION_LOG << "Could not create a resource allocator.";
62 return;
63 }
64 }
65
66 device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
67
68 // Create the sampler library.
69 {
70 sampler_library_ =
71 std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
72 device_capabilities_->SupportsDecalSamplerAddressMode()));
73 }
74 gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
75 enable_gpu_tracing);
76 command_queue_ = std::make_shared<CommandQueue>();
77 is_valid_ = true;
78 }
79
80 ContextGLES::~ContextGLES() = default;
81
82 Context::BackendType ContextGLES::GetBackendType() const {
83 return Context::BackendType::kOpenGLES;
84 }
85
86 const std::shared_ptr<ReactorGLES>& ContextGLES::GetReactor() const {
87 return reactor_;
88 }
89
90 std::optional<ReactorGLES::WorkerID> ContextGLES::AddReactorWorker(
91 const std::shared_ptr<ReactorGLES::Worker>& worker) {
92 if (!IsValid()) {
93 return std::nullopt;
94 }
95 return reactor_->AddWorker(worker);
96 }
97
98 bool ContextGLES::RemoveReactorWorker(ReactorGLES::WorkerID id) {
99 if (!IsValid()) {
100 return false;
101 }
102 return reactor_->RemoveWorker(id);
103 }
104
105 bool ContextGLES::IsValid() const {
106 return is_valid_;
107 }
108
109 void ContextGLES::Shutdown() {}
110
111 // |Context|
112 std::string ContextGLES::DescribeGpuModel() const {
113 return reactor_->GetProcTable().GetDescription()->GetString();
114 }
115
116 // |Context|
117 std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
118 return resource_allocator_;
119 }
120
121 // |Context|
122 std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
123 return shader_library_;
124 }
125
126 // |Context|
127 std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
128 return sampler_library_;
129 }
130
131 // |Context|
132 std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
133 return pipeline_library_;
134 }
135
136 // |Context|
137 std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
138 return std::shared_ptr<CommandBufferGLES>(
139 new CommandBufferGLES(weak_from_this(), reactor_));
140 }
141
142 // |Context|
143 const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
144 const {
145 return device_capabilities_;
146 }
147
148 // |Context|
149 std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
150 return command_queue_;
151 }
152
153 // |Context|
154 void ContextGLES::ResetThreadLocalState() const {
155 if (!IsValid()) {
156 return;
157 }
158 [[maybe_unused]] auto result =
159 reactor_->AddOperation([](const ReactorGLES& reactor) {
160 RenderPassGLES::ResetGLState(reactor.GetProcTable());
161 });
162 }
163
164 bool ContextGLES::EnqueueCommandBuffer(
165 std::shared_ptr<CommandBuffer> command_buffer) {
166 return true;
167 }
168
169 // |Context|
170 [[nodiscard]] bool ContextGLES::FlushCommandBuffers() {
171 return reactor_->React();
172 }
173
174 // |Context|
175 bool ContextGLES::AddTrackingFence(
176 const std::shared_ptr<Texture>& texture) const {
177 if (!reactor_->GetProcTable().FenceSync.IsAvailable()) {
178 return false;
179 }
180 HandleGLES fence = reactor_->CreateHandle(HandleType::kFence);
181 TextureGLES::Cast(*texture).SetFence(fence);
182 return true;
183 }
184
185 // |Context|
186 RuntimeStageBackend ContextGLES::GetRuntimeStageBackend() const {
187 if (GetReactor()->GetProcTable().GetDescription()->GetGlVersion().IsAtLeast(
188 Version{3, 0, 0})) {
189 return RuntimeStageBackend::kOpenGLES3;
190 }
191 return RuntimeStageBackend::kOpenGLES;
192 }
193
194 } // 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:82
impeller::ContextGLES::RemoveReactorWorker
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
Definition: context_gles.cc:98
impeller::ContextGLES::GetReactor
const std::shared_ptr< ReactorGLES > & GetReactor() const
Definition: context_gles.cc:86
impeller::ContextGLES::Create
static std::shared_ptr< ContextGLES > Create(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:90
impeller::Context::BackendType
BackendType
Definition: context.h:48
impeller::Context::BackendType::kOpenGLES
@ kOpenGLES
impeller::RenderPassGLES::ResetGLState
static void ResetGLState(const ProcTableGLES &gl)
Definition: render_pass_gles.cc:178
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:652
command_buffer_gles.h
command_queue.h
context_gles.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
runtime_types.h
impeller::UniqueID
Definition: comparable.h:16
texture_gles.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
version.h