5#include "flutter/testing/test_gl_surface.h"
9#include <EGL/eglplatform.h>
15#include "flutter/fml/build_config.h"
16#include "flutter/fml/logging.h"
33 auto error = ::eglGetError();
41 case EGL_NOT_INITIALIZED:
42 stream <<
"EGL_NOT_INITIALIZED";
45 stream <<
"EGL_BAD_ACCESS";
50 case EGL_BAD_ATTRIBUTE:
51 stream <<
"EGL_BAD_ATTRIBUTE";
54 stream <<
"EGL_BAD_CONTEXT";
57 stream <<
"EGL_BAD_CONFIG";
59 case EGL_BAD_CURRENT_SURFACE:
60 stream <<
"EGL_BAD_CURRENT_SURFACE";
63 stream <<
"EGL_BAD_DISPLAY";
66 stream <<
"EGL_BAD_SURFACE";
71 case EGL_BAD_PARAMETER:
72 stream <<
"EGL_BAD_PARAMETER";
74 case EGL_BAD_NATIVE_PIXMAP:
75 stream <<
"EGL_BAD_NATIVE_PIXMAP";
77 case EGL_BAD_NATIVE_WINDOW:
78 stream <<
"EGL_BAD_NATIVE_WINDOW";
80 case EGL_CONTEXT_LOST:
81 stream <<
"EGL_CONTEXT_LOST";
87 stream <<
"' (0x" << std::hex <<
error << std::dec <<
").";
95 return r !=
nullptr && (r[
len] ==
' ' || r[
len] == 0);
99 const char*
extensions = ::eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
104 "EGL_ANGLE_platform_angle_device_type_swiftshader"))
111 PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT =
112 reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC
>(
113 eglGetProcAddress(
"eglGetPlatformDisplayEXT"));
115 <<
"eglGetPlatformDisplayEXT not available.";
117 const EGLint display_config[] = {
119 EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE,
120 EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
121 EGL_PLATFORM_ANGLE_DEVICE_TYPE_SWIFTSHADER_ANGLE,
122 EGL_PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE,
123 EGL_PLATFORM_VULKAN_DISPLAY_MODE_HEADLESS_ANGLE,
127 return egl_get_platform_display_EXT(
129 reinterpret_cast<EGLNativeDisplayType*
>(EGL_DEFAULT_DISPLAY),
134 : surface_size_(surface_size) {
138 auto result = ::eglInitialize(display_,
nullptr,
nullptr);
141 EGLConfig config = {0};
143 EGLint num_config = 0;
144 const EGLint attribute_list[] = {EGL_RED_SIZE,
160 result = ::eglChooseConfig(display_, attribute_list, &config, 1, &num_config);
165 const EGLint onscreen_surface_attributes[] = {
166 EGL_WIDTH, surface_size_.
width(),
167 EGL_HEIGHT, surface_size_.
height(),
171 onscreen_surface_ = ::eglCreatePbufferSurface(
174 onscreen_surface_attributes
180 const EGLint offscreen_surface_attributes[] = {
185 offscreen_surface_ = ::eglCreatePbufferSurface(
188 offscreen_surface_attributes
194 const EGLint context_attributes[] = {
195 EGL_CONTEXT_CLIENT_VERSION,
201 ::eglCreateContext(display_,
209 ::eglCreateContext(display_,
221 auto result = ::eglDestroyContext(display_, onscreen_context_);
224 result = ::eglDestroyContext(display_, offscreen_context_);
227 result = ::eglDestroySurface(display_, onscreen_surface_);
230 result = ::eglDestroySurface(display_, offscreen_surface_);
233 result = ::eglTerminate(display_);
238 return surface_size_;
242 auto result = ::eglMakeCurrent(display_, onscreen_surface_, onscreen_surface_,
245 if (
result == EGL_FALSE) {
249 return result == EGL_TRUE;
253 auto result = ::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
256 if (
result == EGL_FALSE) {
260 return result == EGL_TRUE;
264 auto result = ::eglSwapBuffers(display_, onscreen_surface_);
266 if (
result == EGL_FALSE) {
270 return result == EGL_TRUE;
278 auto result = ::eglMakeCurrent(display_, offscreen_surface_,
279 offscreen_surface_, offscreen_context_);
281 if (
result == EGL_FALSE) {
282 FML_LOG(
ERROR) <<
"Could not make the resource context current. "
286 return result == EGL_TRUE;
290 if (
name ==
nullptr) {
293 auto symbol = ::eglGetProcAddress(
name);
294 if (symbol == NULL) {
297 return reinterpret_cast<void*
>(symbol);
314 reinterpret_cast<PFNGLGETSTRINGPROC
>(
GetProcAddress(
"glGetString"));
320 auto c_version =
reinterpret_cast<const char*
>(
get_string(GL_VERSION));
322 if (c_version == NULL) {
331 std::string
version(c_version);
332 auto interface = version.find("OpenGL ES") == std::string::npos
345 FML_CHECK(::eglGetCurrentContext() != EGL_NO_CONTEXT);
352 framebuffer_info.
fFormat = 0x8058;
354 framebuffer_info.
fFormat = 0x93A1;
357 auto backend_render_target =
369 backend_render_target,
379 FML_LOG(
ERROR) <<
"Could not wrap the surface while attempting to "
380 "snapshot the GL surface.";
391 FML_LOG(
ERROR) <<
"Aborting snapshot because of on-screen surface "
392 "acquisition failure.";
396 auto device_snapshot =
surface->makeImageSnapshot();
398 if (!device_snapshot) {
399 FML_LOG(
ERROR) <<
"Could not create the device snapshot while attempting "
400 "to snapshot the GL surface.";
404 auto host_snapshot = device_snapshot->makeRasterImage();
406 if (!host_snapshot) {
407 FML_LOG(
ERROR) <<
"Could not create the host snapshot while attempting to "
408 "snapshot the GL surface.";
412 return host_snapshot;
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE
#define EGL_PLATFORM_ANGLE_ANGLE
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)
@ kBottomLeft_GrSurfaceOrigin
static const char * get_string(FcPattern *pattern, const char field[], int index=0)
@ kUnknown_SkPixelGeometry
static sk_sp< SkColorSpace > MakeSRGB()
uint32_t GetFramebuffer(uint32_t width, uint32_t height) const
sk_sp< GrDirectContext > GetGrContext()
void * GetProcAddress(const char *name) const
sk_sp< GrDirectContext > CreateGrContext()
uint32_t GetWindowFBOId() const
sk_sp< SkImage > GetRasterSurfaceSnapshot()
const SkISize & GetSurfaceSize() const
sk_sp< SkSurface > GetOnscreenSurface()
TestGLSurface(SkISize surface_size)
bool MakeResourceCurrent()
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
#define FML_CHECK(condition)
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
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)
static void CheckSwanglekExtensions()
static bool HasExtension(const char *extensions, const char *name)
static EGLDisplay CreateSwangleDisplay()
static std::string GetEGLError()
DEF_SWITCHES_START aot vmservice shared library name
const myers::Point & get(const myers::Segment &)
constexpr int32_t width() const
constexpr int32_t height() const