| 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 #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 17 matching lines...) Expand all Loading... |
| 28 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 29 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 29 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 30 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 30 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 31 #import "content/browser/cocoa/system_hotkey_helper_mac.h" | 31 #import "content/browser/cocoa/system_hotkey_helper_mac.h" |
| 32 #import "content/browser/cocoa/system_hotkey_map.h" | 32 #import "content/browser/cocoa/system_hotkey_map.h" |
| 33 #include "content/browser/compositor/resize_lock.h" | 33 #include "content/browser/compositor/resize_lock.h" |
| 34 #include "content/browser/frame_host/frame_tree.h" | 34 #include "content/browser/frame_host/frame_tree.h" |
| 35 #include "content/browser/frame_host/frame_tree_node.h" | 35 #include "content/browser/frame_host/frame_tree_node.h" |
| 36 #include "content/browser/frame_host/render_frame_host_impl.h" | 36 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 37 #include "content/browser/gpu/compositor_util.h" | 37 #include "content/browser/gpu/compositor_util.h" |
| 38 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | |
| 39 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | |
| 40 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | |
| 41 #include "content/browser/renderer_host/render_widget_helper.h" | 38 #include "content/browser/renderer_host/render_widget_helper.h" |
| 42 #include "content/browser/renderer_host/render_view_host_impl.h" | 39 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 43 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" | 40 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" |
| 44 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" | 41 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" |
| 45 #import "content/browser/renderer_host/software_layer_mac.h" | |
| 46 #import "content/browser/renderer_host/text_input_client_mac.h" | 42 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 47 #include "content/common/accessibility_messages.h" | 43 #include "content/common/accessibility_messages.h" |
| 48 #include "content/common/edit_command.h" | 44 #include "content/common/edit_command.h" |
| 49 #include "content/common/gpu/gpu_messages.h" | 45 #include "content/common/gpu/gpu_messages.h" |
| 50 #include "content/common/gpu/surface_handle_types_mac.h" | 46 #include "content/common/gpu/surface_handle_types_mac.h" |
| 51 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
| 52 #include "content/common/view_messages.h" | 48 #include "content/common/view_messages.h" |
| 53 #include "content/common/webplugin_geometry.h" | 49 #include "content/common/webplugin_geometry.h" |
| 54 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 55 #include "content/public/browser/native_web_keyboard_event.h" | 51 #include "content/public/browser/native_web_keyboard_event.h" |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 441 |
| 446 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { | 442 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { |
| 447 return delegated_frame_host_.get(); | 443 return delegated_frame_host_.get(); |
| 448 } | 444 } |
| 449 | 445 |
| 450 //////////////////////////////////////////////////////////////////////////////// | 446 //////////////////////////////////////////////////////////////////////////////// |
| 451 // BrowserCompositorViewMacClient, public: | 447 // BrowserCompositorViewMacClient, public: |
| 452 | 448 |
| 453 bool RenderWidgetHostViewMac::BrowserCompositorViewShouldAckImmediately() | 449 bool RenderWidgetHostViewMac::BrowserCompositorViewShouldAckImmediately() |
| 454 const { | 450 const { |
| 455 // The logic for delegated and non-delegated rendering is the same. | 451 // If vsync is disabled, then always draw and ack frames immediately. |
| 456 return AcceleratedLayerShouldAckImmediately(); | 452 static bool is_vsync_disabled = |
| 453 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 454 switches::kDisableGpuVsync); |
| 455 if (is_vsync_disabled) |
| 456 return true; |
| 457 |
| 458 // If the window is occluded, then this frame's display call may be severely |
| 459 // throttled. This is a good thing, unless tab capture may be active, because |
| 460 // the broadcast will be inappropriately throttled. |
| 461 // http://crbug.com/350410 |
| 462 |
| 463 // If tab capture isn't active then only ack frames when we draw them. |
| 464 if (delegated_frame_host_ && !delegated_frame_host_->HasFrameSubscriber()) |
| 465 return false; |
| 466 |
| 467 NSWindow* window = [cocoa_view_ window]; |
| 468 // If the view isn't even in the heirarchy then frames will never be drawn, |
| 469 // so ack them immediately. |
| 470 if (!window) |
| 471 return true; |
| 472 |
| 473 // Check the window occlusion API. |
| 474 if ([window respondsToSelector:@selector(occlusionState)]) { |
| 475 if ([window occlusionState] & NSWindowOcclusionStateVisible) { |
| 476 // If the window is visible then it is safe to wait until frames are |
| 477 // drawn to ack them. |
| 478 return false; |
| 479 } else { |
| 480 // If the window is occluded then frames may never be drawn, so ack them |
| 481 // immediately. |
| 482 return true; |
| 483 } |
| 484 } |
| 485 |
| 486 // If the window occlusion API is not present then ack frames when we draw |
| 487 // them. |
| 488 return false; |
| 457 } | 489 } |
| 458 | 490 |
| 459 void RenderWidgetHostViewMac::BrowserCompositorViewFrameSwapped( | 491 void RenderWidgetHostViewMac::BrowserCompositorViewFrameSwapped( |
| 460 const std::vector<ui::LatencyInfo>& all_latency_info) { | 492 const std::vector<ui::LatencyInfo>& all_latency_info) { |
| 461 if (!render_widget_host_) | 493 if (!render_widget_host_) |
| 462 return; | 494 return; |
| 463 for (auto latency_info : all_latency_info) { | 495 for (auto latency_info : all_latency_info) { |
| 464 latency_info.AddLatencyNumber( | 496 latency_info.AddLatencyNumber( |
| 465 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 497 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
| 466 render_widget_host_->FrameSwapped(latency_info); | 498 render_widget_host_->FrameSwapped(latency_info); |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 render_widget_host_->PauseForPendingResizeOrRepaints(); | 1619 render_widget_host_->PauseForPendingResizeOrRepaints(); |
| 1588 if (browser_compositor_view_) | 1620 if (browser_compositor_view_) |
| 1589 browser_compositor_view_->EndPumpingFrames(); | 1621 browser_compositor_view_->EndPumpingFrames(); |
| 1590 } | 1622 } |
| 1591 | 1623 |
| 1592 SkColorType RenderWidgetHostViewMac::PreferredReadbackFormat() { | 1624 SkColorType RenderWidgetHostViewMac::PreferredReadbackFormat() { |
| 1593 return kN32_SkColorType; | 1625 return kN32_SkColorType; |
| 1594 } | 1626 } |
| 1595 | 1627 |
| 1596 //////////////////////////////////////////////////////////////////////////////// | 1628 //////////////////////////////////////////////////////////////////////////////// |
| 1597 // CompositingIOSurfaceLayerClient, public: | |
| 1598 | |
| 1599 bool RenderWidgetHostViewMac::AcceleratedLayerShouldAckImmediately() const { | |
| 1600 // If vsync is disabled, then always draw and ack frames immediately. | |
| 1601 static bool is_vsync_disabled = | |
| 1602 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1603 switches::kDisableGpuVsync); | |
| 1604 if (is_vsync_disabled) | |
| 1605 return true; | |
| 1606 | |
| 1607 // If the window is occluded, then this frame's display call may be severely | |
| 1608 // throttled. This is a good thing, unless tab capture may be active, because | |
| 1609 // the broadcast will be inappropriately throttled. | |
| 1610 // http://crbug.com/350410 | |
| 1611 | |
| 1612 // If tab capture isn't active then only ack frames when we draw them. | |
| 1613 if (delegated_frame_host_ && !delegated_frame_host_->HasFrameSubscriber()) | |
| 1614 return false; | |
| 1615 | |
| 1616 NSWindow* window = [cocoa_view_ window]; | |
| 1617 // If the view isn't even in the heirarchy then frames will never be drawn, | |
| 1618 // so ack them immediately. | |
| 1619 if (!window) | |
| 1620 return true; | |
| 1621 | |
| 1622 // Check the window occlusion API. | |
| 1623 if ([window respondsToSelector:@selector(occlusionState)]) { | |
| 1624 if ([window occlusionState] & NSWindowOcclusionStateVisible) { | |
| 1625 // If the window is visible then it is safe to wait until frames are | |
| 1626 // drawn to ack them. | |
| 1627 return false; | |
| 1628 } else { | |
| 1629 // If the window is occluded then frames may never be drawn, so ack them | |
| 1630 // immediately. | |
| 1631 return true; | |
| 1632 } | |
| 1633 } | |
| 1634 | |
| 1635 // If the window occlusion API is not present then ack frames when we draw | |
| 1636 // them. | |
| 1637 return false; | |
| 1638 } | |
| 1639 | |
| 1640 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame() { | |
| 1641 } | |
| 1642 | |
| 1643 void RenderWidgetHostViewMac::AcceleratedLayerHitError() { | |
| 1644 } | |
| 1645 | |
| 1646 //////////////////////////////////////////////////////////////////////////////// | |
| 1647 // gfx::DisplayObserver, public: | 1629 // gfx::DisplayObserver, public: |
| 1648 | 1630 |
| 1649 void RenderWidgetHostViewMac::OnDisplayAdded(const gfx::Display& display) { | 1631 void RenderWidgetHostViewMac::OnDisplayAdded(const gfx::Display& display) { |
| 1650 } | 1632 } |
| 1651 | 1633 |
| 1652 void RenderWidgetHostViewMac::OnDisplayRemoved(const gfx::Display& display) { | 1634 void RenderWidgetHostViewMac::OnDisplayRemoved(const gfx::Display& display) { |
| 1653 } | 1635 } |
| 1654 | 1636 |
| 1655 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( | 1637 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
| 1656 const gfx::Display& display, uint32_t metrics) { | 1638 const gfx::Display& display, uint32_t metrics) { |
| (...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3348 | 3330 |
| 3349 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3331 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3350 // regions that are not draggable. (See ControlRegionView in | 3332 // regions that are not draggable. (See ControlRegionView in |
| 3351 // native_app_window_cocoa.mm). This requires the render host view to be | 3333 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3352 // draggable by default. | 3334 // draggable by default. |
| 3353 - (BOOL)mouseDownCanMoveWindow { | 3335 - (BOOL)mouseDownCanMoveWindow { |
| 3354 return YES; | 3336 return YES; |
| 3355 } | 3337 } |
| 3356 | 3338 |
| 3357 @end | 3339 @end |
| OLD | NEW |