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> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 LOG(ERROR) << "CVPixelBufferCreateWithIOSurface failed with " << cv_return; | 122 LOG(ERROR) << "CVPixelBufferCreateWithIOSurface failed with " << cv_return; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 return AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, | 126 return AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, |
127 cv_pixel_buffer); | 127 cv_pixel_buffer); |
128 } | 128 } |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 CARendererLayerTree::CARendererLayerTree() {} | 132 CARendererLayerTree::CARendererLayerTree( |
| 133 bool allow_av_sample_buffer_display_layer) |
| 134 : allow_av_sample_buffer_display_layer_( |
| 135 allow_av_sample_buffer_display_layer) {} |
133 CARendererLayerTree::~CARendererLayerTree() {} | 136 CARendererLayerTree::~CARendererLayerTree() {} |
134 | 137 |
135 bool CARendererLayerTree::ScheduleCALayer(const CARendererLayerParams& params) { | 138 bool CARendererLayerTree::ScheduleCALayer(const CARendererLayerParams& params) { |
136 // Excessive logging to debug white screens (crbug.com/583805). | 139 // Excessive logging to debug white screens (crbug.com/583805). |
137 // TODO(ccameron): change this back to a DLOG. | 140 // TODO(ccameron): change this back to a DLOG. |
138 if (has_committed_) { | 141 if (has_committed_) { |
139 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; | 142 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; |
140 return false; | 143 return false; |
141 } | 144 } |
142 return root_layer_.AddContentLayer(params); | 145 return root_layer_.AddContentLayer(this, params); |
143 } | 146 } |
144 | 147 |
145 void CARendererLayerTree::CommitScheduledCALayers( | 148 void CARendererLayerTree::CommitScheduledCALayers( |
146 CALayer* superlayer, | 149 CALayer* superlayer, |
147 std::unique_ptr<CARendererLayerTree> old_tree, | 150 std::unique_ptr<CARendererLayerTree> old_tree, |
148 float scale_factor) { | 151 float scale_factor) { |
149 TRACE_EVENT0("gpu", "CARendererLayerTree::CommitScheduledCALayers"); | 152 TRACE_EVENT0("gpu", "CARendererLayerTree::CommitScheduledCALayers"); |
150 RootLayer* old_root_layer = nullptr; | 153 RootLayer* old_root_layer = nullptr; |
151 if (old_tree) { | 154 if (old_tree) { |
152 DCHECK(old_tree->has_committed_); | 155 DCHECK(old_tree->has_committed_); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 content_layers(std::move(layer.content_layers)), | 263 content_layers(std::move(layer.content_layers)), |
261 ca_layer(layer.ca_layer) { | 264 ca_layer(layer.ca_layer) { |
262 layer.ca_layer.reset(); | 265 layer.ca_layer.reset(); |
263 } | 266 } |
264 | 267 |
265 CARendererLayerTree::TransformLayer::~TransformLayer() { | 268 CARendererLayerTree::TransformLayer::~TransformLayer() { |
266 [ca_layer removeFromSuperlayer]; | 269 [ca_layer removeFromSuperlayer]; |
267 } | 270 } |
268 | 271 |
269 CARendererLayerTree::ContentLayer::ContentLayer( | 272 CARendererLayerTree::ContentLayer::ContentLayer( |
| 273 CARendererLayerTree* tree, |
270 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 274 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
271 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | 275 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
272 const gfx::RectF& contents_rect, | 276 const gfx::RectF& contents_rect, |
273 const gfx::Rect& rect, | 277 const gfx::Rect& rect, |
274 unsigned background_color, | 278 unsigned background_color, |
275 unsigned edge_aa_mask, | 279 unsigned edge_aa_mask, |
276 float opacity, | 280 float opacity, |
277 unsigned filter) | 281 unsigned filter) |
278 : io_surface(io_surface), | 282 : io_surface(io_surface), |
279 cv_pixel_buffer(cv_pixel_buffer), | 283 cv_pixel_buffer(cv_pixel_buffer), |
(...skipping 24 matching lines...) Expand all Loading... |
304 ca_edge_aa_mask |= kCALayerTopEdge; | 308 ca_edge_aa_mask |= kCALayerTopEdge; |
305 } else { | 309 } else { |
306 if (edge_aa_mask & GL_CA_LAYER_EDGE_TOP_CHROMIUM) | 310 if (edge_aa_mask & GL_CA_LAYER_EDGE_TOP_CHROMIUM) |
307 ca_edge_aa_mask |= kCALayerTopEdge; | 311 ca_edge_aa_mask |= kCALayerTopEdge; |
308 if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM) | 312 if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM) |
309 ca_edge_aa_mask |= kCALayerBottomEdge; | 313 ca_edge_aa_mask |= kCALayerBottomEdge; |
310 } | 314 } |
311 | 315 |
312 // Only allow 4:2:0 frames which fill the layer's contents to be promoted to | 316 // Only allow 4:2:0 frames which fill the layer's contents to be promoted to |
313 // AV layers. | 317 // AV layers. |
314 if (IOSurfaceGetPixelFormat(io_surface) == | 318 if (tree->allow_av_sample_buffer_display_layer_ && |
| 319 IOSurfaceGetPixelFormat(io_surface) == |
315 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange && | 320 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange && |
316 contents_rect == gfx::RectF(0, 0, 1, 1)) { | 321 contents_rect == gfx::RectF(0, 0, 1, 1)) { |
317 use_av_layer = true; | 322 use_av_layer = true; |
318 } | 323 } |
319 } | 324 } |
320 | 325 |
321 CARendererLayerTree::ContentLayer::ContentLayer(ContentLayer&& layer) | 326 CARendererLayerTree::ContentLayer::ContentLayer(ContentLayer&& layer) |
322 : io_surface(layer.io_surface), | 327 : io_surface(layer.io_surface), |
323 cv_pixel_buffer(layer.cv_pixel_buffer), | 328 cv_pixel_buffer(layer.cv_pixel_buffer), |
324 contents_rect(layer.contents_rect), | 329 contents_rect(layer.contents_rect), |
325 rect(layer.rect), | 330 rect(layer.rect), |
326 background_color(layer.background_color), | 331 background_color(layer.background_color), |
327 ca_edge_aa_mask(layer.ca_edge_aa_mask), | 332 ca_edge_aa_mask(layer.ca_edge_aa_mask), |
328 opacity(layer.opacity), | 333 opacity(layer.opacity), |
329 ca_filter(layer.ca_filter), | 334 ca_filter(layer.ca_filter), |
330 ca_layer(std::move(layer.ca_layer)), | 335 ca_layer(std::move(layer.ca_layer)), |
331 av_layer(std::move(layer.av_layer)), | 336 av_layer(std::move(layer.av_layer)), |
332 use_av_layer(layer.use_av_layer) { | 337 use_av_layer(layer.use_av_layer) { |
333 DCHECK(!layer.ca_layer); | 338 DCHECK(!layer.ca_layer); |
334 DCHECK(!layer.av_layer); | 339 DCHECK(!layer.av_layer); |
335 } | 340 } |
336 | 341 |
337 CARendererLayerTree::ContentLayer::~ContentLayer() { | 342 CARendererLayerTree::ContentLayer::~ContentLayer() { |
338 [ca_layer removeFromSuperlayer]; | 343 [ca_layer removeFromSuperlayer]; |
339 } | 344 } |
340 | 345 |
341 bool CARendererLayerTree::RootLayer::AddContentLayer( | 346 bool CARendererLayerTree::RootLayer::AddContentLayer( |
| 347 CARendererLayerTree* tree, |
342 const CARendererLayerParams& params) { | 348 const CARendererLayerParams& params) { |
343 bool needs_new_clip_and_sorting_layer = true; | 349 bool needs_new_clip_and_sorting_layer = true; |
344 | 350 |
345 // In sorting_context_id 0, all quads are listed in back-to-front order. | 351 // 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. | 352 // 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 | 353 // 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. | 354 // context, so that it will not intersect with quads before and after it. |
349 bool is_singleton_sorting_context = | 355 bool is_singleton_sorting_context = |
350 !params.sorting_context_id && !params.transform.IsFlat(); | 356 !params.sorting_context_id && !params.transform.IsFlat(); |
351 | 357 |
(...skipping 16 matching lines...) Expand all Loading... |
368 current_layer.clip_rect == params.clip_rect && | 374 current_layer.clip_rect == params.clip_rect && |
369 current_layer.sorting_context_id == params.sorting_context_id) { | 375 current_layer.sorting_context_id == params.sorting_context_id) { |
370 needs_new_clip_and_sorting_layer = false; | 376 needs_new_clip_and_sorting_layer = false; |
371 } | 377 } |
372 } | 378 } |
373 if (needs_new_clip_and_sorting_layer) { | 379 if (needs_new_clip_and_sorting_layer) { |
374 clip_and_sorting_layers.push_back(ClipAndSortingLayer( | 380 clip_and_sorting_layers.push_back(ClipAndSortingLayer( |
375 params.is_clipped, params.clip_rect, params.sorting_context_id, | 381 params.is_clipped, params.clip_rect, params.sorting_context_id, |
376 is_singleton_sorting_context)); | 382 is_singleton_sorting_context)); |
377 } | 383 } |
378 clip_and_sorting_layers.back().AddContentLayer(params); | 384 clip_and_sorting_layers.back().AddContentLayer(tree, params); |
379 return true; | 385 return true; |
380 } | 386 } |
381 | 387 |
382 void CARendererLayerTree::ClipAndSortingLayer::AddContentLayer( | 388 void CARendererLayerTree::ClipAndSortingLayer::AddContentLayer( |
| 389 CARendererLayerTree* tree, |
383 const CARendererLayerParams& params) { | 390 const CARendererLayerParams& params) { |
384 bool needs_new_transform_layer = true; | 391 bool needs_new_transform_layer = true; |
385 if (!transform_layers.empty()) { | 392 if (!transform_layers.empty()) { |
386 const TransformLayer& current_layer = transform_layers.back(); | 393 const TransformLayer& current_layer = transform_layers.back(); |
387 if (current_layer.transform == params.transform) | 394 if (current_layer.transform == params.transform) |
388 needs_new_transform_layer = false; | 395 needs_new_transform_layer = false; |
389 } | 396 } |
390 if (needs_new_transform_layer) | 397 if (needs_new_transform_layer) |
391 transform_layers.push_back(TransformLayer(params.transform)); | 398 transform_layers.push_back(TransformLayer(params.transform)); |
392 transform_layers.back().AddContentLayer(params); | 399 transform_layers.back().AddContentLayer(tree, params); |
393 } | 400 } |
394 | 401 |
395 void CARendererLayerTree::TransformLayer::AddContentLayer( | 402 void CARendererLayerTree::TransformLayer::AddContentLayer( |
| 403 CARendererLayerTree* tree, |
396 const CARendererLayerParams& params) { | 404 const CARendererLayerParams& params) { |
397 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; | 405 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
398 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | 406 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
399 if (params.image) { | 407 if (params.image) { |
400 gl::GLImageIOSurface* io_surface_image = | 408 gl::GLImageIOSurface* io_surface_image = |
401 gl::GLImageIOSurface::FromGLImage(params.image); | 409 gl::GLImageIOSurface::FromGLImage(params.image); |
402 DCHECK(io_surface_image); | 410 DCHECK(io_surface_image); |
403 io_surface = io_surface_image->io_surface(); | 411 io_surface = io_surface_image->io_surface(); |
404 cv_pixel_buffer = io_surface_image->cv_pixel_buffer(); | 412 cv_pixel_buffer = io_surface_image->cv_pixel_buffer(); |
405 } | 413 } |
406 | 414 |
407 content_layers.push_back( | 415 content_layers.push_back( |
408 ContentLayer(io_surface, cv_pixel_buffer, params.contents_rect, | 416 ContentLayer(tree, io_surface, cv_pixel_buffer, params.contents_rect, |
409 params.rect, params.background_color, params.edge_aa_mask, | 417 params.rect, params.background_color, params.edge_aa_mask, |
410 params.opacity, params.filter)); | 418 params.opacity, params.filter)); |
411 } | 419 } |
412 | 420 |
413 void CARendererLayerTree::RootLayer::CommitToCA(CALayer* superlayer, | 421 void CARendererLayerTree::RootLayer::CommitToCA(CALayer* superlayer, |
414 RootLayer* old_layer, | 422 RootLayer* old_layer, |
415 float scale_factor) { | 423 float scale_factor) { |
416 if (old_layer) { | 424 if (old_layer) { |
417 DCHECK(old_layer->ca_layer); | 425 DCHECK(old_layer->ca_layer); |
418 std::swap(ca_layer, old_layer->ca_layer); | 426 std::swap(ca_layer, old_layer->ca_layer); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 } else { | 633 } else { |
626 // Grey represents a CALayer that has not changed. | 634 // Grey represents a CALayer that has not changed. |
627 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); | 635 color.reset(CGColorCreateGenericRGB(0.5, 0.5, 0.5, 1)); |
628 } | 636 } |
629 [ca_layer setBorderWidth:1]; | 637 [ca_layer setBorderWidth:1]; |
630 [ca_layer setBorderColor:color]; | 638 [ca_layer setBorderColor:color]; |
631 } | 639 } |
632 } | 640 } |
633 | 641 |
634 } // namespace ui | 642 } // namespace ui |
OLD | NEW |