| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GL_GL_SURFACE_H_ | 5 #ifndef UI_GL_GL_SURFACE_H_ |
| 6 #define UI_GL_GL_SURFACE_H_ | 6 #define UI_GL_GL_SURFACE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/rect_f.h" | 15 #include "ui/gfx/geometry/rect_f.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 18 #include "ui/gfx/overlay_transform.h" | 18 #include "ui/gfx/overlay_transform.h" |
| 19 #include "ui/gfx/swap_result.h" | 19 #include "ui/gfx/swap_result.h" |
| 20 #include "ui/gl/gl_export.h" | 20 #include "ui/gl/gl_export.h" |
| 21 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
| 22 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
| 23 #include "ui/gl/gl_surface_format.h" |
| 23 | 24 |
| 24 namespace gfx { | 25 namespace gfx { |
| 25 class VSyncProvider; | 26 class VSyncProvider; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 struct CARendererLayerParams; | 30 struct CARendererLayerParams; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace gl { | 33 namespace gl { |
| 33 | 34 |
| 34 class GLContext; | 35 class GLContext; |
| 35 | 36 |
| 36 // Encapsulates a surface that can be rendered to with GL, hiding platform | 37 // Encapsulates a surface that can be rendered to with GL, hiding platform |
| 37 // specific management. | 38 // specific management. |
| 38 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { | 39 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { |
| 39 public: | 40 public: |
| 40 GLSurface(); | 41 GLSurface(); |
| 41 | 42 |
| 42 // Minimum bit depth of surface. | 43 // Non-virtual initialization, this always calls Initialize with a |
| 43 enum Format { | 44 // default GLSurfaceFormat. Subclasses should override the format- |
| 44 SURFACE_ARGB8888, | 45 // specific Initialize method below and interpret the default format |
| 45 SURFACE_RGB565, | 46 // as appropriate. |
| 46 SURFACE_OSMESA_BGRA, | 47 bool Initialize(); |
| 47 SURFACE_OSMESA_RGBA, | |
| 48 SURFACE_SURFACELESS, | |
| 49 SURFACE_DEFAULT = SURFACE_ARGB8888 | |
| 50 }; | |
| 51 | 48 |
| 52 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the | 49 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the |
| 53 // EGL surface associated to be recreated without destroying the associated | 50 // EGL surface associated to be recreated without destroying the associated |
| 54 // context. The implementation of this function for other GLSurface derived | 51 // context. The implementation of this function for other GLSurface derived |
| 55 // classes is in a pending changelist. | 52 // classes is in a pending changelist. |
| 56 virtual bool Initialize(); | 53 virtual bool Initialize(GLSurfaceFormat format); |
| 57 virtual bool Initialize(GLSurface::Format format); | |
| 58 | 54 |
| 59 // Destroys the surface. | 55 // Destroys the surface. |
| 60 virtual void Destroy() = 0; | 56 virtual void Destroy() = 0; |
| 61 | 57 |
| 62 virtual bool Resize(const gfx::Size& size, | 58 virtual bool Resize(const gfx::Size& size, |
| 63 float scale_factor, | 59 float scale_factor, |
| 64 bool has_alpha); | 60 bool has_alpha); |
| 65 | 61 |
| 66 // Recreate the surface without changing the size. | 62 // Recreate the surface without changing the size. |
| 67 virtual bool Recreate(); | 63 virtual bool Recreate(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 virtual void* GetDisplay(); | 153 virtual void* GetDisplay(); |
| 158 | 154 |
| 159 // Get the platfrom specific configuration for this surface, if available. | 155 // Get the platfrom specific configuration for this surface, if available. |
| 160 virtual void* GetConfig(); | 156 virtual void* GetConfig(); |
| 161 | 157 |
| 162 // Get the key corresponding to the set of GLSurfaces that can be made current | 158 // Get the key corresponding to the set of GLSurfaces that can be made current |
| 163 // with this GLSurface. | 159 // with this GLSurface. |
| 164 virtual unsigned long GetCompatibilityKey(); | 160 virtual unsigned long GetCompatibilityKey(); |
| 165 | 161 |
| 166 // Get the GL pixel format of the surface, if available. | 162 // Get the GL pixel format of the surface, if available. |
| 167 virtual GLSurface::Format GetFormat(); | 163 virtual GLSurfaceFormat GetFormat(); |
| 168 | 164 |
| 169 // Get access to a helper providing time of recent refresh and period | 165 // Get access to a helper providing time of recent refresh and period |
| 170 // of screen refresh. If unavailable, returns NULL. | 166 // of screen refresh. If unavailable, returns NULL. |
| 171 virtual gfx::VSyncProvider* GetVSyncProvider(); | 167 virtual gfx::VSyncProvider* GetVSyncProvider(); |
| 172 | 168 |
| 173 // Schedule an overlay plane to be shown at swap time, or on the next | 169 // Schedule an overlay plane to be shown at swap time, or on the next |
| 174 // CommitOverlayPlanes call. | 170 // CommitOverlayPlanes call. |
| 175 // |z_order| specifies the stacking order of the plane relative to the | 171 // |z_order| specifies the stacking order of the plane relative to the |
| 176 // main framebuffer located at index 0. For the case where there is no | 172 // main framebuffer located at index 0. For the case where there is no |
| 177 // main framebuffer, overlays may be scheduled at 0, taking its place. | 173 // main framebuffer, overlays may be scheduled at 0, taking its place. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 223 |
| 228 DISALLOW_COPY_AND_ASSIGN(GLSurface); | 224 DISALLOW_COPY_AND_ASSIGN(GLSurface); |
| 229 }; | 225 }; |
| 230 | 226 |
| 231 // Implementation of GLSurface that forwards all calls through to another | 227 // Implementation of GLSurface that forwards all calls through to another |
| 232 // GLSurface. | 228 // GLSurface. |
| 233 class GL_EXPORT GLSurfaceAdapter : public GLSurface { | 229 class GL_EXPORT GLSurfaceAdapter : public GLSurface { |
| 234 public: | 230 public: |
| 235 explicit GLSurfaceAdapter(GLSurface* surface); | 231 explicit GLSurfaceAdapter(GLSurface* surface); |
| 236 | 232 |
| 237 bool Initialize(GLSurface::Format format) override; | 233 bool Initialize(GLSurfaceFormat format) override; |
| 238 void Destroy() override; | 234 void Destroy() override; |
| 239 bool Resize(const gfx::Size& size, | 235 bool Resize(const gfx::Size& size, |
| 240 float scale_factor, | 236 float scale_factor, |
| 241 bool has_alpha) override; | 237 bool has_alpha) override; |
| 242 bool Recreate() override; | 238 bool Recreate() override; |
| 243 bool DeferDraws() override; | 239 bool DeferDraws() override; |
| 244 bool IsOffscreen() override; | 240 bool IsOffscreen() override; |
| 245 gfx::SwapResult SwapBuffers() override; | 241 gfx::SwapResult SwapBuffers() override; |
| 246 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; | 242 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; |
| 247 gfx::SwapResult SwapBuffersWithDamage(int x, | 243 gfx::SwapResult SwapBuffersWithDamage(int x, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 264 gfx::Size GetSize() override; | 260 gfx::Size GetSize() override; |
| 265 void* GetHandle() override; | 261 void* GetHandle() override; |
| 266 unsigned int GetBackingFramebufferObject() override; | 262 unsigned int GetBackingFramebufferObject() override; |
| 267 bool OnMakeCurrent(GLContext* context) override; | 263 bool OnMakeCurrent(GLContext* context) override; |
| 268 bool SetBackbufferAllocation(bool allocated) override; | 264 bool SetBackbufferAllocation(bool allocated) override; |
| 269 void SetFrontbufferAllocation(bool allocated) override; | 265 void SetFrontbufferAllocation(bool allocated) override; |
| 270 void* GetShareHandle() override; | 266 void* GetShareHandle() override; |
| 271 void* GetDisplay() override; | 267 void* GetDisplay() override; |
| 272 void* GetConfig() override; | 268 void* GetConfig() override; |
| 273 unsigned long GetCompatibilityKey() override; | 269 unsigned long GetCompatibilityKey() override; |
| 274 GLSurface::Format GetFormat() override; | 270 GLSurfaceFormat GetFormat() override; |
| 275 gfx::VSyncProvider* GetVSyncProvider() override; | 271 gfx::VSyncProvider* GetVSyncProvider() override; |
| 276 bool ScheduleOverlayPlane(int z_order, | 272 bool ScheduleOverlayPlane(int z_order, |
| 277 gfx::OverlayTransform transform, | 273 gfx::OverlayTransform transform, |
| 278 GLImage* image, | 274 GLImage* image, |
| 279 const gfx::Rect& bounds_rect, | 275 const gfx::Rect& bounds_rect, |
| 280 const gfx::RectF& crop_rect) override; | 276 const gfx::RectF& crop_rect) override; |
| 281 bool IsSurfaceless() const override; | 277 bool IsSurfaceless() const override; |
| 282 bool FlipsVertically() const override; | 278 bool FlipsVertically() const override; |
| 283 bool BuffersFlipped() const override; | 279 bool BuffersFlipped() const override; |
| 284 | 280 |
| 285 GLSurface* surface() const { return surface_.get(); } | 281 GLSurface* surface() const { return surface_.get(); } |
| 286 | 282 |
| 287 protected: | 283 protected: |
| 288 ~GLSurfaceAdapter() override; | 284 ~GLSurfaceAdapter() override; |
| 289 | 285 |
| 290 private: | 286 private: |
| 291 scoped_refptr<GLSurface> surface_; | 287 scoped_refptr<GLSurface> surface_; |
| 292 | 288 |
| 293 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter); | 289 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter); |
| 294 }; | 290 }; |
| 295 | 291 |
| 296 // Wraps GLSurface in scoped_refptr and tries to initializes it. Returns a | 292 // Wraps GLSurface in scoped_refptr and tries to initializes it. Returns a |
| 297 // scoped_refptr containing the initialized GLSurface or nullptr if | 293 // scoped_refptr containing the initialized GLSurface or nullptr if |
| 298 // initialization fails. | 294 // initialization fails. |
| 299 GL_EXPORT scoped_refptr<GLSurface> InitializeGLSurface( | 295 GL_EXPORT scoped_refptr<GLSurface> InitializeGLSurface( |
| 300 scoped_refptr<GLSurface> surface); | 296 scoped_refptr<GLSurface> surface); |
| 301 | 297 |
| 298 GL_EXPORT scoped_refptr<GLSurface> InitializeGLSurfaceWithFormat( |
| 299 scoped_refptr<GLSurface> surface, GLSurfaceFormat format); |
| 300 |
| 302 } // namespace gl | 301 } // namespace gl |
| 303 | 302 |
| 304 #endif // UI_GL_GL_SURFACE_H_ | 303 #endif // UI_GL_GL_SURFACE_H_ |
| OLD | NEW |