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 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();
64 ~GLSurfaceEGL() override
;
67 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL
);
70 // Encapsulates an EGL surface bound to a view.
71 class GL_EXPORT NativeViewGLSurfaceEGL
: public GLSurfaceEGL
{
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
);
94 ~NativeViewGLSurfaceEGL() override
;
96 EGLNativeWindowType window_
;
98 void OnSetSwapInterval(int interval
) override
;
102 bool supports_post_sub_buffer_
;
106 scoped_ptr
<VSyncProvider
> vsync_provider_
;
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_
;
119 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL
);
122 // Encapsulates a pbuffer EGL surface.
123 class GL_EXPORT PbufferGLSurfaceEGL
: public GLSurfaceEGL
{
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
;
139 ~PbufferGLSurfaceEGL() override
;
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
{
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
;
168 ~SurfacelessEGL() override
;
172 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL
);
177 #endif // UI_GL_GL_SURFACE_EGL_H_