Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" | 5 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" |
| 6 | 6 |
| 7 #include <AVFoundation/AVFoundation.h> | 7 #include <AVFoundation/AVFoundation.h> |
| 8 #include <CoreMedia/CoreMedia.h> | 8 #include <CoreMedia/CoreMedia.h> |
| 9 #include <CoreVideo/CoreVideo.h> | 9 #include <CoreVideo/CoreVideo.h> |
| 10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/mac/mac_util.h" | |
| 15 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
| 16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "ui/base/cocoa/animation_utils.h" | 17 #include "ui/base/cocoa/animation_utils.h" |
| 19 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
| 20 #include "ui/gfx/geometry/dip_util.h" | 19 #include "ui/gfx/geometry/dip_util.h" |
| 21 #include "ui/gl/ca_renderer_layer_params.h" | 20 #include "ui/gl/ca_renderer_layer_params.h" |
| 22 #include "ui/gl/gl_image_io_surface.h" | 21 #include "ui/gl/gl_image_io_surface.h" |
| 23 | 22 |
| 24 #if !defined(MAC_OS_X_VERSION_10_8) || \ | 23 #if !defined(MAC_OS_X_VERSION_10_8) || \ |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 193 } |
| 195 | 194 |
| 196 CARendererLayerTree::SolidColorContents::~SolidColorContents() { | 195 CARendererLayerTree::SolidColorContents::~SolidColorContents() { |
| 197 auto found = map_.Get().find(color_); | 196 auto found = map_.Get().find(color_); |
| 198 DCHECK(found != map_.Get().end()); | 197 DCHECK(found != map_.Get().end()); |
| 199 DCHECK(found->second == this); | 198 DCHECK(found->second == this); |
| 200 map_.Get().erase(color_); | 199 map_.Get().erase(color_); |
| 201 } | 200 } |
| 202 | 201 |
| 203 CARendererLayerTree::CARendererLayerTree( | 202 CARendererLayerTree::CARendererLayerTree( |
| 204 bool allow_av_sample_buffer_display_layer) | 203 bool allow_av_sample_buffer_display_layer, |
| 204 bool allow_solid_color_layers) | |
| 205 : allow_av_sample_buffer_display_layer_( | 205 : allow_av_sample_buffer_display_layer_( |
| 206 allow_av_sample_buffer_display_layer) {} | 206 allow_av_sample_buffer_display_layer), |
| 207 allow_solid_color_layers_(allow_solid_color_layers) {} | |
| 207 CARendererLayerTree::~CARendererLayerTree() {} | 208 CARendererLayerTree::~CARendererLayerTree() {} |
| 208 | 209 |
| 209 bool CARendererLayerTree::ScheduleCALayer(const CARendererLayerParams& params) { | 210 bool CARendererLayerTree::ScheduleCALayer(const CARendererLayerParams& params) { |
| 210 // Excessive logging to debug white screens (crbug.com/583805). | 211 // Excessive logging to debug white screens (crbug.com/583805). |
| 211 // TODO(ccameron): change this back to a DLOG. | 212 // TODO(ccameron): change this back to a DLOG. |
| 212 if (has_committed_) { | 213 if (has_committed_) { |
| 213 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; | 214 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; |
| 214 return false; | 215 return false; |
| 215 } | 216 } |
| 216 return root_layer_.AddContentLayer(this, params); | 217 return root_layer_.AddContentLayer(this, params); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 fullscreen_low_power_layer, video_layer->cv_pixel_buffer); | 281 fullscreen_low_power_layer, video_layer->cv_pixel_buffer); |
| 281 } else { | 282 } else { |
| 282 AVSampleBufferDisplayLayerEnqueueIOSurface(fullscreen_low_power_layer, | 283 AVSampleBufferDisplayLayerEnqueueIOSurface(fullscreen_low_power_layer, |
| 283 video_layer->io_surface); | 284 video_layer->io_surface); |
| 284 } | 285 } |
| 285 [fullscreen_low_power_layer setVideoGravity:AVLayerVideoGravityResize]; | 286 [fullscreen_low_power_layer setVideoGravity:AVLayerVideoGravityResize]; |
| 286 [fullscreen_low_power_layer setFrame:video_layer_frame_dip.ToCGRect()]; | 287 [fullscreen_low_power_layer setFrame:video_layer_frame_dip.ToCGRect()]; |
| 287 return true; | 288 return true; |
| 288 } | 289 } |
| 289 | 290 |
| 291 id CARendererLayerTree::ContentsForSolidColorForTesting(SkColor color) { | |
| 292 return SolidColorContents::Get(color)->GetContents(); | |
| 293 } | |
| 290 | 294 |
| 291 CARendererLayerTree::RootLayer::RootLayer() {} | 295 CARendererLayerTree::RootLayer::RootLayer() {} |
| 292 | 296 |
| 293 // Note that for all destructors, the the CALayer will have been reset to nil if | 297 // Note that for all destructors, the the CALayer will have been reset to nil if |
| 294 // another layer has taken it. | 298 // another layer has taken it. |
| 295 CARendererLayerTree::RootLayer::~RootLayer() { | 299 CARendererLayerTree::RootLayer::~RootLayer() { |
| 296 [ca_layer removeFromSuperlayer]; | 300 [ca_layer removeFromSuperlayer]; |
| 297 } | 301 } |
| 298 | 302 |
| 299 CARendererLayerTree::ClipAndSortingLayer::ClipAndSortingLayer( | 303 CARendererLayerTree::ClipAndSortingLayer::ClipAndSortingLayer( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 opacity(opacity), | 363 opacity(opacity), |
| 360 ca_filter(filter == GL_LINEAR ? kCAFilterLinear : kCAFilterNearest) { | 364 ca_filter(filter == GL_LINEAR ? kCAFilterLinear : kCAFilterNearest) { |
| 361 DCHECK(filter == GL_LINEAR || filter == GL_NEAREST); | 365 DCHECK(filter == GL_LINEAR || filter == GL_NEAREST); |
| 362 | 366 |
| 363 // On Mac OS Sierra, solid color layers are not color color corrected to the | 367 // On Mac OS Sierra, solid color layers are not color color corrected to the |
| 364 // output monitor color space, but IOSurface-backed layers are color | 368 // output monitor color space, but IOSurface-backed layers are color |
| 365 // corrected. Note that this is only the case when the CALayers are shared | 369 // corrected. Note that this is only the case when the CALayers are shared |
| 366 // across processes. To make colors consistent across both solid color and | 370 // across processes. To make colors consistent across both solid color and |
| 367 // IOSurface-backed layers, use a cache of solid-color IOSurfaces as contents. | 371 // IOSurface-backed layers, use a cache of solid-color IOSurfaces as contents. |
| 368 // https://crbug.com/633805 | 372 // https://crbug.com/633805 |
| 369 if (base::mac::IsAtLeastOS10_12()) { | 373 if (!io_surface && !tree->allow_solid_color_layers_) { |
|
ccameron
2016/09/30 22:14:18
I was testing this on 10.11, so I screwed up this
| |
| 370 solid_color_contents = SolidColorContents::Get(background_color); | 374 solid_color_contents = SolidColorContents::Get(background_color); |
| 371 ContentLayer::contents_rect = gfx::RectF(0, 0, 1, 1); | 375 ContentLayer::contents_rect = gfx::RectF(0, 0, 1, 1); |
| 372 } | 376 } |
| 373 | 377 |
| 374 // Because the root layer has setGeometryFlipped:YES, there is some ambiguity | 378 // Because the root layer has setGeometryFlipped:YES, there is some ambiguity |
| 375 // about what exactly top and bottom mean. This ambiguity is resolved in | 379 // about what exactly top and bottom mean. This ambiguity is resolved in |
| 376 // different ways for solid color CALayers and for CALayers that have content | 380 // different ways for solid color CALayers and for CALayers that have content |
| 377 // (surprise!). For CALayers with IOSurface content, the top edge in the AA | 381 // (surprise!). For CALayers with IOSurface content, the top edge in the AA |
| 378 // mask refers to what appears as the bottom edge on-screen. For CALayers | 382 // mask refers to what appears as the bottom edge on-screen. For CALayers |
| 379 // without content (solid color layers), the top edge in the AA mask is the | 383 // without content (solid color layers), the top edge in the AA mask is the |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 } else { | 670 } else { |
| 667 AVSampleBufferDisplayLayerEnqueueIOSurface(av_layer, io_surface); | 671 AVSampleBufferDisplayLayerEnqueueIOSurface(av_layer, io_surface); |
| 668 } | 672 } |
| 669 } | 673 } |
| 670 } else { | 674 } else { |
| 671 if (update_contents) { | 675 if (update_contents) { |
| 672 if (io_surface) { | 676 if (io_surface) { |
| 673 [ca_layer setContents:static_cast<id>(io_surface.get())]; | 677 [ca_layer setContents:static_cast<id>(io_surface.get())]; |
| 674 } else if (solid_color_contents) { | 678 } else if (solid_color_contents) { |
| 675 [ca_layer setContents:solid_color_contents->GetContents()]; | 679 [ca_layer setContents:solid_color_contents->GetContents()]; |
| 680 } else { | |
| 681 [ca_layer setContents:nil]; | |
| 676 } | 682 } |
| 677 if ([ca_layer respondsToSelector:(@selector(setContentsScale:))]) | 683 if ([ca_layer respondsToSelector:(@selector(setContentsScale:))]) |
| 678 [ca_layer setContentsScale:scale_factor]; | 684 [ca_layer setContentsScale:scale_factor]; |
| 679 } | 685 } |
| 680 if (update_contents_rect) | 686 if (update_contents_rect) |
| 681 [ca_layer setContentsRect:contents_rect.ToCGRect()]; | 687 [ca_layer setContentsRect:contents_rect.ToCGRect()]; |
| 682 } | 688 } |
| 683 if (update_rect) { | 689 if (update_rect) { |
| 684 gfx::RectF dip_rect = gfx::RectF(rect); | 690 gfx::RectF dip_rect = gfx::RectF(rect); |
| 685 dip_rect.Scale(1 / scale_factor); | 691 dip_rect.Scale(1 / scale_factor); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 708 | 714 |
| 709 static bool show_borders = base::CommandLine::ForCurrentProcess()->HasSwitch( | 715 static bool show_borders = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 710 switches::kShowMacOverlayBorders); | 716 switches::kShowMacOverlayBorders); |
| 711 if (show_borders) { | 717 if (show_borders) { |
| 712 base::ScopedCFTypeRef<CGColorRef> color; | 718 base::ScopedCFTypeRef<CGColorRef> color; |
| 713 if (update_anything) { | 719 if (update_anything) { |
| 714 if (use_av_layer) { | 720 if (use_av_layer) { |
| 715 // Yellow represents an AV layer that changed this frame. | 721 // Yellow represents an AV layer that changed this frame. |
| 716 color.reset(CGColorCreateGenericRGB(1, 1, 0, 1)); | 722 color.reset(CGColorCreateGenericRGB(1, 1, 0, 1)); |
| 717 } else if (io_surface) { | 723 } else if (io_surface) { |
| 718 // Pink represents a CALayer that changed this frame. | 724 // Magenta represents a CALayer that changed this frame. |
| 719 color.reset(CGColorCreateGenericRGB(1, 0, 1, 1)); | 725 color.reset(CGColorCreateGenericRGB(1, 0, 1, 1)); |
| 720 } else if (solid_color_contents) { | 726 } else if (solid_color_contents) { |
| 721 // Cyan represents a solid color IOSurface-backed layer. | 727 // Cyan represents a solid color IOSurface-backed layer. |
| 722 color.reset(CGColorCreateGenericRGB(0, 1, 1, 1)); | 728 color.reset(CGColorCreateGenericRGB(0, 1, 1, 1)); |
| 723 } else { | 729 } else { |
| 724 // Red represents a solid color layer. | 730 // Red represents a solid color layer. |
| 725 color.reset(CGColorCreateGenericRGB(1, 0, 0, 1)); | 731 color.reset(CGColorCreateGenericRGB(1, 0, 0, 1)); |
| 726 } | 732 } |
| 727 } else { | 733 } else { |
| 728 // Grey represents a CALayer that has not changed. | 734 // Grey represents a CALayer that has not changed. |
| 729 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); | 735 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); |
| 730 } | 736 } |
| 731 [ca_layer setBorderWidth:1]; | 737 [ca_layer setBorderWidth:1]; |
| 732 [ca_layer setBorderColor:color]; | 738 [ca_layer setBorderColor:color]; |
| 733 } | 739 } |
| 734 } | 740 } |
| 735 | 741 |
| 736 } // namespace ui | 742 } // namespace ui |
| OLD | NEW |