Flutter Engine
 
Loading...
Searching...
No Matches
flutter::testing::TestGLOnscreenOnlySurface Class Reference

#include <test_gl_surface.h>

Inheritance diagram for flutter::testing::TestGLOnscreenOnlySurface:
flutter::testing::TestGLSurface

Public Member Functions

 TestGLOnscreenOnlySurface (DlISize surface_size)
 
 TestGLOnscreenOnlySurface (std::shared_ptr< TestEGLContext > context, DlISize size)
 
 ~TestGLOnscreenOnlySurface ()
 
const DlISizeGetSurfaceSize () const
 
bool MakeCurrent ()
 
bool ClearCurrent ()
 
bool Present ()
 
uint32_t GetFramebuffer (uint32_t width, uint32_t height) const
 
void * GetProcAddress (const char *name) const
 
sk_sp< SkSurface > GetOnscreenSurface ()
 
sk_sp< GrDirectContext > GetGrContext ()
 
sk_sp< GrDirectContext > CreateGrContext ()
 
sk_sp< SkImage > GetRasterSurfaceSnapshot ()
 
uint32_t GetWindowFBOId () const
 

Protected Types

using EGLSurface = void *
 

Protected Member Functions

 FML_DISALLOW_COPY_AND_ASSIGN (TestGLOnscreenOnlySurface)
 

Protected Attributes

const DlISize surface_size_
 
std::shared_ptr< TestEGLContextegl_context_
 
EGLSurface onscreen_surface_
 
sk_sp< GrDirectContext > skia_context_
 

Detailed Description

Definition at line 18 of file test_gl_surface.h.

Member Typedef Documentation

◆ EGLSurface

Definition at line 50 of file test_gl_surface.h.

Constructor & Destructor Documentation

◆ TestGLOnscreenOnlySurface() [1/2]

flutter::testing::TestGLOnscreenOnlySurface::TestGLOnscreenOnlySurface ( DlISize  surface_size)
explicit

◆ TestGLOnscreenOnlySurface() [2/2]

flutter::testing::TestGLOnscreenOnlySurface::TestGLOnscreenOnlySurface ( std::shared_ptr< TestEGLContext context,
DlISize  size 
)
explicit

Definition at line 27 of file test_gl_surface.cc.

30 : surface_size_(size), egl_context_(std::move(context)) {
31 const EGLint attributes[] = {
32 EGL_WIDTH, size.width, //
33 EGL_HEIGHT, size.height, //
34 EGL_NONE,
35 };
36
38 ::eglCreatePbufferSurface(egl_context_->display, // display connection
39 egl_context_->config, // config
40 attributes // surface attributes
41 );
42 FML_CHECK(onscreen_surface_ != EGL_NO_SURFACE) << GetEGLError();
43}
std::shared_ptr< TestEGLContext > egl_context_
#define FML_CHECK(condition)
Definition logging.h:104
std::string GetEGLError()
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Type width
Definition size.h:28

References egl_context_, FML_CHECK, flutter::testing::GetEGLError(), onscreen_surface_, and flutter::size.

◆ ~TestGLOnscreenOnlySurface()

flutter::testing::TestGLOnscreenOnlySurface::~TestGLOnscreenOnlySurface ( )

Definition at line 45 of file test_gl_surface.cc.

45 {
46 skia_context_ = nullptr;
47
48 auto result = ::eglDestroySurface(egl_context_->display, onscreen_surface_);
49 FML_CHECK(result == EGL_TRUE) << GetEGLError();
50}

References egl_context_, FML_CHECK, flutter::testing::GetEGLError(), onscreen_surface_, and skia_context_.

Member Function Documentation

◆ ClearCurrent()

bool flutter::testing::TestGLOnscreenOnlySurface::ClearCurrent ( )

Definition at line 68 of file test_gl_surface.cc.

68 {
69 auto result = ::eglMakeCurrent(egl_context_->display, EGL_NO_SURFACE,
70 EGL_NO_SURFACE, EGL_NO_CONTEXT);
71
72 if (result == EGL_FALSE) {
73 FML_LOG(ERROR) << "Could not clear the current context. " << GetEGLError();
74 }
75
76 return result == EGL_TRUE;
77}
#define FML_LOG(severity)
Definition logging.h:101

