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

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: Created 6 years, 5 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( 1405 void RenderWidgetHostViewMac::PluginImeCompositionCompleted(
1404 const base::string16& text, int plugin_id) { 1406 const base::string16& text, int plugin_id) {
1405 if (render_widget_host_) { 1407 if (render_widget_host_) {
1406 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1408 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1407 render_widget_host_->GetRoutingID(), text, plugin_id)); 1409 render_widget_host_->GetRoutingID(), text, plugin_id));
1408 } 1410 }
1409 } 1411 }
1410 1412
1411 void RenderWidgetHostViewMac::CompositorSwapBuffers( 1413 void RenderWidgetHostViewMac::CompositorSwapBuffers(
1412 IOSurfaceID surface_handle, 1414 IOSurfaceID surface_handle,
1415 const gfx::Rect& damage_rect,
1413 const gfx::Size& size, 1416 const gfx::Size& size,
1414 float surface_scale_factor, 1417 float surface_scale_factor,
1415 const std::vector<ui::LatencyInfo>& latency_info) { 1418 const std::vector<ui::LatencyInfo>& latency_info) {
1416 // Ensure that the frame be acked unless it is explicitly passed to a 1419 // Ensure that the frame be acked unless it is explicitly passed to a
1417 // display function. 1420 // display function.
1418 base::ScopedClosureRunner scoped_ack( 1421 base::ScopedClosureRunner scoped_ack(
1419 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, 1422 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck,
1420 weak_factory_.GetWeakPtr())); 1423 weak_factory_.GetWeakPtr()));
1421 1424
1422 if (render_widget_host_->is_hidden()) 1425 if (render_widget_host_->is_hidden())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; 1464 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac";
1462 return; 1465 return;
1463 } 1466 }
1464 } 1467 }
1465 1468
1466 // Grab video frames now that the IOSurface has been set up. Note that this 1469 // Grab video frames now that the IOSurface has been set up. Note that this
1467 // will be done in an offscreen context, so it is necessary to re-set the 1470 // will be done in an offscreen context, so it is necessary to re-set the
1468 // current context afterward. 1471 // current context afterward.
1469 bool frame_was_captured = false; 1472 bool frame_was_captured = false;
1470 if (frame_subscriber_) { 1473 if (frame_subscriber_) {
1471 const base::TimeTicks present_time = base::TimeTicks::Now(); 1474 const base::TimeTicks now = gfx::FrameTime::Now();
1475 base::TimeTicks present_time;
1476 if (vsync_timebase_.is_null() || vsync_interval_ <= base::TimeDelta()) {
1477 present_time = now;
1478 } else {
1479 const int64 intervals_elapsed = (now - vsync_timebase_) / vsync_interval_;
1480 present_time = vsync_timebase_ +
1481 (intervals_elapsed + 1) * vsync_interval_;
1482 }
1483
1472 scoped_refptr<media::VideoFrame> frame; 1484 scoped_refptr<media::VideoFrame> frame;
1473 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1485 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1474 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1486 if (frame_subscriber_->ShouldCaptureFrame(
1475 &frame, &callback)) { 1487 damage_rect, present_time, &frame, &callback)) {
1476 // Flush the context that updated the IOSurface, to ensure that the 1488 // Flush the context that updated the IOSurface, to ensure that the
1477 // context that does the copy picks up the correct version. 1489 // context that does the copy picks up the correct version.
1478 { 1490 {
1479 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( 1491 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1480 compositing_iosurface_context_->cgl_context()); 1492 compositing_iosurface_context_->cgl_context());
1481 glFlush(); 1493 glFlush();
1482 } 1494 }
1483 compositing_iosurface_->CopyToVideoFrame( 1495 compositing_iosurface_->CopyToVideoFrame(
1484 gfx::Rect(size), frame, 1496 gfx::Rect(size), frame,
1485 base::Bind(callback, present_time)); 1497 base::Bind(callback, present_time));
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 gpu_host_id, 1733 gpu_host_id,
1722 compositing_iosurface_ ? 1734 compositing_iosurface_ ?
1723 compositing_iosurface_->GetRendererID() : 0); 1735 compositing_iosurface_->GetRendererID() : 0);
1724 1736
1725 switch (GetSurfaceHandleType(params.surface_handle)) { 1737 switch (GetSurfaceHandleType(params.surface_handle)) {
1726 case kSurfaceHandleTypeIOSurface: { 1738 case kSurfaceHandleTypeIOSurface: {
1727 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle( 1739 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(
1728 params.surface_handle); 1740 params.surface_handle);
1729 1741
1730 CompositorSwapBuffers(io_surface_id, 1742 CompositorSwapBuffers(io_surface_id,
1743 gfx::Rect(),
ccameron 2014/07/25 17:21:52 I think that this should be from params.size ... b
miu 2014/07/25 18:00:13 tl;dr: I fell back on passing an empty Rect since
1731 params.size, 1744 params.size,
1732 params.scale_factor, 1745 params.scale_factor,
1733 params.latency_info); 1746 params.latency_info);
1734 } break; 1747 } break;
1735 case kSurfaceHandleTypeCAContext: { 1748 case kSurfaceHandleTypeCAContext: {
1736 // Disable the fade-out animation as the layer is added. 1749 // Disable the fade-out animation as the layer is added.
1737 ScopedCAActionDisabler disabler; 1750 ScopedCAActionDisabler disabler;
1738 1751
1739 CAContextID context_id = CAContextIDFromSurfaceHandle( 1752 CAContextID context_id = CAContextIDFromSurfaceHandle(
1740 params.surface_handle); 1753 params.surface_handle);
(...skipping 24 matching lines...) Expand all
1765 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 1778 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
1766 int gpu_host_id) { 1779 int gpu_host_id) {
1767 TRACE_EVENT0("browser", 1780 TRACE_EVENT0("browser",
1768 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); 1781 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer");
1769 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1770 1783
1771 AddPendingSwapAck(params.route_id, 1784 AddPendingSwapAck(params.route_id,
1772 gpu_host_id, 1785 gpu_host_id,
1773 compositing_iosurface_ ? 1786 compositing_iosurface_ ?
1774 compositing_iosurface_->GetRendererID() : 0); 1787 compositing_iosurface_->GetRendererID() : 0);
1775 CompositorSwapBuffers(IOSurfaceIDFromSurfaceHandle(params.surface_handle), 1788 CompositorSwapBuffers(
1776 params.surface_size, 1789 IOSurfaceIDFromSurfaceHandle(params.surface_handle),
1777 params.surface_scale_factor, 1790 gfx::Rect(params.x, params.y, params.width, params.height),
1778 params.latency_info); 1791 params.surface_size,
1792 params.surface_scale_factor,
1793 params.latency_info);
1779 } 1794 }
1780 1795
1781 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1796 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1782 if (render_widget_host_->is_hidden()) 1797 if (render_widget_host_->is_hidden())
1783 DestroyCompositedIOSurfaceAndLayer(); 1798 DestroyCompositedIOSurfaceAndLayer();
1784 } 1799 }
1785 1800
1786 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { 1801 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() {
1787 DestroyCompositedIOSurfaceAndLayer(); 1802 DestroyCompositedIOSurfaceAndLayer();
1788 } 1803 }
(...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4010 4025
4011 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4026 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
4012 // regions that are not draggable. (See ControlRegionView in 4027 // regions that are not draggable. (See ControlRegionView in
4013 // native_app_window_cocoa.mm). This requires the render host view to be 4028 // native_app_window_cocoa.mm). This requires the render host view to be
4014 // draggable by default. 4029 // draggable by default.
4015 - (BOOL)mouseDownCanMoveWindow { 4030 - (BOOL)mouseDownCanMoveWindow {
4016 return YES; 4031 return YES;
4017 } 4032 }
4018 4033
4019 @end 4034 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698