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