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