Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / gl / gl_surface_egl.h
blobc8c7ddf3122c1e57e6cce4bab180f1ba572cd817
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GL_GL_SURFACE_EGL_H_
6 #define UI_GL_GL_SURFACE_EGL_H_
8 #if defined(OS_WIN)
9 #include <windows.h>
10 #endif
12 #include <string>
14 #include "base/command_line.h"
15 #include "base/compiler_specific.h"
16 #include "base/time/time.h"
17 #include "ui/gfx/geometry/size.h"
18 #include "ui/gfx/vsync_provider.h"
19 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_surface.h"
22 namespace gfx {
24 // Get default EGL display for GLSurfaceEGL (differs by platform).
25 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay();
27 enum DisplayType {
28 DEFAULT,
29 SWIFT_SHADER,
30 ANGLE_WARP,
31 ANGLE_D3D9,
32 ANGLE_D3D11,
33 ANGLE_OPENGL,
34 ANGLE_OPENGLES,
37 GL_EXPORT void GetEGLInitDisplays(bool supports_angle_d3d,
38 bool supports_angle_opengl,
39 const base::CommandLine* command_line,
40 std::vector<DisplayType>* init_displays);
42 // Interface for EGL surface.
43 class GL_EXPORT GLSurfaceEGL : public GLSurface {
44 public:
45 GLSurfaceEGL();
47 // Implement GLSurface.
48 EGLDisplay GetDisplay() override;
50 static bool InitializeOneOff();
51 static EGLDisplay GetHardwareDisplay();
52 static EGLDisplay InitializeDisplay();
53 static EGLNativeDisplayType GetNativeDisplay();
55 // These aren't particularly tied to surfaces, but since we already
56 // have the static InitializeOneOff here, it's easiest to reuse its
57 // initialization guards.
58 static const char* GetEGLExtensions();
59 static bool HasEGLExtension(const char* name);
60 static bool IsCreateContextRobustnessSupported();
61 static bool IsEGLSurfacelessContextSupported();
63 protected:
64 ~GLSurfaceEGL() override;
66 private:
67 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
70 // Encapsulates an EGL surface bound to a view.
71 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
72 public:
73 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
75 // Implement GLSurface.
76 EGLConfig GetConfig() override;
77 bool Initialize() override;
78 void Destroy() override;
79 bool Resize(const gfx::Size& size) override;
80 bool Recreate() override;
81 bool IsOffscreen() override;
82 gfx::SwapResult SwapBuffers() override;
83 gfx::Size GetSize() override;
84 EGLSurface GetHandle() override;
85 bool SupportsPostSubBuffer() override;
86 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override;
87 VSyncProvider* GetVSyncProvider() override;
89 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
90 // Takes ownership of the VSyncProvider.
91 virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
93 protected:
94 ~NativeViewGLSurfaceEGL() override;
96 EGLNativeWindowType window_;
98 void OnSetSwapInterval(int interval) override;
100 private:
101 EGLSurface surface_;
102 bool supports_post_sub_buffer_;
103 EGLConfig config_;
104 gfx::Size size_;
106 scoped_ptr<VSyncProvider> vsync_provider_;
108 int swap_interval_;
110 #if defined(OS_WIN)
111 bool vsync_override_;
113 unsigned int swap_generation_;
114 static unsigned int current_swap_generation_;
115 static unsigned int swaps_this_generation_;
116 static unsigned int last_multiswap_generation_;
117 #endif
119 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
122 // Encapsulates a pbuffer EGL surface.
123 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
124 public:
125 explicit PbufferGLSurfaceEGL(const gfx::Size& size);
127 // Implement GLSurface.
128 EGLConfig GetConfig() override;
129 bool Initialize() override;
130 void Destroy() override;
131 bool IsOffscreen() override;
132 gfx::SwapResult SwapBuffers() override;
133 gfx::Size GetSize() override;
134 bool Resize(const gfx::Size& size) override;
135 EGLSurface GetHandle() override;
136 void* GetShareHandle() override;
138 protected:
139 ~PbufferGLSurfaceEGL() override;
141 private:
142 gfx::Size size_;
143 EGLSurface surface_;
145 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
148 // SurfacelessEGL is used as Offscreen surface when platform supports
149 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
150 // need to create a dummy EGLsurface in case we render to client API targets.
151 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
152 public:
153 explicit SurfacelessEGL(const gfx::Size& size);
155 // Implement GLSurface.
156 EGLConfig GetConfig() override;
157 bool Initialize() override;
158 void Destroy() override;
159 bool IsOffscreen() override;
160 bool IsSurfaceless() const override;
161 gfx::SwapResult SwapBuffers() override;
162 gfx::Size GetSize() override;
163 bool Resize(const gfx::Size& size) override;
164 EGLSurface GetHandle() override;
165 void* GetShareHandle() override;
167 protected:
168 ~SurfacelessEGL() override;
170 private:
171 gfx::Size size_;
172 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
175 } // namespace gfx
177 #endif // UI_GL_GL_SURFACE_EGL_H_