@@ -105,14 +105,6 @@ static bool TeardownContext(EGLDisplay display, EGLContext context) {
105105 return true ;
106106}
107107
108- AndroidEGLSurface::AndroidEGLSurface (EGLSurface surface, EGLDisplay display)
109- : surface(surface), display_(display) {}
110-
111- AndroidEGLSurface::~AndroidEGLSurface () {
112- auto result = eglDestroySurface (display_, surface);
113- FML_DCHECK (result == EGL_TRUE);
114- }
115-
116108AndroidContextGL::AndroidContextGL (
117109 AndroidRenderingAPI rendering_api,
118110 fml::RefPtr<AndroidEnvironmentGL> environment)
@@ -169,28 +161,25 @@ AndroidContextGL::~AndroidContextGL() {
169161 }
170162}
171163
172- std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOnscreenSurface (
164+ EGLSurface AndroidContextGL::CreateOnscreenSurface (
173165 fml::RefPtr<AndroidNativeWindow> window) const {
174166 EGLDisplay display = environment_->Display ();
175167
176168 const EGLint attribs[] = {EGL_NONE};
177169
178- EGLSurface surface = eglCreateWindowSurface (
170+ return eglCreateWindowSurface (
179171 display, config_, reinterpret_cast <EGLNativeWindowType>(window->handle ()),
180172 attribs);
181- return std::make_unique<AndroidEGLSurface>(surface, display);
182173}
183174
184- std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOffscreenSurface ()
185- const {
175+ EGLSurface AndroidContextGL::CreateOffscreenSurface () const {
186176 // We only ever create pbuffer surfaces for background resource loading
187177 // contexts. We never bind the pbuffer to anything.
188178 EGLDisplay display = environment_->Display ();
189179
190180 const EGLint attribs[] = {EGL_WIDTH, 1 , EGL_HEIGHT, 1 , EGL_NONE};
191181
192- EGLSurface surface = eglCreatePbufferSurface (display, config_, attribs);
193- return std::make_unique<AndroidEGLSurface>(surface, display);
182+ return eglCreatePbufferSurface (display, config_, attribs);
194183}
195184
196185fml::RefPtr<AndroidEnvironmentGL> AndroidContextGL::Environment () const {
@@ -201,21 +190,19 @@ bool AndroidContextGL::IsValid() const {
201190 return valid_;
202191}
203192
204- bool AndroidContextGL::MakeCurrent (
205- std::unique_ptr<AndroidEGLSurface> surface_wrapper) {
206- if (eglMakeCurrent (environment_->Display (), surface_wrapper->surface ,
207- surface_wrapper->surface , context_) != EGL_TRUE) {
193+ bool AndroidContextGL::MakeCurrent (EGLSurface& surface) {
194+ if (eglMakeCurrent (environment_->Display (), surface, surface, context_) !=
195+ EGL_TRUE) {
208196 FML_LOG (ERROR) << " Could not make the context current" ;
209197 LogLastEGLError ();
210198 return false ;
211199 }
212200 return true ;
213201}
214202
215- bool AndroidContextGL::ResourceMakeCurrent (
216- std::unique_ptr<AndroidEGLSurface> surface_wrapper) {
217- if (eglMakeCurrent (environment_->Display (), surface_wrapper->surface ,
218- surface_wrapper->surface , resource_context_) != EGL_TRUE) {
203+ bool AndroidContextGL::ResourceMakeCurrent (EGLSurface& surface) {
204+ if (eglMakeCurrent (environment_->Display (), surface, surface,
205+ resource_context_) != EGL_TRUE) {
219206 FML_LOG (ERROR) << " Could not make the context current" ;
220207 LogLastEGLError ();
221208 return false ;
@@ -236,26 +223,30 @@ bool AndroidContextGL::ClearCurrent() {
236223 return true ;
237224}
238225
239- bool AndroidContextGL::SwapBuffers (
240- std::unique_ptr<AndroidEGLSurface> surface_wrapper) {
226+ bool AndroidContextGL::SwapBuffers (EGLSurface& surface) {
241227 TRACE_EVENT0 (" flutter" , " AndroidContextGL::SwapBuffers" );
242- return eglSwapBuffers (environment_->Display (), surface_wrapper-> surface );
228+ return eglSwapBuffers (environment_->Display (), surface);
243229}
244230
245- SkISize AndroidContextGL::GetSize (
246- std::unique_ptr<AndroidEGLSurface> surface_wrapper) {
231+ SkISize AndroidContextGL::GetSize (EGLSurface& surface) {
247232 EGLint width = 0 ;
248233 EGLint height = 0 ;
249234
250- if (!eglQuerySurface (environment_->Display (), surface_wrapper->surface ,
251- EGL_WIDTH, &width) ||
252- !eglQuerySurface (environment_->Display (), surface_wrapper->surface ,
253- EGL_HEIGHT, &height)) {
235+ if (!eglQuerySurface (environment_->Display (), surface, EGL_WIDTH, &width) ||
236+ !eglQuerySurface (environment_->Display (), surface, EGL_HEIGHT, &height)) {
254237 FML_LOG (ERROR) << " Unable to query EGL surface size" ;
255238 LogLastEGLError ();
256239 return SkISize::Make (0 , 0 );
257240 }
258241 return SkISize::Make (width, height);
259242}
260243
244+ bool AndroidContextGL::TeardownSurface (EGLSurface& surface) {
245+ if (surface != EGL_NO_SURFACE) {
246+ return eglDestroySurface (environment_->Display (), surface) == EGL_TRUE;
247+ }
248+
249+ return true ;
250+ }
251+
261252} // namespace flutter
0 commit comments