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

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: Un-inline some methods, plus REBASE. 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" 65 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h"
66 #import "third_party/mozilla/ComplexTextInputPanel.h" 66 #import "third_party/mozilla/ComplexTextInputPanel.h"
67 #include "ui/base/cocoa/animation_utils.h" 67 #include "ui/base/cocoa/animation_utils.h"
68 #import "ui/base/cocoa/fullscreen_window_manager.h" 68 #import "ui/base/cocoa/fullscreen_window_manager.h"
69 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 69 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
70 #include "ui/events/keycodes/keyboard_codes.h" 70 #include "ui/events/keycodes/keyboard_codes.h"
71 #include "ui/base/layout.h" 71 #include "ui/base/layout.h"
72 #include "ui/compositor/compositor.h" 72 #include "ui/compositor/compositor.h"
73 #include "ui/compositor/layer.h" 73 #include "ui/compositor/layer.h"
74 #include "ui/gfx/display.h" 74 #include "ui/gfx/display.h"
75 #include "ui/gfx/frame_time.h"
75 #include "ui/gfx/point.h" 76 #include "ui/gfx/point.h"
76 #include "ui/gfx/rect_conversions.h" 77 #include "ui/gfx/rect_conversions.h"
77 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 78 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
78 #include "ui/gfx/screen.h" 79 #include "ui/gfx/screen.h"
79 #include "ui/gfx/size_conversions.h" 80 #include "ui/gfx/size_conversions.h"
80 #include "ui/gl/gl_switches.h" 81 #include "ui/gl/gl_switches.h"
81 82
82 using content::BrowserAccessibility; 83 using content::BrowserAccessibility;
83 using content::BrowserAccessibilityManager; 84 using content::BrowserAccessibilityManager;
84 using content::EditCommand; 85 using content::EditCommand;
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // Note that on some headless systems, the display link will fail to be 858 // Note that on some headless systems, the display link will fail to be
858 // created, so this should not be a fatal error. 859 // created, so this should not be a fatal error.
859 LOG(ERROR) << "Failed to create display link."; 860 LOG(ERROR) << "Failed to create display link.";
860 } 861 }
861 } 862 }
862 863
863 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { 864 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() {
864 if (!render_widget_host_ || !display_link_) 865 if (!render_widget_host_ || !display_link_)
865 return; 866 return;
866 867
867 base::TimeTicks timebase; 868 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) {
868 base::TimeDelta interval; 869 vsync_timebase_ = base::TimeTicks();
869 if (!display_link_->GetVSyncParameters(&timebase, &interval)) 870 vsync_interval_ = base::TimeDelta();
870 return; 871 return;
872 }
871 873
872 render_widget_host_->UpdateVSyncParameters(timebase, interval); 874 render_widget_host_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_);
873 } 875 }
874 876
875 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() { 877 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() {
876 if (!render_widget_host_) 878 if (!render_widget_host_)
877 return; 879 return;
878 880
879 float new_scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_); 881 float new_scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_);
880 if (new_scale_factor == backing_store_scale_factor_) 882 if (new_scale_factor == backing_store_scale_factor_)
881 return; 883 return;
882 backing_store_scale_factor_ = new_scale_factor; 884 backing_store_scale_factor_ = new_scale_factor;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( 1423 void RenderWidgetHostViewMac::PluginImeCompositionCompleted(
1422 const base::string16& text, int plugin_id) { 1424 const base::string16& text, int plugin_id) {
1423 if (render_widget_host_) { 1425 if (render_widget_host_) {
1424 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1426 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1425 render_widget_host_->GetRoutingID(), text, plugin_id)); 1427 render_widget_host_->GetRoutingID(), text, plugin_id));
1426 } 1428 }
1427 } 1429 }
1428 1430
1429 void RenderWidgetHostViewMac::CompositorSwapBuffers( 1431 void RenderWidgetHostViewMac::CompositorSwapBuffers(
1430 IOSurfaceID surface_handle, 1432 IOSurfaceID surface_handle,
1433 const gfx::Rect& damage_rect,
1431 const gfx::Size& size, 1434 const gfx::Size& size,
1432 float surface_scale_factor, 1435 float surface_scale_factor,
1433 const std::vector<ui::LatencyInfo>& latency_info) { 1436 const std::vector<ui::LatencyInfo>& latency_info) {
1434 // Ensure that the frame be acked unless it is explicitly passed to a 1437 // Ensure that the frame be acked unless it is explicitly passed to a
1435 // display function. 1438 // display function.
1436 base::ScopedClosureRunner scoped_ack( 1439 base::ScopedClosureRunner scoped_ack(
1437 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, 1440 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck,
1438 weak_factory_.GetWeakPtr())); 1441 weak_factory_.GetWeakPtr()));
1439 1442
1440 if (render_widget_host_->is_hidden()) 1443 if (render_widget_host_->is_hidden())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac"; 1482 LOG(ERROR) << "Failed SetIOSurface on CompositingIOSurfaceMac";
1480 return; 1483 return;
1481 } 1484 }
1482 } 1485 }
1483 1486
1484 // Grab video frames now that the IOSurface has been set up. Note that this 1487 // Grab video frames now that the IOSurface has been set up. Note that this
1485 // will be done in an offscreen context, so it is necessary to re-set the 1488 // will be done in an offscreen context, so it is necessary to re-set the
1486 // current context afterward. 1489 // current context afterward.
1487 bool frame_was_captured = false; 1490 bool frame_was_captured = false;
1488 if (frame_subscriber_) { 1491 if (frame_subscriber_) {
1489 const base::TimeTicks present_time = base::TimeTicks::Now(); 1492 const base::TimeTicks now = gfx::FrameTime::Now();
1493 base::TimeTicks present_time;
1494 if (vsync_timebase_.is_null() || vsync_interval_ <= base::TimeDelta()) {
1495 present_time = now;
1496 } else {
1497 const int64 intervals_elapsed = (now - vsync_timebase_) / vsync_interval_;
1498 present_time = vsync_timebase_ +
1499 (intervals_elapsed + 1) * vsync_interval_;
1500 }
1501
1490 scoped_refptr<media::VideoFrame> frame; 1502 scoped_refptr<media::VideoFrame> frame;
1491 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1503 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1492 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1504 if (frame_subscriber_->ShouldCaptureFrame(
1493 &frame, &callback)) { 1505 damage_rect, present_time, &frame, &callback)) {
1494 // Flush the context that updated the IOSurface, to ensure that the 1506 // Flush the context that updated the IOSurface, to ensure that the
1495 // context that does the copy picks up the correct version. 1507 // context that does the copy picks up the correct version.
1496 { 1508 {
1497 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( 1509 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
1498 compositing_iosurface_context_->cgl_context()); 1510 compositing_iosurface_context_->cgl_context());
1499 glFlush(); 1511 glFlush();
1500 } 1512 }
1501 compositing_iosurface_->CopyToVideoFrame( 1513 compositing_iosurface_->CopyToVideoFrame(
1502 gfx::Rect(size), frame, 1514 gfx::Rect(size), frame,
1503 base::Bind(callback, present_time)); 1515 base::Bind(callback, present_time));
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 gpu_host_id, 1751 gpu_host_id,
1740 compositing_iosurface_ ? 1752 compositing_iosurface_ ?
1741 compositing_iosurface_->GetRendererID() : 0); 1753 compositing_iosurface_->GetRendererID() : 0);
1742 1754
1743 switch (GetSurfaceHandleType(params.surface_handle)) { 1755 switch (GetSurfaceHandleType(params.surface_handle)) {
1744 case kSurfaceHandleTypeIOSurface: { 1756 case kSurfaceHandleTypeIOSurface: {
1745 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle( 1757 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(
1746 params.surface_handle); 1758 params.surface_handle);
1747 1759
1748 CompositorSwapBuffers(io_surface_id, 1760 CompositorSwapBuffers(io_surface_id,
1761 gfx::Rect(),
1749 params.size, 1762 params.size,
1750 params.scale_factor, 1763 params.scale_factor,
1751 params.latency_info); 1764 params.latency_info);
1752 } break; 1765 } break;
1753 case kSurfaceHandleTypeCAContext: { 1766 case kSurfaceHandleTypeCAContext: {
1754 // Disable the fade-out animation as the layer is added. 1767 // Disable the fade-out animation as the layer is added.
1755 ScopedCAActionDisabler disabler; 1768 ScopedCAActionDisabler disabler;
1756 1769
1757 CAContextID context_id = CAContextIDFromSurfaceHandle( 1770 CAContextID context_id = CAContextIDFromSurfaceHandle(
1758 params.surface_handle); 1771 params.surface_handle);
(...skipping 24 matching lines...) Expand all
1783 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 1796 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
1784 int gpu_host_id) { 1797 int gpu_host_id) {
1785 TRACE_EVENT0("browser", 1798 TRACE_EVENT0("browser",
1786 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); 1799 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer");
1787 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1800 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1788 1801
1789 AddPendingSwapAck(params.route_id, 1802 AddPendingSwapAck(params.route_id,
1790 gpu_host_id, 1803 gpu_host_id,
1791 compositing_iosurface_ ? 1804 compositing_iosurface_ ?
1792 compositing_iosurface_->GetRendererID() : 0); 1805 compositing_iosurface_->GetRendererID() : 0);
1793 CompositorSwapBuffers(IOSurfaceIDFromSurfaceHandle(params.surface_handle), 1806 CompositorSwapBuffers(
1794 params.surface_size, 1807 IOSurfaceIDFromSurfaceHandle(params.surface_handle),
1795 params.surface_scale_factor, 1808 gfx::Rect(params.x, params.y, params.width, params.height),
1796 params.latency_info); 1809 params.surface_size,
1810 params.surface_scale_factor,
1811 params.latency_info);
1797 } 1812 }
1798 1813
1799 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1814 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1800 if (render_widget_host_->is_hidden()) 1815 if (render_widget_host_->is_hidden())
1801 DestroyCompositedIOSurfaceAndLayer(); 1816 DestroyCompositedIOSurfaceAndLayer();
1802 } 1817 }
1803 1818
1804 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { 1819 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() {
1805 DestroyCompositedIOSurfaceAndLayer(); 1820 DestroyCompositedIOSurfaceAndLayer();
1806 } 1821 }
(...skipping 2215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4022 4037
4023 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4038 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
4024 // regions that are not draggable. (See ControlRegionView in 4039 // regions that are not draggable. (See ControlRegionView in
4025 // native_app_window_cocoa.mm). This requires the render host view to be 4040 // native_app_window_cocoa.mm). This requires the render host view to be
4026 // draggable by default. 4041 // draggable by default.
4027 - (BOOL)mouseDownCanMoveWindow { 4042 - (BOOL)mouseDownCanMoveWindow {
4028 return YES; 4043 return YES;
4029 } 4044 }
4030 4045
4031 @end 4046 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698