Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / gl / gl_surface_egl.h
blob2c0a046b2b52719d0e9484dd11c4b1c2b6212324
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_
8 #if defined(OS_WIN)
9 #include <windows.h>
10 #endif
12 #include <string>
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"
21 namespace gfx {
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 {
28 public:
29 GLSurfaceEGL();
31 // Implement GLSurface.
32 virtual 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();
46 protected:
47 virtual ~GLSurfaceEGL();
49 private:
50 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
53 // Encapsulates an EGL surface bound to a view.
54 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
55 public:
56 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
58 // Implement GLSurface.
59 virtual EGLConfig GetConfig() OVERRIDE;
60 virtual bool Initialize() OVERRIDE;
61 virtual void Destroy() OVERRIDE;
62 virtual bool Resize(const gfx::Size& size) OVERRIDE;
63 virtual bool Recreate() OVERRIDE;
64 virtual bool IsOffscreen() OVERRIDE;
65 virtual bool SwapBuffers() OVERRIDE;
66 virtual gfx::Size GetSize() OVERRIDE;
67 virtual EGLSurface GetHandle() OVERRIDE;
68 virtual bool SupportsPostSubBuffer() OVERRIDE;
69 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
70 virtual VSyncProvider* GetVSyncProvider() OVERRIDE;
72 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
73 // Takes ownership of the VSyncProvider.
74 virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
76 protected:
77 virtual ~NativeViewGLSurfaceEGL();
79 EGLNativeWindowType window_;
81 private:
82 EGLSurface surface_;
83 bool supports_post_sub_buffer_;
84 EGLConfig config_;
85 gfx::Size size_;
87 scoped_ptr<VSyncProvider> vsync_provider_;
89 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
92 // Encapsulates a pbuffer EGL surface.
93 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
94 public:
95 explicit PbufferGLSurfaceEGL(const gfx::Size& size);
97 // Implement GLSurface.
98 virtual EGLConfig GetConfig() OVERRIDE;
99 virtual bool Initialize() OVERRIDE;
100 virtual void Destroy() OVERRIDE;
101 virtual bool IsOffscreen() OVERRIDE;
102 virtual bool SwapBuffers() OVERRIDE;
103 virtual gfx::Size GetSize() OVERRIDE;
104 virtual bool Resize(const gfx::Size& size) OVERRIDE;
105 virtual EGLSurface GetHandle() OVERRIDE;
106 virtual void* GetShareHandle() OVERRIDE;
108 protected:
109 virtual ~PbufferGLSurfaceEGL();
111 private:
112 gfx::Size size_;
113 EGLSurface surface_;
115 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
118 // SurfacelessEGL is used as Offscreen surface when platform supports
119 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
120 // need to create a dummy EGLsurface in case we render to client API targets.
121 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
122 public:
123 explicit SurfacelessEGL(const gfx::Size& size);
125 // Implement GLSurface.
126 virtual EGLConfig GetConfig() OVERRIDE;
127 virtual bool Initialize() OVERRIDE;
128 virtual void Destroy() OVERRIDE;
129 virtual bool IsOffscreen() OVERRIDE;
130 virtual bool SwapBuffers() OVERRIDE;
131 virtual gfx::Size GetSize() OVERRIDE;
132 virtual bool Resize(const gfx::Size& size) OVERRIDE;
133 virtual EGLSurface GetHandle() OVERRIDE;
134 virtual void* GetShareHandle() OVERRIDE;
136 protected:
137 virtual ~SurfacelessEGL();
139 private:
140 gfx::Size size_;
141 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
144 } // namespace gfx
146 #endif // UI_GL_GL_SURFACE_EGL_H_