References egl_context_, FML_LOG, and flutter::testing::GetEGLError().

◆ CreateGrContext()

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

Definition at line 113 of file test_gl_surface.cc.

113 {
114 if (!MakeCurrent()) {
115 return nullptr;
116 }
117
118 auto get_string =
119 reinterpret_cast<PFNGLGETSTRINGPROC>(GetProcAddress("glGetString"));
120
121 if (!get_string) {
122 return nullptr;
123 }
124
125 auto c_version = reinterpret_cast<const char*>(get_string(GL_VERSION));
126
127 if (c_version == NULL) {
128 return nullptr;
129 }
130
131 GrGLGetProc get_proc = [](void* context, const char name[]) -> GrGLFuncPtr {
132 return reinterpret_cast<GrGLFuncPtr>(
133 reinterpret_cast<TestGLOnscreenOnlySurface*>(context)->GetProcAddress(
134 name));
135 };
136
137 std::string version(c_version);
138 auto interface = version.find("OpenGL ES") == std::string::npos
139 ? GrGLMakeAssembledGLInterface(this, get_proc)
140 : GrGLMakeAssembledGLESInterface(this, get_proc);
141
142 if (!interface) {
143 return nullptr;
144 }
145
146 skia_context_ = GrDirectContexts::MakeGL(interface);
147 return skia_context_;
148}
void * GetProcAddress(const char *name) const
TestGLOnscreenOnlySurface(DlISize surface_size)
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27

References GetProcAddress(), MakeCurrent(), flutter::name, and skia_context_.

Referenced by GetGrContext().

◆ FML_DISALLOW_COPY_AND_ASSIGN()

flutter::testing::TestGLOnscreenOnlySurface::FML_DISALLOW_COPY_AND_ASSIGN ( TestGLOnscreenOnlySurface  )
protected

◆ GetFramebuffer()

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

Definition at line 89 of file test_gl_surface.cc.

90 {
91 return GetWindowFBOId();
92}

References GetWindowFBOId().

Referenced by GetOnscreenSurface().

◆ GetGrContext()

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

Definition at line 105 of file test_gl_surface.cc.

105 {
106 if (skia_context_) {
107 return skia_context_;
108 }
109
110 return CreateGrContext();
111}

References CreateGrContext(), and skia_context_.

Referenced by GetOnscreenSurface().

◆ GetOnscreenSurface()

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

Definition at line 150 of file test_gl_surface.cc.

150 {
151 FML_CHECK(::eglGetCurrentContext() != EGL_NO_CONTEXT);
152
153 GrGLFramebufferInfo framebuffer_info = {};
154 const uint32_t width = surface_size_.width;
155 const uint32_t height = surface_size_.height;
156 framebuffer_info.fFBOID = GetFramebuffer(width, height);
157#if FML_OS_MACOSX
158 framebuffer_info.fFormat = 0x8058; // GL_RGBA8
159#else
160 framebuffer_info.fFormat = 0x93A1; // GL_BGRA8;
161#endif
162
163 auto backend_render_target =
164 GrBackendRenderTargets::MakeGL(width, // width
165 height, // height
166 1, // sample count
167 8, // stencil bits
168 framebuffer_info // framebuffer info
169 );
170
171 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
172
173 auto surface = SkSurfaces::WrapBackendRenderTarget(
174 GetGrContext().get(), // context
175 backend_render_target, // backend render target
176 kBottomLeft_GrSurfaceOrigin, // surface origin
177 kN32_SkColorType, // color type
178 SkColorSpace::MakeSRGB(), // color space
179 &surface_properties, // surface properties
180 nullptr, // release proc
181 nullptr // release context
182 );
183
184 if (!surface) {
185 FML_LOG(ERROR) << "Could not wrap the surface while attempting to "
186 "snapshot the GL surface.";
187 return nullptr;
188 }
189
190 return surface;
191}
uint32_t GetFramebuffer(uint32_t width, uint32_t height) const
VkSurfaceKHR surface
Definition main.cc:65
int32_t height
int32_t width
Type height
Definition size.h:29

