| 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
13 namespace impeller {
14
15 std::shared_ptr<ContextGLES> ContextGLES::Create(
16 std::unique_ptr<ProcTableGLES> gl,
17 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries,
18 bool enable_gpu_tracing) {
19 return std::shared_ptr<ContextGLES>(
20 new ContextGLES(std::move(gl), shader_libraries, enable_gpu_tracing));
21 }
22
23 ContextGLES::ContextGLES(
24 std::unique_ptr<ProcTableGLES> gl,
25 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
26 bool enable_gpu_tracing) {
27 reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
28 if (!reactor_->IsValid()) {
29 VALIDATION_LOG << "Could not create valid reactor.";
30 return;
31 }
32
33 // Create the shader library.
34 {
35 auto library = std::shared_ptr<ShaderLibraryGLES>(
36 new ShaderLibraryGLES(shader_libraries_mappings));
37 if (!library->IsValid()) {
38 VALIDATION_LOG << "Could not create valid shader library.";
39 return;
40 }
41 shader_library_ = std::move(library);
42 }
43
44 // Create the pipeline library.
45 {
46 pipeline_library_ =
47 std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
48 }
49
50 // Create allocators.
51 {
52 resource_allocator_ =
53 std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
54 if (!resource_allocator_->IsValid()) {
55 VALIDATION_LOG << "Could not create a resource allocator.";
56 return;
57 }
58 }
59
60 device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
61
62 // Create the sampler library.
63 {
64 sampler_library_ =
65 std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
66 device_capabilities_->SupportsDecalSamplerAddressMode()));
67 }
68 gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
69 enable_gpu_tracing);
70 is_valid_ = true;
71 }
72
73 ContextGLES::~ContextGLES() = default;
74
75 Context::BackendType ContextGLES::GetBackendType() const {
76 return Context::BackendType::kOpenGLES;
77 }
78
79 const ReactorGLES::Ref& ContextGLES::GetReactor() const {
80 return reactor_;
81 }
82
83 std::optional<ReactorGLES::WorkerID> ContextGLES::AddReactorWorker(
84 const std::shared_ptr<ReactorGLES::Worker>& worker) {
85 if (!IsValid()) {
86 return std::nullopt;
87 }
88 return reactor_->AddWorker(worker);
89 }
90
91 bool ContextGLES::RemoveReactorWorker(ReactorGLES::WorkerID id) {
92 if (!IsValid()) {
93 return false;
94 }
95 return reactor_->RemoveWorker(id);
96 }
97
98 bool ContextGLES::IsValid() const {
99 return is_valid_;
100 }
101
102 void ContextGLES::Shutdown() {}
103
104 // |Context|
105 std::string ContextGLES::DescribeGpuModel() const {
106 return reactor_->GetProcTable().GetDescription()->GetString();
107 }
108
109 // |Context|
110 std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
111 return resource_allocator_;
112 }
113
114 // |Context|
115 std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
116 return shader_library_;
117 }
118
119 // |Context|
120 std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
121 return sampler_library_;
122 }
123
124 // |Context|
125 std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
126 return pipeline_library_;
127 }
128
129 // |Context|
130 std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
131 return std::shared_ptr<CommandBufferGLES>(
132 new CommandBufferGLES(weak_from_this(), reactor_));
133 }
134
135 // |Context|
136 const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
137 const {
138 return device_capabilities_;
139 }
140
141 } // namespace impeller
impeller::ContextGLES::RemoveReactorWorker
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
Definition: context_gles.cc:91
impeller::Context::BackendType
BackendType
Definition: context.h:49
impeller::ContextGLES::AddReactorWorker
std::optional< ReactorGLES::WorkerID > AddReactorWorker(const std::shared_ptr< ReactorGLES::Worker > &worker)
Definition: context_gles.cc:83
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:87
context_gles.h
impeller::ContextGLES::GetReactor
const ReactorGLES::Ref & GetReactor() const
Definition: context_gles.cc:79
validation.h
impeller::ContextGLES
Definition: context_gles.h:24
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:15
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:75
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::ContextGLES::~ContextGLES
~ContextGLES() override
impeller::UniqueID
Definition: comparable.h:16
command_buffer_gles.h
config.h
impeller
Definition: aiks_context.cc:10