Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / ui / gl / gl_surface.h
blob54bcc37174c32fdb52726d2f7a4a4c7d06e17e1c
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_H_
6 #define UI_GL_GL_SURFACE_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "build/build_config.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/gfx/overlay_transform.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/rect_f.h"
16 #include "ui/gfx/size.h"
17 #include "ui/gl/gl_export.h"
18 #include "ui/gl/gl_implementation.h"
20 namespace gfx {
22 class GLContext;
23 class GLImage;
24 class VSyncProvider;
26 // Encapsulates a surface that can be rendered to with GL, hiding platform
27 // specific management.
28 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> {
29 public:
30 GLSurface();
32 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the
33 // EGL surface associated to be recreated without destroying the associated
34 // context. The implementation of this function for other GLSurface derived
35 // classes is in a pending changelist.
36 virtual bool Initialize();
38 // Destroys the surface.
39 virtual void Destroy() = 0;
41 virtual bool Resize(const gfx::Size& size);
43 // Recreate the surface without changing the size.
44 virtual bool Recreate();
46 // Unschedule the GpuScheduler and return true to abort the processing of
47 // a GL draw call to this surface and defer it until the GpuScheduler is
48 // rescheduled.
49 virtual bool DeferDraws();
51 // Returns true if this surface is offscreen.
52 virtual bool IsOffscreen() = 0;
54 // Swaps front and back buffers. This has no effect for off-screen
55 // contexts.
56 virtual bool SwapBuffers() = 0;
58 // Get the size of the surface.
59 virtual gfx::Size GetSize() = 0;
61 // Get the underlying platform specific surface "handle".
62 virtual void* GetHandle() = 0;
64 // Returns whether or not the surface supports PostSubBuffer.
65 virtual bool SupportsPostSubBuffer();
67 // Returns the internal frame buffer object name if the surface is backed by
68 // FBO. Otherwise returns 0.
69 virtual unsigned int GetBackingFrameBufferObject();
71 // Copy part of the backbuffer to the frontbuffer.
72 virtual bool PostSubBuffer(int x, int y, int width, int height);
74 // Initialize GL bindings.
75 static bool InitializeOneOff();
77 // Unit tests should call these instead of InitializeOneOff() to set up
78 // GL bindings appropriate for tests.
79 static void InitializeOneOffForTests();
80 static void InitializeOneOffWithMockBindingsForTests();
81 static void InitializeDynamicMockBindingsForTests(GLContext* context);
83 // Called after a context is made current with this surface. Returns false
84 // on error.
85 virtual bool OnMakeCurrent(GLContext* context);
87 // Used for explicit buffer management.
88 virtual bool SetBackbufferAllocation(bool allocated);
89 virtual void SetFrontbufferAllocation(bool allocated);
91 // Get a handle used to share the surface with another process. Returns null
92 // if this is not possible.
93 virtual void* GetShareHandle();
95 // Get the platform specific display on which this surface resides, if
96 // available.
97 virtual void* GetDisplay();
99 // Get the platfrom specific configuration for this surface, if available.
100 virtual void* GetConfig();
102 // Get the GL pixel format of the surface, if available.
103 virtual unsigned GetFormat();
105 // Get access to a helper providing time of recent refresh and period
106 // of screen refresh. If unavailable, returns NULL.
107 virtual VSyncProvider* GetVSyncProvider();
109 // Schedule an overlay plane to be shown at swap time.
110 // |z_order| specifies the stacking order of the plane relative to the
111 // main framebuffer located at index 0. For the case where there is no
112 // main framebuffer, overlays may be scheduled at 0, taking its place.
113 // |transform| specifies how the buffer is to be transformed during
114 // composition.
115 // |image| to be presented by the overlay.
116 // |bounds_rect| specify where it is supposed to be on the screen in pixels.
117 // |crop_rect| specifies the region within the buffer to be placed inside
118 // |bounds_rect|.
119 virtual bool ScheduleOverlayPlane(int z_order,
120 OverlayTransform transform,
121 GLImage* image,
122 const Rect& bounds_rect,
123 const RectF& crop_rect);
125 virtual bool IsSurfaceless() const;
127 // Create a GL surface that renders directly to a view.
128 static scoped_refptr<GLSurface> CreateViewGLSurface(
129 gfx::AcceleratedWidget window);
131 // Create a GL surface used for offscreen rendering.
132 static scoped_refptr<GLSurface> CreateOffscreenGLSurface(
133 const gfx::Size& size);
135 static GLSurface* GetCurrent();
137 protected:
138 virtual ~GLSurface();
139 static bool InitializeOneOffImplementation(GLImplementation impl,
140 bool fallback_to_osmesa,
141 bool gpu_service_logging,
142 bool disable_gl_drawing);
143 static bool InitializeOneOffInternal();
144 static void SetCurrent(GLSurface* surface);
146 static bool ExtensionsContain(const char* extensions, const char* name);
148 private:
149 friend class base::RefCounted<GLSurface>;
150 friend class GLContext;
152 DISALLOW_COPY_AND_ASSIGN(GLSurface);
155 // Implementation of GLSurface that forwards all calls through to another
156 // GLSurface.
157 class GL_EXPORT GLSurfaceAdapter : public GLSurface {
158 public:
159 explicit GLSurfaceAdapter(GLSurface* surface);
161 bool Initialize() override;
162 void Destroy() override;
163 bool Resize(const gfx::Size& size) override;
164 bool Recreate() override;
165 bool DeferDraws() override;
166 bool IsOffscreen() override;
167 bool SwapBuffers() override;
168 bool PostSubBuffer(int x, int y, int width, int height) override;
169 bool SupportsPostSubBuffer() override;
170 gfx::Size GetSize() override;
171 void* GetHandle() override;
172 unsigned int GetBackingFrameBufferObject() override;
173 bool OnMakeCurrent(GLContext* context) override;
174 bool SetBackbufferAllocation(bool allocated) override;
175 void SetFrontbufferAllocation(bool allocated) override;
176 void* GetShareHandle() override;
177 void* GetDisplay() override;
178 void* GetConfig() override;
179 unsigned GetFormat() override;
180 VSyncProvider* GetVSyncProvider() override;
181 bool ScheduleOverlayPlane(int z_order,
182 OverlayTransform transform,
183 GLImage* image,
184 const Rect& bounds_rect,
185 const RectF& crop_rect) override;
186 bool IsSurfaceless() const override;
188 GLSurface* surface() const { return surface_.get(); }
190 protected:
191 ~GLSurfaceAdapter() override;
193 private:
194 scoped_refptr<GLSurface> surface_;
196 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter);
199 } // namespace gfx
201 #endif // UI_GL_GL_SURFACE_H_