Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/common/gpu/image_transport_surface_overlay_mac.h" | 5 #include "content/common/gpu/image_transport_surface_overlay_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <IOSurface/IOSurface.h> | 8 #include <IOSurface/IOSurface.h> |
| 9 #include <OpenGL/CGLRenderers.h> | 9 #include <OpenGL/CGLRenderers.h> |
| 10 #include <OpenGL/CGLTypes.h> | 10 #include <OpenGL/CGLTypes.h> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 @interface CALayer(Private) | 83 @interface CALayer(Private) |
| 84 -(void)setContentsChanged; | 84 -(void)setContentsChanged; |
| 85 @end | 85 @end |
| 86 | 86 |
| 87 namespace content { | 87 namespace content { |
| 88 | 88 |
| 89 class ImageTransportSurfaceOverlayMac::OverlayPlane { | 89 class ImageTransportSurfaceOverlayMac::OverlayPlane { |
| 90 public: | 90 public: |
| 91 enum Type { | 91 OverlayPlane(int z_order, |
| 92 ROOT = 0, | |
| 93 ROOT_PARTIAL_DAMAGE = 1, | |
| 94 OVERLAY = 2, | |
| 95 }; | |
| 96 | |
| 97 OverlayPlane(Type type, | |
| 98 int z_order, | |
| 99 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 92 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 100 const gfx::RectF& dip_frame_rect, | 93 const gfx::RectF& dip_frame_rect, |
| 101 const gfx::RectF& contents_rect) | 94 const gfx::RectF& contents_rect) |
| 102 : type(type), | 95 : z_order(z_order), |
| 103 z_order(z_order), | |
| 104 io_surface(io_surface), | 96 io_surface(io_surface), |
| 105 dip_frame_rect(dip_frame_rect), | 97 dip_frame_rect(dip_frame_rect), |
| 106 contents_rect(contents_rect), | 98 contents_rect(contents_rect), |
| 107 layer_needs_update(true) {} | 99 layer_needs_update(true) {} |
| 108 ~OverlayPlane() { DCHECK(!ca_layer); } | 100 ~OverlayPlane() { DCHECK(!ca_layer); } |
| 109 | 101 |
| 110 const Type type; | |
| 111 const int z_order; | 102 const int z_order; |
| 112 base::scoped_nsobject<CALayer> ca_layer; | 103 base::scoped_nsobject<CALayer> ca_layer; |
| 113 | 104 |
| 114 // The IOSurface to set the CALayer's contents to. | 105 // The IOSurface to set the CALayer's contents to. |
| 115 const base::ScopedCFTypeRef<IOSurfaceRef> io_surface; | 106 const base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 116 const gfx::RectF dip_frame_rect; | 107 const gfx::RectF dip_frame_rect; |
| 117 const gfx::RectF contents_rect; | 108 const gfx::RectF contents_rect; |
| 118 | 109 |
| 119 bool layer_needs_update; | 110 bool layer_needs_update; |
| 120 | 111 |
| 121 static bool Compare(const linked_ptr<OverlayPlane>& a, | 112 static bool Compare(const linked_ptr<OverlayPlane>& a, |
| 122 const linked_ptr<OverlayPlane>& b) { | 113 const linked_ptr<OverlayPlane>& b) { |
| 123 // Sort by z_order first. | 114 return (a->z_order < b->z_order); |
| 124 if (a->z_order < b->z_order) | |
| 125 return true; | |
| 126 if (a->z_order > b->z_order) | |
| 127 return false; | |
| 128 // Then ensure that the root partial damage is after the root. | |
| 129 if (a->type < b->type) | |
| 130 return true; | |
| 131 if (a->type > b->type) | |
| 132 return false; | |
| 133 // Then sort by x. | |
| 134 if (a->dip_frame_rect.x() < b->dip_frame_rect.x()) | |
| 135 return true; | |
| 136 if (a->dip_frame_rect.x() > b->dip_frame_rect.x()) | |
| 137 return false; | |
| 138 // Then sort by y. | |
| 139 if (a->dip_frame_rect.y() < b->dip_frame_rect.y()) | |
| 140 return true; | |
| 141 if (a->dip_frame_rect.y() > b->dip_frame_rect.y()) | |
| 142 return false; | |
| 143 | |
| 144 return false; | |
| 145 } | 115 } |
| 146 | 116 |
| 147 void TakeCALayerFrom(OverlayPlane* other_plane) { | 117 void TakeCALayerFrom(OverlayPlane* other_plane) { |
| 148 ca_layer.swap(other_plane->ca_layer); | 118 ca_layer.swap(other_plane->ca_layer); |
| 149 } | 119 } |
| 150 | 120 |
| 151 void UpdateProperties() { | 121 void UpdateProperties() { |
| 152 if (layer_needs_update) { | 122 if (layer_needs_update) { |
| 153 [ca_layer setOpaque:YES]; | 123 [ca_layer setOpaque:YES]; |
| 154 [ca_layer setFrame:dip_frame_rect.ToCGRect()]; | 124 [ca_layer setFrame:dip_frame_rect.ToCGRect()]; |
| 155 [ca_layer setContentsRect:contents_rect.ToCGRect()]; | 125 [ca_layer setContentsRect:contents_rect.ToCGRect()]; |
| 156 id new_contents = static_cast<id>(io_surface.get()); | 126 id new_contents = static_cast<id>(io_surface.get()); |
| 157 if ([ca_layer contents] == new_contents && type != OVERLAY) { | 127 if ([ca_layer contents] == new_contents && z_order == 0) { |
| 158 [ca_layer setContentsChanged]; | 128 [ca_layer setContentsChanged]; |
| 159 } else { | 129 } else { |
| 160 [ca_layer setContents:new_contents]; | 130 [ca_layer setContents:new_contents]; |
| 161 } | 131 } |
| 162 } | 132 } |
| 163 static bool show_borders = | 133 static bool show_borders = |
| 164 base::CommandLine::ForCurrentProcess()->HasSwitch( | 134 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 165 switches::kShowMacOverlayBorders); | 135 switches::kShowMacOverlayBorders); |
| 166 if (show_borders) { | 136 if (show_borders) { |
| 167 base::ScopedCFTypeRef<CGColorRef> color; | 137 base::ScopedCFTypeRef<CGColorRef> color; |
| 168 if (!layer_needs_update) { | 138 if (!layer_needs_update) { |
| 169 // Green represents contents that are unchanged across frames. | 139 // Green represents contents that are unchanged across frames. |
| 170 color.reset(CGColorCreateGenericRGB(0, 1, 0, 1)); | 140 color.reset(CGColorCreateGenericRGB(0, 1, 0, 1)); |
| 171 } else if (type == OverlayPlane::OVERLAY) { | 141 } else if (z_order != 0) { |
| 172 // Pink represents overlay planes | 142 // Pink represents overlay planes |
| 173 color.reset(CGColorCreateGenericRGB(1, 0, 1, 1)); | 143 color.reset(CGColorCreateGenericRGB(1, 0, 1, 1)); |
| 174 } else { | 144 } else { |
| 175 // Red represents damaged contents. | 145 // Red represents damaged contents. |
| 176 color.reset(CGColorCreateGenericRGB(1, 0, 0, 1)); | 146 color.reset(CGColorCreateGenericRGB(1, 0, 0, 1)); |
| 177 } | 147 } |
| 178 [ca_layer setBorderWidth:2]; | 148 [ca_layer setBorderWidth:2]; |
| 179 [ca_layer setBorderColor:color]; | 149 [ca_layer setBorderColor:color]; |
| 180 } | 150 } |
| 181 layer_needs_update = false; | 151 layer_needs_update = false; |
| 182 } | 152 } |
| 183 | 153 |
| 184 void Destroy() { | 154 void Destroy() { |
| 185 if (!ca_layer) | 155 if (!ca_layer) |
| 186 return; | 156 return; |
| 187 [ca_layer setContents:nil]; | 157 [ca_layer setContents:nil]; |
| 188 if (type != ROOT) | 158 [ca_layer removeFromSuperlayer]; |
|
ccameron
2015/10/05 20:44:42
I was vaguely concerned about this having odd inte
Andre
2015/10/05 20:53:13
We could check if ([ca_layer superlayer]), but rem
| |
| 189 [ca_layer removeFromSuperlayer]; | |
| 190 ca_layer.reset(); | 159 ca_layer.reset(); |
| 191 } | 160 } |
| 192 }; | 161 }; |
| 193 | 162 |
| 194 class ImageTransportSurfaceOverlayMac::PendingSwap { | 163 class ImageTransportSurfaceOverlayMac::PendingSwap { |
| 195 public: | 164 public: |
| 196 PendingSwap() {} | 165 PendingSwap() {} |
| 197 ~PendingSwap() { DCHECK(!gl_fence); } | 166 ~PendingSwap() { DCHECK(!gl_fence); } |
| 198 | 167 |
| 199 gfx::Size pixel_size; | 168 gfx::Size pixel_size; |
| 200 float scale_factor; | 169 float scale_factor; |
| 201 gfx::Rect pixel_damage_rect; | 170 gfx::Rect pixel_damage_rect; |
| 202 | 171 |
| 172 linked_ptr<OverlayPlane> root_plane; | |
| 203 std::vector<linked_ptr<OverlayPlane>> overlay_planes; | 173 std::vector<linked_ptr<OverlayPlane>> overlay_planes; |
| 204 std::vector<ui::LatencyInfo> latency_info; | 174 std::vector<ui::LatencyInfo> latency_info; |
| 205 | 175 |
| 206 // A fence object, and the CGL context it was issued in. | 176 // A fence object, and the CGL context it was issued in. |
| 207 base::ScopedTypeRef<CGLContextObj> cgl_context; | 177 base::ScopedTypeRef<CGLContextObj> cgl_context; |
| 208 scoped_ptr<gfx::GLFence> gl_fence; | 178 scoped_ptr<gfx::GLFence> gl_fence; |
| 209 | 179 |
| 210 // The earliest time that this frame may be drawn. A frame is not allowed | 180 // The earliest time that this frame may be drawn. A frame is not allowed |
| 211 // to draw until a fraction of the way through the vsync interval after its | 181 // to draw until a fraction of the way through the vsync interval after its |
| 212 // This extra latency is to allow wiggle-room for smoothness. | 182 // This extra latency is to allow wiggle-room for smoothness. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 if (IsFirstPendingSwapReadyToDisplay(now)) | 262 if (IsFirstPendingSwapReadyToDisplay(now)) |
| 293 DisplayFirstPendingSwapImmediately(); | 263 DisplayFirstPendingSwapImmediately(); |
| 294 } | 264 } |
| 295 | 265 |
| 296 // The remainder of the function will populate the PendingSwap structure and | 266 // The remainder of the function will populate the PendingSwap structure and |
| 297 // then enqueue it. | 267 // then enqueue it. |
| 298 linked_ptr<PendingSwap> new_swap(new PendingSwap); | 268 linked_ptr<PendingSwap> new_swap(new PendingSwap); |
| 299 new_swap->pixel_size = pixel_size_; | 269 new_swap->pixel_size = pixel_size_; |
| 300 new_swap->scale_factor = scale_factor_; | 270 new_swap->scale_factor = scale_factor_; |
| 301 new_swap->pixel_damage_rect = pixel_damage_rect; | 271 new_swap->pixel_damage_rect = pixel_damage_rect; |
| 272 new_swap->root_plane = pending_root_plane_; | |
| 273 pending_root_plane_ = linked_ptr<OverlayPlane>(); | |
| 302 new_swap->overlay_planes.swap(pending_overlay_planes_); | 274 new_swap->overlay_planes.swap(pending_overlay_planes_); |
| 303 new_swap->latency_info.swap(latency_info_); | 275 new_swap->latency_info.swap(latency_info_); |
| 304 | 276 |
| 305 // A flush is required to ensure that all content appears in the layer. | 277 // A flush is required to ensure that all content appears in the layer. |
| 306 { | 278 { |
| 307 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; | 279 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| 308 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush"); | 280 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush"); |
| 309 CheckGLErrors("before flushing frame"); | 281 CheckGLErrors("before flushing frame"); |
| 310 new_swap->cgl_context.reset(CGLGetCurrentContext(), | 282 new_swap->cgl_context.reset(CGLGetCurrentContext(), |
| 311 base::scoped_policy::RETAIN); | 283 base::scoped_policy::RETAIN); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; | 345 gfx::ScopedSetGLToRealGLApi scoped_set_gl_api; |
| 374 gfx::ScopedCGLSetCurrentContext scoped_set_current(swap->cgl_context); | 346 gfx::ScopedCGLSetCurrentContext scoped_set_current(swap->cgl_context); |
| 375 | 347 |
| 376 CheckGLErrors("before deleting active fence"); | 348 CheckGLErrors("before deleting active fence"); |
| 377 swap->gl_fence.reset(); | 349 swap->gl_fence.reset(); |
| 378 CheckGLErrors("while deleting active fence"); | 350 CheckGLErrors("while deleting active fence"); |
| 379 } | 351 } |
| 380 | 352 |
| 381 // Update the plane lists. | 353 // Update the plane lists. |
| 382 { | 354 { |
| 383 // Sort the input planes by z-index and type, and remove any overlays from | 355 // Sort the input planes by z-index, and remove any overlays from the |
| 384 // the damage rect. | 356 // damage rect. |
| 385 gfx::RectF dip_damage_rect = ConvertRectToDIPF( | 357 gfx::RectF dip_damage_rect = ConvertRectToDIPF( |
| 386 swap->scale_factor, swap->pixel_damage_rect); | 358 swap->scale_factor, swap->pixel_damage_rect); |
| 387 std::sort(swap->overlay_planes.begin(), swap->overlay_planes.end(), | 359 std::sort(swap->overlay_planes.begin(), swap->overlay_planes.end(), |
| 388 OverlayPlane::Compare); | 360 OverlayPlane::Compare); |
| 389 for (auto& plane : swap->overlay_planes) { | 361 for (auto& plane : swap->overlay_planes) |
| 390 if (plane->type == OverlayPlane::OVERLAY) | 362 dip_damage_rect.Subtract(plane->dip_frame_rect); |
| 391 dip_damage_rect.Subtract(plane->dip_frame_rect); | |
| 392 } | |
| 393 | 363 |
| 394 ScopedCAActionDisabler disabler; | 364 ScopedCAActionDisabler disabler; |
| 395 UpdateRootAndPartialDamagePlanes(swap->overlay_planes, dip_damage_rect); | 365 if (swap->root_plane.get()) |
| 366 UpdateRootAndPartialDamagePlanes(swap->root_plane, dip_damage_rect); | |
| 396 UpdateOverlayPlanes(swap->overlay_planes); | 367 UpdateOverlayPlanes(swap->overlay_planes); |
| 397 UpdateCALayerTree(); | 368 UpdateCALayerTree(); |
| 398 swap->overlay_planes.clear(); | 369 swap->overlay_planes.clear(); |
| 399 } | 370 } |
| 400 | 371 |
| 401 // Send acknowledgement to the browser. | 372 // Send acknowledgement to the browser. |
| 402 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 373 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 403 params.surface_handle = | 374 params.surface_handle = |
| 404 ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); | 375 ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); |
| 405 params.size = swap->pixel_size; | 376 params.size = swap->pixel_size; |
| 406 params.scale_factor = swap->scale_factor; | 377 params.scale_factor = swap->scale_factor; |
| 407 params.latency_info.swap(swap->latency_info); | 378 params.latency_info.swap(swap->latency_info); |
| 408 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 379 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 409 | 380 |
| 410 // Remove this from the queue, and reset any callback timers. | 381 // Remove this from the queue, and reset any callback timers. |
| 411 pending_swaps_.pop_front(); | 382 pending_swaps_.pop_front(); |
| 412 } | 383 } |
| 413 | 384 |
| 414 void ImageTransportSurfaceOverlayMac::UpdateOverlayPlanes( | 385 void ImageTransportSurfaceOverlayMac::UpdateOverlayPlanes( |
| 415 const std::vector<linked_ptr<OverlayPlane>>& new_overlay_planes) { | 386 const std::vector<linked_ptr<OverlayPlane>>& new_overlay_planes) { |
| 416 std::list<linked_ptr<OverlayPlane>> old_overlay_planes; | 387 std::list<linked_ptr<OverlayPlane>> old_overlay_planes; |
| 417 old_overlay_planes.swap(current_overlay_planes_); | 388 old_overlay_planes.swap(current_overlay_planes_); |
| 418 | 389 |
| 419 // Move the new overlay planes into the |current_overlay_planes_| list, | 390 // Move the new overlay planes into the |current_overlay_planes_| list, |
| 420 // cannibalizing from the old |current_overlay_planes_| as much as possible. | 391 // cannibalizing from the old |current_overlay_planes_| as much as possible. |
| 421 for (auto& new_plane : new_overlay_planes) { | 392 for (auto& new_plane : new_overlay_planes) { |
| 422 if (new_plane->type == OverlayPlane::OVERLAY) { | 393 if (!old_overlay_planes.empty()) { |
| 423 if (!old_overlay_planes.empty()) { | 394 new_plane->TakeCALayerFrom(old_overlay_planes.front().get()); |
| 424 new_plane->TakeCALayerFrom(old_overlay_planes.front().get()); | 395 old_overlay_planes.pop_front(); |
| 425 old_overlay_planes.pop_front(); | |
| 426 } | |
| 427 current_overlay_planes_.push_back(new_plane); | |
| 428 } | 396 } |
| 397 current_overlay_planes_.push_back(new_plane); | |
| 429 } | 398 } |
| 430 | 399 |
| 431 // Destroy any of the previous |current_overlay_planes_| that we couldn't | 400 // Destroy any of the previous |current_overlay_planes_| that we couldn't |
| 432 // cannibalize. | 401 // cannibalize. |
| 433 for (auto& old_plane : old_overlay_planes) | 402 for (auto& old_plane : old_overlay_planes) |
| 434 old_plane->Destroy(); | 403 old_plane->Destroy(); |
| 435 } | 404 } |
| 436 | 405 |
| 437 void ImageTransportSurfaceOverlayMac::UpdateRootAndPartialDamagePlanes( | 406 void ImageTransportSurfaceOverlayMac::UpdateRootAndPartialDamagePlanes( |
| 438 const std::vector<linked_ptr<OverlayPlane>>& new_overlay_planes, | 407 const linked_ptr<OverlayPlane>& new_root_plane, |
| 439 const gfx::RectF& dip_damage_rect) { | 408 const gfx::RectF& dip_damage_rect) { |
| 440 std::list<linked_ptr<OverlayPlane>> old_partial_damage_planes; | 409 std::list<linked_ptr<OverlayPlane>> old_partial_damage_planes; |
| 441 old_partial_damage_planes.swap(current_partial_damage_planes_); | 410 old_partial_damage_planes.swap(current_partial_damage_planes_); |
| 442 linked_ptr<OverlayPlane> new_root_plane = new_overlay_planes.front(); | |
| 443 linked_ptr<OverlayPlane> plane_for_swap; | 411 linked_ptr<OverlayPlane> plane_for_swap; |
| 444 | 412 |
| 445 // If the frame's size changed, if we haven't updated the root layer, or if | 413 // If the frame's size changed, if we haven't updated the root layer, or if |
| 446 // we have full damage, then use the root layer directly. | 414 // we have full damage, then use the root layer directly. |
| 447 if (!current_root_plane_.get() || | 415 if (!current_root_plane_.get() || |
| 448 current_root_plane_->dip_frame_rect != new_root_plane->dip_frame_rect || | 416 current_root_plane_->dip_frame_rect != new_root_plane->dip_frame_rect || |
| 449 dip_damage_rect == new_root_plane->dip_frame_rect) { | 417 dip_damage_rect == new_root_plane->dip_frame_rect) { |
| 450 plane_for_swap = new_root_plane; | 418 plane_for_swap = new_root_plane; |
| 451 } | 419 } |
| 452 | 420 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 474 plane_to_reuse_dip_enlarged_rect.Union(dip_enlarged_rect); | 442 plane_to_reuse_dip_enlarged_rect.Union(dip_enlarged_rect); |
| 475 } | 443 } |
| 476 | 444 |
| 477 if (plane_to_reuse.get()) { | 445 if (plane_to_reuse.get()) { |
| 478 gfx::RectF enlarged_contents_rect = plane_to_reuse_dip_enlarged_rect; | 446 gfx::RectF enlarged_contents_rect = plane_to_reuse_dip_enlarged_rect; |
| 479 enlarged_contents_rect.Scale( | 447 enlarged_contents_rect.Scale( |
| 480 1. / new_root_plane->dip_frame_rect.width(), | 448 1. / new_root_plane->dip_frame_rect.width(), |
| 481 1. / new_root_plane->dip_frame_rect.height()); | 449 1. / new_root_plane->dip_frame_rect.height()); |
| 482 | 450 |
| 483 plane_for_swap = linked_ptr<OverlayPlane>(new OverlayPlane( | 451 plane_for_swap = linked_ptr<OverlayPlane>(new OverlayPlane( |
| 484 OverlayPlane::ROOT_PARTIAL_DAMAGE, 0, new_root_plane->io_surface, | 452 0, new_root_plane->io_surface, plane_to_reuse_dip_enlarged_rect, |
| 485 plane_to_reuse_dip_enlarged_rect, enlarged_contents_rect)); | 453 enlarged_contents_rect)); |
| 486 | 454 |
| 487 plane_for_swap->TakeCALayerFrom(plane_to_reuse.get()); | 455 plane_for_swap->TakeCALayerFrom(plane_to_reuse.get()); |
| 488 if (plane_to_reuse != old_partial_damage_planes.back()) | 456 if (plane_to_reuse != old_partial_damage_planes.back()) |
| 489 [plane_for_swap->ca_layer removeFromSuperlayer]; | 457 [plane_for_swap->ca_layer removeFromSuperlayer]; |
| 490 } | 458 } |
| 491 } | 459 } |
| 492 | 460 |
| 493 // If we haven't found an appropriate layer to re-use, create a new one, if | 461 // If we haven't found an appropriate layer to re-use, create a new one, if |
| 494 // we haven't already created too many. | 462 // we haven't already created too many. |
| 495 if (!plane_for_swap.get() && !dip_damage_rect.IsEmpty() && | 463 if (!plane_for_swap.get() && !dip_damage_rect.IsEmpty() && |
| 496 old_partial_damage_planes.size() < kMaximumPartialDamageLayers) { | 464 old_partial_damage_planes.size() < kMaximumPartialDamageLayers) { |
| 497 gfx::RectF contents_rect = gfx::RectF(dip_damage_rect); | 465 gfx::RectF contents_rect = gfx::RectF(dip_damage_rect); |
| 498 contents_rect.Scale(1. / new_root_plane->dip_frame_rect.width(), | 466 contents_rect.Scale(1. / new_root_plane->dip_frame_rect.width(), |
| 499 1. / new_root_plane->dip_frame_rect.height()); | 467 1. / new_root_plane->dip_frame_rect.height()); |
| 500 plane_for_swap = linked_ptr<OverlayPlane>(new OverlayPlane( | 468 plane_for_swap = linked_ptr<OverlayPlane>(new OverlayPlane( |
| 501 OverlayPlane::ROOT_PARTIAL_DAMAGE, 0, new_root_plane->io_surface, | 469 0, new_root_plane->io_surface, dip_damage_rect, contents_rect)); |
| 502 dip_damage_rect, contents_rect)); | |
| 503 } | 470 } |
| 504 | 471 |
| 505 // And if we still don't have a layer, use the root layer. | 472 // And if we still don't have a layer, use the root layer. |
| 506 if (!plane_for_swap.get() && !dip_damage_rect.IsEmpty()) | 473 if (!plane_for_swap.get() && !dip_damage_rect.IsEmpty()) |
| 507 plane_for_swap = new_root_plane; | 474 plane_for_swap = new_root_plane; |
| 508 | 475 |
| 509 // Walk all old partial damage planes. Remove anything that is now completely | 476 // Walk all old partial damage planes. Remove anything that is now completely |
| 510 // covered, and move everything else into the new | 477 // covered, and move everything else into the new |
| 511 // |current_partial_damage_planes_|. | 478 // |current_partial_damage_planes_|. |
| 512 for (auto& old_plane : old_partial_damage_planes) { | 479 for (auto& old_plane : old_partial_damage_planes) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 if (first_overlay_ca_layer) { | 527 if (first_overlay_ca_layer) { |
| 561 [ca_root_layer_ insertSublayer:plane->ca_layer | 528 [ca_root_layer_ insertSublayer:plane->ca_layer |
| 562 below:first_overlay_ca_layer]; | 529 below:first_overlay_ca_layer]; |
| 563 } else { | 530 } else { |
| 564 [ca_root_layer_ addSublayer:plane->ca_layer]; | 531 [ca_root_layer_ addSublayer:plane->ca_layer]; |
| 565 } | 532 } |
| 566 } | 533 } |
| 567 } | 534 } |
| 568 | 535 |
| 569 // Update CALayer contents, frames, and borders. | 536 // Update CALayer contents, frames, and borders. |
| 570 current_root_plane_->UpdateProperties(); | 537 if (current_root_plane_.get()) |
| 538 current_root_plane_->UpdateProperties(); | |
| 571 for (auto& plane : current_partial_damage_planes_) | 539 for (auto& plane : current_partial_damage_planes_) |
| 572 plane->UpdateProperties(); | 540 plane->UpdateProperties(); |
| 573 for (auto& plane : current_overlay_planes_) | 541 for (auto& plane : current_overlay_planes_) |
| 574 plane->UpdateProperties(); | 542 plane->UpdateProperties(); |
| 575 | 543 |
| 576 DCHECK_EQ( | 544 DCHECK_EQ( |
| 577 static_cast<size_t>([[ca_root_layer_ sublayers] count]), | 545 static_cast<size_t>([[ca_root_layer_ sublayers] count]), |
| 578 current_partial_damage_planes_.size() + current_overlay_planes_.size()); | 546 current_partial_damage_planes_.size() + current_overlay_planes_.size()); |
| 579 } | 547 } |
| 580 | 548 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 } | 621 } |
| 654 return true; | 622 return true; |
| 655 } | 623 } |
| 656 | 624 |
| 657 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( | 625 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( |
| 658 int z_order, | 626 int z_order, |
| 659 gfx::OverlayTransform transform, | 627 gfx::OverlayTransform transform, |
| 660 gfx::GLImage* image, | 628 gfx::GLImage* image, |
| 661 const gfx::Rect& bounds_rect, | 629 const gfx::Rect& bounds_rect, |
| 662 const gfx::RectF& crop_rect) { | 630 const gfx::RectF& crop_rect) { |
| 663 DCHECK_GE(z_order, 0); | |
| 664 DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); | 631 DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); |
| 665 if (z_order < 0 || transform != gfx::OVERLAY_TRANSFORM_NONE) | 632 if (transform != gfx::OVERLAY_TRANSFORM_NONE) |
| 666 return false; | 633 return false; |
| 667 | 634 |
| 668 OverlayPlane::Type type = z_order == 0 ? | |
| 669 OverlayPlane::ROOT : OverlayPlane::OVERLAY; | |
| 670 gfx::RectF dip_frame_rect = ConvertRectToDIPF( | 635 gfx::RectF dip_frame_rect = ConvertRectToDIPF( |
| 671 scale_factor_, bounds_rect); | 636 scale_factor_, bounds_rect); |
| 672 gfx::RectF contents_rect = crop_rect; | |
| 673 | 637 |
| 674 gfx::GLImageIOSurface* image_io_surface = | 638 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 675 static_cast<gfx::GLImageIOSurface*>(image); | 639 if (image) |
|
ccameron
2015/10/05 20:44:42
Do we need this -- is image ever nullptr?
Andre
2015/10/05 20:53:13
This was leftover from scheduling SolidColor tiles
| |
| 640 io_surface = static_cast<gfx::GLImageIOSurface*>(image)->io_surface(); | |
| 676 | 641 |
| 677 pending_overlay_planes_.push_back(linked_ptr<OverlayPlane>( | 642 linked_ptr<OverlayPlane> plane( |
| 678 new OverlayPlane( | 643 new OverlayPlane(z_order, io_surface, dip_frame_rect, crop_rect)); |
| 679 type, z_order, image_io_surface->io_surface(), dip_frame_rect, | 644 if (z_order == 0) |
| 680 contents_rect))); | 645 pending_root_plane_ = plane; |
| 646 else | |
| 647 pending_overlay_planes_.push_back(plane); | |
| 648 | |
| 681 return true; | 649 return true; |
| 682 } | 650 } |
| 683 | 651 |
| 684 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { | 652 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { |
| 685 return true; | 653 return true; |
| 686 } | 654 } |
| 687 | 655 |
| 688 void ImageTransportSurfaceOverlayMac::OnBufferPresented( | 656 void ImageTransportSurfaceOverlayMac::OnBufferPresented( |
| 689 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { | 657 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
| 690 vsync_timebase_ = params.vsync_timebase; | 658 vsync_timebase_ = params.vsync_timebase; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 // Compute the previous vsync time. | 711 // Compute the previous vsync time. |
| 744 base::TimeTicks previous_vsync = | 712 base::TimeTicks previous_vsync = |
| 745 vsync_interval_ * ((from - vsync_timebase_) / vsync_interval_) + | 713 vsync_interval_ * ((from - vsync_timebase_) / vsync_interval_) + |
| 746 vsync_timebase_; | 714 vsync_timebase_; |
| 747 | 715 |
| 748 // Return |interval_fraction| through the next vsync. | 716 // Return |interval_fraction| through the next vsync. |
| 749 return previous_vsync + (1 + interval_fraction) * vsync_interval_; | 717 return previous_vsync + (1 + interval_fraction) * vsync_interval_; |
| 750 } | 718 } |
| 751 | 719 |
| 752 } // namespace content | 720 } // namespace content |
| OLD | NEW |