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_;
84 scoped_ptr<VSyncProvider> vsync_provider_;
86 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
89 // Encapsulates a pbuffer EGL surface.
90 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
92 explicit PbufferGLSurfaceEGL(const gfx::Size& size);
94 // Implement GLSurface.
95 virtual EGLConfig GetConfig() OVERRIDE;
96 virtual bool Initialize() OVERRIDE;
97 virtual void Destroy() OVERRIDE;
98 virtual bool IsOffscreen() OVERRIDE;
99 virtual bool SwapBuffers() OVERRIDE;
100 virtual gfx::Size GetSize() OVERRIDE;
101 virtual bool Resize(const gfx::Size& size) OVERRIDE;
102 virtual EGLSurface GetHandle() OVERRIDE;
103 virtual void* GetShareHandle() OVERRIDE;
106 virtual ~PbufferGLSurfaceEGL();
112 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
115 // SurfacelessEGL is used as Offscreen surface when platform supports
116 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
117 // need to create a dummy EGLsurface in case we render to client API targets.
118 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
120 explicit SurfacelessEGL(const gfx::Size& size);
122 // Implement GLSurface.
123 virtual EGLConfig GetConfig() OVERRIDE;
124 virtual bool Initialize() OVERRIDE;
125 virtual void Destroy() OVERRIDE;
126 virtual bool IsOffscreen() OVERRIDE;
127 virtual bool SwapBuffers() OVERRIDE;
128 virtual gfx::Size GetSize() OVERRIDE;
129 virtual bool Resize(const gfx::Size& size) OVERRIDE;
130 virtual EGLSurface GetHandle() OVERRIDE;
131 virtual void* GetShareHandle() OVERRIDE;
134 virtual ~SurfacelessEGL();
138 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
143 #endif // UI_GL_GL_SURFACE_EGL_H_