Chromium Code Reviews| 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 <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 604 } |
| 605 | 605 |
| 606 return true; | 606 return true; |
| 607 } | 607 } |
| 608 | 608 |
| 609 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { | 609 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { |
| 610 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); | 610 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); |
| 611 if (software_layer_ || !use_core_animation_) | 611 if (software_layer_ || !use_core_animation_) |
| 612 return; | 612 return; |
| 613 | 613 |
| 614 software_layer_.reset([[SoftwareLayer alloc] | 614 software_layer_.reset([[SoftwareLayer alloc] init]); |
| 615 initWithRenderWidgetHostViewMac:this]); | |
| 616 DCHECK(software_layer_); | 615 DCHECK(software_layer_); |
| 617 | 616 |
| 618 // Disable the fade-in animation as the layer is added. | 617 // Disable the fade-in animation as the layer is added. |
| 619 ScopedCAActionDisabler disabler; | 618 ScopedCAActionDisabler disabler; |
| 620 [background_layer_ addSublayer:software_layer_]; | 619 [background_layer_ addSublayer:software_layer_]; |
| 621 } | 620 } |
| 622 | 621 |
| 623 void RenderWidgetHostViewMac::DestroySoftwareLayer() { | 622 void RenderWidgetHostViewMac::DestroySoftwareLayer() { |
| 624 if (!software_layer_) | 623 if (!software_layer_) |
| 625 return; | 624 return; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 | 864 |
| 866 if (web_contents_switch_paint_time_.is_null()) | 865 if (web_contents_switch_paint_time_.is_null()) |
| 867 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 866 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
| 868 render_widget_host_->WasShown(); | 867 render_widget_host_->WasShown(); |
| 869 software_frame_manager_->SetVisibility(true); | 868 software_frame_manager_->SetVisibility(true); |
| 870 if (delegated_frame_host_) | 869 if (delegated_frame_host_) |
| 871 delegated_frame_host_->WasShown(); | 870 delegated_frame_host_->WasShown(); |
| 872 | 871 |
| 873 // Call setNeedsDisplay before pausing for new frames to come in -- if any | 872 // Call setNeedsDisplay before pausing for new frames to come in -- if any |
| 874 // do, and are drawn, then the needsDisplay bit will be cleared. | 873 // do, and are drawn, then the needsDisplay bit will be cleared. |
| 875 [software_layer_ setNeedsDisplay]; | |
| 876 [compositing_iosurface_layer_ setNeedsDisplay]; | 874 [compositing_iosurface_layer_ setNeedsDisplay]; |
| 877 PauseForPendingResizeOrRepaintsAndDraw(); | 875 PauseForPendingResizeOrRepaintsAndDraw(); |
| 878 | 876 |
| 879 // We're messing with the window, so do this to ensure no flashes. | 877 // We're messing with the window, so do this to ensure no flashes. |
| 880 if (!use_core_animation_) | 878 if (!use_core_animation_) |
| 881 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 879 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 882 } | 880 } |
| 883 | 881 |
| 884 void RenderWidgetHostViewMac::WasHidden() { | 882 void RenderWidgetHostViewMac::WasHidden() { |
| 885 if (render_widget_host_->is_hidden()) | 883 if (render_widget_host_->is_hidden()) |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1567 | 1565 |
| 1568 // Try to finish previous copy requests after draw to get better pipelining. | 1566 // Try to finish previous copy requests after draw to get better pipelining. |
| 1569 if (compositing_iosurface_) | 1567 if (compositing_iosurface_) |
| 1570 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); | 1568 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); |
| 1571 | 1569 |
| 1572 // The IOSurface's size may have changed, so re-layout the layers to take | 1570 // The IOSurface's size may have changed, so re-layout the layers to take |
| 1573 // this into account. This may force an immediate draw. | 1571 // this into account. This may force an immediate draw. |
| 1574 LayoutLayers(); | 1572 LayoutLayers(); |
| 1575 } | 1573 } |
| 1576 | 1574 |
| 1575 void RenderWidgetHostViewMac::GotBrowserCompositorSoftwareFrame( | |
| 1576 cc::SoftwareFrameData* frame_data, | |
| 1577 float scale_factor, | |
| 1578 SkCanvas* canvas) { | |
| 1579 if (!frame_data || !canvas) | |
| 1580 return; | |
| 1581 | |
| 1582 // Disable animating the contents change or the scale factor change. | |
| 1583 ScopedCAActionDisabler disabler; | |
| 1584 EnsureSoftwareLayer(); | |
| 1585 | |
| 1586 // Set the contents of the software CALayer to be a CGImage with the provided | |
| 1587 // pixel data. | |
| 1588 SkImageInfo info; | |
| 1589 size_t row_bytes; | |
| 1590 const void* pixels = canvas->peekPixels(&info, &row_bytes); | |
| 1591 base::ScopedCFTypeRef<CGDataProviderRef> data_provider( | |
| 1592 CGDataProviderCreateWithData( | |
| 1593 NULL, pixels, 4 * info.fWidth * info.fHeight, NULL)); | |
|
piman
2014/05/20 07:04:17
Doesn't this assume that CoreAnimation won't look
ccameron
2014/05/20 19:15:50
The documentation is very unclear, but this does a
| |
| 1594 base::ScopedCFTypeRef<CGImageRef> image( | |
| 1595 CGImageCreate(info.fWidth, | |
| 1596 info.fHeight, | |
| 1597 8, | |
| 1598 32, | |
| 1599 row_bytes, | |
| 1600 base::mac::GetSystemColorSpace(), | |
| 1601 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | |
| 1602 data_provider, | |
| 1603 NULL, | |
| 1604 false, | |
| 1605 kCGRenderingIntentDefault)); | |
| 1606 [software_layer_ setContents:(id)image.get()]; | |
| 1607 | |
| 1608 // Set the contents scale of the software CALayer. | |
| 1609 if ([software_layer_ respondsToSelector:(@selector(contentsScale))] && | |
| 1610 [software_layer_ respondsToSelector:(@selector(setContentsScale:))] && | |
| 1611 [software_layer_ contentsScale] != scale_factor) { | |
| 1612 [software_layer_ setContentsScale:scale_factor]; | |
| 1613 } | |
| 1614 | |
| 1615 LayoutLayers(); | |
| 1616 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | |
| 1617 } | |
| 1618 | |
| 1577 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { | 1619 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { |
| 1578 CHECK(!use_core_animation_); | 1620 CHECK(!use_core_animation_); |
| 1579 CHECK(compositing_iosurface_); | 1621 CHECK(compositing_iosurface_); |
| 1580 | 1622 |
| 1581 // If there is a pending frame, it should be acked by the end of this | 1623 // If there is a pending frame, it should be acked by the end of this |
| 1582 // function. Note that the ack should happen only after all drawing is | 1624 // function. Note that the ack should happen only after all drawing is |
| 1583 // complete, so that the ack happens after any blocking due to vsync. | 1625 // complete, so that the ack happens after any blocking due to vsync. |
| 1584 base::ScopedClosureRunner scoped_ack( | 1626 base::ScopedClosureRunner scoped_ack( |
| 1585 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, | 1627 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, |
| 1586 weak_factory_.GetWeakPtr())); | 1628 weak_factory_.GetWeakPtr())); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 return (software_frame_manager_->HasCurrentFrame() && | 1932 return (software_frame_manager_->HasCurrentFrame() && |
| 1891 (desired_size.IsEmpty() || | 1933 (desired_size.IsEmpty() || |
| 1892 software_frame_manager_->GetCurrentFrameSizeInDIP() == | 1934 software_frame_manager_->GetCurrentFrameSizeInDIP() == |
| 1893 desired_size)); | 1935 desired_size)); |
| 1894 } | 1936 } |
| 1895 return false; | 1937 return false; |
| 1896 } | 1938 } |
| 1897 | 1939 |
| 1898 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1940 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
| 1899 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1941 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
| 1942 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | |
| 1943 | |
| 1900 if (frame->delegated_frame_data) { | 1944 if (frame->delegated_frame_data) { |
| 1901 if (!compositor_) { | 1945 if (!compositor_) { |
| 1902 compositor_.reset(new ui::Compositor(cocoa_view_)); | 1946 compositor_.reset(new ui::Compositor(cocoa_view_)); |
| 1903 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | 1947 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
| 1904 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 1948 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
| 1905 } | 1949 } |
| 1906 | 1950 |
| 1907 // TODO(ccameron): Having the root layer set while swapping the frame will | 1951 // TODO(ccameron): Having the root layer set while swapping the frame will |
| 1908 // result in frames not appearing. Fix this. | 1952 // result in frames not appearing. Fix this. |
| 1909 compositor_->SetRootLayer(NULL); | 1953 compositor_->SetRootLayer(NULL); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1929 frame->metadata.device_scale_factor, | 1973 frame->metadata.device_scale_factor, |
| 1930 render_widget_host_->GetProcess()->GetHandle())) { | 1974 render_widget_host_->GetProcess()->GetHandle())) { |
| 1931 render_widget_host_->GetProcess()->ReceivedBadMessage(); | 1975 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
| 1932 return; | 1976 return; |
| 1933 } | 1977 } |
| 1934 | 1978 |
| 1935 // Add latency info to report when the frame finishes drawing. | 1979 // Add latency info to report when the frame finishes drawing. |
| 1936 AddPendingLatencyInfo(frame->metadata.latency_info); | 1980 AddPendingLatencyInfo(frame->metadata.latency_info); |
| 1937 GotSoftwareFrame(); | 1981 GotSoftwareFrame(); |
| 1938 | 1982 |
| 1983 if (use_core_animation_) { | |
| 1984 // Disable animating the contents change or the scale factor change. | |
| 1985 ScopedCAActionDisabler disabler; | |
| 1986 EnsureSoftwareLayer(); | |
| 1987 | |
| 1988 // Set the contents of the software CALayer to be a CGImage with the | |
| 1989 // provided pixel data. | |
| 1990 gfx::Size size_in_pixels = | |
| 1991 software_frame_manager_->GetCurrentFrameSizeInPixels(); | |
| 1992 base::ScopedCFTypeRef<CGDataProviderRef> data_provider( | |
| 1993 CGDataProviderCreateWithData( | |
| 1994 NULL, | |
| 1995 software_frame_manager_->GetCurrentFramePixels(), | |
| 1996 4 * size_in_pixels.width() * size_in_pixels.height(), | |
| 1997 NULL)); | |
| 1998 base::ScopedCFTypeRef<CGImageRef> image(CGImageCreate( | |
| 1999 size_in_pixels.width(), | |
| 2000 size_in_pixels.height(), | |
| 2001 8, | |
| 2002 32, | |
| 2003 4 * size_in_pixels.width(), | |
| 2004 base::mac::GetSystemColorSpace(), | |
| 2005 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | |
| 2006 data_provider, | |
| 2007 NULL, | |
| 2008 false, | |
| 2009 kCGRenderingIntentDefault)); | |
| 2010 [software_layer_ setContents:(id)image.get()]; | |
| 2011 | |
| 2012 // Set the contents scale of the software CALayer. | |
| 2013 if ([software_layer_ respondsToSelector:(@selector(contentsScale))] && | |
| 2014 [software_layer_ respondsToSelector:(@selector(setContentsScale:))] && | |
| 2015 [software_layer_ contentsScale] != | |
| 2016 frame->metadata.device_scale_factor) { | |
| 2017 [software_layer_ setContentsScale:frame->metadata.device_scale_factor]; | |
| 2018 } | |
| 2019 | |
| 2020 // Send latency information to the host immediately, as there will be no | |
| 2021 // subsequent draw call in which to do so. | |
| 2022 SendPendingLatencyInfoToHost(); | |
| 2023 } | |
| 2024 | |
| 1939 cc::CompositorFrameAck ack; | 2025 cc::CompositorFrameAck ack; |
| 1940 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 2026 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1941 render_widget_host_->GetRoutingID(), | 2027 render_widget_host_->GetRoutingID(), |
| 1942 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), | 2028 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), |
| 1943 render_widget_host_->GetProcess()->GetID(), | 2029 render_widget_host_->GetProcess()->GetID(), |
| 1944 ack); | 2030 ack); |
| 1945 software_frame_manager_->SwapToNewFrameComplete( | 2031 software_frame_manager_->SwapToNewFrameComplete( |
| 1946 !render_widget_host_->is_hidden()); | 2032 !render_widget_host_->is_hidden()); |
| 1947 | 2033 |
| 1948 // Notify observers, tab capture observers in particular, that a new | 2034 // Notify observers, tab capture observers in particular, that a new |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2070 [cocoa_view_ setNeedsDisplay:YES]; | 2156 [cocoa_view_ setNeedsDisplay:YES]; |
| 2071 } | 2157 } |
| 2072 | 2158 |
| 2073 // Delete software backingstore and layer. | 2159 // Delete software backingstore and layer. |
| 2074 software_frame_manager_->DiscardCurrentFrame(); | 2160 software_frame_manager_->DiscardCurrentFrame(); |
| 2075 DestroySoftwareLayer(); | 2161 DestroySoftwareLayer(); |
| 2076 } | 2162 } |
| 2077 } | 2163 } |
| 2078 | 2164 |
| 2079 void RenderWidgetHostViewMac::GotSoftwareFrame() { | 2165 void RenderWidgetHostViewMac::GotSoftwareFrame() { |
| 2166 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::GotSoftwareFrame"); | |
| 2167 | |
| 2080 if (!render_widget_host_) | 2168 if (!render_widget_host_) |
| 2081 return; | 2169 return; |
| 2082 | 2170 |
| 2083 EnsureSoftwareLayer(); | 2171 EnsureSoftwareLayer(); |
| 2084 LayoutLayers(); | 2172 LayoutLayers(); |
| 2085 SendVSyncParametersToRenderer(); | 2173 SendVSyncParametersToRenderer(); |
| 2086 | 2174 |
| 2087 // Draw the contents of the frame immediately. It is critical that this | 2175 // Draw the contents of the frame immediately. It is critical that this |
| 2088 // happen before the frame be acked, otherwise the new frame will likely be | 2176 // happen before the frame be acked, otherwise the new frame will likely be |
| 2089 // ready before the drawing is complete, thrashing the browser main thread. | 2177 // ready before the drawing is complete, thrashing the browser main thread. |
| 2090 if (use_core_animation_) { | 2178 if (use_core_animation_) { |
| 2091 [software_layer_ setNeedsDisplay]; | |
| 2092 [software_layer_ displayIfNeeded]; | 2179 [software_layer_ displayIfNeeded]; |
| 2093 } else { | 2180 } else { |
| 2094 [cocoa_view_ setNeedsDisplay:YES]; | 2181 [cocoa_view_ setNeedsDisplay:YES]; |
| 2095 [cocoa_view_ displayIfNeeded]; | 2182 [cocoa_view_ displayIfNeeded]; |
| 2096 } | 2183 } |
| 2097 | 2184 |
| 2098 if (last_frame_was_accelerated_) { | 2185 if (last_frame_was_accelerated_) { |
| 2099 last_frame_was_accelerated_ = false; | 2186 last_frame_was_accelerated_ = false; |
| 2100 | 2187 |
| 2101 // If overlapping views are allowed, then don't unbind the context | 2188 // If overlapping views are allowed, then don't unbind the context |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2326 if (compositing_iosurface_layer_) { | 2413 if (compositing_iosurface_layer_) { |
| 2327 // Keep calling gotNewFrame in a loop until enough display calls come in. | 2414 // Keep calling gotNewFrame in a loop until enough display calls come in. |
| 2328 // Each call will be separated by about a vsync. | 2415 // Each call will be separated by about a vsync. |
| 2329 base::MessageLoop::current()->PostTask( | 2416 base::MessageLoop::current()->PostTask( |
| 2330 FROM_HERE, | 2417 FROM_HERE, |
| 2331 base::Bind(&RenderWidgetHostViewMac::TickPendingLatencyInfoDelay, | 2418 base::Bind(&RenderWidgetHostViewMac::TickPendingLatencyInfoDelay, |
| 2332 pending_latency_info_delay_weak_ptr_factory_.GetWeakPtr())); | 2419 pending_latency_info_delay_weak_ptr_factory_.GetWeakPtr())); |
| 2333 [compositing_iosurface_layer_ gotNewFrame]; | 2420 [compositing_iosurface_layer_ gotNewFrame]; |
| 2334 } | 2421 } |
| 2335 if (software_layer_) { | 2422 if (software_layer_) { |
| 2336 // In software mode, setNeedsDisplay will almost immediately result in the | 2423 // In software mode there is not an explicit setNeedsDisplay/display loop, |
| 2337 // layer's draw function being called, so manually insert a pretend-vsync | 2424 // so just wait a pretend-vsync at 60 Hz. |
| 2338 // at 60 Hz. | |
| 2339 base::MessageLoop::current()->PostDelayedTask( | 2425 base::MessageLoop::current()->PostDelayedTask( |
| 2340 FROM_HERE, | 2426 FROM_HERE, |
| 2341 base::Bind(&RenderWidgetHostViewMac::TickPendingLatencyInfoDelay, | 2427 base::Bind(&RenderWidgetHostViewMac::TickPendingLatencyInfoDelay, |
| 2342 pending_latency_info_delay_weak_ptr_factory_.GetWeakPtr()), | 2428 pending_latency_info_delay_weak_ptr_factory_.GetWeakPtr()), |
| 2343 base::TimeDelta::FromMilliseconds(1000/60)); | 2429 base::TimeDelta::FromMilliseconds(1000/60)); |
| 2344 [software_layer_ setNeedsDisplay]; | 2430 SendPendingLatencyInfoToHost(); |
| 2345 } | 2431 } |
| 2346 } | 2432 } |
| 2347 | 2433 |
| 2348 void RenderWidgetHostViewMac::AddPendingSwapAck( | 2434 void RenderWidgetHostViewMac::AddPendingSwapAck( |
| 2349 int32 route_id, int gpu_host_id, int32 renderer_id) { | 2435 int32 route_id, int gpu_host_id, int32 renderer_id) { |
| 2350 // Note that multiple un-acked swaps can come in the event of a GPU process | 2436 // Note that multiple un-acked swaps can come in the event of a GPU process |
| 2351 // loss. Drop the old acks. | 2437 // loss. Drop the old acks. |
| 2352 pending_swap_ack_.reset(new PendingSwapAck( | 2438 pending_swap_ack_.reset(new PendingSwapAck( |
| 2353 route_id, gpu_host_id, renderer_id)); | 2439 route_id, gpu_host_id, renderer_id)); |
| 2354 | 2440 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2440 // Also, sometimes, especially when infobars are being removed, the | 2526 // Also, sometimes, especially when infobars are being removed, the |
| 2441 // setNeedsDisplay calls are dropped on the floor, and stale content is | 2527 // setNeedsDisplay calls are dropped on the floor, and stale content is |
| 2442 // displayed. Calling displayIfNeeded will ensure that the right size | 2528 // displayed. Calling displayIfNeeded will ensure that the right size |
| 2443 // frame is drawn to the screen. | 2529 // frame is drawn to the screen. |
| 2444 // http://crbug.com/350817 | 2530 // http://crbug.com/350817 |
| 2445 [compositing_iosurface_layer_ setNeedsDisplay]; | 2531 [compositing_iosurface_layer_ setNeedsDisplay]; |
| 2446 [compositing_iosurface_layer_ displayIfNeeded]; | 2532 [compositing_iosurface_layer_ displayIfNeeded]; |
| 2447 } | 2533 } |
| 2448 } | 2534 } |
| 2449 | 2535 |
| 2450 // Dynamically update the software layer's contents scale to match the | |
| 2451 // software frame. | |
| 2452 if (software_frame_manager_->HasCurrentFrame() && | |
| 2453 [software_layer_ respondsToSelector:(@selector(contentsScale))] && | |
| 2454 [software_layer_ respondsToSelector:(@selector(setContentsScale:))]) { | |
| 2455 if (software_frame_manager_->GetCurrentFrameDeviceScaleFactor() != | |
| 2456 [software_layer_ contentsScale]) { | |
| 2457 [software_layer_ setContentsScale: | |
| 2458 software_frame_manager_->GetCurrentFrameDeviceScaleFactor()]; | |
| 2459 } | |
| 2460 } | |
| 2461 // Changing the software layer's bounds and position doesn't always result | 2536 // Changing the software layer's bounds and position doesn't always result |
| 2462 // in the layer being anchored to the top-left. Set the layer's frame | 2537 // in the layer being anchored to the top-left. Set the layer's frame |
| 2463 // explicitly, since this is more reliable in practice. | 2538 // explicitly, since this is more reliable in practice. |
| 2464 if (software_layer_) { | 2539 if (software_layer_) { |
| 2465 bool frame_changed = !CGRectEqualToRect( | 2540 bool frame_changed = !CGRectEqualToRect( |
| 2466 new_background_frame, [software_layer_ frame]); | 2541 new_background_frame, [software_layer_ frame]); |
| 2467 if (frame_changed) { | 2542 if (frame_changed) { |
| 2468 [software_layer_ setFrame:new_background_frame]; | 2543 [software_layer_ setFrame:new_background_frame]; |
| 2469 [software_layer_ setNeedsDisplay]; | |
| 2470 } | 2544 } |
| 2471 } | 2545 } |
| 2472 } | 2546 } |
| 2473 | 2547 |
| 2474 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { | 2548 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { |
| 2475 return SkBitmap::kARGB_8888_Config; | 2549 return SkBitmap::kARGB_8888_Config; |
| 2476 } | 2550 } |
| 2477 | 2551 |
| 2478 } // namespace content | 2552 } // namespace content |
| 2479 | 2553 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3312 - (void)onNativeSurfaceBuffersSwappedWithParams: | 3386 - (void)onNativeSurfaceBuffersSwappedWithParams: |
| 3313 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { | 3387 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { |
| 3314 | 3388 |
| 3315 renderWidgetHostView_->CompositorSwapBuffers( | 3389 renderWidgetHostView_->CompositorSwapBuffers( |
| 3316 params.surface_handle, | 3390 params.surface_handle, |
| 3317 params.size, | 3391 params.size, |
| 3318 params.scale_factor, | 3392 params.scale_factor, |
| 3319 params.latency_info); | 3393 params.latency_info); |
| 3320 } | 3394 } |
| 3321 | 3395 |
| 3396 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data | |
| 3397 withScaleFactor:(float)scale_factor | |
| 3398 withCanvas:(SkCanvas*)canvas { | |
| 3399 renderWidgetHostView_->GotBrowserCompositorSoftwareFrame( | |
| 3400 frame_data, scale_factor, canvas); | |
| 3401 } | |
| 3402 | |
| 3322 - (void)drawRect:(NSRect)dirtyRect { | 3403 - (void)drawRect:(NSRect)dirtyRect { |
| 3323 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); | 3404 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
| 3324 DCHECK(!renderWidgetHostView_->use_core_animation_); | 3405 DCHECK(!renderWidgetHostView_->use_core_animation_); |
| 3325 | 3406 |
| 3326 if (!renderWidgetHostView_->render_widget_host_) { | 3407 if (!renderWidgetHostView_->render_widget_host_) { |
| 3327 // When using CoreAnimation, this path is used to paint the contents area | 3408 // When using CoreAnimation, this path is used to paint the contents area |
| 3328 // white before any frames come in. When layers to draw frames exist, this | 3409 // white before any frames come in. When layers to draw frames exist, this |
| 3329 // is not hit. | 3410 // is not hit. |
| 3330 [[NSColor whiteColor] set]; | 3411 [[NSColor whiteColor] set]; |
| 3331 NSRectFill(dirtyRect); | 3412 NSRectFill(dirtyRect); |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4382 // native_app_window_cocoa.mm). This requires the render host view to be | 4463 // native_app_window_cocoa.mm). This requires the render host view to be |
| 4383 // draggable by default. | 4464 // draggable by default. |
| 4384 - (BOOL)mouseDownCanMoveWindow { | 4465 - (BOOL)mouseDownCanMoveWindow { |
| 4385 return YES; | 4466 return YES; |
| 4386 } | 4467 } |
| 4387 | 4468 |
| 4388 @end | 4469 @end |
| 4389 | 4470 |
| 4390 @implementation SoftwareLayer | 4471 @implementation SoftwareLayer |
| 4391 | 4472 |
| 4392 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r { | 4473 - (id)init { |
| 4393 if (self = [super init]) { | 4474 if (self = [super init]) { |
| 4394 renderWidgetHostView_ = r; | |
| 4395 | |
| 4396 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 4475 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| 4397 [self setAnchorPoint:CGPointMake(0, 0)]; | 4476 [self setAnchorPoint:CGPointMake(0, 0)]; |
| 4398 // Setting contents gravity is necessary to prevent the layer from being | 4477 // Setting contents gravity is necessary to prevent the layer from being |
| 4399 // scaled during dyanmic resizes (especially with devtools open). | 4478 // scaled during dyanmic resizes (especially with devtools open). |
| 4400 [self setContentsGravity:kCAGravityTopLeft]; | 4479 [self setContentsGravity:kCAGravityTopLeft]; |
| 4401 if (renderWidgetHostView_->software_frame_manager_->HasCurrentFrame() && | |
| 4402 [self respondsToSelector:(@selector(setContentsScale:))]) { | |
| 4403 [self setContentsScale:renderWidgetHostView_->software_frame_manager_-> | |
| 4404 GetCurrentFrameDeviceScaleFactor()]; | |
| 4405 } | |
| 4406 | |
| 4407 // Ensure that the transition between frames not be animated. | |
| 4408 [self setActions:@{ @"contents" : [NSNull null] }]; | |
| 4409 } | 4480 } |
| 4410 return self; | 4481 return self; |
| 4411 } | 4482 } |
| 4412 | 4483 |
| 4413 - (void)drawInContext:(CGContextRef)context { | |
| 4414 TRACE_EVENT0("browser", "SoftwareLayer::drawInContext"); | |
| 4415 | |
| 4416 CGRect clipRect = CGContextGetClipBoundingBox(context); | |
| 4417 if (renderWidgetHostView_) { | |
| 4418 [renderWidgetHostView_->cocoa_view() drawWithDirtyRect:clipRect | |
| 4419 inContext:context]; | |
| 4420 } else { | |
| 4421 CGContextSetFillColorWithColor(context, | |
| 4422 CGColorGetConstantColor(kCGColorWhite)); | |
| 4423 CGContextFillRect(context, clipRect); | |
| 4424 } | |
| 4425 } | |
| 4426 | |
| 4427 - (void)disableRendering { | 4484 - (void)disableRendering { |
| 4428 // Disable the fade-out animation as the layer is removed. | 4485 // Disable the fade-out animation as the layer is removed. |
| 4429 ScopedCAActionDisabler disabler; | 4486 ScopedCAActionDisabler disabler; |
| 4430 [self removeFromSuperlayer]; | 4487 [self removeFromSuperlayer]; |
| 4431 renderWidgetHostView_ = nil; | |
| 4432 } | 4488 } |
| 4433 | 4489 |
| 4434 @end // implementation SoftwareLayer | 4490 @end // implementation SoftwareLayer |
| OLD | NEW |