Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / ui / gl / gl_surface_glx.h
blobc1fca6006a1726b5971bd0494d284220ad61e22d
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_GLX_H_
6 #define UI_GL_GL_SURFACE_GLX_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "ui/events/platform/platform_event_dispatcher.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/gfx/vsync_provider.h"
15 #include "ui/gfx/x/x11_types.h"
16 #include "ui/gl/gl_export.h"
17 #include "ui/gl/gl_surface.h"
19 namespace gfx {
21 // Base class for GLX surfaces.
22 class GL_EXPORT GLSurfaceGLX : public GLSurface {
23 public:
24 GLSurfaceGLX();
26 static bool InitializeOneOff();
28 // These aren't particularly tied to surfaces, but since we already
29 // have the static InitializeOneOff here, it's easiest to reuse its
30 // initialization guards.
31 static const char* GetGLXExtensions();
32 static bool HasGLXExtension(const char* name);
33 static bool IsCreateContextSupported();
34 static bool IsCreateContextRobustnessSupported();
35 static bool IsTextureFromPixmapSupported();
36 static bool IsOMLSyncControlSupported();
38 void* GetDisplay() override;
40 // Get the FB config that the surface was created with or NULL if it is not
41 // a GLX drawable.
42 void* GetConfig() override = 0;
44 protected:
45 ~GLSurfaceGLX() override;
47 private:
48 DISALLOW_COPY_AND_ASSIGN(GLSurfaceGLX);
51 // A surface used to render to a view.
52 class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX,
53 public ui::PlatformEventDispatcher {
54 public:
55 explicit NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window);
57 // Implement GLSurfaceGLX.
58 bool Initialize() override;
59 void Destroy() override;
60 bool Resize(const gfx::Size& size) override;
61 bool IsOffscreen() override;
62 bool SwapBuffers() override;
63 gfx::Size GetSize() override;
64 void* GetHandle() override;
65 bool SupportsPostSubBuffer() override;
66 void* GetConfig() override;
67 bool PostSubBuffer(int x, int y, int width, int height) override;
68 VSyncProvider* GetVSyncProvider() override;
70 protected:
71 ~NativeViewGLSurfaceGLX() override;
73 private:
74 // The handle for the drawable to make current or swap.
75 gfx::AcceleratedWidget GetDrawableHandle() const;
77 // PlatformEventDispatcher implementation
78 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
79 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
81 // Window passed in at creation. Always valid.
82 gfx::AcceleratedWidget parent_window_;
84 // Child window, used to control resizes so that they're in-order with GL.
85 gfx::AcceleratedWidget window_;
87 void* config_;
88 gfx::Size size_;
90 scoped_ptr<VSyncProvider> vsync_provider_;
92 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLX);
95 // A surface used to render to an offscreen pbuffer.
96 class GL_EXPORT PbufferGLSurfaceGLX : public GLSurfaceGLX {
97 public:
98 explicit PbufferGLSurfaceGLX(const gfx::Size& size);
100 // Implement GLSurfaceGLX.
101 bool Initialize() override;
102 void Destroy() override;
103 bool IsOffscreen() override;
104 bool SwapBuffers() override;
105 gfx::Size GetSize() override;
106 void* GetHandle() override;
107 void* GetConfig() override;
109 protected:
110 ~PbufferGLSurfaceGLX() override;
112 private:
113 gfx::Size size_;
114 void* config_;
115 XID pbuffer_;
117 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceGLX);
120 } // namespace gfx
122 #endif // UI_GL_GL_SURFACE_GLX_H_