[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gl / gl_surface_glx.h
blob1db5e4c72e3da142e0c198d6791c4083876b2b48
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 static void* GetConfig(gfx::AcceleratedWidget window);
49 private:
50 DISALLOW_COPY_AND_ASSIGN(GLSurfaceGLX);
53 // A surface used to render to a view.
54 class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX,
55 public ui::PlatformEventDispatcher {
56 public:
57 explicit NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window);
59 // Implement GLSurfaceGLX.
60 bool Initialize() override;
61 void Destroy() override;
62 bool Resize(const gfx::Size& size) override;
63 bool IsOffscreen() override;
64 gfx::SwapResult SwapBuffers() override;
65 gfx::Size GetSize() override;
66 void* GetHandle() override;
67 bool SupportsPostSubBuffer() override;
68 void* GetConfig() override;
69 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override;
70 VSyncProvider* GetVSyncProvider() override;
72 protected:
73 ~NativeViewGLSurfaceGLX() override;
75 private:
76 // The handle for the drawable to make current or swap.
77 gfx::AcceleratedWidget GetDrawableHandle() const;
79 // PlatformEventDispatcher implementation
80 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
81 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
83 // Window passed in at creation. Always valid.
84 gfx::AcceleratedWidget parent_window_;
86 // Child window, used to control resizes so that they're in-order with GL.
87 gfx::AcceleratedWidget window_;
89 void* config_;
90 gfx::Size size_;
92 scoped_ptr<VSyncProvider> vsync_provider_;
94 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLX);
97 // A surface used to render to an offscreen pbuffer.
98 class GL_EXPORT UnmappedNativeViewGLSurfaceGLX : public GLSurfaceGLX {
99 public:
100 explicit UnmappedNativeViewGLSurfaceGLX(const gfx::Size& size);
102 // Implement GLSurfaceGLX.
103 bool Initialize() override;
104 void Destroy() override;
105 bool IsOffscreen() override;
106 gfx::SwapResult SwapBuffers() override;
107 gfx::Size GetSize() override;
108 void* GetHandle() override;
109 void* GetConfig() override;
111 protected:
112 ~UnmappedNativeViewGLSurfaceGLX() override;
114 private:
115 gfx::Size size_;
116 void* config_;
117 // Unmapped dummy window, used to provide a compatible surface.
118 gfx::AcceleratedWidget window_;
120 DISALLOW_COPY_AND_ASSIGN(UnmappedNativeViewGLSurfaceGLX);
123 } // namespace gfx
125 #endif // UI_GL_GL_SURFACE_GLX_H_