Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / gl / gl_surface_egl.h
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.
4
5 #ifndef UI_GL_GL_SURFACE_EGL_H_
6 #define UI_GL_GL_SURFACE_EGL_H_
7
8 #if defined(OS_WIN)
9 #include <windows.h>
10 #endif
11
12 #include <string>
13
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"
20
21 namespace gfx {
22
23 // Get default EGL display for GLSurfaceEGL (differs by platform).
24 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay();
25
26 // Interface for EGL surface.
27 class GL_EXPORT GLSurfaceEGL : public GLSurface {
28  public:
29   GLSurfaceEGL();
30
31   // Implement GLSurface.
32   EGLDisplay GetDisplay() override;
33
34   static bool InitializeOneOff();
35   static EGLDisplay GetHardwareDisplay();
36   static EGLNativeDisplayType GetNativeDisplay();
37
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();
45
46  protected:
47   ~GLSurfaceEGL() override;
48
49  private:
50 #if defined(OS_WIN)
51   static EGLDisplay GetPlatformDisplay(EGLNativeDisplayType native_display);
52 #endif
53
54   DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
55 };
56
57 // Encapsulates an EGL surface bound to a view.
58 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
59  public:
60   explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
61
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;
75
76   // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
77   // Takes ownership of the VSyncProvider.
78   virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
79
80  protected:
81   ~NativeViewGLSurfaceEGL() override;
82
83   EGLNativeWindowType window_;
84
85   virtual void SetSwapInterval(int interval) override;
86
87  private:
88   EGLSurface surface_;
89   bool supports_post_sub_buffer_;
90   EGLConfig config_;
91   gfx::Size size_;
92
93   scoped_ptr<VSyncProvider> vsync_provider_;
94
95   int swap_interval_;
96   unsigned int swap_generation_;
97   static unsigned int current_swap_generation_;
98
99   DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
100 };
101
102 // Encapsulates a pbuffer EGL surface.
103 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
104  public:
105   explicit PbufferGLSurfaceEGL(const gfx::Size& size);
106
107   // Implement GLSurface.
108   EGLConfig GetConfig() override;
109   bool Initialize() override;
110   void Destroy() override;
111   bool IsOffscreen() override;
112   bool SwapBuffers() override;
113   gfx::Size GetSize() override;
114   bool Resize(const gfx::Size& size) override;
115   EGLSurface GetHandle() override;
116   void* GetShareHandle() override;
117
118  protected:
119   ~PbufferGLSurfaceEGL() override;
120
121  private:
122   gfx::Size size_;
123   EGLSurface surface_;
124
125   DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
126 };
127
128 // SurfacelessEGL is used as Offscreen surface when platform supports
129 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
130 // need to create a dummy EGLsurface in case we render to client API targets.
131 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
132  public:
133   explicit SurfacelessEGL(const gfx::Size& size);
134
135   // Implement GLSurface.
136   EGLConfig GetConfig() override;
137   bool Initialize() override;
138   void Destroy() override;
139   bool IsOffscreen() override;
140   bool IsSurfaceless() const override;
141   bool SwapBuffers() override;
142   gfx::Size GetSize() override;
143   bool Resize(const gfx::Size& size) override;
144   EGLSurface GetHandle() override;
145   void* GetShareHandle() override;
146
147  protected:
148   ~SurfacelessEGL() override;
149
150  private:
151   gfx::Size size_;
152   DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
153 };
154
155 }  // namespace gfx
156
157 #endif  // UI_GL_GL_SURFACE_EGL_H_