Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::testing::TestGLSurface Class Reference

#include <test_gl_surface.h>

Public Member Functions

 TestGLSurface (SkISize surface_size)
 
 ~TestGLSurface ()
 
const SkISizeGetSurfaceSize () const
 
bool MakeCurrent ()
 
bool ClearCurrent ()
 
bool Present ()
 
uint32_t GetFramebuffer (uint32_t width, uint32_t height) const
 
bool MakeResourceCurrent ()
 
void * GetProcAddress (const char *name) const
 
sk_sp< SkSurfaceGetOnscreenSurface ()
 
sk_sp< GrDirectContextGetGrContext ()
 
sk_sp< GrDirectContextCreateGrContext ()
 
sk_sp< SkImageGetRasterSurfaceSnapshot ()
 
uint32_t GetWindowFBOId () const
 

Detailed Description

Definition at line 18 of file test_gl_surface.h.

Constructor & Destructor Documentation

◆ TestGLSurface()

flutter::testing::TestGLSurface::TestGLSurface ( SkISize  surface_size)
explicit

Definition at line 133 of file test_gl_surface.cc.

134 : surface_size_(surface_size) {
135 display_ = CreateSwangleDisplay();
136 FML_CHECK(display_ != EGL_NO_DISPLAY);
137
138 auto result = ::eglInitialize(display_, nullptr, nullptr);
139 FML_CHECK(result == EGL_TRUE) << GetEGLError();
140
141 EGLConfig config = {0};
142
143 EGLint num_config = 0;
144 const EGLint attribute_list[] = {EGL_RED_SIZE,
145 8,
146 EGL_GREEN_SIZE,
147 8,
148 EGL_BLUE_SIZE,
149 8,
150 EGL_ALPHA_SIZE,
151 8,
152 EGL_SURFACE_TYPE,
153 EGL_PBUFFER_BIT,
154 EGL_CONFORMANT,
155 EGL_OPENGL_ES2_BIT,
156 EGL_RENDERABLE_TYPE,
157 EGL_OPENGL_ES2_BIT,
158 EGL_NONE};
159
160 result = ::eglChooseConfig(display_, attribute_list, &config, 1, &num_config);
161 FML_CHECK(result == EGL_TRUE) << GetEGLError();
162 FML_CHECK(num_config == 1) << GetEGLError();
163
164 {
165 const EGLint onscreen_surface_attributes[] = {
166 EGL_WIDTH, surface_size_.width(), //
167 EGL_HEIGHT, surface_size_.height(), //
168 EGL_NONE,
169 };
170
171 onscreen_surface_ = ::eglCreatePbufferSurface(
172 display_, // display connection
173 config, // config
174 onscreen_surface_attributes // surface attributes
175 );
176 FML_CHECK(onscreen_surface_ != EGL_NO_SURFACE) << GetEGLError();
177 }
178
179 {
180 const EGLint offscreen_surface_attributes[] = {
181 EGL_WIDTH, 1, //
182 EGL_HEIGHT, 1, //
183 EGL_NONE,
184 };
185 offscreen_surface_ = ::eglCreatePbufferSurface(
186 display_, // display connection
187 config, // config
188 offscreen_surface_attributes // surface attributes
189 );
190 FML_CHECK(offscreen_surface_ != EGL_NO_SURFACE) << GetEGLError();
191 }
192
193 {
194 const EGLint context_attributes[] = {
195 EGL_CONTEXT_CLIENT_VERSION, //
196 2, //
197 EGL_NONE //
198 };
199
200 onscreen_context_ =
201 ::eglCreateContext(display_, // display connection
202 config, // config
203 EGL_NO_CONTEXT, // sharegroup
204 context_attributes // context attributes
205 );
206 FML_CHECK(onscreen_context_ != EGL_NO_CONTEXT) << GetEGLError();
207
208 offscreen_context_ =
209 ::eglCreateContext(display_, // display connection
210 config, // config
211 onscreen_context_, // sharegroup
212 context_attributes // context attributes
213 );
214 FML_CHECK(offscreen_context_ != EGL_NO_CONTEXT) << GetEGLError();
215 }
216}
GAsyncResult * result
#define FML_CHECK(condition)
Definition: logging.h:85
static EGLDisplay CreateSwangleDisplay()
static std::string GetEGLError()
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ ~TestGLSurface()

flutter::testing::TestGLSurface::~TestGLSurface ( )

