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