1 // 2 // Copyright 2020 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 // WindowSurfaceEAGL.h: EAGL implementation of egl::Surface 8 9 #ifndef LIBANGLE_RENDERER_GL_EAGL_WINDOWSURFACEEAGL_H_ 10 #define LIBANGLE_RENDERER_GL_EAGL_WINDOWSURFACEEAGL_H_ 11 12 #include "libANGLE/renderer/gl/SurfaceGL.h" 13 14 #ifdef __OBJC__ 15 @class EAGLContext; 16 typedef EAGLContext *EAGLContextObj; 17 #else 18 typedef void *EAGLContextObj; 19 #endif 20 @class CALayer; 21 struct __IOSurface; 22 typedef __IOSurface *IOSurfaceRef; 23 24 // WebKit's build process requires that every Objective-C class name has the prefix "Web". 25 @class WebSwapLayer; 26 27 namespace rx 28 { 29 30 class DisplayEAGL; 31 class FramebufferGL; 32 class FunctionsGL; 33 class RendererGL; 34 class StateManagerGL; 35 36 struct SharedSwapState 37 { 38 struct SwapTexture 39 { 40 GLuint texture; 41 unsigned int width; 42 unsigned int height; 43 uint64_t swapId; 44 }; 45 46 SwapTexture textures[3]; 47 48 // This code path is not going to be used by Chrome so we take the liberty 49 // to use pthreads directly instead of using mutexes and condition variables 50 // via the Platform API. 51 pthread_mutex_t mutex; 52 // The following members should be accessed only when holding the mutex 53 // (or doing construction / destruction) 54 SwapTexture *beingRendered; 55 SwapTexture *lastRendered; 56 SwapTexture *beingPresented; 57 }; 58 59 class WindowSurfaceEAGL : public SurfaceGL 60 { 61 public: 62 WindowSurfaceEAGL(const egl::SurfaceState &state, 63 RendererGL *renderer, 64 EGLNativeWindowType layer, 65 EAGLContextObj context); 66 ~WindowSurfaceEAGL() override; 67 68 egl::Error initialize(const egl::Display *display) override; 69 egl::Error makeCurrent(const gl::Context *context) override; 70 71 egl::Error swap(const gl::Context *context) override; 72 egl::Error postSubBuffer(const gl::Context *context, 73 EGLint x, 74 EGLint y, 75 EGLint width, 76 EGLint height) override; 77 egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override; 78 egl::Error bindTexImage(const gl::Context *context, 79 gl::Texture *texture, 80 EGLint buffer) override; 81 egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; 82 void setSwapInterval(EGLint interval) override; 83 84 EGLint getWidth() const override; 85 EGLint getHeight() const override; 86 87 EGLint isPostSubBufferSupported() const override; 88 EGLint getSwapBehavior() const override; 89 90 FramebufferImpl *createDefaultFramebuffer(const gl::Context *context, 91 const gl::FramebufferState &state) override; 92 93 private: 94 WebSwapLayer *mSwapLayer; 95 SharedSwapState mSwapState; 96 uint64_t mCurrentSwapId; 97 98 CALayer *mLayer; 99 EAGLContextObj mContext; 100 const FunctionsGL *mFunctions; 101 StateManagerGL *mStateManager; 102 103 GLuint mDSRenderbuffer; 104 }; 105 106 } // namespace rx 107 108 #endif // LIBANGLE_RENDERER_GL_EAGL_WINDOWSURFACEEAGL_H_ 109