Definition at line 218 of file test_gl_surface.cc.

218 {
219 context_ = nullptr;
220
221 auto result = ::eglDestroyContext(display_, onscreen_context_);
222 FML_CHECK(result == EGL_TRUE) << GetEGLError();
223
224 result = ::eglDestroyContext(display_, offscreen_context_);
225 FML_CHECK(result == EGL_TRUE) << GetEGLError();
226
227 result = ::eglDestroySurface(display_, onscreen_surface_);
228 FML_CHECK(result == EGL_TRUE) << GetEGLError();
229
230 result = ::eglDestroySurface(display_, offscreen_surface_);
231 FML_CHECK(result == EGL_TRUE) << GetEGLError();
232
233 result = ::eglTerminate(display_);
234 FML_CHECK(result == EGL_TRUE);
235}

Member Function Documentation

◆ ClearCurrent()

bool flutter::testing::TestGLSurface::ClearCurrent ( )

Definition at line 252 of file test_gl_surface.cc.

252 {
253 auto result = ::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
254 EGL_NO_CONTEXT);
255
256 if (result == EGL_FALSE) {
257 FML_LOG(ERROR) << "Could not clear the current context. " << GetEGLError();
258 }
259
260 return result == EGL_TRUE;
261}
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

◆ CreateGrContext()

sk_sp< GrDirectContext > flutter::testing::TestGLSurface::CreateGrContext ( )

Definition at line 308 of file test_gl_surface.cc.

308 {
309 if (!MakeCurrent()) {
310 return nullptr;
311 }
312
313 auto get_string =
314 reinterpret_cast<PFNGLGETSTRINGPROC>(GetProcAddress("glGetString"));
315
316 if (!get_string) {
317 return nullptr;
318 }
319
320 auto c_version = reinterpret_cast<const char*>(get_string(GL_VERSION));
321
322 if (c_version == NULL) {
323 return nullptr;
324 }
325
326 GrGLGetProc get_proc = [](void* context, const char name[]) -> GrGLFuncPtr {
327 return reinterpret_cast<GrGLFuncPtr>(
328 reinterpret_cast<TestGLSurface*>(context)->GetProcAddress(name));
329 };
330
331 std::string version(c_version);
332 auto interface = version.find("OpenGL ES") == std::string::npos
333 ? GrGLMakeAssembledGLInterface(this, get_proc)
334 : GrGLMakeAssembledGLESInterface(this, get_proc);
335
336 if (!interface) {
337 return nullptr;
338 }
339
340 context_ = GrDirectContexts::MakeGL(interface);
341 return context_;
342}
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get)
GrGLFuncPtr(* GrGLGetProc)(void *ctx, const char name[])
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get)
void(* GrGLFuncPtr)()
Definition: GrGLInterface.h:17
static const char * get_string(FcPattern *pattern, const char field[], int index=0)
void * GetProcAddress(const char *name) const
TestGLSurface(SkISize surface_size)
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetFramebuffer()

uint32_t flutter::testing::TestGLSurface::GetFramebuffer ( uint32_t  width,
uint32_t  height 
) const

Definition at line 273 of file test_gl_surface.cc.

273 {
274 return GetWindowFBOId();
275}

◆ GetGrContext()

sk_sp< GrDirectContext > flutter::testing::TestGLSurface::GetGrContext ( )

Definition at line 300 of file test_gl_surface.cc.

300 {
301 if (context_) {
302 return context_;
303 }
304
305 return CreateGrContext();
306}
sk_sp< GrDirectContext > CreateGrContext()

◆ GetOnscreenSurface()

sk_sp< SkSurface > flutter::testing::TestGLSurface::GetOnscreenSurface ( )

Definition at line 344 of file test_gl_surface.cc.

