Flutter Engine
The 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
13
14namespace impeller {
15
16std::shared_ptr<ContextGLES> ContextGLES::Create(
17 std::unique_ptr<ProcTableGLES> gl,
18 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries,
19 bool enable_gpu_tracing) {
20 return std::shared_ptr<ContextGLES>(
21 new ContextGLES(std::move(gl), shader_libraries, enable_gpu_tracing));
22}
23
24ContextGLES::ContextGLES(
25 std::unique_ptr<ProcTableGLES> gl,
26 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
27 bool enable_gpu_tracing) {
28 reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
29 if (!reactor_->IsValid()) {
30 VALIDATION_LOG << "Could not create valid reactor.";
31 return;
32 }
33
34 // Create the shader library.
35 {
36 auto library = std::shared_ptr<ShaderLibraryGLES>(
37 new ShaderLibraryGLES(shader_libraries_mappings));
38 if (!library->IsValid()) {
39 VALIDATION_LOG << "Could not create valid shader library.";
40 return;
41 }
42 shader_library_ = std::move(library);
43 }
44
45 // Create the pipeline library.
46 {
47 pipeline_library_ =
48 std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
49 }
50
51 // Create allocators.
52 {
53 resource_allocator_ =
54 std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
55 if (!resource_allocator_->IsValid()) {
56 VALIDATION_LOG << "Could not create a resource allocator.";
57 return;
58 }
59 }
60
61 device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
62
63 // Create the sampler library.
64 {
65 sampler_library_ =
66 std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
67 device_capabilities_->SupportsDecalSamplerAddressMode()));
68 }
69 gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
70 enable_gpu_tracing);
71 command_queue_ = std::make_shared<CommandQueue>();
72 is_valid_ = true;
73}
74
76
80
82 return reactor_;
83}
84
85std::optional<ReactorGLES::WorkerID> ContextGLES::AddReactorWorker(
86 const std::shared_ptr<ReactorGLES::Worker>& worker) {
87 if (!IsValid()) {
88 return std::nullopt;
89 }
90 return reactor_->AddWorker(worker);
91}
92
94 if (!IsValid()) {
95 return false;
96 }
97 return reactor_->RemoveWorker(id);
98}
99
101 return is_valid_;
102}
103
105
106// |Context|
107std::string ContextGLES::DescribeGpuModel() const {
108 return reactor_->GetProcTable().GetDescription()->GetString();
109}
110
111// |Context|
112std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
113 return resource_allocator_;
114}
115
116// |Context|
117std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
118 return shader_library_;
119}
120
121// |Context|
122std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
123 return sampler_library_;
124}
125
126// |Context|
127std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
128 return pipeline_library_;
129}
130
131// |Context|
132std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
133 return std::shared_ptr<CommandBufferGLES>(
134 new CommandBufferGLES(weak_from_this(), reactor_));
135}
136
137// |Context|
138const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
139 const {
140 return device_capabilities_;
141}
142
143// |Context|
144std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
145 return command_queue_;
146}
147
148} // namespace impeller
std::string DescribeGpuModel() const override
const ReactorGLES::Ref & GetReactor() const
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
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)
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
std::optional< ReactorGLES::WorkerID > AddReactorWorker(const std::shared_ptr< ReactorGLES::Worker > &worker)
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
std::shared_ptr< ReactorGLES > Ref
const ProcTable & GetProcTable()
Definition proc_table.cc:12
#define VALIDATION_LOG
Definition validation.h:73