| 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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 namespace gfx { | 30 namespace gfx { |
| 31 class Rect; | 31 class Rect; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 class CompositingIOSurfaceContext; | 36 class CompositingIOSurfaceContext; |
| 37 class CompositingIOSurfaceShaderPrograms; | 37 class CompositingIOSurfaceShaderPrograms; |
| 38 class CompositingIOSurfaceTransformer; | 38 class CompositingIOSurfaceTransformer; |
| 39 class RenderWidgetHostViewFrameSubscriber; | 39 class RenderWidgetHostViewFrameSubscriber; |
| 40 class RenderWidgetHostViewMac; |
| 40 | 41 |
| 41 // This class manages an OpenGL context and IOSurface for the accelerated | 42 // This class manages an OpenGL context and IOSurface for the accelerated |
| 42 // compositing code path. The GL context is attached to | 43 // compositing code path. The GL context is attached to |
| 43 // RenderWidgetHostViewCocoa for blitting the IOSurface. | 44 // RenderWidgetHostViewCocoa for blitting the IOSurface. |
| 44 class CompositingIOSurfaceMac { | 45 class CompositingIOSurfaceMac { |
| 45 public: | 46 public: |
| 46 // Passed to Create() to specify the ordering of the surface relative to the | 47 // Passed to Create() to specify the ordering of the surface relative to the |
| 47 // containing window. | 48 // containing window. |
| 48 enum SurfaceOrder { | 49 enum SurfaceOrder { |
| 49 SURFACE_ORDER_ABOVE_WINDOW = 0, | 50 SURFACE_ORDER_ABOVE_WINDOW = 0, |
| 50 SURFACE_ORDER_BELOW_WINDOW = 1, | 51 SURFACE_ORDER_BELOW_WINDOW = 1, |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 // Returns NULL if IOSurface support is missing or GL APIs fail. Specify in | 54 // Returns NULL if IOSurface support is missing or GL APIs fail. Specify in |
| 54 // |order| the desired ordering relationship of the surface to the containing | 55 // |order| the desired ordering relationship of the surface to the containing |
| 55 // window. | 56 // window. |
| 56 static CompositingIOSurfaceMac* Create(int window_number, | 57 static CompositingIOSurfaceMac* Create(int window_number, |
| 57 SurfaceOrder order); | 58 SurfaceOrder order); |
| 59 static CompositingIOSurfaceMac* Create( |
| 60 const scoped_refptr<CompositingIOSurfaceContext>& context); |
| 58 ~CompositingIOSurfaceMac(); | 61 ~CompositingIOSurfaceMac(); |
| 59 | 62 |
| 60 // Set IOSurface that will be drawn on the next NSView drawRect. | 63 // Set IOSurface that will be drawn on the next NSView drawRect. |
| 61 void SetIOSurface(uint64 io_surface_handle, | 64 void SetIOSurface(uint64 io_surface_handle, |
| 62 const gfx::Size& size, | 65 const gfx::Size& size, |
| 63 float scale_factor); | 66 float scale_factor); |
| 64 | 67 |
| 65 // Get the CGL renderer ID currently associated with this context. | 68 // Get the CGL renderer ID currently associated with this context. |
| 66 int GetRendererID(); | 69 int GetRendererID(); |
| 67 | 70 |
| 68 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window | 71 // Blit the IOSurface at the upper-left corner of the of the specified |
| 69 // size is larger than the IOSurface, the remaining right and bottom edges | 72 // window_size. If the window size is larger than the IOSurface, the |
| 70 // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views. | 73 // remaining right and bottom edges will be white. |scaleFactor| is 1 |
| 71 // |frame_subscriber| listens to this draw event and provides output buffer | 74 // in normal views, 2 in HiDPI views. |frame_subscriber| listens to |
| 72 // for copying this frame into. | 75 // this draw event and provides output buffer for copying this frame into. |
| 73 void DrawIOSurface(NSView* view, | 76 void DrawIOSurface(const gfx::Size& window_size, |
| 74 float scale_factor, | 77 float window_scale_factor, |
| 75 int window_number, | |
| 76 SurfaceOrder surface_order, | |
| 77 RenderWidgetHostViewFrameSubscriber* frame_subscriber); | 78 RenderWidgetHostViewFrameSubscriber* frame_subscriber); |
| 79 void DrawIOSurface(RenderWidgetHostViewMac* render_widget_host_view); |
| 78 | 80 |
| 79 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef | 81 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef |
| 80 // into |out|. The copied region is specified with |src_pixel_subrect| and | 82 // into |out|. The copied region is specified with |src_pixel_subrect| and |
| 81 // the data is transformed so that it fits in |dst_pixel_size|. | 83 // the data is transformed so that it fits in |dst_pixel_size|. |
| 82 // |src_pixel_subrect| and |dst_pixel_size| are not in DIP but in pixel. | 84 // |src_pixel_subrect| and |dst_pixel_size| are not in DIP but in pixel. |
| 83 // Caller must ensure that |out| is allocated to dimensions that match | 85 // Caller must ensure that |out| is allocated to dimensions that match |
| 84 // dst_pixel_size, with no additional padding. | 86 // dst_pixel_size, with no additional padding. |
| 85 // |callback| is invoked when the operation is completed or failed. | 87 // |callback| is invoked when the operation is completed or failed. |
| 86 // Do no call this method again before |callback| is invoked. | 88 // Do no call this method again before |callback| is invoked. |
| 87 void CopyTo(const gfx::Rect& src_pixel_subrect, | 89 void CopyTo(const gfx::Rect& src_pixel_subrect, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 106 // this to switch to software drawing mode. | 108 // this to switch to software drawing mode. |
| 107 void ClearDrawable(); | 109 void ClearDrawable(); |
| 108 | 110 |
| 109 bool HasIOSurface() { return !!io_surface_.get(); } | 111 bool HasIOSurface() { return !!io_surface_.get(); } |
| 110 | 112 |
| 111 const gfx::Size& pixel_io_surface_size() const { | 113 const gfx::Size& pixel_io_surface_size() const { |
| 112 return pixel_io_surface_size_; | 114 return pixel_io_surface_size_; |
| 113 } | 115 } |
| 114 // In cocoa view units / DIPs. | 116 // In cocoa view units / DIPs. |
| 115 const gfx::Size& dip_io_surface_size() const { return dip_io_surface_size_; } | 117 const gfx::Size& dip_io_surface_size() const { return dip_io_surface_size_; } |
| 118 float scale_factor() const { return scale_factor_; } |
| 116 | 119 |
| 117 bool is_vsync_disabled() const; | 120 bool is_vsync_disabled() const; |
| 118 | 121 |
| 122 const scoped_refptr<CompositingIOSurfaceContext>& context() { |
| 123 return context_; |
| 124 } |
| 125 |
| 119 // Get vsync scheduling parameters. | 126 // Get vsync scheduling parameters. |
| 120 // |interval_numerator/interval_denominator| equates to fractional number of | 127 // |interval_numerator/interval_denominator| equates to fractional number of |
| 121 // seconds between vsyncs. | 128 // seconds between vsyncs. |
| 122 void GetVSyncParameters(base::TimeTicks* timebase, | 129 void GetVSyncParameters(base::TimeTicks* timebase, |
| 123 uint32* interval_numerator, | 130 uint32* interval_numerator, |
| 124 uint32* interval_denominator); | 131 uint32* interval_denominator); |
| 125 | 132 |
| 126 // Returns true if asynchronous readback is supported on this system. | 133 // Returns true if asynchronous readback is supported on this system. |
| 127 bool IsAsynchronousReadbackSupported(); | 134 bool IsAsynchronousReadbackSupported(); |
| 128 | 135 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 GLuint frame_buffers[3]; | 222 GLuint frame_buffers[3]; |
| 216 GLuint pixel_buffers[3]; | 223 GLuint pixel_buffers[3]; |
| 217 GLuint fence; // When non-zero, doing an asynchronous copy. | 224 GLuint fence; // When non-zero, doing an asynchronous copy. |
| 218 int cycles_elapsed; | 225 int cycles_elapsed; |
| 219 base::Callback<bool(const void*, int)> map_buffer_callback; | 226 base::Callback<bool(const void*, int)> map_buffer_callback; |
| 220 base::Callback<void(bool)> done_callback; | 227 base::Callback<void(bool)> done_callback; |
| 221 }; | 228 }; |
| 222 | 229 |
| 223 CompositingIOSurfaceMac( | 230 CompositingIOSurfaceMac( |
| 224 IOSurfaceSupport* io_surface_support, | 231 IOSurfaceSupport* io_surface_support, |
| 225 scoped_refptr<CompositingIOSurfaceContext> context); | 232 const scoped_refptr<CompositingIOSurfaceContext>& context); |
| 226 | 233 |
| 227 void SetupCVDisplayLink(); | 234 void SetupCVDisplayLink(); |
| 228 | 235 |
| 229 // If this IOSurface has moved to a different window, use that window's | 236 // If this IOSurface has moved to a different window, use that window's |
| 230 // GL context (if multiple visible windows are using the same GL context | 237 // GL context (if multiple visible windows are using the same GL context |
| 231 // then call to setView call can stall and prevent reaching 60fps). | 238 // then call to setView call can stall and prevent reaching 60fps). |
| 232 void SwitchToContextOnNewWindow(NSView* view, | 239 void SwitchToContextOnNewWindow(NSView* view, |
| 233 int window_number, | 240 int window_number, |
| 234 SurfaceOrder surface_order); | 241 SurfaceOrder surface_order); |
| 235 | 242 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // moving between windows, but will never be NULL. | 315 // moving between windows, but will never be NULL. |
| 309 scoped_refptr<CompositingIOSurfaceContext> context_; | 316 scoped_refptr<CompositingIOSurfaceContext> context_; |
| 310 | 317 |
| 311 // IOSurface data. | 318 // IOSurface data. |
| 312 uint64 io_surface_handle_; | 319 uint64 io_surface_handle_; |
| 313 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; | 320 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; |
| 314 | 321 |
| 315 // The width and height of the io surface. | 322 // The width and height of the io surface. |
| 316 gfx::Size pixel_io_surface_size_; // In pixels. | 323 gfx::Size pixel_io_surface_size_; // In pixels. |
| 317 gfx::Size dip_io_surface_size_; // In view / density independent pixels. | 324 gfx::Size dip_io_surface_size_; // In view / density independent pixels. |
| 325 float scale_factor_; |
| 318 | 326 |
| 319 // The "live" OpenGL texture referring to this IOSurfaceRef. Note | 327 // The "live" OpenGL texture referring to this IOSurfaceRef. Note |
| 320 // that per the CGLTexImageIOSurface2D API we do not need to | 328 // that per the CGLTexImageIOSurface2D API we do not need to |
| 321 // explicitly update this texture's contents once created. All we | 329 // explicitly update this texture's contents once created. All we |
| 322 // need to do is ensure it is re-bound before attempting to draw | 330 // need to do is ensure it is re-bound before attempting to draw |
| 323 // with it. | 331 // with it. |
| 324 GLuint texture_; | 332 GLuint texture_; |
| 325 | 333 |
| 326 // A pool of CopyContexts with OpenGL objects ready for re-use. Prefer to | 334 // A pool of CopyContexts with OpenGL objects ready for re-use. Prefer to |
| 327 // pull one from the pool before creating a new CopyContext. | 335 // pull one from the pool before creating a new CopyContext. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 352 uint32 vsync_interval_denominator_; | 360 uint32 vsync_interval_denominator_; |
| 353 | 361 |
| 354 bool initialized_is_intel_; | 362 bool initialized_is_intel_; |
| 355 bool is_intel_; | 363 bool is_intel_; |
| 356 GLint screen_; | 364 GLint screen_; |
| 357 }; | 365 }; |
| 358 | 366 |
| 359 } // namespace content | 367 } // namespace content |
| 360 | 368 |
| 361 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 369 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| OLD | NEW |