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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 return scoped_ptr<ResizeLock>(lock); | 442 return scoped_ptr<ResizeLock>(lock); |
443 } | 443 } |
444 | 444 |
445 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { | 445 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { |
446 return delegated_frame_host_.get(); | 446 return delegated_frame_host_.get(); |
447 } | 447 } |
448 | 448 |
449 //////////////////////////////////////////////////////////////////////////////// | 449 //////////////////////////////////////////////////////////////////////////////// |
450 // BrowserCompositorViewMacClient, public: | 450 // BrowserCompositorViewMacClient, public: |
451 | 451 |
| 452 bool RenderWidgetHostViewMac::BrowserCompositorViewShouldAckImmediately() |
| 453 const { |
| 454 // The logic for delegated and non-delegated rendering is the same. |
| 455 return AcceleratedLayerShouldAckImmediately(); |
| 456 } |
| 457 |
452 void RenderWidgetHostViewMac::BrowserCompositorViewFrameSwapped( | 458 void RenderWidgetHostViewMac::BrowserCompositorViewFrameSwapped( |
453 const std::vector<ui::LatencyInfo>& all_latency_info) { | 459 const std::vector<ui::LatencyInfo>& all_latency_info) { |
454 if (!render_widget_host_) | 460 if (!render_widget_host_) |
455 return; | 461 return; |
456 for (auto latency_info : all_latency_info) { | 462 for (auto latency_info : all_latency_info) { |
457 latency_info.AddLatencyNumber( | 463 latency_info.AddLatencyNumber( |
458 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 464 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
459 render_widget_host_->FrameSwapped(latency_info); | 465 render_widget_host_->FrameSwapped(latency_info); |
460 } | 466 } |
461 } | 467 } |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 std::string value = | 1525 std::string value = |
1520 base::StringPrintf("window %s delegate %s controller %s", | 1526 base::StringPrintf("window %s delegate %s controller %s", |
1521 object_getClassName(window), | 1527 object_getClassName(window), |
1522 object_getClassName([window delegate]), | 1528 object_getClassName([window delegate]), |
1523 object_getClassName([window windowController])); | 1529 object_getClassName([window windowController])); |
1524 base::debug::SetCrashKeyValue(kCrashKey, value); | 1530 base::debug::SetCrashKeyValue(kCrashKey, value); |
1525 } | 1531 } |
1526 return; | 1532 return; |
1527 } | 1533 } |
1528 | 1534 |
1529 // If the window is occluded, then this frame's display call may be severely | |
1530 // throttled. This is a good thing, unless tab capture may be active, | |
1531 // because the broadcast will be inappropriately throttled. | |
1532 // http://crbug.com/350410 | |
1533 NSWindow* window = [cocoa_view_ window]; | |
1534 if (window && [window respondsToSelector:@selector(occlusionState)]) { | |
1535 bool window_is_occluded = | |
1536 !([window occlusionState] & NSWindowOcclusionStateVisible); | |
1537 // Note that we aggressively ack even if this particular frame is not being | |
1538 // captured. | |
1539 if (window_is_occluded && frame_subscriber_) | |
1540 scoped_ack.Reset(); | |
1541 } | |
1542 | |
1543 // If we reach here, then the frame will be displayed by a future draw | 1535 // If we reach here, then the frame will be displayed by a future draw |
1544 // call, so don't make the callback. | 1536 // call, so don't make the callback. |
1545 ignore_result(scoped_ack.Release()); | 1537 ignore_result(scoped_ack.Release()); |
1546 DCHECK(compositing_iosurface_layer_); | 1538 DCHECK(compositing_iosurface_layer_); |
1547 [compositing_iosurface_layer_ gotNewFrame]; | 1539 [compositing_iosurface_layer_ gotNewFrame]; |
1548 | 1540 |
1549 // Try to finish previous copy requests after draw to get better pipelining. | 1541 // Try to finish previous copy requests after draw to get better pipelining. |
1550 if (compositing_iosurface_) | 1542 if (compositing_iosurface_) |
1551 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); | 1543 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); |
1552 | 1544 |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 } | 2229 } |
2238 } | 2230 } |
2239 | 2231 |
2240 SkColorType RenderWidgetHostViewMac::PreferredReadbackFormat() { | 2232 SkColorType RenderWidgetHostViewMac::PreferredReadbackFormat() { |
2241 return kN32_SkColorType; | 2233 return kN32_SkColorType; |
2242 } | 2234 } |
2243 | 2235 |
2244 //////////////////////////////////////////////////////////////////////////////// | 2236 //////////////////////////////////////////////////////////////////////////////// |
2245 // CompositingIOSurfaceLayerClient, public: | 2237 // CompositingIOSurfaceLayerClient, public: |
2246 | 2238 |
| 2239 bool RenderWidgetHostViewMac::AcceleratedLayerShouldAckImmediately() const { |
| 2240 // If vsync is disabled, then always draw and ack frames immediately. |
| 2241 static bool is_vsync_disabled = |
| 2242 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync); |
| 2243 if (is_vsync_disabled) |
| 2244 return true; |
| 2245 |
| 2246 // If the window is occluded, then this frame's display call may be severely |
| 2247 // throttled. This is a good thing, unless tab capture may be active, because |
| 2248 // the broadcast will be inappropriately throttled. |
| 2249 // http://crbug.com/350410 |
| 2250 |
| 2251 // If tab capture isn't active then only ack frames when we draw them. |
| 2252 if (delegated_frame_host_) { |
| 2253 if (!delegated_frame_host_->HasFrameSubscriber()) |
| 2254 return false; |
| 2255 } else { |
| 2256 if (!frame_subscriber_) |
| 2257 return false; |
| 2258 } |
| 2259 |
| 2260 NSWindow* window = [cocoa_view_ window]; |
| 2261 // If the view isn't even in the heirarchy then frames will never be drawn, |
| 2262 // so ack them immediately. |
| 2263 if (!window) |
| 2264 return true; |
| 2265 |
| 2266 // Check the window occlusion API. |
| 2267 if ([window respondsToSelector:@selector(occlusionState)]) { |
| 2268 if ([window occlusionState] & NSWindowOcclusionStateVisible) { |
| 2269 // If the window is visible then it is safe to wait until frames are |
| 2270 // drawn to ack them. |
| 2271 return false; |
| 2272 } else { |
| 2273 // If the window is occluded then frames may never be drawn, so ack them |
| 2274 // immediately. |
| 2275 return true; |
| 2276 } |
| 2277 } |
| 2278 |
| 2279 // If the window occlusion API is not present then ack frames when we draw |
| 2280 // them. |
| 2281 return false; |
| 2282 } |
| 2283 |
2247 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { | 2284 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { |
2248 if (!render_widget_host_) | 2285 if (!render_widget_host_) |
2249 return; | 2286 return; |
2250 | 2287 |
2251 SendPendingLatencyInfoToHost(); | 2288 SendPendingLatencyInfoToHost(); |
2252 SendPendingSwapAck(); | 2289 SendPendingSwapAck(); |
2253 if (!succeeded) | 2290 if (!succeeded) |
2254 GotAcceleratedCompositingError(); | 2291 GotAcceleratedCompositingError(); |
2255 } | 2292 } |
2256 | 2293 |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3950 | 3987 |
3951 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3988 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3952 // regions that are not draggable. (See ControlRegionView in | 3989 // regions that are not draggable. (See ControlRegionView in |
3953 // native_app_window_cocoa.mm). This requires the render host view to be | 3990 // native_app_window_cocoa.mm). This requires the render host view to be |
3954 // draggable by default. | 3991 // draggable by default. |
3955 - (BOOL)mouseDownCanMoveWindow { | 3992 - (BOOL)mouseDownCanMoveWindow { |
3956 return YES; | 3993 return YES; |
3957 } | 3994 } |
3958 | 3995 |
3959 @end | 3996 @end |
OLD | NEW |