forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext_gles.cc
More file actions
183 lines (153 loc) · 4.96 KB
/
context_gles.cc
File metadata and controls
183 lines (153 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/backend/gles/context_gles.h"
#include <memory>
#include "impeller/base/config.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/command_buffer_gles.h"
#include "impeller/renderer/backend/gles/gpu_tracer_gles.h"
#include "impeller/renderer/backend/gles/handle_gles.h"
#include "impeller/renderer/backend/gles/render_pass_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h"
#include "impeller/renderer/command_queue.h"
namespace impeller {
std::shared_ptr<ContextGLES> ContextGLES::Create(
std::unique_ptr<ProcTableGLES> gl,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries,
bool enable_gpu_tracing) {
return std::shared_ptr<ContextGLES>(
new ContextGLES(std::move(gl), shader_libraries, enable_gpu_tracing));
}
ContextGLES::ContextGLES(
std::unique_ptr<ProcTableGLES> gl,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
bool enable_gpu_tracing) {
reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
if (!reactor_->IsValid()) {
VALIDATION_LOG << "Could not create valid reactor.";
return;
}
// Create the shader library.
{
auto library = std::shared_ptr<ShaderLibraryGLES>(
new ShaderLibraryGLES(shader_libraries_mappings));
if (!library->IsValid()) {
VALIDATION_LOG << "Could not create valid shader library.";
return;
}
shader_library_ = std::move(library);
}
// Create the pipeline library.
{
pipeline_library_ =
std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
}
// Create allocators.
{
resource_allocator_ =
std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
if (!resource_allocator_->IsValid()) {
VALIDATION_LOG << "Could not create a resource allocator.";
return;
}
}
device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
// Create the sampler library.
{
sampler_library_ =
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES(
device_capabilities_->SupportsDecalSamplerAddressMode()));
}
gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
enable_gpu_tracing);
command_queue_ = std::make_shared<CommandQueue>();
is_valid_ = true;
}
ContextGLES::~ContextGLES() = default;
Context::BackendType ContextGLES::GetBackendType() const {
return Context::BackendType::kOpenGLES;
}
const ReactorGLES::Ref& ContextGLES::GetReactor() const {
return reactor_;
}
std::optional<ReactorGLES::WorkerID> ContextGLES::AddReactorWorker(
const std::shared_ptr<ReactorGLES::Worker>& worker) {
if (!IsValid()) {
return std::nullopt;
}
return reactor_->AddWorker(worker);
}
bool ContextGLES::RemoveReactorWorker(ReactorGLES::WorkerID id) {
if (!IsValid()) {
return false;
}
return reactor_->RemoveWorker(id);
}
bool ContextGLES::IsValid() const {
return is_valid_;
}
void ContextGLES::Shutdown() {}
// |Context|
std::string ContextGLES::DescribeGpuModel() const {
return reactor_->GetProcTable().GetDescription()->GetString();
}
// |Context|
std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
return resource_allocator_;
}
// |Context|
std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
return shader_library_;
}
// |Context|
std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
return sampler_library_;
}
// |Context|
std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
return pipeline_library_;
}
// |Context|
std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
return std::shared_ptr<CommandBufferGLES>(
new CommandBufferGLES(weak_from_this(), reactor_));
}
// |Context|
const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
const {
return device_capabilities_;
}
// |Context|
std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
return command_queue_;
}
// |Context|
void ContextGLES::ResetThreadLocalState() const {
if (!IsValid()) {
return;
}
[[maybe_unused]] auto result =
reactor_->AddOperation([](const ReactorGLES& reactor) {
RenderPassGLES::ResetGLState(reactor.GetProcTable());
});
}
bool ContextGLES::EnqueueCommandBuffer(
std::shared_ptr<CommandBuffer> command_buffer) {
return true;
}
// |Context|
[[nodiscard]] bool ContextGLES::FlushCommandBuffers() {
return reactor_->React();
}
// |Context|
bool ContextGLES::AddTrackingFence(
const std::shared_ptr<Texture>& texture) const {
if (!reactor_->GetProcTable().FenceSync.IsAvailable()) {
return false;
}
HandleGLES fence = reactor_->CreateHandle(HandleType::kFence);
TextureGLES::Cast(*texture).SetFence(fence);
return true;
}
} // namespace impeller