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