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/compiler_specific.h"
15 #include "base/time/time.h"
16 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/vsync_provider.h"
18 #include "ui/gl/gl_bindings.h"
19 #include "ui/gl/gl_surface.h"
23 // Get default EGL display for GLSurfaceEGL (differs by platform).
24 EGLNativeDisplayType
GetPlatformDefaultEGLNativeDisplay();
26 // Interface for EGL surface.
27 class GL_EXPORT GLSurfaceEGL
: public GLSurface
{
31 // Implement GLSurface.
32 void DestroyAndTerminateDisplay() override
;
33 EGLDisplay
GetDisplay() override
;
35 static bool InitializeOneOff();
36 static EGLDisplay
GetHardwareDisplay();
37 static EGLNativeDisplayType
GetNativeDisplay();
39 // These aren't particularly tied to surfaces, but since we already
40 // have the static InitializeOneOff here, it's easiest to reuse its
41 // initialization guards.
42 static const char* GetEGLExtensions();
43 static bool HasEGLExtension(const char* name
);
44 static bool IsCreateContextRobustnessSupported();
45 static bool IsEGLSurfacelessContextSupported();
48 ~GLSurfaceEGL() override
;
52 friend struct DriverEGL
;
53 static EGLDisplay
GetPlatformDisplay(EGLNativeDisplayType native_display
);
56 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL
);
59 // Encapsulates an EGL surface bound to a view.
60 class GL_EXPORT NativeViewGLSurfaceEGL
: public GLSurfaceEGL
{
62 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window
);
64 // Implement GLSurface.
65 EGLConfig
GetConfig() override
;
66 bool Initialize() override
;
67 void Destroy() override
;
68 bool Resize(const gfx::Size
& size
) override
;
69 bool Recreate() override
;
70 bool IsOffscreen() override
;
71 bool SwapBuffers() override
;
72 gfx::Size
GetSize() override
;
73 EGLSurface
GetHandle() override
;
74 bool SupportsPostSubBuffer() override
;
75 bool PostSubBuffer(int x
, int y
, int width
, int height
) override
;
76 VSyncProvider
* GetVSyncProvider() override
;
78 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
79 // Takes ownership of the VSyncProvider.
80 virtual bool Initialize(scoped_ptr
<VSyncProvider
> sync_provider
);
83 ~NativeViewGLSurfaceEGL() override
;
85 EGLNativeWindowType window_
;
87 void OnSetSwapInterval(int interval
) override
;
91 bool supports_post_sub_buffer_
;
95 scoped_ptr
<VSyncProvider
> vsync_provider_
;
100 bool vsync_override_
;
102 unsigned int swap_generation_
;
103 static unsigned int current_swap_generation_
;
104 static unsigned int swaps_this_generation_
;
105 static unsigned int last_multiswap_generation_
;
108 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL
);
111 // Encapsulates a pbuffer EGL surface.
112 class GL_EXPORT PbufferGLSurfaceEGL
: public GLSurfaceEGL
{
114 explicit PbufferGLSurfaceEGL(const gfx::Size
& size
);
116 // Implement GLSurface.
117 EGLConfig
GetConfig() override
;
118 bool Initialize() override
;
119 void Destroy() override
;
120 bool IsOffscreen() override
;
121 bool SwapBuffers() override
;
122 gfx::Size
GetSize() override
;
123 bool Resize(const gfx::Size
& size
) override
;
124 EGLSurface
GetHandle() override
;
125 void* GetShareHandle() override
;
128 ~PbufferGLSurfaceEGL() override
;
134 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL
);
137 // SurfacelessEGL is used as Offscreen surface when platform supports
138 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
139 // need to create a dummy EGLsurface in case we render to client API targets.
140 class GL_EXPORT SurfacelessEGL
: public GLSurfaceEGL
{
142 explicit SurfacelessEGL(const gfx::Size
& size
);
144 // Implement GLSurface.
145 EGLConfig
GetConfig() override
;
146 bool Initialize() override
;
147 void Destroy() override
;
148 bool IsOffscreen() override
;
149 bool IsSurfaceless() const override
;
150 bool SwapBuffers() override
;
151 gfx::Size
GetSize() override
;
152 bool Resize(const gfx::Size
& size
) override
;
153 EGLSurface
GetHandle() override
;
154 void* GetShareHandle() override
;
157 ~SurfacelessEGL() override
;
161 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL
);
166 #endif // UI_GL_GL_SURFACE_EGL_H_