| 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/mac/sdk_forward_declarations.h" | 13 #include "base/mac/sdk_forward_declarations.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/accelerated_widget_mac/ca_renderer_layer_params.h" |
| 16 #include "ui/base/cocoa/animation_utils.h" | 17 #include "ui/base/cocoa/animation_utils.h" |
| 17 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
| 18 #include "ui/gfx/geometry/dip_util.h" | 19 #include "ui/gfx/geometry/dip_util.h" |
| 19 | 20 |
| 20 #if !defined(MAC_OS_X_VERSION_10_8) || \ | 21 #if !defined(MAC_OS_X_VERSION_10_8) || \ |
| 21 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 | 22 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 |
| 22 extern NSString* const AVLayerVideoGravityResize; | 23 extern NSString* const AVLayerVideoGravityResize; |
| 23 extern "C" void NSAccessibilityPostNotificationWithUserInfo( | 24 extern "C" void NSAccessibilityPostNotificationWithUserInfo( |
| 24 id object, | 25 id object, |
| 25 NSString* notification, | 26 NSString* notification, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 return AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, | 125 return AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, |
| 125 cv_pixel_buffer); | 126 cv_pixel_buffer); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace | 129 } // namespace |
| 129 | 130 |
| 130 CARendererLayerTree::CARendererLayerTree() {} | 131 CARendererLayerTree::CARendererLayerTree() {} |
| 131 CARendererLayerTree::~CARendererLayerTree() {} | 132 CARendererLayerTree::~CARendererLayerTree() {} |
| 132 | 133 |
| 133 bool CARendererLayerTree::ScheduleCALayer( | 134 bool CARendererLayerTree::ScheduleCALayer(const CARendererLayerParams& params) { |
| 134 bool is_clipped, | |
| 135 const gfx::Rect& clip_rect, | |
| 136 unsigned sorting_context_id, | |
| 137 const gfx::Transform& transform, | |
| 138 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 139 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 140 const gfx::RectF& contents_rect, | |
| 141 const gfx::Rect& rect, | |
| 142 unsigned background_color, | |
| 143 unsigned edge_aa_mask, | |
| 144 float opacity, | |
| 145 unsigned filter) { | |
| 146 // Excessive logging to debug white screens (crbug.com/583805). | 135 // Excessive logging to debug white screens (crbug.com/583805). |
| 147 // TODO(ccameron): change this back to a DLOG. | 136 // TODO(ccameron): change this back to a DLOG. |
| 148 if (has_committed_) { | 137 if (has_committed_) { |
| 149 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; | 138 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; |
| 150 return false; | 139 return false; |
| 151 } | 140 } |
| 152 return root_layer_.AddContentLayer(is_clipped, clip_rect, sorting_context_id, | 141 return root_layer_.AddContentLayer(params); |
| 153 transform, io_surface, cv_pixel_buffer, | |
| 154 contents_rect, rect, background_color, | |
| 155 edge_aa_mask, opacity, filter); | |
| 156 } | 142 } |
| 157 | 143 |
| 158 void CARendererLayerTree::CommitScheduledCALayers( | 144 void CARendererLayerTree::CommitScheduledCALayers( |
| 159 CALayer* superlayer, | 145 CALayer* superlayer, |
| 160 std::unique_ptr<CARendererLayerTree> old_tree, | 146 std::unique_ptr<CARendererLayerTree> old_tree, |
| 161 float scale_factor) { | 147 float scale_factor) { |
| 162 TRACE_EVENT0("gpu", "CARendererLayerTree::CommitScheduledCALayers"); | 148 TRACE_EVENT0("gpu", "CARendererLayerTree::CommitScheduledCALayers"); |
| 163 RootLayer* old_root_layer = nullptr; | 149 RootLayer* old_root_layer = nullptr; |
| 164 if (old_tree) { | 150 if (old_tree) { |
| 165 DCHECK(old_tree->has_committed_); | 151 DCHECK(old_tree->has_committed_); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 use_av_layer(layer.use_av_layer) { | 331 use_av_layer(layer.use_av_layer) { |
| 346 DCHECK(!layer.ca_layer); | 332 DCHECK(!layer.ca_layer); |
| 347 DCHECK(!layer.av_layer); | 333 DCHECK(!layer.av_layer); |
| 348 } | 334 } |
| 349 | 335 |
| 350 CARendererLayerTree::ContentLayer::~ContentLayer() { | 336 CARendererLayerTree::ContentLayer::~ContentLayer() { |
| 351 [ca_layer removeFromSuperlayer]; | 337 [ca_layer removeFromSuperlayer]; |
| 352 } | 338 } |
| 353 | 339 |
| 354 bool CARendererLayerTree::RootLayer::AddContentLayer( | 340 bool CARendererLayerTree::RootLayer::AddContentLayer( |
| 355 bool is_clipped, | 341 const CARendererLayerParams& params) { |
| 356 const gfx::Rect& clip_rect, | |
| 357 unsigned sorting_context_id, | |
| 358 const gfx::Transform& transform, | |
| 359 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 360 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 361 const gfx::RectF& contents_rect, | |
| 362 const gfx::Rect& rect, | |
| 363 unsigned background_color, | |
| 364 unsigned edge_aa_mask, | |
| 365 float opacity, | |
| 366 unsigned filter) { | |
| 367 bool needs_new_clip_and_sorting_layer = true; | 342 bool needs_new_clip_and_sorting_layer = true; |
| 368 | 343 |
| 369 // In sorting_context_id 0, all quads are listed in back-to-front order. | 344 // In sorting_context_id 0, all quads are listed in back-to-front order. |
| 370 // This is accomplished by having the CALayers be siblings of each other. | 345 // This is accomplished by having the CALayers be siblings of each other. |
| 371 // If a quad has a 3D transform, it is necessary to put it in its own sorting | 346 // If a quad has a 3D transform, it is necessary to put it in its own sorting |
| 372 // context, so that it will not intersect with quads before and after it. | 347 // context, so that it will not intersect with quads before and after it. |
| 373 bool is_singleton_sorting_context = | 348 bool is_singleton_sorting_context = |
| 374 !sorting_context_id && !transform.IsFlat(); | 349 !params.sorting_context_id && !params.transform.IsFlat(); |
| 375 | 350 |
| 376 if (!clip_and_sorting_layers.empty()) { | 351 if (!clip_and_sorting_layers.empty()) { |
| 377 ClipAndSortingLayer& current_layer = clip_and_sorting_layers.back(); | 352 ClipAndSortingLayer& current_layer = clip_and_sorting_layers.back(); |
| 378 // It is in error to change the clipping settings within a non-zero sorting | 353 // It is in error to change the clipping settings within a non-zero sorting |
| 379 // context. The result will be incorrect layering and intersection. | 354 // context. The result will be incorrect layering and intersection. |
| 380 if (sorting_context_id && | 355 if (params.sorting_context_id && |
| 381 current_layer.sorting_context_id == sorting_context_id && | 356 current_layer.sorting_context_id == params.sorting_context_id && |
| 382 (current_layer.is_clipped != is_clipped || | 357 (current_layer.is_clipped != params.is_clipped || |
| 383 current_layer.clip_rect != clip_rect)) { | 358 current_layer.clip_rect != params.clip_rect)) { |
| 384 // Excessive logging to debug white screens (crbug.com/583805). | 359 // Excessive logging to debug white screens (crbug.com/583805). |
| 385 // TODO(ccameron): change this back to a DLOG. | 360 // TODO(ccameron): change this back to a DLOG. |
| 386 LOG(ERROR) << "CALayer changed clip inside non-zero sorting context."; | 361 LOG(ERROR) << "CALayer changed clip inside non-zero sorting context."; |
| 387 return false; | 362 return false; |
| 388 } | 363 } |
| 389 if (!is_singleton_sorting_context && | 364 if (!is_singleton_sorting_context && |
| 390 !current_layer.is_singleton_sorting_context && | 365 !current_layer.is_singleton_sorting_context && |
| 391 current_layer.is_clipped == is_clipped && | 366 current_layer.is_clipped == params.is_clipped && |
| 392 current_layer.clip_rect == clip_rect && | 367 current_layer.clip_rect == params.clip_rect && |
| 393 current_layer.sorting_context_id == sorting_context_id) { | 368 current_layer.sorting_context_id == params.sorting_context_id) { |
| 394 needs_new_clip_and_sorting_layer = false; | 369 needs_new_clip_and_sorting_layer = false; |
| 395 } | 370 } |
| 396 } | 371 } |
| 397 if (needs_new_clip_and_sorting_layer) { | 372 if (needs_new_clip_and_sorting_layer) { |
| 398 clip_and_sorting_layers.push_back( | 373 clip_and_sorting_layers.push_back(ClipAndSortingLayer( |
| 399 ClipAndSortingLayer(is_clipped, clip_rect, sorting_context_id, | 374 params.is_clipped, params.clip_rect, params.sorting_context_id, |
| 400 is_singleton_sorting_context)); | 375 is_singleton_sorting_context)); |
| 401 } | 376 } |
| 402 clip_and_sorting_layers.back().AddContentLayer( | 377 clip_and_sorting_layers.back().AddContentLayer(params); |
| 403 transform, io_surface, cv_pixel_buffer, contents_rect, rect, | |
| 404 background_color, edge_aa_mask, opacity, filter); | |
| 405 return true; | 378 return true; |
| 406 } | 379 } |
| 407 | 380 |
| 408 void CARendererLayerTree::ClipAndSortingLayer::AddContentLayer( | 381 void CARendererLayerTree::ClipAndSortingLayer::AddContentLayer( |
| 409 const gfx::Transform& transform, | 382 const CARendererLayerParams& params) { |
| 410 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 411 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 412 const gfx::RectF& contents_rect, | |
| 413 const gfx::Rect& rect, | |
| 414 unsigned background_color, | |
| 415 unsigned edge_aa_mask, | |
| 416 float opacity, | |
| 417 unsigned filter) { | |
| 418 bool needs_new_transform_layer = true; | 383 bool needs_new_transform_layer = true; |
| 419 if (!transform_layers.empty()) { | 384 if (!transform_layers.empty()) { |
| 420 const TransformLayer& current_layer = transform_layers.back(); | 385 const TransformLayer& current_layer = transform_layers.back(); |
| 421 if (current_layer.transform == transform) | 386 if (current_layer.transform == params.transform) |
| 422 needs_new_transform_layer = false; | 387 needs_new_transform_layer = false; |
| 423 } | 388 } |
| 424 if (needs_new_transform_layer) | 389 if (needs_new_transform_layer) |
| 425 transform_layers.push_back(TransformLayer(transform)); | 390 transform_layers.push_back(TransformLayer(params.transform)); |
| 426 transform_layers.back().AddContentLayer(io_surface, cv_pixel_buffer, | 391 transform_layers.back().AddContentLayer(params); |
| 427 contents_rect, rect, background_color, | |
| 428 edge_aa_mask, opacity, filter); | |
| 429 } | 392 } |
| 430 | 393 |
| 431 void CARendererLayerTree::TransformLayer::AddContentLayer( | 394 void CARendererLayerTree::TransformLayer::AddContentLayer( |
| 432 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 395 const CARendererLayerParams& params) { |
| 433 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | 396 content_layers.push_back( |
| 434 const gfx::RectF& contents_rect, | 397 ContentLayer(params.io_surface, params.cv_pixel_buffer, |
| 435 const gfx::Rect& rect, | 398 params.contents_rect, params.rect, params.background_color, |
| 436 unsigned background_color, | 399 params.edge_aa_mask, params.opacity, params.filter)); |
| 437 unsigned edge_aa_mask, | |
| 438 float opacity, | |
| 439 unsigned filter) { | |
| 440 content_layers.push_back(ContentLayer(io_surface, cv_pixel_buffer, | |
| 441 contents_rect, rect, background_color, | |
| 442 edge_aa_mask, opacity, filter)); | |
| 443 } | 400 } |
| 444 | 401 |
| 445 void CARendererLayerTree::RootLayer::CommitToCA(CALayer* superlayer, | 402 void CARendererLayerTree::RootLayer::CommitToCA(CALayer* superlayer, |
| 446 RootLayer* old_layer, | 403 RootLayer* old_layer, |
| 447 float scale_factor) { | 404 float scale_factor) { |
| 448 if (old_layer) { | 405 if (old_layer) { |
| 449 DCHECK(old_layer->ca_layer); | 406 DCHECK(old_layer->ca_layer); |
| 450 std::swap(ca_layer, old_layer->ca_layer); | 407 std::swap(ca_layer, old_layer->ca_layer); |
| 451 } else { | 408 } else { |
| 452 ca_layer.reset([[CALayer alloc] init]); | 409 ca_layer.reset([[CALayer alloc] init]); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 } else { | 611 } else { |
| 655 // Grey represents a CALayer that has not changed. | 612 // Grey represents a CALayer that has not changed. |
| 656 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); | 613 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); |
| 657 } | 614 } |
| 658 [ca_layer setBorderWidth:1]; | 615 [ca_layer setBorderWidth:1]; |
| 659 [ca_layer setBorderColor:color]; | 616 [ca_layer setBorderColor:color]; |
| 660 } | 617 } |
| 661 } | 618 } |
| 662 | 619 |
| 663 } // namespace ui | 620 } // namespace ui |
| OLD | NEW |