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 
6 
7 #include "impeller/base/config.h"
9 
10 namespace impeller {
11 
12 std::shared_ptr<ContextGLES> ContextGLES::Create(
13  std::unique_ptr<ProcTableGLES> gl,
14  const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries) {
15  return std::shared_ptr<ContextGLES>(
16  new ContextGLES(std::move(gl), shader_libraries));
17 }
18 
19 ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
20  const std::vector<std::shared_ptr<fml::Mapping>>&
21  shader_libraries_mappings) {
22  reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
23  if (!reactor_->IsValid()) {
24  VALIDATION_LOG << "Could not create valid reactor.";
25  return;
26  }
27 
28  // Create the shader library.
29  {
30  auto library = std::shared_ptr<ShaderLibraryGLES>(
31  new ShaderLibraryGLES(shader_libraries_mappings));
32  if (!library->IsValid()) {
33  VALIDATION_LOG << "Could not create valid shader library.";
34  return;
35  }
36  shader_library_ = std::move(library);
37  }
38 
39  // Create the pipeline library.
40  {
41  pipeline_library_ =
42  std::shared_ptr<PipelineLibraryGLES>(new PipelineLibraryGLES(reactor_));
43  }
44 
45  // Create allocators.
46  {
47  resource_allocator_ =
48  std::shared_ptr<AllocatorGLES>(new AllocatorGLES(reactor_));
49  if (!resource_allocator_->IsValid()) {
50  VALIDATION_LOG << "Could not create a resource allocator.";
51  return;
52  }
53  }
54 
55  // Create the sampler library.
56  {
57  sampler_library_ =
58  std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES());
59  }
60 
61  // Create the device capabilities.
62  {
63  device_capabilities_ =
64  CapabilitiesBuilder()
65  .SetSupportsOffscreenMSAA(false)
66  .SetSupportsSSBO(false)
67  .SetSupportsBufferToTextureBlits(false)
68  .SetSupportsTextureToTextureBlits(
69  reactor_->GetProcTable().BlitFramebuffer.IsAvailable())
70  .SetSupportsFramebufferFetch(false)
71  .SetDefaultColorFormat(PixelFormat::kR8G8B8A8UNormInt)
72  .SetDefaultStencilFormat(PixelFormat::kS8UInt)
73  .SetDefaultDepthStencilFormat(PixelFormat::kD24UnormS8Uint)
74  .SetSupportsCompute(false)
75  .SetSupportsComputeSubgroups(false)
76  .SetSupportsReadFromResolve(false)
77  .SetSupportsReadFromOnscreenTexture(false)
78  .SetSupportsDecalSamplerAddressMode(false)
79  .SetSupportsDeviceTransientTextures(false)
80  .Build();
81  }
82 
83  is_valid_ = true;
84 }
85 
86 ContextGLES::~ContextGLES() = default;
87 
90 }
91 
93  return reactor_;
94 }
95 
96 std::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 
111 bool ContextGLES::IsValid() const {
112  return is_valid_;
113 }
114 
115 void ContextGLES::Shutdown() {}
116 
117 // |Context|
118 std::string ContextGLES::DescribeGpuModel() const {
119  return reactor_->GetProcTable().GetDescription()->GetString();
120 }
121 
122 // |Context|
123 std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
124  return resource_allocator_;
125 }
126 
127 // |Context|
128 std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
129  return shader_library_;
130 }
131 
132 // |Context|
133 std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
134  return sampler_library_;
135 }
136 
137 // |Context|
138 std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
139  return pipeline_library_;
140 }
141 
142 // |Context|
143 std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
144  return std::shared_ptr<CommandBufferGLES>(
145  new CommandBufferGLES(weak_from_this(), reactor_));
146 }
147 
148 // |Context|
149 const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
150  const {
151  return device_capabilities_;
152 }
153 
154 } // namespace impeller
impeller::ContextGLES::RemoveReactorWorker
bool RemoveReactorWorker(ReactorGLES::WorkerID id)
Definition: context_gles.cc:104
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:96
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:31
context_gles.h
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::ContextGLES::GetReactor
const ReactorGLES::Ref & GetReactor() const
Definition: context_gles.cc:92
validation.h
impeller::ContextGLES
Definition: context_gles.h:20
impeller::Context::BackendType::kOpenGLES
@ kOpenGLES
impeller::ContextGLES::GetBackendType
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
Definition: context_gles.cc:88
impeller::PixelFormat::kD24UnormS8Uint
@ kD24UnormS8Uint
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::PixelFormat::kS8UInt
@ kS8UInt
impeller::ContextGLES::~ContextGLES
~ContextGLES() override
impeller::ContextGLES::Create
static std::shared_ptr< ContextGLES > Create(std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping >> &shader_libraries)
Definition: context_gles.cc:12
impeller::UniqueID
Definition: comparable.h:19
config.h
impeller
Definition: aiks_context.cc:10