| 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_layer_tree_mac.h" | 5 #include "ui/accelerated_widget_mac/ca_layer_tree_mac.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 30 matching lines...) Expand all Loading... |
| 41 CMVideoFormatDescriptionRef*); | 41 CMVideoFormatDescriptionRef*); |
| 42 extern "C" CMTime CMTimeMake(int64_t, int32_t); | 42 extern "C" CMTime CMTimeMake(int64_t, int32_t); |
| 43 extern CFStringRef const kCMSampleAttachmentKey_DisplayImmediately; | 43 extern CFStringRef const kCMSampleAttachmentKey_DisplayImmediately; |
| 44 extern const CMTime kCMTimeInvalid; | 44 extern const CMTime kCMTimeInvalid; |
| 45 #endif // MAC_OS_X_VERSION_10_8 | 45 #endif // MAC_OS_X_VERSION_10_8 |
| 46 | 46 |
| 47 namespace ui { | 47 namespace ui { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // This will enqueue |io_surface| to be drawn by |av_layer| by wrapping | 51 // This will enqueue |io_surface| to be drawn by |av_layer|. This will |
| 52 // |io_surface| in a CVPixelBuffer. This will increase the in-use count | 52 // retain |cv_pixel_buffer| until it is no longer being displayed. |
| 53 // of and retain |io_surface| until it is no longer being displayed. | 53 bool AVSampleBufferDisplayLayerEnqueueCVPixelBuffer( |
| 54 bool AVSampleBufferDisplayLayerEnqueueIOSurface( | |
| 55 AVSampleBufferDisplayLayer* av_layer, | 54 AVSampleBufferDisplayLayer* av_layer, |
| 56 IOSurfaceRef io_surface) { | 55 CVPixelBufferRef cv_pixel_buffer) { |
| 57 OSStatus os_status = noErr; | 56 OSStatus os_status = noErr; |
| 58 CVReturn cv_return = kCVReturnSuccess; | |
| 59 | |
| 60 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | |
| 61 cv_return = CVPixelBufferCreateWithIOSurface( | |
| 62 nullptr, io_surface, nullptr, cv_pixel_buffer.InitializeInto()); | |
| 63 if (cv_return != kCVReturnSuccess) { | |
| 64 LOG(ERROR) << "CVPixelBufferCreateWithIOSurface failed with " << cv_return; | |
| 65 return false; | |
| 66 } | |
| 67 | 57 |
| 68 base::ScopedCFTypeRef<CMVideoFormatDescriptionRef> video_info; | 58 base::ScopedCFTypeRef<CMVideoFormatDescriptionRef> video_info; |
| 69 os_status = CMVideoFormatDescriptionCreateForImageBuffer( | 59 os_status = CMVideoFormatDescriptionCreateForImageBuffer( |
| 70 nullptr, cv_pixel_buffer, video_info.InitializeInto()); | 60 nullptr, cv_pixel_buffer, video_info.InitializeInto()); |
| 71 if (os_status != noErr) { | 61 if (os_status != noErr) { |
| 72 LOG(ERROR) << "CMVideoFormatDescriptionCreateForImageBuffer failed with " | 62 LOG(ERROR) << "CMVideoFormatDescriptionCreateForImageBuffer failed with " |
| 73 << os_status; | 63 << os_status; |
| 74 return false; | 64 return false; |
| 75 } | 65 } |
| 76 | 66 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return false; | 98 return false; |
| 109 } | 99 } |
| 110 CFDictionarySetValue(attachments_dictionary, | 100 CFDictionarySetValue(attachments_dictionary, |
| 111 kCMSampleAttachmentKey_DisplayImmediately, | 101 kCMSampleAttachmentKey_DisplayImmediately, |
| 112 kCFBooleanTrue); | 102 kCFBooleanTrue); |
| 113 | 103 |
| 114 [av_layer enqueueSampleBuffer:sample_buffer]; | 104 [av_layer enqueueSampleBuffer:sample_buffer]; |
| 115 return true; | 105 return true; |
| 116 } | 106 } |
| 117 | 107 |
| 108 // This will enqueue |io_surface| to be drawn by |av_layer| by wrapping |
| 109 // |io_surface| in a CVPixelBuffer. This will increase the in-use count |
| 110 // of and retain |io_surface| until it is no longer being displayed. |
| 111 bool AVSampleBufferDisplayLayerEnqueueIOSurface( |
| 112 AVSampleBufferDisplayLayer* av_layer, |
| 113 IOSurfaceRef io_surface) { |
| 114 CVReturn cv_return = kCVReturnSuccess; |
| 115 |
| 116 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 117 cv_return = CVPixelBufferCreateWithIOSurface( |
| 118 nullptr, io_surface, nullptr, cv_pixel_buffer.InitializeInto()); |
| 119 if (cv_return != kCVReturnSuccess) { |
| 120 LOG(ERROR) << "CVPixelBufferCreateWithIOSurface failed with " << cv_return; |
| 121 return false; |
| 122 } |
| 123 |
| 124 return AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, |
| 125 cv_pixel_buffer); |
| 126 } |
| 127 |
| 118 } // namespace | 128 } // namespace |
| 119 | 129 |
| 120 CALayerTree::CALayerTree() {} | 130 CALayerTree::CALayerTree() {} |
| 121 CALayerTree::~CALayerTree() {} | 131 CALayerTree::~CALayerTree() {} |
| 122 | 132 |
| 123 bool CALayerTree::ScheduleCALayer( | 133 bool CALayerTree::ScheduleCALayer( |
| 124 bool is_clipped, | 134 bool is_clipped, |
| 125 const gfx::Rect& clip_rect, | 135 const gfx::Rect& clip_rect, |
| 126 unsigned sorting_context_id, | 136 unsigned sorting_context_id, |
| 127 const gfx::Transform& transform, | 137 const gfx::Transform& transform, |
| 128 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 138 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 139 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
| 129 const gfx::RectF& contents_rect, | 140 const gfx::RectF& contents_rect, |
| 130 const gfx::Rect& rect, | 141 const gfx::Rect& rect, |
| 131 unsigned background_color, | 142 unsigned background_color, |
| 132 unsigned edge_aa_mask, | 143 unsigned edge_aa_mask, |
| 133 float opacity) { | 144 float opacity) { |
| 134 // Excessive logging to debug white screens (crbug.com/583805). | 145 // Excessive logging to debug white screens (crbug.com/583805). |
| 135 // TODO(ccameron): change this back to a DLOG. | 146 // TODO(ccameron): change this back to a DLOG. |
| 136 if (has_committed_) { | 147 if (has_committed_) { |
| 137 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; | 148 LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers."; |
| 138 return false; | 149 return false; |
| 139 } | 150 } |
| 140 return root_layer_.AddContentLayer(is_clipped, clip_rect, sorting_context_id, | 151 return root_layer_.AddContentLayer(is_clipped, clip_rect, sorting_context_id, |
| 141 transform, io_surface, contents_rect, rect, | 152 transform, io_surface, cv_pixel_buffer, |
| 142 background_color, edge_aa_mask, opacity); | 153 contents_rect, rect, background_color, |
| 154 edge_aa_mask, opacity); |
| 143 } | 155 } |
| 144 | 156 |
| 145 void CALayerTree::CommitScheduledCALayers(CALayer* superlayer, | 157 void CALayerTree::CommitScheduledCALayers(CALayer* superlayer, |
| 146 std::unique_ptr<CALayerTree> old_tree, | 158 std::unique_ptr<CALayerTree> old_tree, |
| 147 float scale_factor) { | 159 float scale_factor) { |
| 148 TRACE_EVENT0("gpu", "CALayerTree::CommitScheduledCALayers"); | 160 TRACE_EVENT0("gpu", "CALayerTree::CommitScheduledCALayers"); |
| 149 RootLayer* old_root_layer = nullptr; | 161 RootLayer* old_root_layer = nullptr; |
| 150 if (old_tree) { | 162 if (old_tree) { |
| 151 DCHECK(old_tree->has_committed_); | 163 DCHECK(old_tree->has_committed_); |
| 152 if (old_tree->scale_factor_ == scale_factor) | 164 if (old_tree->scale_factor_ == scale_factor) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ca_layer(layer.ca_layer) { | 220 ca_layer(layer.ca_layer) { |
| 209 layer.ca_layer.reset(); | 221 layer.ca_layer.reset(); |
| 210 } | 222 } |
| 211 | 223 |
| 212 CALayerTree::TransformLayer::~TransformLayer() { | 224 CALayerTree::TransformLayer::~TransformLayer() { |
| 213 [ca_layer removeFromSuperlayer]; | 225 [ca_layer removeFromSuperlayer]; |
| 214 } | 226 } |
| 215 | 227 |
| 216 CALayerTree::ContentLayer::ContentLayer( | 228 CALayerTree::ContentLayer::ContentLayer( |
| 217 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 229 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 230 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
| 218 const gfx::RectF& contents_rect, | 231 const gfx::RectF& contents_rect, |
| 219 const gfx::Rect& rect, | 232 const gfx::Rect& rect, |
| 220 unsigned background_color, | 233 unsigned background_color, |
| 221 unsigned edge_aa_mask, | 234 unsigned edge_aa_mask, |
| 222 float opacity) | 235 float opacity) |
| 223 : io_surface(io_surface), | 236 : io_surface(io_surface), |
| 237 cv_pixel_buffer(cv_pixel_buffer), |
| 224 contents_rect(contents_rect), | 238 contents_rect(contents_rect), |
| 225 rect(rect), | 239 rect(rect), |
| 226 background_color(background_color), | 240 background_color(background_color), |
| 227 ca_edge_aa_mask(0), | 241 ca_edge_aa_mask(0), |
| 228 opacity(opacity) { | 242 opacity(opacity) { |
| 229 // Because the root layer has setGeometryFlipped:YES, there is some ambiguity | 243 // Because the root layer has setGeometryFlipped:YES, there is some ambiguity |
| 230 // about what exactly top and bottom mean. This ambiguity is resolved in | 244 // about what exactly top and bottom mean. This ambiguity is resolved in |
| 231 // different ways for solid color CALayers and for CALayers that have content | 245 // different ways for solid color CALayers and for CALayers that have content |
| 232 // (surprise!). For CALayers with IOSurface content, the top edge in the AA | 246 // (surprise!). For CALayers with IOSurface content, the top edge in the AA |
| 233 // mask refers to what appears as the bottom edge on-screen. For CALayers | 247 // mask refers to what appears as the bottom edge on-screen. For CALayers |
| (...skipping 14 matching lines...) Expand all Loading... |
| 248 ca_edge_aa_mask |= kCALayerTopEdge; | 262 ca_edge_aa_mask |= kCALayerTopEdge; |
| 249 if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM) | 263 if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM) |
| 250 ca_edge_aa_mask |= kCALayerBottomEdge; | 264 ca_edge_aa_mask |= kCALayerBottomEdge; |
| 251 } | 265 } |
| 252 | 266 |
| 253 // Only allow 4:2:0 frames which fill the layer's contents to be promoted to | 267 // Only allow 4:2:0 frames which fill the layer's contents to be promoted to |
| 254 // AV layers. | 268 // AV layers. |
| 255 if (IOSurfaceGetPixelFormat(io_surface) == | 269 if (IOSurfaceGetPixelFormat(io_surface) == |
| 256 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange && | 270 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange && |
| 257 contents_rect == gfx::RectF(0, 0, 1, 1)) { | 271 contents_rect == gfx::RectF(0, 0, 1, 1)) { |
| 258 // Leave AVFoundation disabled for now while crashing and flashing bugs are | 272 // Enable only for hardware decoded frames, to see if flashing bugs are |
| 259 // being investigated. | 273 // particular to software IOSurfaces. |
| 260 // https://crbug.com/598243, https://crbug.com/598388 | 274 // https://crbug.com/598269 |
| 261 use_av_layer = false; | 275 if (cv_pixel_buffer) |
| 276 use_av_layer = true; |
| 262 } | 277 } |
| 263 } | 278 } |
| 264 | 279 |
| 265 CALayerTree::ContentLayer::ContentLayer(ContentLayer&& layer) | 280 CALayerTree::ContentLayer::ContentLayer(ContentLayer&& layer) |
| 266 : io_surface(layer.io_surface), | 281 : io_surface(layer.io_surface), |
| 282 cv_pixel_buffer(layer.cv_pixel_buffer), |
| 267 contents_rect(layer.contents_rect), | 283 contents_rect(layer.contents_rect), |
| 268 rect(layer.rect), | 284 rect(layer.rect), |
| 269 background_color(layer.background_color), | 285 background_color(layer.background_color), |
| 270 ca_edge_aa_mask(layer.ca_edge_aa_mask), | 286 ca_edge_aa_mask(layer.ca_edge_aa_mask), |
| 271 opacity(layer.opacity), | 287 opacity(layer.opacity), |
| 272 ca_layer(std::move(layer.ca_layer)), | 288 ca_layer(std::move(layer.ca_layer)), |
| 273 av_layer(std::move(layer.av_layer)), | 289 av_layer(std::move(layer.av_layer)), |
| 274 use_av_layer(layer.use_av_layer) { | 290 use_av_layer(layer.use_av_layer) { |
| 275 DCHECK(!layer.ca_layer); | 291 DCHECK(!layer.ca_layer); |
| 276 DCHECK(!layer.av_layer); | 292 DCHECK(!layer.av_layer); |
| 277 } | 293 } |
| 278 | 294 |
| 279 CALayerTree::ContentLayer::~ContentLayer() { | 295 CALayerTree::ContentLayer::~ContentLayer() { |
| 280 [ca_layer removeFromSuperlayer]; | 296 [ca_layer removeFromSuperlayer]; |
| 281 } | 297 } |
| 282 | 298 |
| 283 bool CALayerTree::RootLayer::AddContentLayer( | 299 bool CALayerTree::RootLayer::AddContentLayer( |
| 284 bool is_clipped, | 300 bool is_clipped, |
| 285 const gfx::Rect& clip_rect, | 301 const gfx::Rect& clip_rect, |
| 286 unsigned sorting_context_id, | 302 unsigned sorting_context_id, |
| 287 const gfx::Transform& transform, | 303 const gfx::Transform& transform, |
| 288 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 304 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 305 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
| 289 const gfx::RectF& contents_rect, | 306 const gfx::RectF& contents_rect, |
| 290 const gfx::Rect& rect, | 307 const gfx::Rect& rect, |
| 291 unsigned background_color, | 308 unsigned background_color, |
| 292 unsigned edge_aa_mask, | 309 unsigned edge_aa_mask, |
| 293 float opacity) { | 310 float opacity) { |
| 294 bool needs_new_clip_and_sorting_layer = true; | 311 bool needs_new_clip_and_sorting_layer = true; |
| 295 | 312 |
| 296 // In sorting_context_id 0, all quads are listed in back-to-front order. | 313 // In sorting_context_id 0, all quads are listed in back-to-front order. |
| 297 // This is accomplished by having the CALayers be siblings of each other. | 314 // This is accomplished by having the CALayers be siblings of each other. |
| 298 // If a quad has a 3D transform, it is necessary to put it in its own sorting | 315 // If a quad has a 3D transform, it is necessary to put it in its own sorting |
| (...skipping 21 matching lines...) Expand all Loading... |
| 320 current_layer.sorting_context_id == sorting_context_id) { | 337 current_layer.sorting_context_id == sorting_context_id) { |
| 321 needs_new_clip_and_sorting_layer = false; | 338 needs_new_clip_and_sorting_layer = false; |
| 322 } | 339 } |
| 323 } | 340 } |
| 324 if (needs_new_clip_and_sorting_layer) { | 341 if (needs_new_clip_and_sorting_layer) { |
| 325 clip_and_sorting_layers.push_back( | 342 clip_and_sorting_layers.push_back( |
| 326 ClipAndSortingLayer(is_clipped, clip_rect, sorting_context_id, | 343 ClipAndSortingLayer(is_clipped, clip_rect, sorting_context_id, |
| 327 is_singleton_sorting_context)); | 344 is_singleton_sorting_context)); |
| 328 } | 345 } |
| 329 clip_and_sorting_layers.back().AddContentLayer( | 346 clip_and_sorting_layers.back().AddContentLayer( |
| 330 transform, io_surface, contents_rect, rect, background_color, | 347 transform, io_surface, cv_pixel_buffer, contents_rect, rect, |
| 331 edge_aa_mask, opacity); | 348 background_color, edge_aa_mask, opacity); |
| 332 return true; | 349 return true; |
| 333 } | 350 } |
| 334 | 351 |
| 335 void CALayerTree::ClipAndSortingLayer::AddContentLayer( | 352 void CALayerTree::ClipAndSortingLayer::AddContentLayer( |
| 336 const gfx::Transform& transform, | 353 const gfx::Transform& transform, |
| 337 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 354 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 355 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
| 338 const gfx::RectF& contents_rect, | 356 const gfx::RectF& contents_rect, |
| 339 const gfx::Rect& rect, | 357 const gfx::Rect& rect, |
| 340 unsigned background_color, | 358 unsigned background_color, |
| 341 unsigned edge_aa_mask, | 359 unsigned edge_aa_mask, |
| 342 float opacity) { | 360 float opacity) { |
| 343 bool needs_new_transform_layer = true; | 361 bool needs_new_transform_layer = true; |
| 344 if (!transform_layers.empty()) { | 362 if (!transform_layers.empty()) { |
| 345 const TransformLayer& current_layer = transform_layers.back(); | 363 const TransformLayer& current_layer = transform_layers.back(); |
| 346 if (current_layer.transform == transform) | 364 if (current_layer.transform == transform) |
| 347 needs_new_transform_layer = false; | 365 needs_new_transform_layer = false; |
| 348 } | 366 } |
| 349 if (needs_new_transform_layer) | 367 if (needs_new_transform_layer) |
| 350 transform_layers.push_back(TransformLayer(transform)); | 368 transform_layers.push_back(TransformLayer(transform)); |
| 351 transform_layers.back().AddContentLayer( | 369 transform_layers.back().AddContentLayer(io_surface, cv_pixel_buffer, |
| 352 io_surface, contents_rect, rect, background_color, edge_aa_mask, opacity); | 370 contents_rect, rect, background_color, |
| 371 edge_aa_mask, opacity); |
| 353 } | 372 } |
| 354 | 373 |
| 355 void CALayerTree::TransformLayer::AddContentLayer( | 374 void CALayerTree::TransformLayer::AddContentLayer( |
| 356 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 375 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 376 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, |
| 357 const gfx::RectF& contents_rect, | 377 const gfx::RectF& contents_rect, |
| 358 const gfx::Rect& rect, | 378 const gfx::Rect& rect, |
| 359 unsigned background_color, | 379 unsigned background_color, |
| 360 unsigned edge_aa_mask, | 380 unsigned edge_aa_mask, |
| 361 float opacity) { | 381 float opacity) { |
| 362 content_layers.push_back(ContentLayer(io_surface, contents_rect, rect, | 382 content_layers.push_back(ContentLayer(io_surface, cv_pixel_buffer, |
| 363 background_color, edge_aa_mask, | 383 contents_rect, rect, background_color, |
| 364 opacity)); | 384 edge_aa_mask, opacity)); |
| 365 } | 385 } |
| 366 | 386 |
| 367 void CALayerTree::RootLayer::CommitToCA(CALayer* superlayer, | 387 void CALayerTree::RootLayer::CommitToCA(CALayer* superlayer, |
| 368 RootLayer* old_layer, | 388 RootLayer* old_layer, |
| 369 float scale_factor) { | 389 float scale_factor) { |
| 370 if (old_layer) { | 390 if (old_layer) { |
| 371 DCHECK(old_layer->ca_layer); | 391 DCHECK(old_layer->ca_layer); |
| 372 std::swap(ca_layer, old_layer->ca_layer); | 392 std::swap(ca_layer, old_layer->ca_layer); |
| 373 } else { | 393 } else { |
| 374 ca_layer.reset([[CALayer alloc] init]); | 394 ca_layer.reset([[CALayer alloc] init]); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 bool update_contents = true; | 505 bool update_contents = true; |
| 486 bool update_contents_rect = true; | 506 bool update_contents_rect = true; |
| 487 bool update_rect = true; | 507 bool update_rect = true; |
| 488 bool update_background_color = true; | 508 bool update_background_color = true; |
| 489 bool update_ca_edge_aa_mask = true; | 509 bool update_ca_edge_aa_mask = true; |
| 490 bool update_opacity = true; | 510 bool update_opacity = true; |
| 491 if (old_layer && old_layer->use_av_layer == use_av_layer) { | 511 if (old_layer && old_layer->use_av_layer == use_av_layer) { |
| 492 DCHECK(old_layer->ca_layer); | 512 DCHECK(old_layer->ca_layer); |
| 493 std::swap(ca_layer, old_layer->ca_layer); | 513 std::swap(ca_layer, old_layer->ca_layer); |
| 494 std::swap(av_layer, old_layer->av_layer); | 514 std::swap(av_layer, old_layer->av_layer); |
| 495 update_contents = old_layer->io_surface != io_surface; | 515 update_contents = old_layer->io_surface != io_surface || |
| 516 old_layer->cv_pixel_buffer != cv_pixel_buffer; |
| 496 update_contents_rect = old_layer->contents_rect != contents_rect; | 517 update_contents_rect = old_layer->contents_rect != contents_rect; |
| 497 update_rect = old_layer->rect != rect; | 518 update_rect = old_layer->rect != rect; |
| 498 update_background_color = old_layer->background_color != background_color; | 519 update_background_color = old_layer->background_color != background_color; |
| 499 update_ca_edge_aa_mask = old_layer->ca_edge_aa_mask != ca_edge_aa_mask; | 520 update_ca_edge_aa_mask = old_layer->ca_edge_aa_mask != ca_edge_aa_mask; |
| 500 update_opacity = old_layer->opacity != opacity; | 521 update_opacity = old_layer->opacity != opacity; |
| 501 } else { | 522 } else { |
| 502 if (use_av_layer) { | 523 if (use_av_layer) { |
| 503 av_layer.reset([[AVSampleBufferDisplayLayer alloc] init]); | 524 av_layer.reset([[AVSampleBufferDisplayLayer alloc] init]); |
| 504 ca_layer.reset([av_layer retain]); | 525 ca_layer.reset([av_layer retain]); |
| 505 [av_layer setVideoGravity:AVLayerVideoGravityResize]; | 526 [av_layer setVideoGravity:AVLayerVideoGravityResize]; |
| 506 } else { | 527 } else { |
| 507 ca_layer.reset([[CALayer alloc] init]); | 528 ca_layer.reset([[CALayer alloc] init]); |
| 508 } | 529 } |
| 509 [ca_layer setAnchorPoint:CGPointZero]; | 530 [ca_layer setAnchorPoint:CGPointZero]; |
| 510 [superlayer addSublayer:ca_layer]; | 531 [superlayer addSublayer:ca_layer]; |
| 511 } | 532 } |
| 512 DCHECK_EQ([ca_layer superlayer], superlayer); | 533 DCHECK_EQ([ca_layer superlayer], superlayer); |
| 513 bool update_anything = update_contents || update_contents_rect || | 534 bool update_anything = update_contents || update_contents_rect || |
| 514 update_rect || update_background_color || | 535 update_rect || update_background_color || |
| 515 update_ca_edge_aa_mask || update_opacity; | 536 update_ca_edge_aa_mask || update_opacity; |
| 516 if (use_av_layer) { | 537 if (use_av_layer) { |
| 517 if (update_contents) | 538 if (update_contents) { |
| 518 AVSampleBufferDisplayLayerEnqueueIOSurface(av_layer, io_surface); | 539 if (cv_pixel_buffer) { |
| 540 AVSampleBufferDisplayLayerEnqueueCVPixelBuffer(av_layer, |
| 541 cv_pixel_buffer); |
| 542 } else { |
| 543 AVSampleBufferDisplayLayerEnqueueIOSurface(av_layer, io_surface); |
| 544 } |
| 545 } |
| 519 } else { | 546 } else { |
| 520 if (update_contents) { | 547 if (update_contents) { |
| 521 [ca_layer setContents:static_cast<id>(io_surface.get())]; | 548 [ca_layer setContents:static_cast<id>(io_surface.get())]; |
| 522 if ([ca_layer respondsToSelector:(@selector(setContentsScale:))]) | 549 if ([ca_layer respondsToSelector:(@selector(setContentsScale:))]) |
| 523 [ca_layer setContentsScale:scale_factor]; | 550 [ca_layer setContentsScale:scale_factor]; |
| 524 } | 551 } |
| 525 if (update_contents_rect) | 552 if (update_contents_rect) |
| 526 [ca_layer setContentsRect:contents_rect.ToCGRect()]; | 553 [ca_layer setContentsRect:contents_rect.ToCGRect()]; |
| 527 } | 554 } |
| 528 if (update_rect) { | 555 if (update_rect) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } else { | 589 } else { |
| 563 // Grey represents a CALayer that has not changed. | 590 // Grey represents a CALayer that has not changed. |
| 564 color.reset(CGColorCreateGenericRGB(0, 0, 0, 0.1)); | 591 color.reset(CGColorCreateGenericRGB(0, 0, 0, 0.1)); |
| 565 } | 592 } |
| 566 [ca_layer setBorderWidth:1]; | 593 [ca_layer setBorderWidth:1]; |
| 567 [ca_layer setBorderColor:color]; | 594 [ca_layer setBorderColor:color]; |
| 568 } | 595 } |
| 569 } | 596 } |
| 570 | 597 |
| 571 } // namespace ui | 598 } // namespace ui |
| OLD | NEW |