344 {
345 FML_CHECK(::eglGetCurrentContext() != EGL_NO_CONTEXT);
346
347 GrGLFramebufferInfo framebuffer_info = {};
348 const uint32_t width = surface_size_.width();
349 const uint32_t height = surface_size_.height();
350 framebuffer_info.fFBOID = GetFramebuffer(width, height);
351#if FML_OS_MACOSX
352 framebuffer_info.fFormat = 0x8058; // GL_RGBA8
353#else
354 framebuffer_info.fFormat = 0x93A1; // GL_BGRA8;
355#endif
356
357 auto backend_render_target =
359 height, // height
360 1, // sample count
361 8, // stencil bits
362 framebuffer_info // framebuffer info
363 );
364
365 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
366
368 GetGrContext().get(), // context
369 backend_render_target, // backend render target
370 kBottomLeft_GrSurfaceOrigin, // surface origin
371 kN32_SkColorType, // color type
372 SkColorSpace::MakeSRGB(), // color space
373 &surface_properties, // surface properties
374 nullptr, // release proc
375 nullptr // release context
376 );
377
378 if (!surface) {
379 FML_LOG(ERROR) << "Could not wrap the surface while attempting to "
380 "snapshot the GL surface.";
381 return nullptr;
382 }
383
384 return surface;
385}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kUnknown_SkPixelGeometry
static sk_sp< SkColorSpace > MakeSRGB()
uint32_t GetFramebuffer(uint32_t width, uint32_t height) const
sk_sp< GrDirectContext > GetGrContext()
VkSurfaceKHR surface
Definition: main.cc:49
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
const myers::Point & get(const myers::Segment &)
int32_t height
int32_t width

◆ GetProcAddress()

void * flutter::testing::TestGLSurface::GetProcAddress ( const char *  name) const

Definition at line 289 of file test_gl_surface.cc.

289 {
290 if (name == nullptr) {
291 return nullptr;
292 }
293 auto symbol = ::eglGetProcAddress(name);
294 if (symbol == NULL) {
295 FML_LOG(ERROR) << "Could not fetch symbol for name: " << name;
296 }
297 return reinterpret_cast<void*>(symbol);
298}

◆ GetRasterSurfaceSnapshot()

sk_sp< SkImage > flutter::testing::TestGLSurface::GetRasterSurfaceSnapshot ( )

Definition at line 387 of file test_gl_surface.cc.

387 {
389
390 if (!surface) {
391 FML_LOG(ERROR) << "Aborting snapshot because of on-screen surface "
392 "acquisition failure.";
393 return nullptr;
394 }
395
396 auto device_snapshot = surface->makeImageSnapshot();
397
398 if (!device_snapshot) {
399 FML_LOG(ERROR) << "Could not create the device snapshot while attempting "
400 "to snapshot the GL surface.";
401 return nullptr;
402 }
403
404 auto host_snapshot = device_snapshot->makeRasterImage();
405
406 if (!host_snapshot) {
407 FML_LOG(ERROR) << "Could not create the host snapshot while attempting to "
408 "snapshot the GL surface.";
409 return nullptr;
410 }
411
412 return host_snapshot;
413}
sk_sp< SkSurface > GetOnscreenSurface()

◆ GetSurfaceSize()

const SkISize & flutter::testing::TestGLSurface::GetSurfaceSize ( ) const

Definition at line 237 of file test_gl_surface.cc.

237 {
238 return surface_size_;
239}

◆ GetWindowFBOId()

uint32_t flutter::testing::TestGLSurface::GetWindowFBOId ( ) const

Definition at line 415 of file test_gl_surface.cc.

415 {
416 return 0u;
417}

◆ MakeCurrent()

bool flutter::testing::TestGLSurface::MakeCurrent ( )

Definition at line 241 of file test_gl_surface.cc.

241 {
242 auto result = ::eglMakeCurrent(display_, onscreen_surface_, onscreen_surface_,
243 onscreen_context_);
244
245 if (result == EGL_FALSE) {
246 FML_LOG(ERROR) << "Could not make the context current. " << GetEGLError();
247 }
248
249 return result == EGL_TRUE;
250}

◆ MakeResourceCurrent()

bool flutter::testing::TestGLSurface::MakeResourceCurrent ( )

Definition at line 277 of file test_gl_surface.cc.

277 {
278 auto result = ::eglMakeCurrent(display_, offscreen_surface_,
279 offscreen_surface_, offscreen_context_);
280
281 if (result == EGL_FALSE) {
282 FML_LOG(ERROR) << "Could not make the resource context current. "
283 << GetEGLError();
284 }
285
286 return result == EGL_TRUE;
287}

◆ Present()

bool flutter::testing::TestGLSurface::Present ( )

Definition at line 263 of file test_gl_surface.cc.

263 {
264 auto result = ::eglSwapBuffers(display_, onscreen_surface_);
265
266 if (result == EGL_FALSE) {
267 FML_LOG(ERROR) << "Could not swap buffers. " << GetEGLError();
268 }
269
270 return result == EGL_TRUE;
271}

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