Flutter Engine
 
Loading...
Searching...
No Matches
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
6#include <memory>
7
18
19namespace impeller {
20
21std::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
30ContextGLES::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
84
88
89const std::shared_ptr<ReactorGLES>& ContextGLES::GetReactor() const {
90 return reactor_;
91}
92
93std::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
102 if (!IsValid()) {
103 return false;
104 }
105 return reactor_->RemoveWorker(id);
106}
107
108bool ContextGLES::IsValid() const {
109 return is_valid_;
110}
111
112void ContextGLES::Shutdown() {}
113
114// |Context|
115std::string ContextGLES::DescribeGpuModel() const {
116 return reactor_->GetProcTable().GetDescription()->GetString();
117}
118
119// |Context|
120std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
121 return resource_allocator_;
122}
123
124// |Context|
125std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
126 return shader_library_;
127}
128
129// |Context|
130std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
131 return sampler_library_;
132}
133
134// |Context|
135std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
136 return pipeline_library_;
137}
138
139// |Context|
140std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
141 return std::shared_ptr<CommandBufferGLES>(
142 new CommandBufferGLES(weak_from_this(), reactor_));
143}
144
145// |Context|
146const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
147 const {
148 return device_capabilities_;
149}
150
151// |Context|
152std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
153 return command_queue_;
154}
155
156// |Context|
157void 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
167bool 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|
178bool 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|
189RuntimeStageBackend ContextGLES::GetRuntimeStageBackend() const {
190 if (GetReactor()->GetProcTable().GetDescription()->GetGlVersion().IsAtLeast(
191 Version{3, 0, 0})) {
193 }
195}
196
197} // namespace impeller
static TextureGLES & Cast(Texture &base)
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
const std::shared_ptr< ReactorGLES > & GetReactor() const
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)
std::optional< ReactorGLES::WorkerID > AddReactorWorker(const std::shared_ptr< ReactorGLES::Worker > &worker)
To do anything rendering related with Impeller, you need a context.
Definition context.h:65
static void ResetGLState(const ProcTableGLES &gl)
void SetFence(HandleGLES fence)
Attach a sync fence to this texture that will be waited on before encoding a rendering operation that...
FlTexture * texture
const ProcTable & GetProcTable()
Definition proc_table.cc:12
#define VALIDATION_LOG
Definition validation.h:91