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