Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / ui / gl / gl_surface_egl.h
blob21669d74bb7f25fed815618c829620832494d650
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/geometry/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 void DestroyAndTerminateDisplay() override;
33 EGLDisplay GetDisplay() override;
35 static bool InitializeOneOff();
36 static EGLDisplay GetHardwareDisplay();
37 static EGLNativeDisplayType GetNativeDisplay();
39 // These aren't particularly tied to surfaces, but since we already
40 // have the static InitializeOneOff here, it's easiest to reuse its
41 // initialization guards.
42 static const char* GetEGLExtensions();
43 static bool HasEGLExtension(const char* name);
44 static bool IsCreateContextRobustnessSupported();
45 static bool IsEGLSurfacelessContextSupported();
47 protected:
48 ~GLSurfaceEGL() override;
50 private:
51 #if defined(OS_WIN)
52 friend struct DriverEGL;
53 static EGLDisplay GetPlatformDisplay(EGLNativeDisplayType native_display);
54 #endif
56 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
59 // Encapsulates an EGL surface bound to a view.
60 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
61 public:
62 explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
64 // Implement GLSurface.
65 EGLConfig GetConfig() override;
66 bool Initialize() override;
67 void Destroy() override;
68 bool Resize(const gfx::Size& size) override;
69 bool Recreate() override;
70 bool IsOffscreen() override;
71 bool SwapBuffers() override;
72 gfx::Size GetSize() override;
73 EGLSurface GetHandle() override;
74 bool SupportsPostSubBuffer() override;
75 bool PostSubBuffer(int x, int y, int width, int height) override;
76 VSyncProvider* GetVSyncProvider() override;
78 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
79 // Takes ownership of the VSyncProvider.
80 virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
82 protected:
83 ~NativeViewGLSurfaceEGL() override;
85 EGLNativeWindowType window_;
87 void OnSetSwapInterval(int interval) override;
89 private:
90 EGLSurface surface_;
91 bool supports_post_sub_buffer_;
92 EGLConfig config_;
93 gfx::Size size_;
95 scoped_ptr<VSyncProvider> vsync_provider_;
97 int swap_interval_;
99 #if defined(OS_WIN)
100 bool vsync_override_;
102 unsigned int swap_generation_;
103 static unsigned int current_swap_generation_;
104 static unsigned int swaps_this_generation_;
105 static unsigned int last_multiswap_generation_;
106 #endif
108 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
111 // Encapsulates a pbuffer EGL surface.
112 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
113 public:
114 explicit PbufferGLSurfaceEGL(const gfx::Size& size);
116 // Implement GLSurface.
117 EGLConfig GetConfig() override;
118 bool Initialize() override;
119 void Destroy() override;
120 bool IsOffscreen() override;
121 bool SwapBuffers() override;
122 gfx::Size GetSize() override;
123 bool Resize(const gfx::Size& size) override;
124 EGLSurface GetHandle() override;
125 void* GetShareHandle() override;
127 protected:
128 ~PbufferGLSurfaceEGL() override;
130 private:
131 gfx::Size size_;
132 EGLSurface surface_;
134 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
137 // SurfacelessEGL is used as Offscreen surface when platform supports
138 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
139 // need to create a dummy EGLsurface in case we render to client API targets.
140 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
141 public:
142 explicit SurfacelessEGL(const gfx::Size& size);
144 // Implement GLSurface.
145 EGLConfig GetConfig() override;
146 bool Initialize() override;
147 void Destroy() override;
148 bool IsOffscreen() override;
149 bool IsSurfaceless() const override;
150 bool SwapBuffers() override;
151 gfx::Size GetSize() override;
152 bool Resize(const gfx::Size& size) override;
153 EGLSurface GetHandle() override;
154 void* GetShareHandle() override;
156 protected:
157 ~SurfacelessEGL() override;
159 private:
160 gfx::Size size_;
161 DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
164 } // namespace gfx
166 #endif // UI_GL_GL_SURFACE_EGL_H_