• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // DisplayOzone.h: Ozone implementation of egl::Display
8 
9 #ifndef LIBANGLE_RENDERER_GL_EGL_OZONE_DISPLAYOZONE_H_
10 #define LIBANGLE_RENDERER_GL_EGL_OZONE_DISPLAYOZONE_H_
11 
12 #include <xf86drm.h>
13 #include <xf86drmMode.h>
14 
15 #include <string>
16 
17 #include "libANGLE/renderer/gl/egl/DisplayEGL.h"
18 
19 struct gbm_device;
20 struct gbm_bo;
21 
22 namespace gl
23 {
24 class FramebufferState;
25 }
26 
27 namespace rx
28 {
29 
30 class FramebufferGL;
31 class RendererEGL;
32 
33 // TODO(fjhenigman) Implement swap control.  The following struct will be used for that.
34 // State-tracking data for the swap control to allow DisplayOzone to remember per
35 // drawable information for swap control.
36 struct SwapControlData final
37 {
38     SwapControlData();
39 
40     // Set by the drawable
41     int targetSwapInterval;
42 
43     // DisplayOzone-side state-tracking
44     int maxSwapInterval;
45     int currentSwapInterval;
46 };
47 
48 class DisplayOzone final : public DisplayEGL
49 {
50   public:
51     struct NativeWindow
52     {
53         int32_t x;
54         int32_t y;
55         int32_t width;
56         int32_t height;
57         int32_t borderWidth;
58         int32_t borderHeight;
59         int32_t visible;
60         int32_t depth;
61     };
62 
63     class Buffer final : angle::NonCopyable
64     {
65       public:
66         Buffer(DisplayOzone *display,
67                uint32_t useFlags,
68                uint32_t gbmFormat,
69                uint32_t drmFormat,
70                uint32_t drmFormatFB,
71                int depthBits,
72                int stencilBits);
73 
74         ~Buffer();
75         bool initialize(const NativeWindow *window);
76         bool initialize(int32_t width, int32_t height);
77         void reset();
78         bool resize(int32_t width, int32_t height);
79         GLuint createGLFB(const gl::Context *context);
80         FramebufferGL *framebufferGL(const gl::Context *context, const gl::FramebufferState &state);
81         void present(const gl::Context *context);
82         uint32_t getDRMFB();
83         void bindTexImage();
84         GLuint getTexture();
getWidth()85         int32_t getWidth() const { return mWidth; }
getHeight()86         int32_t getHeight() const { return mHeight; }
getNative()87         const NativeWindow *getNative() const { return mNative; }
88 
89       private:
90         bool createRenderbuffers();
91 
92         DisplayOzone *mDisplay;
93         const NativeWindow *mNative;
94         int mWidth;
95         int mHeight;
96         const int mDepthBits;
97         const int mStencilBits;
98         const uint32_t mUseFlags;
99         const uint32_t mGBMFormat;
100         const uint32_t mDRMFormat;
101         const uint32_t mDRMFormatFB;
102         gbm_bo *mBO;
103         int mDMABuf;
104         bool mHasDRMFB;
105         uint32_t mDRMFB;
106         EGLImageKHR mImage;
107         GLuint mColorBuffer;
108         GLuint mDSBuffer;
109         GLuint mTexture;
110     };
111 
112     DisplayOzone(const egl::DisplayState &state);
113     ~DisplayOzone() override;
114 
115     egl::Error initialize(egl::Display *display) override;
116     void terminate() override;
117 
118     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
119                                      EGLNativeWindowType window,
120                                      const egl::AttributeMap &attribs) override;
121     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
122                                       const egl::AttributeMap &attribs) override;
123 
124     ContextImpl *createContext(const gl::State &state,
125                                gl::ErrorSet *errorSet,
126                                const egl::Config *configuration,
127                                const gl::Context *shareContext,
128                                const egl::AttributeMap &attribs) override;
129 
130     egl::Error makeCurrent(egl::Surface *drawSurface,
131                            egl::Surface *readSurface,
132                            gl::Context *context) override;
133 
134     egl::ConfigSet generateConfigs() override;
135 
136     bool isValidNativeWindow(EGLNativeWindowType window) const override;
137 
138     // TODO(fjhenigman) Implement this.
139     // Swap interval can be set globally or per drawable.
140     // This function will make sure the drawable's swap interval is the
141     // one required so that the subsequent swapBuffers acts as expected.
142     void setSwapInterval(EGLSurface drawable, SwapControlData *data);
143 
144     WorkerContext *createWorkerContext(std::string *infoLog,
145                                        EGLContext sharedContext,
146                                        const native_egl::AttributeVector workerAttribs) override;
147 
148   private:
149     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
150 
151     GLuint makeShader(GLuint type, const char *src);
152     void drawBuffer(const gl::Context *context, Buffer *buffer);
153     void drawWithTexture(const gl::Context *context, Buffer *buffer);
154     void flushGL();
155     bool hasUsableScreen(int fd);
156     void presentScreen();
157     static void pageFlipHandler(int fd,
158                                 unsigned int sequence,
159                                 unsigned int tv_sec,
160                                 unsigned int tv_usec,
161                                 void *data);
162     void pageFlipHandler(unsigned int sequence, uint64_t tv);
163 
164     gbm_device *mGBM;
165     drmModeConnectorPtr mConnector;
166     drmModeModeInfoPtr mMode;
167     drmModeCrtcPtr mCRTC;
168     bool mSetCRTC;
169 
170     int32_t mWidth;
171     int32_t mHeight;
172 
173     // Three scanout buffers cycle through four states.  The state of a buffer
174     // is indicated by which of these pointers points to it.
175     // TODO(fjhenigman) It might be simpler/clearer to use a ring buffer.
176     Buffer *mScanning;
177     Buffer *mPending;
178     Buffer *mDrawing;
179     Buffer *mUnused;
180 
181     GLuint mProgram;
182     GLuint mVertexShader;
183     GLuint mFragmentShader;
184     GLuint mVertexBuffer;
185     GLuint mIndexBuffer;
186     GLint mCenterUniform;
187     GLint mWindowSizeUniform;
188     GLint mBorderSizeUniform;
189     GLint mDepthUniform;
190 };
191 }  // namespace rx
192 
193 #endif  // LIBANGLE_RENDERER_GL_EGL_OZONE_DISPLAYOZONE_H_
194