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/native_widget_types.h"
17 #include "ui/gfx/size.h"
18 #include "ui/gfx/vsync_provider.h"
19 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_surface.h"
24 // Interface for EGL surface.
25 class GL_EXPORT GLSurfaceEGL
: public GLSurface
{
29 // Implement GLSurface.
30 virtual EGLDisplay
GetDisplay() OVERRIDE
;
32 static bool InitializeOneOff();
33 static EGLDisplay
GetHardwareDisplay();
34 static EGLNativeDisplayType
GetNativeDisplay();
36 // These aren't particularly tied to surfaces, but since we already
37 // have the static InitializeOneOff here, it's easiest to reuse its
38 // initialization guards.
39 static const char* GetEGLExtensions();
40 static bool HasEGLExtension(const char* name
);
41 static bool IsCreateContextRobustnessSupported();
44 virtual ~GLSurfaceEGL();
47 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL
);
50 // Encapsulates an EGL surface bound to a view.
51 class GL_EXPORT NativeViewGLSurfaceEGL
: public GLSurfaceEGL
{
53 explicit NativeViewGLSurfaceEGL(gfx::AcceleratedWidget window
);
55 // Implement GLSurface.
56 virtual EGLConfig
GetConfig() OVERRIDE
;
57 virtual bool Initialize() OVERRIDE
;
58 virtual void Destroy() OVERRIDE
;
59 virtual bool Resize(const gfx::Size
& size
) OVERRIDE
;
60 virtual bool Recreate() OVERRIDE
;
61 virtual bool IsOffscreen() OVERRIDE
;
62 virtual bool SwapBuffers() OVERRIDE
;
63 virtual gfx::Size
GetSize() OVERRIDE
;
64 virtual EGLSurface
GetHandle() OVERRIDE
;
65 virtual std::string
GetExtensions() OVERRIDE
;
66 virtual bool PostSubBuffer(int x
, int y
, int width
, int height
) OVERRIDE
;
67 virtual VSyncProvider
* GetVSyncProvider() OVERRIDE
;
69 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
70 // Takes ownership of the VSyncProvider.
71 virtual bool Initialize(scoped_ptr
<VSyncProvider
> sync_provider
);
74 virtual ~NativeViewGLSurfaceEGL();
75 void SetHandle(EGLSurface surface
);
78 gfx::AcceleratedWidget window_
;
80 bool supports_post_sub_buffer_
;
83 scoped_ptr
<VSyncProvider
> vsync_provider_
;
85 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL
);
88 // Encapsulates a pbuffer EGL surface.
89 class GL_EXPORT PbufferGLSurfaceEGL
: public GLSurfaceEGL
{
91 explicit PbufferGLSurfaceEGL(const gfx::Size
& size
);
93 // Implement GLSurface.
94 virtual EGLConfig
GetConfig() OVERRIDE
;
95 virtual bool Initialize() OVERRIDE
;
96 virtual void Destroy() OVERRIDE
;
97 virtual bool IsOffscreen() OVERRIDE
;
98 virtual bool SwapBuffers() OVERRIDE
;
99 virtual gfx::Size
GetSize() OVERRIDE
;
100 virtual bool Resize(const gfx::Size
& size
) OVERRIDE
;
101 virtual EGLSurface
GetHandle() OVERRIDE
;
102 virtual void* GetShareHandle() OVERRIDE
;
105 virtual ~PbufferGLSurfaceEGL();
111 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL
);
114 // SurfacelessEGL is used as Offscreen surface when platform supports
115 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
116 // need to create a dummy EGLsurface in case we render to client API targets.
117 class GL_EXPORT SurfacelessEGL
: public GLSurfaceEGL
{
119 explicit SurfacelessEGL(const gfx::Size
& size
);
121 // Implement GLSurface.
122 virtual EGLConfig
GetConfig() OVERRIDE
;
123 virtual bool Initialize() OVERRIDE
;
124 virtual void Destroy() OVERRIDE
;
125 virtual bool IsOffscreen() OVERRIDE
;
126 virtual bool SwapBuffers() OVERRIDE
;
127 virtual gfx::Size
GetSize() OVERRIDE
;
128 virtual bool Resize(const gfx::Size
& size
) OVERRIDE
;
129 virtual EGLSurface
GetHandle() OVERRIDE
;
130 virtual void* GetShareHandle() OVERRIDE
;
133 virtual ~SurfacelessEGL();
137 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL
);
142 #endif // UI_GL_GL_SURFACE_EGL_H_