| 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/renderer/backend/gles/command_buffer_gles.h"
11 #include "impeller/renderer/backend/gles/gpu_tracer_gles.h"
12 #include "impeller/renderer/command_queue.h"
13
14 namespace impeller {
15
16 std::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
24 ContextGLES::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
75 ContextGLES::~ContextGLES() = default;
76
77 Context::BackendType ContextGLES::GetBackendType() const {
78 return Context::BackendType::kOpenGLES;
79 }
80
81 const ReactorGLES::Ref& ContextGLES::GetReactor() const {
82 return reactor_;
83 }
84
85 std::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
93 bool ContextGLES::RemoveReactorWorker(ReactorGLES::WorkerID id) {
94 if (!IsValid()) {
95 return false;
96 }
97 return reactor_->RemoveWorker(id);
98 }
99
100 bool ContextGLES::IsValid() const {
101 return is_valid_;
102 }
103
104 void ContextGLES::Shutdown() {}
105
106 // |Context|
107 std::string ContextGLES::DescribeGpuModel() const {
108 return reactor_->GetProcTable().GetDescription()->GetString();
109 }
110
111 // |Context|
112 std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
113 return resource_allocator_;
114 }
115
116 // |Context|
117 std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
118 return shader_library_;
119 }
120
121 // |Context|
122 std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
123 return sampler_library_;
124 }
125
126 // |Context|
127 std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
128 return pipeline_library_;
129 }
130
131 // |Context|
132 std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
133 return std::shared_ptr<CommandBufferGLES>(
134 new CommandBufferGLES(weak_from_this(), reactor_));
135 }
136
137 // |Context|
138 const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
139 const {
140 return device_capabilities_;
141 }
142
143 // |Context|
144 std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
145 return command_queue_;
146 }
147
148 } // namespace impeller
impeller::ContextGLES::RemoveReactorWorker
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
Definition: context_gles.cc:93
impeller::Context::BackendType
BackendType
Definition: context.h:48
impeller::ContextGLES::AddReactorWorker
std::optional< ReactorGLES::WorkerID > AddReactorWorker(const std::shared_ptr< ReactorGLES::Worker > &worker)
Definition: context_gles.cc:85
command_queue.h
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:86
context_gles.h
impeller::ContextGLES::GetReactor
const ReactorGLES::Ref & GetReactor() const
Definition: context_gles.cc:81
validation.h
impeller::ContextGLES
Definition: context_gles.h:22
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:16
gpu_tracer_gles.h
impeller::Context::BackendType::kOpenGLES
@ kOpenGLES
impeller::ContextGLES::GetBackendType
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
Definition: context_gles.cc:77
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
impeller::ContextGLES::~ContextGLES
~ContextGLES() override
impeller::UniqueID
Definition: comparable.h:16
command_buffer_gles.h
config.h
impeller
Definition: allocation.cc:12