References FML_CHECK, FML_LOG, GetFramebuffer(), GetGrContext(), impeller::TSize< T >::height, height, surface, surface_size_, impeller::TSize< T >::width, and width.

Referenced by GetRasterSurfaceSnapshot().

◆ GetProcAddress()

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

Definition at line 94 of file test_gl_surface.cc.

94 {
95 if (name == nullptr) {
96 return nullptr;
97 }
98 auto symbol = ::eglGetProcAddress(name);
99 if (symbol == NULL) {
100 FML_LOG(ERROR) << "Could not fetch symbol for name: " << name;
101 }
102 return reinterpret_cast<void*>(symbol);
103}

References FML_LOG, and flutter::name.

Referenced by CreateGrContext().

◆ GetRasterSurfaceSnapshot()

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

Definition at line 193 of file test_gl_surface.cc.

193 {
195
196 if (!surface) {
197 FML_LOG(ERROR) << "Aborting snapshot because of on-screen surface "
198 "acquisition failure.";
199 return nullptr;
200 }
201
202 auto device_snapshot = surface->makeImageSnapshot();
203
204 if (!device_snapshot) {
205 FML_LOG(ERROR) << "Could not create the device snapshot while attempting "
206 "to snapshot the GL surface.";
207 return nullptr;
208 }
209
210 auto host_snapshot = device_snapshot->makeRasterImage(nullptr);
211
212 if (!host_snapshot) {
213 FML_LOG(ERROR) << "Could not create the host snapshot while attempting to "
214 "snapshot the GL surface.";
215 return nullptr;
216 }
217
218 return host_snapshot;
219}

References FML_LOG, GetOnscreenSurface(), and surface.

◆ GetSurfaceSize()

const DlISize & flutter::testing::TestGLOnscreenOnlySurface::GetSurfaceSize ( ) const

Definition at line 52 of file test_gl_surface.cc.

52 {
53 return surface_size_;
54}

References surface_size_.

◆ GetWindowFBOId()

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

Definition at line 221 of file test_gl_surface.cc.

221 {
222 return 0u;
223}

Referenced by GetFramebuffer().

◆ MakeCurrent()

bool flutter::testing::TestGLOnscreenOnlySurface::MakeCurrent ( )

Definition at line 56 of file test_gl_surface.cc.

56 {
57 auto result =
58 ::eglMakeCurrent(egl_context_->display, onscreen_surface_,
59 onscreen_surface_, egl_context_->onscreen_context);
60
61 if (result == EGL_FALSE) {
62 FML_LOG(ERROR) << "Could not make the context current. " << GetEGLError();
63 }
64
65 return result == EGL_TRUE;
66}

References egl_context_, FML_LOG, flutter::testing::GetEGLError(), and onscreen_surface_.

Referenced by CreateGrContext(), and flutter::testing::ShellTestPlatformViewGL::ShellTestPlatformViewGL().

◆ Present()

bool flutter::testing::TestGLOnscreenOnlySurface::Present ( )

Definition at line 79 of file test_gl_surface.cc.

79 {
80 auto result = ::eglSwapBuffers(egl_context_->display, onscreen_surface_);
81
82 if (result == EGL_FALSE) {
83 FML_LOG(ERROR) << "Could not swap buffers. " << GetEGLError();
84 }
85
86 return result == EGL_TRUE;
87}

References egl_context_, FML_LOG, flutter::testing::GetEGLError(), and onscreen_surface_.

Member Data Documentation

◆ egl_context_

◆ onscreen_surface_

EGLSurface flutter::testing::TestGLOnscreenOnlySurface::onscreen_surface_
protected

◆ skia_context_

sk_sp<GrDirectContext> flutter::testing::TestGLOnscreenOnlySurface::skia_context_
protected

Definition at line 56 of file test_gl_surface.h.

Referenced by CreateGrContext(), GetGrContext(), and ~TestGLOnscreenOnlySurface().

◆ surface_size_

const DlISize flutter::testing::TestGLOnscreenOnlySurface::surface_size_
protected

Definition at line 52 of file test_gl_surface.h.

Referenced by GetOnscreenSurface(), and GetSurfaceSize().


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