Chromium Code Reviews| Index: content/browser/renderer_host/compositing_iosurface_mac.mm |
| diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm |
| index 131a947f91054e58bb7f5859d9724ac30d482cac..c325631274bebb3b413dd2c0b6ae071549a2597c 100644 |
| --- a/content/browser/renderer_host/compositing_iosurface_mac.mm |
| +++ b/content/browser/renderer_host/compositing_iosurface_mac.mm |
| @@ -13,6 +13,7 @@ |
| #include "base/message_loop.h" |
| #include "base/threading/platform_thread.h" |
| #include "content/common/content_constants_internal.h" |
| +#include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
| #include "gpu/command_buffer/service/gpu_switches.h" |
| #include "media/base/video_util.h" |
| #include "ui/gfx/rect.h" |
| @@ -348,7 +349,9 @@ void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle, |
| CGLSetCurrentContext(0); |
| } |
| -void CompositingIOSurfaceMac::DrawIOSurface(NSView* view, float scale_factor) { |
| +void CompositingIOSurfaceMac::DrawIOSurface( |
| + NSView* view, float scale_factor, |
| + RenderWidgetHostViewFrameSubscriber* frame_subscriber) { |
| CGLSetCurrentContext(cglContext_); |
| bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_); |
| @@ -449,6 +452,19 @@ void CompositingIOSurfaceMac::DrawIOSurface(NSView* view, float scale_factor) { |
| glFinish(); |
| } |
| + base::Closure copy_done_cb; |
|
Nico
2013/03/04 08:35:22
nit: style guide says "no abbreviations"
Alpha Left Google
2013/03/04 18:43:18
okay, done.
Alpha Left Google
2013/03/04 18:43:18
Done.
|
| + if (frame_subscriber) { |
| + scoped_refptr<media::VideoFrame> frame; |
| + RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
| + bool should_copy = frame_subscriber->ShouldCaptureFrame(&frame, &callback); |
| + |
| + if (should_copy) { |
| + copy_done_cb = CopyToVideoFrameInternal( |
| + gfx::Rect(io_surface_size_), scale_factor, frame, |
| + base::Bind(callback, base::Time::Now())); |
| + } |
| + } |
| + |
| CGLFlushDrawable(cglContext_); |
| // For latency_tests.cc: |
| @@ -456,6 +472,9 @@ void CompositingIOSurfaceMac::DrawIOSurface(NSView* view, float scale_factor) { |
| CGLSetCurrentContext(0); |
| + if (!copy_done_cb.is_null()) |
| + copy_done_cb.Run(); |
| + |
| StartOrContinueDisplayLink(); |
| if (!is_vsync_disabled_) |
| @@ -504,7 +523,21 @@ void CompositingIOSurfaceMac::CopyToVideoFrame( |
| const scoped_refptr<media::VideoFrame>& target, |
| const base::Callback<void(bool)>& callback) { |
| CGLSetCurrentContext(cglContext_); |
| + base::Closure done_callback = CopyToVideoFrameInternal(requested_src_subrect, |
| + src_scale_factor, |
| + target, callback); |
| + CGLSetCurrentContext(0); |
| + |
| + if (done_callback.is_null()) |
| + return; |
| + done_callback.Run(); |
| +} |
| +base::Closure CompositingIOSurfaceMac::CopyToVideoFrameInternal( |
| + const gfx::Rect& requested_src_subrect, |
| + float src_scale_factor, |
| + const scoped_refptr<media::VideoFrame>& target, |
| + const base::Callback<void(bool)>& callback) { |
| // Using PBO crashes on Intel drivers but not on newer Mountain Lion |
| // systems. See bug http://crbug.com/152225. |
| const bool async_copy = HasPixelBufferObjectExtension() && |
| @@ -546,18 +579,21 @@ void CompositingIOSurfaceMac::CopyToVideoFrame( |
| } |
| } |
| - CGLSetCurrentContext(0); |
|
Nico
2013/03/04 08:35:22
Why is this no longer needed?
Alpha Left Google
2013/03/04 18:43:18
CopyVideoFrameInternal() should now always be call
|
| - |
| if (!ret) { |
| VLOG(1) << "Failed to copy IOSurface to video frame, asynchronous mode: " |
| << async_copy; |
| } |
| if (async_copy) { |
| + // Asynchronous copy failed, return a callback to be executed now. |
| if (!ret) |
| - callback.Run(false); |
| + return base::Bind(callback, false); |
| + |
| + // Asynchornous copy started, return a null closure. |
|
Nico
2013/03/04 08:35:22
spelling
|
| + return base::Closure(); |
| } else { |
| - callback.Run(ret); |
| + // Synchronous copy, return a callback to be executed now. |
| + return base::Bind(callback, ret); |
| } |
| } |