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/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 EGLDisplay
GetDisplay() override
;
34 static bool InitializeOneOff();
35 static EGLDisplay
GetHardwareDisplay();
36 static EGLNativeDisplayType
GetNativeDisplay();
38 // These aren't particularly tied to surfaces, but since we already
39 // have the static InitializeOneOff here, it's easiest to reuse its
40 // initialization guards.
41 static const char* GetEGLExtensions();
42 static bool HasEGLExtension(const char* name
);
43 static bool IsCreateContextRobustnessSupported();
44 static bool IsEGLSurfacelessContextSupported();
47 ~GLSurfaceEGL() override
;
51 static EGLDisplay
GetPlatformDisplay(EGLNativeDisplayType native_display
);
54 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL
);
57 // Encapsulates an EGL surface bound to a view.
58 class GL_EXPORT NativeViewGLSurfaceEGL
: public GLSurfaceEGL
{
60 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window
);
62 // Implement GLSurface.
63 EGLConfig
GetConfig() override
;
64 bool Initialize() override
;
65 void Destroy() override
;
66 bool Resize(const gfx::Size
& size
) override
;
67 bool Recreate() override
;
68 bool IsOffscreen() override
;
69 bool SwapBuffers() override
;
70 gfx::Size
GetSize() override
;
71 EGLSurface
GetHandle() override
;
72 bool SupportsPostSubBuffer() override
;
73 bool PostSubBuffer(int x
, int y
, int width
, int height
) override
;
74 VSyncProvider
* GetVSyncProvider() override
;
76 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
77 // Takes ownership of the VSyncProvider.
78 virtual bool Initialize(scoped_ptr
<VSyncProvider
> sync_provider
);
81 ~NativeViewGLSurfaceEGL() override
;
83 EGLNativeWindowType window_
;
87 bool supports_post_sub_buffer_
;
91 scoped_ptr
<VSyncProvider
> vsync_provider_
;
93 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL
);
96 // Encapsulates a pbuffer EGL surface.
97 class GL_EXPORT PbufferGLSurfaceEGL
: public GLSurfaceEGL
{
99 explicit PbufferGLSurfaceEGL(const gfx::Size
& size
);
101 // Implement GLSurface.
102 EGLConfig
GetConfig() override
;
103 bool Initialize() override
;
104 void Destroy() override
;
105 bool IsOffscreen() override
;
106 bool SwapBuffers() override
;
107 gfx::Size
GetSize() override
;
108 bool Resize(const gfx::Size
& size
) override
;
109 EGLSurface
GetHandle() override
;
110 void* GetShareHandle() override
;
113 ~PbufferGLSurfaceEGL() override
;
119 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL
);
122 // SurfacelessEGL is used as Offscreen surface when platform supports
123 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
124 // need to create a dummy EGLsurface in case we render to client API targets.
125 class GL_EXPORT SurfacelessEGL
: public GLSurfaceEGL
{
127 explicit SurfacelessEGL(const gfx::Size
& size
);
129 // Implement GLSurface.
130 EGLConfig
GetConfig() override
;
131 bool Initialize() override
;
132 void Destroy() override
;
133 bool IsOffscreen() override
;
134 bool IsSurfaceless() const override
;
135 bool SwapBuffers() override
;
136 gfx::Size
GetSize() override
;
137 bool Resize(const gfx::Size
& size
) override
;
138 EGLSurface
GetHandle() override
;
139 void* GetShareHandle() override
;
142 ~SurfacelessEGL() override
;
146 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL
);
151 #endif // UI_GL_GL_SURFACE_EGL_H_