Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 418283003: "Buttery Smooth" Tab Capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now pixel-weighted. Lots of add'l unit tests. (rebased against ToT) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" 63 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h"
64 #import "third_party/mozilla/ComplexTextInputPanel.h" 64 #import "third_party/mozilla/ComplexTextInputPanel.h"
65 #include "ui/base/cocoa/animation_utils.h" 65 #include "ui/base/cocoa/animation_utils.h"
66 #import "ui/base/cocoa/fullscreen_window_manager.h" 66 #import "ui/base/cocoa/fullscreen_window_manager.h"
67 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 67 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
68 #include "ui/events/keycodes/keyboard_codes.h" 68 #include "ui/events/keycodes/keyboard_codes.h"
69 #include "ui/base/layout.h" 69 #include "ui/base/layout.h"
70 #include "ui/compositor/compositor.h" 70 #include "ui/compositor/compositor.h"
71 #include "ui/compositor/layer.h" 71 #include "ui/compositor/layer.h"
72 #include "ui/gfx/display.h" 72 #include "ui/gfx/display.h"
73 #include "ui/gfx/frame_time.h"
73 #include "ui/gfx/point.h" 74 #include "ui/gfx/point.h"
74 #include "ui/gfx/rect_conversions.h" 75 #include "ui/gfx/rect_conversions.h"
75 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 76 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
76 #include "ui/gfx/screen.h" 77 #include "ui/gfx/screen.h"
77 #include "ui/gfx/size_conversions.h" 78 #include "ui/gfx/size_conversions.h"
78 #include "ui/gl/gl_switches.h" 79 #include "ui/gl/gl_switches.h"
79 80
80 using content::BrowserAccessibility; 81 using content::BrowserAccessibility;
81 using content::BrowserAccessibilityManager; 82 using content::BrowserAccessibilityManager;
82 using content::EditCommand; 83 using content::EditCommand;
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // Note that on some headless systems, the display link will fail to be 845 // Note that on some headless systems, the display link will fail to be
845 // created, so this should not be a fatal error. 846 // created, so this should not be a fatal error.
846 LOG(ERROR) << "Failed to create display link."; 847 LOG(ERROR) << "Failed to create display link.";
847 } 848 }
848 } 849 }
849 850
850 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { 851 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() {
851 if (!render_widget_host_ || !display_link_) 852 if (!render_widget_host_ || !display_link_)
852 return; 853 return;
853 854
854 base::TimeTicks timebase; 855 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) {
855 base::TimeDelta interval; 856 vsync_timebase_ = base::TimeTicks();
856 if (!display_link_->GetVSyncParameters(&timebase, &interval)) 857 vsync_interval_ = base::TimeDelta();
857 return; 858 return;
859 }
858 860
859 render_widget_host_->UpdateVSyncParameters(timebase, interval); 861 render_widget_host_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_);
860 } 862 }
861 863
862 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() { 864 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() {
863 if (!render_widget_host_) 865 if (!render_widget_host_)
864 return; 866 return;
865 867
866 float new_scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_); 868 float new_scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_);
867 if (new_scale_factor == backing_store_scale_factor_) 869 if (new_scale_factor == backing_store_scale_factor_)
868 return; 870 return;
869 backing_store_scale_factor_ = new_scale_factor; 871 backing_store_scale_factor_ = new_scale_factor;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( 1410 void RenderWidgetHostViewMac::PluginImeCompositionCompleted(
1409 const base::string16& text, int plugin_id) { 1411 const base::string16& text, int plugin_id) {
1410 if (render_widget_host_) { 1412 if (render_widget_host_) {
1411 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1413 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1412 render_widget_host_->GetRoutingID(), text, plugin_id)); 1414 render_widget_host_->GetRoutingID(), text, plugin_id));
1413 } 1415 }
1414 } 1416 }
1415 1417
1416 void RenderWidgetHostViewMac::CompositorSwapBuffers( 1418 void RenderWidgetHostViewMac::CompositorSwapBuffers(
1417 IOSurfaceID surface_handle, 1419 IOSurfaceID surface_handle,
1420 const gfx::Rect& damage_rect,
1418 const gfx::Size& size, 1421 const gfx::Size& size,
1419 float surface_scale_factor, 1422 float surface_scale_factor,
1420 const std::vector<ui::LatencyInfo>& latency_info) { 1423 const std::vector<ui::LatencyInfo>& latency_info) {
1421 // Ensure that the frame be acked unless it is explicitly passed to a 1424 // Ensure that the frame be acked unless it is explicitly passed to a
1422 // display function. 1425 // display function.
1423 base::ScopedClosureRunner scoped_ack( 1426 base::ScopedClosureRunner scoped_ack(
1424 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, 1427 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck,
1425 weak_factory_.GetWeakPtr())); 1428 weak_factory_.GetWeakPtr()));
1426 1429
1427 if (render_widget_host_->is_hidden()) 1430 if (render_widget_host_->is_hidden())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; 1469 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac";
1467 return; 1470 return;
1468 } 1471 }
1469 } 1472 }
1470 1473
1471 // Grab video frames now that the IOSurface has been set up. Note that this 1474 // Grab video frames now that the IOSurface has been set up. Note that this
1472 // will be done in an offscreen context, so it is necessary to re-set the 1475 // will be done in an offscreen context, so it is necessary to re-set the
1473 // current context afterward. 1476 // current context afterward.
1474 bool frame_was_captured = false; 1477 bool frame_was_captured = false;
1475 if (frame_subscriber_) { 1478 if (frame_subscriber_) {
1476 const base::TimeTicks present_time = base::TimeTicks::Now(); 1479 const base::TimeTicks now = gfx::FrameTime::Now();
1480 base::TimeTicks present_time;
1481 if (vsync_timebase_.is_null() || vsync_interval_ <= base::TimeDelta()) {
1482 present_time = now;
1483 } else {
1484 const int64 intervals_elapsed = (now - vsync_timebase_) / vsync_interval_;
1485 present_time = vsync_timebase_ +
1486 (intervals_elapsed + 1) * vsync_interval_;
1487 }
1488
1477 scoped_refptr<media::VideoFrame> frame; 1489 scoped_refptr<media::VideoFrame> frame;
1478 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1490 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1479 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1491 if (frame_subscriber_->ShouldCaptureFrame(
1480 &frame, &callback)) { 1492 damage_rect, present_time, &frame, &callback)) {
1481 // Flush the context that updated the IOSurface, to ensure that the 1493 // Flush the context that updated the IOSurface, to ensure that the
1482 // context that does the copy picks up the correct version. 1494 // context that does the copy picks up the correct version.
1483 { 1495 {
1484 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( 1496 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1485 compositing_iosurface_context_->cgl_context()); 1497 compositing_iosurface_context_->cgl_context());
1486 glFlush(); 1498 glFlush();
1487 } 1499 }
1488 compositing_iosurface_->CopyToVideoFrame( 1500 compositing_iosurface_->CopyToVideoFrame(
1489 gfx::Rect(size), frame, 1501 gfx::Rect(size), frame,
1490 base::Bind(callback, present_time)); 1502 base::Bind(callback, present_time));
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 gpu_host_id, 1738 gpu_host_id,
1727 compositing_iosurface_ ? 1739 compositing_iosurface_ ?
1728 compositing_iosurface_->GetRendererID() : 0); 1740 compositing_iosurface_->GetRendererID() : 0);
1729 1741
1730 switch (GetSurfaceHandleType(params.surface_handle)) { 1742 switch (GetSurfaceHandleType(params.surface_handle)) {
1731 case kSurfaceHandleTypeIOSurface: { 1743 case kSurfaceHandleTypeIOSurface: {
1732 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle( 1744 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(
1733 params.surface_handle); 1745 params.surface_handle);
1734 1746
1735 CompositorSwapBuffers(io_surface_id, 1747 CompositorSwapBuffers(io_surface_id,
1748 gfx::Rect(),
1736 params.size, 1749 params.size,
1737 params.scale_factor, 1750 params.scale_factor,
1738 params.latency_info); 1751 params.latency_info);
1739 } break; 1752 } break;
1740 case kSurfaceHandleTypeCAContext: { 1753 case kSurfaceHandleTypeCAContext: {
1741 // Disable the fade-out animation as the layer is added. 1754 // Disable the fade-out animation as the layer is added.
1742 ScopedCAActionDisabler disabler; 1755 ScopedCAActionDisabler disabler;
1743 1756
1744 CAContextID context_id = CAContextIDFromSurfaceHandle( 1757 CAContextID context_id = CAContextIDFromSurfaceHandle(
1745 params.surface_handle); 1758 params.surface_handle);
(...skipping 24 matching lines...) Expand all
1770 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 1783 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
1771 int gpu_host_id) { 1784 int gpu_host_id) {
1772 TRACE_EVENT0("browser", 1785 TRACE_EVENT0("browser",
1773 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); 1786 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer");
1774 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1787 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1775 1788
1776 AddPendingSwapAck(params.route_id, 1789 AddPendingSwapAck(params.route_id,
1777 gpu_host_id, 1790 gpu_host_id,
1778 compositing_iosurface_ ? 1791 compositing_iosurface_ ?
1779 compositing_iosurface_->GetRendererID() : 0); 1792 compositing_iosurface_->GetRendererID() : 0);
1780 CompositorSwapBuffers(IOSurfaceIDFromSurfaceHandle(params.surface_handle), 1793 CompositorSwapBuffers(
1781 params.surface_size, 1794 IOSurfaceIDFromSurfaceHandle(params.surface_handle),
1782 params.surface_scale_factor, 1795 gfx::Rect(params.x, params.y, params.width, params.height),
1783 params.latency_info); 1796 params.surface_size,
1797 params.surface_scale_factor,
1798 params.latency_info);
1784 } 1799 }
1785 1800
1786 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1801 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1787 if (render_widget_host_->is_hidden()) 1802 if (render_widget_host_->is_hidden())
1788 DestroyCompositedIOSurfaceAndLayer(); 1803 DestroyCompositedIOSurfaceAndLayer();
1789 } 1804 }
1790 1805
1791 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { 1806 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() {
1792 DestroyCompositedIOSurfaceAndLayer(); 1807 DestroyCompositedIOSurfaceAndLayer();
1793 } 1808 }
(...skipping 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3992 4007
3993 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4008 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3994 // regions that are not draggable. (See ControlRegionView in 4009 // regions that are not draggable. (See ControlRegionView in
3995 // native_app_window_cocoa.mm). This requires the render host view to be 4010 // native_app_window_cocoa.mm). This requires the render host view to be
3996 // draggable by default. 4011 // draggable by default.
3997 - (BOOL)mouseDownCanMoveWindow { 4012 - (BOOL)mouseDownCanMoveWindow {
3998 return YES; 4013 return YES;
3999 } 4014 }
4000 4015
4001 @end 4016 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698