Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | List of all members
impeller::PlaygroundImplGLES Class Referencefinal

#include <playground_impl_gles.h>

Inheritance diagram for impeller::PlaygroundImplGLES:
impeller::PlaygroundImpl

Classes

class  ReactorWorker
 

Public Member Functions

 PlaygroundImplGLES (PlaygroundSwitches switches)
 
 ~PlaygroundImplGLES ()
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities) override
 
- Public Member Functions inherited from impeller::PlaygroundImpl
virtual ~PlaygroundImpl ()
 
Vector2 GetContentScale () const
 

Private Member Functions

std::shared_ptr< ContextGetContext () const override
 
WindowHandle GetWindowHandle () const override
 
std::unique_ptr< SurfaceAcquireSurfaceFrame (std::shared_ptr< Context > context) override
 

Additional Inherited Members

- Public Types inherited from impeller::PlaygroundImpl
using WindowHandle = void *
 
- Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImplCreate (PlaygroundBackend backend, PlaygroundSwitches switches)
 
- Protected Member Functions inherited from impeller::PlaygroundImpl
 PlaygroundImpl (PlaygroundSwitches switches)
 
- Protected Attributes inherited from impeller::PlaygroundImpl
const PlaygroundSwitches switches_
 

Detailed Description

Definition at line 13 of file playground_impl_gles.h.

Constructor & Destructor Documentation

◆ PlaygroundImplGLES()

impeller::PlaygroundImplGLES::PlaygroundImplGLES ( PlaygroundSwitches  switches)
explicit

Definition at line 64 of file playground_impl_gles.cc.

65 : PlaygroundImpl(switches),
66 handle_(nullptr, &DestroyWindowHandle),
67 worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
68 use_angle_(switches.use_angle) {
69 if (use_angle_) {
70#if IMPELLER_PLAYGROUND_SUPPORTS_ANGLE
71 angle_glesv2_ = dlopen("libGLESv2.dylib", RTLD_LAZY);
72#endif
73 FML_CHECK(angle_glesv2_ != nullptr);
74 }
75
76 ::glfwDefaultWindowHints();
77
78#if FML_OS_MACOSX
79 FML_CHECK(use_angle_) << "Must use Angle on macOS for OpenGL ES.";
80 ::glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
81#endif // FML_OS_MACOSX
82 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
83 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
84 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
85 ::glfwWindowHint(GLFW_RED_BITS, 8);
86 ::glfwWindowHint(GLFW_GREEN_BITS, 8);
87 ::glfwWindowHint(GLFW_BLUE_BITS, 8);
88 ::glfwWindowHint(GLFW_ALPHA_BITS, 8);
89 ::glfwWindowHint(GLFW_DEPTH_BITS, 32); // 32 bit depth buffer
90 ::glfwWindowHint(GLFW_STENCIL_BITS, 8); // 8 bit stencil buffer
91 ::glfwWindowHint(GLFW_SAMPLES, 4); // 4xMSAA
92
93 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
94
95 auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
96
97 ::glfwMakeContextCurrent(window);
98 worker_->SetReactionsAllowedOnCurrentThread(true);
99
100 handle_.reset(window);
101}
PlaygroundImpl(PlaygroundSwitches switches)
GLFWwindow * window
Definition main.cc:45
#define GLFW_FALSE
#define FML_CHECK(condition)
Definition logging.h:85

◆ ~PlaygroundImplGLES()

impeller::PlaygroundImplGLES::~PlaygroundImplGLES ( )
default

Member Function Documentation

◆ AcquireSurfaceFrame()

std::unique_ptr< Surface > impeller::PlaygroundImplGLES::AcquireSurfaceFrame ( std::shared_ptr< Context context)
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 168 of file playground_impl_gles.cc.

169 {
170 auto window = reinterpret_cast<GLFWwindow*>(GetWindowHandle());
171 int width = 0;
172 int height = 0;
173 ::glfwGetFramebufferSize(window, &width, &height);
174 if (width <= 0 || height <= 0) {
175 return nullptr;
176 }
177 SurfaceGLES::SwapCallback swap_callback = [window]() -> bool {
178 ::glfwSwapBuffers(window);
179 return true;
180 };
181 return SurfaceGLES::WrapFBO(context, //
182 swap_callback, //
183 0u, //
186 );
187}
WindowHandle GetWindowHandle() const override
static std::unique_ptr< Surface > WrapFBO(const std::shared_ptr< Context > &context, SwapCallback swap_callback, GLuint fbo, PixelFormat color_format, ISize fbo_size)
std::function< bool(void)> SwapCallback
int32_t height
int32_t width
static constexpr TSize MakeWH(Type width, Type height)
Definition size.h:34

◆ GetContext()

std::shared_ptr< Context > impeller::PlaygroundImplGLES::GetContext ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 128 of file playground_impl_gles.cc.

128 {
129 auto resolver = use_angle_ ? [](const char* name) -> void* {
130 void* symbol = nullptr;
131#if IMPELLER_PLAYGROUND_SUPPORTS_ANGLE
132 void* angle_glesv2 = dlopen("libGLESv2.dylib", RTLD_LAZY);
133 symbol = dlsym(angle_glesv2, name);
134#endif
135 FML_CHECK(symbol);
136 return symbol;
137 }
138 : [](const char* name) -> void* {
139 return reinterpret_cast<void*>(::glfwGetProcAddress(name));
140 };
141 auto gl = std::make_unique<ProcTableGLES>(resolver);
142 if (!gl->IsValid()) {
143 FML_LOG(ERROR) << "Proc table when creating a playground was invalid.";
144 return nullptr;
145 }
146
147 auto context = ContextGLES::Create(
148 std::move(gl), ShaderLibraryMappingsForPlayground(), true);
149 if (!context) {
150 FML_LOG(ERROR) << "Could not create context.";
151 return nullptr;
152 }
153
154 auto worker_id = context->AddReactorWorker(worker_);
155 if (!worker_id.has_value()) {
156 FML_LOG(ERROR) << "Could not add reactor worker.";
157 return nullptr;
158 }
159 return context;
160}
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)
#define FML_LOG(severity)
Definition logging.h:82
const char * name
Definition fuchsia.cc:50
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
#define ERROR(message)

◆ GetWindowHandle()

PlaygroundImpl::WindowHandle impeller::PlaygroundImplGLES::GetWindowHandle ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 163 of file playground_impl_gles.cc.

163 {
164 return handle_.get();
165}

◆ SetCapabilities()

fml::Status impeller::PlaygroundImplGLES::SetCapabilities ( const std::shared_ptr< Capabilities > &  capabilities)
overridevirtual

Implements impeller::PlaygroundImpl.

Definition at line 189 of file playground_impl_gles.cc.

190 {
191 return fml::Status(
193 "PlaygroundImplGLES doesn't support setting the capabilities.");
194}

The documentation for this class was generated from the following files: