xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/egl/WindowSurfaceEGL.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // WindowSurfaceEGL.h: EGL implementation of egl::Surface for windows
8 
9 #include "libANGLE/renderer/gl/egl/WindowSurfaceEGL.h"
10 
11 #include "libANGLE/Surface.h"
12 #include "libANGLE/renderer/gl/egl/egl_utils.h"
13 
14 namespace rx
15 {
16 
WindowSurfaceEGL(const egl::SurfaceState & state,const FunctionsEGL * egl,EGLConfig config,EGLNativeWindowType window)17 WindowSurfaceEGL::WindowSurfaceEGL(const egl::SurfaceState &state,
18                                    const FunctionsEGL *egl,
19                                    EGLConfig config,
20                                    EGLNativeWindowType window)
21     : SurfaceEGL(state, egl, config), mWindow(window)
22 {}
23 
~WindowSurfaceEGL()24 WindowSurfaceEGL::~WindowSurfaceEGL() {}
25 
initialize(const egl::Display * display)26 egl::Error WindowSurfaceEGL::initialize(const egl::Display *display)
27 {
28     constexpr EGLint kForwardedWindowSurfaceAttributes[] = {
29         EGL_RENDER_BUFFER, EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_GL_COLORSPACE,
30         EGL_COLOR_COMPONENT_TYPE_EXT};
31 
32     native_egl::AttributeVector nativeAttribs =
33         native_egl::TrimAttributeMap(mState.attributes, kForwardedWindowSurfaceAttributes);
34     native_egl::FinalizeAttributeVector(&nativeAttribs);
35 
36     mSurface = mEGL->createWindowSurface(mConfig, mWindow, nativeAttribs.data());
37     if (mSurface == EGL_NO_SURFACE)
38     {
39         return egl::Error(mEGL->getError(), "eglCreateWindowSurface failed");
40     }
41 
42     return egl::NoError();
43 }
44 
getBufferAge(const gl::Context * context,EGLint * age)45 egl::Error WindowSurfaceEGL::getBufferAge(const gl::Context *context, EGLint *age)
46 {
47     ANGLE_UNUSED_VARIABLE(context);
48     EGLBoolean result = mEGL->querySurface(mSurface, EGL_BUFFER_AGE_EXT, age);
49     if (result == EGL_FALSE)
50     {
51         return egl::Error(mEGL->getError(), "eglQuerySurface for EGL_BUFFER_AGE_EXT failed");
52     }
53     return egl::NoError();
54 }
55 
56 }  // namespace rx
57