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_
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"
24 // Get default EGL display for GLSurfaceEGL (differs by platform).
25 EGLNativeDisplayType
GetPlatformDefaultEGLNativeDisplay();
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
{
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();
65 ~GLSurfaceEGL() override
;
68 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL
);
71 // Encapsulates an EGL surface bound to a view.
72 class GL_EXPORT NativeViewGLSurfaceEGL
: public GLSurfaceEGL
{
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
);
95 ~NativeViewGLSurfaceEGL() override
;
97 EGLNativeWindowType window_
;
99 void OnSetSwapInterval(int interval
) override
;
103 bool supports_post_sub_buffer_
;
107 scoped_ptr
<VSyncProvider
> vsync_provider_
;
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_
;
120 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL
);
123 // Encapsulates a pbuffer EGL surface.
124 class GL_EXPORT PbufferGLSurfaceEGL
: public GLSurfaceEGL
{
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
;
140 ~PbufferGLSurfaceEGL() override
;
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
{
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
;
169 ~SurfacelessEGL() override
;
173 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL
);
178 #endif // UI_GL_GL_SURFACE_EGL_H_