| 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/toolkit/interop/backend/gles/context_gles.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/entity/gles/entity_shaders_gles.h"
9 #include "impeller/entity/gles/framebuffer_blend_shaders_gles.h"
10 #include "impeller/renderer/backend/gles/context_gles.h"
11
12 namespace impeller::interop {
13
14 ScopedObject<Context> ContextGLES::Create(
15 std::function<void*(const char* gl_proc_name)> proc_address_callback) {
16 auto proc_table = std::make_unique<ProcTableGLES>(
17 impeller::ProcTableGLES(std::move(proc_address_callback)));
18 if (!proc_table || !proc_table->IsValid()) {
19 VALIDATION_LOG << "Could not create valid OpenGL ES proc. table.";
20 return {};
21 }
22 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
23 std::make_shared<fml::NonOwnedMapping>(
24 impeller_entity_shaders_gles_data,
25 impeller_entity_shaders_gles_length),
26 std::make_shared<fml::NonOwnedMapping>(
27 impeller_framebuffer_blend_shaders_gles_data,
28 impeller_framebuffer_blend_shaders_gles_length),
29 };
30 auto impeller_context = impeller::ContextGLES::Create(
31 Flags{}, std::move(proc_table), shader_mappings, false);
32 if (!impeller_context) {
33 VALIDATION_LOG << "Could not create Impeller context.";
34 return {};
35 }
36 auto reactor_worker = std::make_shared<ReactorWorkerGLES>();
37 auto worker_id = impeller_context->AddReactorWorker(reactor_worker);
38 if (!worker_id.has_value()) {
39 VALIDATION_LOG << "Could not add reactor worker.";
40 return {};
41 }
42 return Create(std::move(impeller_context), std::move(reactor_worker));
43 }
44
45 ScopedObject<Context> ContextGLES::Create(
46 std::shared_ptr<impeller::Context> impeller_context,
47 std::shared_ptr<ReactorWorkerGLES> worker) {
48 // Can't call Create because of private constructor. Adopt the raw pointer
49 // instead.
50 auto context = Adopt<Context>(
51 new ContextGLES(std::move(impeller_context), std::move(worker)));
52
53 if (!context->IsValid()) {
54 VALIDATION_LOG << "Could not create valid context.";
55 return {};
56 }
57 return context;
58 }
59
60 ContextGLES::ContextGLES(std::shared_ptr<impeller::Context> context,
61 std::shared_ptr<ReactorWorkerGLES> worker)
62 : Context(std::move(context)), worker_(std::move(worker)) {}
63
64 ContextGLES::~ContextGLES() = default;
65
66 } // namespace impeller::interop
impeller::ContextGLES::Create
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping >> &shader_libraries, bool enable_gpu_tracing)
Definition: context_gles.cc:21
impeller::ProcTableGLES
Definition: proc_table_gles.h:282
impeller::interop::ContextGLES::~ContextGLES
~ContextGLES() override
impeller::interop::ContextGLES::Create
static ScopedObject< Context > Create(std::function< void *(const char *gl_proc_name)> proc_address_callback)
Definition: context_gles.cc:14
impeller::interop::ContextGLES::ContextGLES
ContextGLES()
impeller::interop::Context
Definition: context.h:16
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop
Definition: context_gles.cc:12
std
Definition: comparable.h:95
context_gles.h
impeller::Flags
Definition: flags.h:9
context_gles.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91