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