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