Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / gl / gl_surface_egl.h
blob07d02712cb902764bf195e58affffbdc182785d9
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 void DestroyAndTerminateDisplay() override;
49 EGLDisplay GetDisplay() override;
51 static bool InitializeOneOff();
52 static EGLDisplay GetHardwareDisplay();
53 static EGLDisplay InitializeDisplay();
54 static EGLNativeDisplayType GetNativeDisplay();
56 // These aren't particularly tied to surfaces, but since we already
57 // have the static InitializeOneOff here, it's easiest to reuse its
58 // initialization guards.
59 static const char* GetEGLExtensions();
60 static bool HasEGLExtension(const char* name);
61 static bool IsCreateContextRobustnessSupported();
62 static bool IsEGLSurfacelessContextSupported();
64 protected:
65 ~GLSurfaceEGL() override;
67 private:
68 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
71 // Encapsulates an EGL surface bound to a view.
72 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
73 public:
74 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
76 // Implement GLSurface.
77 EGLConfig GetConfig() override;
78 bool Initialize() override;
79 void Destroy() override;
80 bool Resize(const gfx::Size& size) override;
81 bool Recreate() override;
82 bool IsOffscreen() override;
83 gfx::SwapResult SwapBuffers() override;
84 gfx::Size GetSize() override;
85 EGLSurface GetHandle() override;
86 bool SupportsPostSubBuffer() override;
87 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override;
88 VSyncProvider* GetVSyncProvider() override;
90 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
91 // Takes ownership of the VSyncProvider.
92 virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
94 protected:
95 ~NativeViewGLSurfaceEGL() override;
97 EGLNativeWindowType window_;
99 void OnSetSwapInterval(int interval) override;
101 private:
102 EGLSurface surface_;
103 bool supports_post_sub_buffer_;
104 EGLConfig config_;
105 gfx::Size size_;
107 scoped_ptr<VSyncProvider> vsync_provider_;
109 int swap_interval_;
111 #if defined(OS_WIN)
112 bool vsync_override_;
114 unsigned int swap_generation_;
115 static unsigned int current_swap_generation_;
116 static unsigned int swaps_this_generation_;
117 static unsigned int last_multiswap_generation_;
118 #endif
120 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
123 // Encapsulates a pbuffer EGL surface.
124 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
125 public:
126 explicit PbufferGLSurfaceEGL(const gfx::Size& size);
128 // Implement GLSurface.
129 EGLConfig GetConfig() override;
130 bool Initialize() override;
131 void Destroy() override;
132 bool IsOffscreen() override;
133 gfx::SwapResult SwapBuffers() override;
134 gfx::Size GetSize() override;
135 bool Resize(const gfx::Size& size) override;
136 EGLSurface GetHandle() override;
137 void* GetShareHandle() override;
139 protected:
140 ~PbufferGLSurfaceEGL() override;
142 private:
143 gfx::Size size_;
144 EGLSurface surface_;
146 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
149 // SurfacelessEGL is used as Offscreen surface when platform supports
150 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
151 // need to create a dummy EGLsurface in case we render to client API targets.
152 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
153 public:
154 explicit SurfacelessEGL(const gfx::Size& size);
156 // Implement GLSurface.
157 EGLConfig GetConfig() override;
158 bool Initialize() override;
159 void Destroy() override;
160 bool IsOffscreen() override;
161 bool IsSurfaceless() const override;
162 gfx::SwapResult SwapBuffers() override;
163 gfx::Size GetSize() override;
164 bool Resize(const gfx::Size& size) override;
165 EGLSurface GetHandle() override;
166 void* GetShareHandle() override;
168 protected:
169 ~SurfacelessEGL() override;
171 private:
172 gfx::Size size_;
173 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
176 } // namespace gfx
178 #endif // UI_GL_GL_SURFACE_EGL_H_