| 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 "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include "cc/layers/content_layer_client.h" | 7 #include "cc/layers/content_layer_client.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/picture_layer.h" | 9 #include "cc/layers/picture_layer.h" |
| 10 #include "cc/playback/compositing_display_item.h" |
| 10 #include "cc/playback/display_item_list.h" | 11 #include "cc/playback/display_item_list.h" |
| 11 #include "cc/playback/display_item_list_settings.h" | 12 #include "cc/playback/display_item_list_settings.h" |
| 12 #include "cc/playback/drawing_display_item.h" | 13 #include "cc/playback/drawing_display_item.h" |
| 14 #include "cc/playback/filter_display_item.h" |
| 15 #include "cc/playback/float_clip_display_item.h" |
| 13 #include "cc/playback/transform_display_item.h" | 16 #include "cc/playback/transform_display_item.h" |
| 14 #include "cc/trees/clip_node.h" | 17 #include "cc/trees/clip_node.h" |
| 15 #include "cc/trees/effect_node.h" | 18 #include "cc/trees/effect_node.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 19 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/property_tree.h" | 20 #include "cc/trees/property_tree.h" |
| 18 #include "cc/trees/scroll_node.h" | 21 #include "cc/trees/scroll_node.h" |
| 19 #include "cc/trees/transform_node.h" | 22 #include "cc/trees/transform_node.h" |
| 20 #include "platform/RuntimeEnabledFeatures.h" | 23 #include "platform/RuntimeEnabledFeatures.h" |
| 21 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 24 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 22 #include "platform/graphics/paint/DisplayItem.h" | 25 #include "platform/graphics/paint/DisplayItem.h" |
| 23 #include "platform/graphics/paint/DrawingDisplayItem.h" | 26 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 24 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" | 27 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" |
| 28 #include "platform/graphics/paint/GeometryMapper.h" |
| 25 #include "platform/graphics/paint/PaintArtifact.h" | 29 #include "platform/graphics/paint/PaintArtifact.h" |
| 30 #include "platform/graphics/paint/PropertyTreeState.h" |
| 26 #include "platform/graphics/paint/RasterInvalidationTracking.h" | 31 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
| 27 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 32 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 28 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 33 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 29 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
| 30 #include "public/platform/WebCompositorSupport.h" | 35 #include "public/platform/WebCompositorSupport.h" |
| 31 #include "public/platform/WebLayer.h" | 36 #include "public/platform/WebLayer.h" |
| 32 #include "ui/gfx/geometry/point.h" | 37 #include "ui/gfx/geometry/point.h" |
| 33 #include "ui/gfx/geometry/point_f.h" | 38 #include "ui/gfx/geometry/point_f.h" |
| 34 #include "ui/gfx/geometry/rect.h" | 39 #include "ui/gfx/geometry/rect.h" |
| 35 #include "ui/gfx/geometry/rect_f.h" | 40 #include "ui/gfx/geometry/rect_f.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // gfx::Rect bounds = gfx::SkIRectToRect(picture->cullRect().roundOut()); | 234 // gfx::Rect bounds = gfx::SkIRectToRect(picture->cullRect().roundOut()); |
| 230 // or use the visual rect directly. However, clip content layers attempt | 235 // or use the visual rect directly. However, clip content layers attempt |
| 231 // to raster in a different space than that of the visual rects. We'll be | 236 // to raster in a different space than that of the visual rects. We'll be |
| 232 // reworking visual rects further for SPv2, so for now we just pass a | 237 // reworking visual rects further for SPv2, so for now we just pass a |
| 233 // visual rect large enough to make sure items raster. | 238 // visual rect large enough to make sure items raster. |
| 234 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( | 239 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( |
| 235 largeRect, sk_ref_sp(picture)); | 240 largeRect, sk_ref_sp(picture)); |
| 236 } | 241 } |
| 237 } | 242 } |
| 238 | 243 |
| 239 static scoped_refptr<cc::DisplayItemList> recordPaintChunk( | |
| 240 const PaintArtifact& artifact, | |
| 241 const PaintChunk& chunk, | |
| 242 const gfx::Rect& combinedBounds) { | |
| 243 cc::DisplayItemListSettings settings; | |
| 244 scoped_refptr<cc::DisplayItemList> list = | |
| 245 cc::DisplayItemList::Create(settings); | |
| 246 | |
| 247 gfx::Transform translation; | |
| 248 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | |
| 249 // Passing combinedBounds as the visual rect for the begin/end transform item | |
| 250 // would normally be the sensible thing to do, but see comment above re: | |
| 251 // visual rects for drawing items and further rework in flight. | |
| 252 list->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | |
| 253 | |
| 254 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | |
| 255 for (const auto& displayItem : displayItems.itemsInPaintChunk(chunk)) | |
| 256 appendDisplayItemToCcDisplayItemList(displayItem, list.get()); | |
| 257 | |
| 258 list->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 259 | |
| 260 list->Finalize(); | |
| 261 return list; | |
| 262 } | |
| 263 | |
| 264 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( | 244 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( |
| 265 const PaintArtifact& paintArtifact, | 245 const PaintArtifact& paintArtifact, |
| 266 const PaintChunk& paintChunk, | 246 const PaintChunk& paintChunk, |
| 267 gfx::Vector2dF& layerOffset) { | 247 gfx::Vector2dF& layerOffset) { |
| 268 if (paintChunk.size() != 1) | 248 if (paintChunk.size() != 1) |
| 269 return nullptr; | 249 return nullptr; |
| 270 | 250 |
| 271 const auto& displayItem = | 251 const auto& displayItem = |
| 272 paintArtifact.getDisplayItemList()[paintChunk.beginIndex]; | 252 paintArtifact.getDisplayItemList()[paintChunk.beginIndex]; |
| 273 if (!displayItem.isForeignLayer()) | 253 if (!displayItem.isForeignLayer()) |
| 274 return nullptr; | 254 return nullptr; |
| 275 | 255 |
| 276 const auto& foreignLayerDisplayItem = | 256 const auto& foreignLayerDisplayItem = |
| 277 static_cast<const ForeignLayerDisplayItem&>(displayItem); | 257 static_cast<const ForeignLayerDisplayItem&>(displayItem); |
| 278 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), | 258 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), |
| 279 foreignLayerDisplayItem.location().y()); | 259 foreignLayerDisplayItem.location().y()); |
| 280 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); | 260 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); |
| 281 layer->SetBounds(foreignLayerDisplayItem.bounds()); | 261 layer->SetBounds(foreignLayerDisplayItem.bounds()); |
| 282 layer->SetIsDrawable(true); | 262 layer->SetIsDrawable(true); |
| 283 return layer; | 263 return layer; |
| 284 } | 264 } |
| 285 | 265 |
| 286 constexpr int kInvalidNodeId = -1; | 266 constexpr int kInvalidNodeId = -1; |
| 287 // cc's property trees use 0 for the root node (always non-null). | 267 // cc's property trees use 0 for the root node (always non-null). |
| 288 constexpr int kRealRootNodeId = 0; | 268 constexpr int kRealRootNodeId = 0; |
| 289 // cc allocates special nodes for root effects such as the device scale. | 269 // cc allocates special nodes for root effects such as the device scale. |
| 290 constexpr int kSecondaryRootNodeId = 1; | 270 constexpr int kSecondaryRootNodeId = 1; |
| 291 constexpr int kPropertyTreeSequenceNumber = 1; | 271 constexpr int kPropertyTreeSequenceNumber = 1; |
| 292 | 272 |
| 273 enum EndDisplayItemType { EndTransform, EndClip, EndEffect }; |
| 274 |
| 275 // Applies the clips between |localState| and |ancestorState| into a single |
| 276 // combined cc::FloatClipDisplayItem on |ccList|. |
| 277 static void applyClipsBetweenStates(const PropertyTreeState& localState, |
| 278 const PropertyTreeState& ancestorState, |
| 279 cc::DisplayItemList& ccList, |
| 280 Vector<EndDisplayItemType>& endDisplayItems, |
| 281 GeometryMapper& geometryMapper) { |
| 282 DCHECK(localState.transform() == ancestorState.transform()); |
| 283 #ifdef DCHECK_IS_ON |
| 284 const TransformPaintPropertyNode* transformNode = |
| 285 localState.clip()->localTransformSpace(); |
| 286 if (transformNode != ancestorState.transform()) { |
| 287 bool success = false; |
| 288 const TransformationMatrix& localToAncestorMatrix = |
| 289 geometryMapper.localToAncestorMatrix(transformNode, ancestorState, |
| 290 success); |
| 291 DCHECK(success); |
| 292 // Clips are only in descendant spaces that are transformed by one |
| 293 // or more scrolls. |
| 294 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); |
| 295 } |
| 296 #endif |
| 297 |
| 298 FloatRect combinedClip; |
| 299 bool success = false; |
| 300 // TODO(chrishtr) :get rid of infiniteIntRect here. |
| 301 combinedClip = geometryMapper.localToVisualRectInAncestorSpace( |
| 302 FloatRect(LayoutRect::infiniteIntRect()), localState, ancestorState, |
| 303 success); |
| 304 |
| 305 DCHECK(success); |
| 306 |
| 307 ccList.CreateAndAppendPairedBeginItem<cc::FloatClipDisplayItem>( |
| 308 gfx::RectF(combinedClip)); |
| 309 endDisplayItems.push_back(EndClip); |
| 310 } |
| 311 |
| 312 static void recordPairedBeginDisplayItems( |
| 313 const Vector<PropertyTreeState>& pairedStates, |
| 314 const PropertyTreeState& pendingLayerState, |
| 315 cc::DisplayItemList& ccList, |
| 316 Vector<EndDisplayItemType>& endDisplayItems, |
| 317 GeometryMapper& geometryMapper) { |
| 318 PropertyTreeState mappedClipDestinationSpace = pendingLayerState; |
| 319 PropertyTreeState clipSpace = pendingLayerState; |
| 320 bool hasClip = false; |
| 321 |
| 322 for (Vector<PropertyTreeState>::const_reverse_iterator pairedState = |
| 323 pairedStates.rbegin(); |
| 324 pairedState != pairedStates.rend(); ++pairedState) { |
| 325 switch (pairedState->innermostNode()) { |
| 326 case PropertyTreeState::Transform: { |
| 327 if (hasClip) { |
| 328 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, |
| 329 endDisplayItems, geometryMapper); |
| 330 hasClip = false; |
| 331 } |
| 332 mappedClipDestinationSpace = *pairedState; |
| 333 clipSpace = *pairedState; |
| 334 |
| 335 TransformationMatrix matrix = pairedState->transform()->matrix(); |
| 336 matrix.applyTransformOrigin(pairedState->transform()->origin()); |
| 337 |
| 338 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 339 transform.matrix() = TransformationMatrix::toSkMatrix44(matrix); |
| 340 |
| 341 ccList.CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>( |
| 342 transform); |
| 343 endDisplayItems.push_back(EndTransform); |
| 344 break; |
| 345 } |
| 346 case PropertyTreeState::Clip: { |
| 347 // Clips are handled in |applyClips| when ending the iterator, or |
| 348 // transitioning between transform spaces. Here we store off the |
| 349 // PropertyTreeState of the first found clip, under the transform of |
| 350 // pairedState->transform(). All subsequent clips before applying the |
| 351 // transform will be applied in applyClips. |
| 352 clipSpace = *pairedState; |
| 353 hasClip = true; |
| 354 #ifdef DCHECK_IS_ON |
| 355 if (pairedState->clip()->localTransformSpace() != |
| 356 pairedState->transform()) { |
| 357 const TransformationMatrix& localTransformMatrix = |
| 358 pairedState->effect()->localTransformSpace()->matrix(); |
| 359 // Clips are only in descendant spaces that are transformed by scroll. |
| 360 DCHECK(localTransformMatrix.isIdentityOrTranslation()); |
| 361 } |
| 362 #endif |
| 363 break; |
| 364 } |
| 365 case PropertyTreeState::Effect: { |
| 366 // TODO(chrishtr): skip effect and/or compositing display items if |
| 367 // not necessary. |
| 368 |
| 369 FloatRect clipRect = |
| 370 pairedState->effect()->outputClip()->clipRect().rect(); |
| 371 // TODO(chrishtr): specify origin of the filter. |
| 372 FloatPoint filterOrigin; |
| 373 if (pairedState->effect()->localTransformSpace() != |
| 374 pairedState->transform()) { |
| 375 bool success = false; |
| 376 const TransformPaintPropertyNode* transformNode = |
| 377 pairedState->effect()->localTransformSpace(); |
| 378 const TransformationMatrix& localToAncestorMatrix = |
| 379 geometryMapper.localToAncestorMatrix(transformNode, *pairedState, |
| 380 success); |
| 381 DCHECK(success); |
| 382 // Effects are only in descendant spaces that are transformed by one |
| 383 // or more scrolls. |
| 384 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); |
| 385 |
| 386 clipRect = localToAncestorMatrix.mapRect(clipRect); |
| 387 filterOrigin = localToAncestorMatrix.mapPoint(filterOrigin); |
| 388 } |
| 389 |
| 390 const bool kLcdTextRequiresOpaqueLayer = true; |
| 391 ccList.CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>( |
| 392 static_cast<uint8_t>( |
| 393 gfx::ToFlooredInt(255 * pairedState->effect()->opacity())), |
| 394 pairedState->effect()->blendMode(), |
| 395 // TODO(chrishtr): compute bounds as necessary. |
| 396 nullptr, nullptr, kLcdTextRequiresOpaqueLayer); |
| 397 |
| 398 ccList.CreateAndAppendPairedBeginItem<cc::FilterDisplayItem>( |
| 399 pairedState->effect()->filter().asCcFilterOperations(), clipRect, |
| 400 gfx::PointF(filterOrigin.x(), filterOrigin.y())); |
| 401 |
| 402 endDisplayItems.push_back(EndEffect); |
| 403 break; |
| 404 } |
| 405 case PropertyTreeState::None: |
| 406 break; |
| 407 } |
| 408 } |
| 409 |
| 410 if (hasClip) { |
| 411 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, |
| 412 endDisplayItems, geometryMapper); |
| 413 } |
| 414 } |
| 415 |
| 416 static void recordPairedEndDisplayItems( |
| 417 const Vector<EndDisplayItemType>& endDisplayItemTypes, |
| 418 cc::DisplayItemList* ccList) { |
| 419 for (Vector<EndDisplayItemType>::const_reverse_iterator endType = |
| 420 endDisplayItemTypes.rbegin(); |
| 421 endType != endDisplayItemTypes.rend(); ++endType) { |
| 422 switch (*endType) { |
| 423 case EndTransform: |
| 424 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); |
| 425 break; |
| 426 case EndClip: |
| 427 ccList->CreateAndAppendPairedEndItem<cc::EndFloatClipDisplayItem>(); |
| 428 break; |
| 429 case EndEffect: |
| 430 ccList->CreateAndAppendPairedEndItem<cc::EndFilterDisplayItem>(); |
| 431 ccList->CreateAndAppendPairedEndItem<cc::EndCompositingDisplayItem>(); |
| 432 break; |
| 433 } |
| 434 } |
| 435 } |
| 436 |
| 293 } // namespace | 437 } // namespace |
| 294 | 438 |
| 439 scoped_refptr<cc::DisplayItemList> PaintArtifactCompositor::recordPendingLayer( |
| 440 const PaintArtifact& artifact, |
| 441 const PendingLayer& pendingLayer, |
| 442 const gfx::Rect& combinedBounds, |
| 443 GeometryMapper& geometryMapper) { |
| 444 cc::DisplayItemListSettings settings; |
| 445 scoped_refptr<cc::DisplayItemList> ccList = |
| 446 cc::DisplayItemList::Create(settings); |
| 447 |
| 448 gfx::Transform translation; |
| 449 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); |
| 450 // Passing combinedBounds as the visual rect for the begin/end transform item |
| 451 // would normally be the sensible thing to do, but see comment above re: |
| 452 // visual rects for drawing items and further rework in flight. |
| 453 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); |
| 454 |
| 455 const DisplayItemList& displayItems = artifact.getDisplayItemList(); |
| 456 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 457 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; |
| 458 PropertyTreeStateIterator iterator(*state); |
| 459 Vector<PropertyTreeState> pairedStates; |
| 460 for (; state && *state != pendingLayer.propertyTreeState; |
| 461 state = iterator.next()) { |
| 462 if (state->innermostNode() != PropertyTreeState::None) |
| 463 pairedStates.push_back(*state); |
| 464 } |
| 465 |
| 466 // TODO(chrishtr): we can avoid some extra paired display items if |
| 467 // multiple PaintChunks share them. We can also collapse clips between |
| 468 // transforms into single clips in the same way that PaintLayerClipper does. |
| 469 Vector<EndDisplayItemType> endDisplayItems; |
| 470 |
| 471 recordPairedBeginDisplayItems(pairedStates, pendingLayer.propertyTreeState, |
| 472 *ccList.get(), endDisplayItems, |
| 473 geometryMapper); |
| 474 |
| 475 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) |
| 476 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); |
| 477 |
| 478 recordPairedEndDisplayItems(endDisplayItems, ccList.get()); |
| 479 } |
| 480 |
| 481 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); |
| 482 |
| 483 ccList->Finalize(); |
| 484 return ccList; |
| 485 } |
| 486 |
| 295 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> | 487 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> |
| 296 PaintArtifactCompositor::clientForPaintChunk( | 488 PaintArtifactCompositor::clientForPaintChunk( |
| 297 const PaintChunk& paintChunk, | 489 const PaintChunk& paintChunk, |
| 298 const PaintArtifact& paintArtifact) { | 490 const PaintArtifact& paintArtifact) { |
| 299 // TODO(chrishtr): for now, just using a linear walk. In the future we can | 491 // TODO(chrishtr): for now, just using a linear walk. In the future we can |
| 300 // optimize this by using the same techniques used in PaintController for | 492 // optimize this by using the same techniques used in PaintController for |
| 301 // display lists. | 493 // display lists. |
| 302 for (auto& client : m_contentLayerClients) { | 494 for (auto& client : m_contentLayerClients) { |
| 303 if (client && client->matches(paintChunk)) | 495 if (client && client->matches(paintChunk)) |
| 304 return std::move(client); | 496 return std::move(client); |
| 305 } | 497 } |
| 306 | 498 |
| 307 return WTF::wrapUnique(new ContentLayerClientImpl( | 499 return WTF::wrapUnique(new ContentLayerClientImpl( |
| 308 paintChunk.id | 500 paintChunk.id |
| 309 ? *paintChunk.id | 501 ? *paintChunk.id |
| 310 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 502 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 311 } | 503 } |
| 312 | 504 |
| 313 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 505 scoped_refptr<cc::Layer> |
| 506 PaintArtifactCompositor::compositedLayerForPendingLayer( |
| 314 const PaintArtifact& paintArtifact, | 507 const PaintArtifact& paintArtifact, |
| 315 const PaintChunk& paintChunk, | 508 const PendingLayer& pendingLayer, |
| 316 gfx::Vector2dF& layerOffset, | 509 gfx::Vector2dF& layerOffset, |
| 317 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 510 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 318 RasterInvalidationTracking* tracking, | 511 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap, |
| 319 bool storeDebugInfo) { | 512 bool storeDebugInfo, |
| 320 DCHECK(paintChunk.size()); | 513 GeometryMapper& geometryMapper) { |
| 514 DCHECK(pendingLayer.paintChunks.size()); |
| 515 const PaintChunk& firstPaintChunk = *pendingLayer.paintChunks[0]; |
| 516 DCHECK(firstPaintChunk.size()); |
| 517 #if DCHECK_IS_ON |
| 518 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 519 DCHECK(paintChunk.properties == firstPaintChunk.properties); |
| 520 } |
| 521 #endif |
| 321 | 522 |
| 322 // If the paint chunk is a foreign layer, just return that layer. | 523 // If the paint chunk is a foreign layer, just return that layer. |
| 323 if (scoped_refptr<cc::Layer> foreignLayer = | 524 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk( |
| 324 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 525 paintArtifact, firstPaintChunk, layerOffset)) { |
| 526 DCHECK_EQ(pendingLayer.paintChunks.size(), 1u); |
| 325 return foreignLayer; | 527 return foreignLayer; |
| 528 } |
| 326 | 529 |
| 327 // The common case: create or reuse a PictureLayer for painted content. | 530 // The common case: create or reuse a PictureLayer for painted content. |
| 328 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 531 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 329 clientForPaintChunk(paintChunk, paintArtifact); | 532 clientForPaintChunk(firstPaintChunk, paintArtifact); |
| 330 | 533 |
| 331 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 534 gfx::Rect ccCombinedBounds(enclosingIntRect(pendingLayer.bounds)); |
| 332 scoped_refptr<cc::DisplayItemList> displayList = | 535 |
| 333 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 536 scoped_refptr<cc::DisplayItemList> displayList = recordPendingLayer( |
| 537 paintArtifact, pendingLayer, ccCombinedBounds, geometryMapper); |
| 334 contentLayerClient->SetDisplayList(std::move(displayList)); | 538 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 335 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 539 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size())); |
| 336 | 540 |
| 337 layerOffset = combinedBounds.OffsetFromOrigin(); | 541 layerOffset = ccCombinedBounds.OffsetFromOrigin(); |
| 542 |
| 338 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 543 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 339 contentLayerClient->ccPictureLayer(); | 544 contentLayerClient->ccPictureLayer(); |
| 340 ccPictureLayer->SetBounds(combinedBounds.size()); | 545 ccPictureLayer->SetBounds(ccCombinedBounds.size()); |
| 341 ccPictureLayer->SetIsDrawable(true); | 546 ccPictureLayer->SetIsDrawable(true); |
| 342 if (paintChunk.knownToBeOpaque) | 547 ccPictureLayer->SetContentsOpaque(pendingLayer.knownToBeOpaque); |
| 343 ccPictureLayer->SetContentsOpaque(true); | 548 contentLayerClient->clearPaintChunkDebugData(); |
| 344 DCHECK(!tracking || | |
| 345 tracking->trackedRasterInvalidations.size() == | |
| 346 paintChunk.rasterInvalidationRects.size()); | |
| 347 | 549 |
| 348 contentLayerClient->clearPaintChunkDebugData(); | 550 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 349 if (storeDebugInfo) { | 551 RasterInvalidationTracking* rasterTracking = |
| 350 contentLayerClient->addPaintChunkDebugData( | 552 trackingMap ? trackingMap->find(paintChunk) : nullptr; |
| 351 paintArtifact.getDisplayItemList().subsequenceAsJSON( | 553 DCHECK(!rasterTracking || |
| 352 paintChunk.beginIndex, paintChunk.endIndex, | 554 rasterTracking->trackedRasterInvalidations.size() == |
| 353 DisplayItemList::SkipNonDrawings | | 555 paintChunk->rasterInvalidationRects.size()); |
| 354 DisplayItemList::ShownOnlyDisplayItemTypes)); | |
| 355 } | |
| 356 | 556 |
| 357 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 557 if (storeDebugInfo) { |
| 358 ++index) { | 558 contentLayerClient->addPaintChunkDebugData( |
| 359 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 559 paintArtifact.getDisplayItemList().subsequenceAsJSON( |
| 360 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 560 paintChunk->beginIndex, paintChunk->endIndex, |
| 361 std::max(0, rect.height())); | 561 DisplayItemList::SkipNonDrawings | |
| 362 // Raster paintChunk.rasterInvalidationRects is in the space of the | 562 DisplayItemList::ShownOnlyDisplayItemTypes)); |
| 363 // containing transform node, so need to subtract off the layer offset. | 563 } |
| 364 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 564 |
| 365 contentLayerClient->setNeedsDisplayRect( | 565 for (unsigned index = 0; index < paintChunk->rasterInvalidationRects.size(); |
| 366 ccInvalidationRect, | 566 ++index) { |
| 367 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); | 567 IntRect rect( |
| 568 enclosingIntRect(paintChunk->rasterInvalidationRects[index])); |
| 569 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), |
| 570 std::max(0, rect.width()), |
| 571 std::max(0, rect.height())); |
| 572 if (ccInvalidationRect.IsEmpty()) |
| 573 continue; |
| 574 // Raster paintChunk.rasterInvalidationRects is in the space of the |
| 575 // containing transform node, so need to subtract off the layer offset. |
| 576 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin()); |
| 577 contentLayerClient->setNeedsDisplayRect( |
| 578 ccInvalidationRect, |
| 579 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index] |
| 580 : nullptr); |
| 581 } |
| 368 } | 582 } |
| 369 | 583 |
| 370 newContentLayerClients.append(std::move(contentLayerClient)); | 584 newContentLayerClients.append(std::move(contentLayerClient)); |
| 371 return ccPictureLayer; | 585 return ccPictureLayer; |
| 372 } | 586 } |
| 373 | 587 |
| 374 namespace { | 588 namespace { |
| 375 | 589 |
| 376 class PropertyTreeManager { | 590 class PropertyTreeManager { |
| 377 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); | 591 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 scrollTree().set_needs_update(true); | 884 scrollTree().set_needs_update(true); |
| 671 } | 885 } |
| 672 | 886 |
| 673 unsigned depth(const EffectPaintPropertyNode* node) { | 887 unsigned depth(const EffectPaintPropertyNode* node) { |
| 674 unsigned result = 0; | 888 unsigned result = 0; |
| 675 for (; node; node = node->parent()) | 889 for (; node; node = node->parent()) |
| 676 result++; | 890 result++; |
| 677 return result; | 891 return result; |
| 678 } | 892 } |
| 679 | 893 |
| 894 // TODO(chrishtr): templatize this to avoid duplication of |
| 895 // GeometryMapper::leastCommonAncestor. |
| 680 const EffectPaintPropertyNode* lowestCommonAncestor( | 896 const EffectPaintPropertyNode* lowestCommonAncestor( |
| 681 const EffectPaintPropertyNode* nodeA, | 897 const EffectPaintPropertyNode* nodeA, |
| 682 const EffectPaintPropertyNode* nodeB) { | 898 const EffectPaintPropertyNode* nodeB) { |
| 683 // Optimized common case. | 899 // Optimized common case. |
| 684 if (nodeA == nodeB) | 900 if (nodeA == nodeB) |
| 685 return nodeA; | 901 return nodeA; |
| 686 | 902 |
| 687 unsigned depthA = depth(nodeA), depthB = depth(nodeB); | 903 unsigned depthA = depth(nodeA), depthB = depth(nodeB); |
| 688 while (depthA > depthB) { | 904 while (depthA > depthB) { |
| 689 nodeA = nodeA->parent(); | 905 nodeA = nodeA->parent(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 1000 |
| 785 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1001 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 786 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 1002 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 787 dummyLayer->SetClipTreeIndex(outputClipId); | 1003 dummyLayer->SetClipTreeIndex(outputClipId); |
| 788 dummyLayer->SetEffectTreeIndex(effectNode.id); | 1004 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 789 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 1005 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 790 } | 1006 } |
| 791 | 1007 |
| 792 } // namespace | 1008 } // namespace |
| 793 | 1009 |
| 1010 bool PaintArtifactCompositor::canMergeInto( |
| 1011 const PaintArtifact& paintArtifact, |
| 1012 const PaintChunk& newChunk, |
| 1013 const PendingLayer& candidatePendingLayer) { |
| 1014 const PaintChunk& pendingLayerFirstChunk = |
| 1015 *candidatePendingLayer.paintChunks[0]; |
| 1016 if (paintArtifact.getDisplayItemList()[newChunk.beginIndex].isForeignLayer()) |
| 1017 return false; |
| 1018 |
| 1019 if (paintArtifact.getDisplayItemList()[pendingLayerFirstChunk.beginIndex] |
| 1020 .isForeignLayer()) |
| 1021 return false; |
| 1022 |
| 1023 if (newChunk.properties.backfaceHidden != |
| 1024 pendingLayerFirstChunk.properties.backfaceHidden) |
| 1025 return false; |
| 1026 |
| 1027 DCHECK_GE(candidatePendingLayer.paintChunks.size(), 1u); |
| 1028 PropertyTreeStateIterator iterator(newChunk.properties.propertyTreeState); |
| 1029 for (const PropertyTreeState* currentState = |
| 1030 &newChunk.properties.propertyTreeState; |
| 1031 currentState; currentState = iterator.next()) { |
| 1032 if (currentState->hasDirectCompositingReasons()) |
| 1033 return false; |
| 1034 if (*currentState == candidatePendingLayer.propertyTreeState) |
| 1035 return true; |
| 1036 } |
| 1037 return false; |
| 1038 } |
| 1039 |
| 1040 bool PaintArtifactCompositor::mightOverlap( |
| 1041 const PaintChunk& paintChunk, |
| 1042 const PendingLayer& candidatePendingLayer, |
| 1043 GeometryMapper& geometryMapper) { |
| 1044 // TODO(chrishtr): implement |
| 1045 return true; |
| 1046 } |
| 1047 |
| 1048 PaintArtifactCompositor::PendingLayer::PendingLayer( |
| 1049 const PaintChunk& firstPaintChunk) |
| 1050 : bounds(firstPaintChunk.bounds), |
| 1051 knownToBeOpaque(firstPaintChunk.knownToBeOpaque), |
| 1052 backfaceHidden(firstPaintChunk.properties.backfaceHidden), |
| 1053 propertyTreeState(firstPaintChunk.properties.propertyTreeState) { |
| 1054 paintChunks.append(&firstPaintChunk); |
| 1055 } |
| 1056 |
| 1057 void PaintArtifactCompositor::PendingLayer::add( |
| 1058 const PaintChunk& paintChunk, |
| 1059 GeometryMapper* geometryMapper) { |
| 1060 DCHECK(paintChunk.properties.backfaceHidden == backfaceHidden); |
| 1061 paintChunks.append(&paintChunk); |
| 1062 FloatRect mappedBounds = paintChunk.bounds; |
| 1063 if (geometryMapper) { |
| 1064 bool success = false; |
| 1065 mappedBounds = geometryMapper->localToAncestorRect( |
| 1066 mappedBounds, paintChunk.properties.propertyTreeState, |
| 1067 propertyTreeState, success); |
| 1068 DCHECK(success); |
| 1069 } |
| 1070 bounds.unite(mappedBounds); |
| 1071 if (bounds.size() != paintChunks[0]->bounds.size()) { |
| 1072 if (bounds.size() != paintChunk.bounds.size()) |
| 1073 knownToBeOpaque = false; |
| 1074 else |
| 1075 knownToBeOpaque = paintChunk.knownToBeOpaque; |
| 1076 } |
| 1077 } |
| 1078 |
| 1079 void PaintArtifactCompositor::collectPendingLayers( |
| 1080 const PaintArtifact& paintArtifact, |
| 1081 Vector<PendingLayer>& pendingLayers, |
| 1082 GeometryMapper& geometryMapper) { |
| 1083 // n = # of paint chunks. Memoizing canMergeInto() can get it to O(n^2), and |
| 1084 // other heuristics can make worst-case behavior better. |
| 1085 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 1086 bool createNew = true; |
| 1087 for (Vector<PendingLayer>::reverse_iterator candidatePendingLayer = |
| 1088 pendingLayers.rbegin(); |
| 1089 candidatePendingLayer != pendingLayers.rend(); |
| 1090 ++candidatePendingLayer) { |
| 1091 if (canMergeInto(paintArtifact, paintChunk, *candidatePendingLayer)) { |
| 1092 candidatePendingLayer->add(paintChunk, &geometryMapper); |
| 1093 createNew = false; |
| 1094 break; |
| 1095 } |
| 1096 if (mightOverlap(paintChunk, *candidatePendingLayer, geometryMapper)) { |
| 1097 break; |
| 1098 } |
| 1099 } |
| 1100 if (createNew) |
| 1101 pendingLayers.append(PendingLayer(paintChunk)); |
| 1102 } |
| 1103 } |
| 1104 |
| 794 void PaintArtifactCompositor::update( | 1105 void PaintArtifactCompositor::update( |
| 795 const PaintArtifact& paintArtifact, | 1106 const PaintArtifact& paintArtifact, |
| 796 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, | 1107 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, |
| 797 bool storeDebugInfo) { | 1108 bool storeDebugInfo) { |
| 1109 #ifndef NDEBUG |
| 1110 storeDebugInfo = true; |
| 1111 #endif |
| 1112 |
| 798 DCHECK(m_rootLayer); | 1113 DCHECK(m_rootLayer); |
| 799 | 1114 |
| 800 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); | 1115 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); |
| 801 | 1116 |
| 802 // The tree will be null after detaching and this update can be ignored. | 1117 // The tree will be null after detaching and this update can be ignored. |
| 803 // See: WebViewImpl::detachPaintArtifactCompositor(). | 1118 // See: WebViewImpl::detachPaintArtifactCompositor(). |
| 804 if (!layerTree) | 1119 if (!layerTree) |
| 805 return; | 1120 return; |
| 806 | 1121 |
| 807 if (m_extraDataForTestingEnabled) | 1122 if (m_extraDataForTestingEnabled) |
| 808 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); | 1123 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); |
| 809 | 1124 |
| 810 m_rootLayer->RemoveAllChildren(); | 1125 m_rootLayer->RemoveAllChildren(); |
| 811 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1126 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 812 | 1127 |
| 813 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), | 1128 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), |
| 814 m_rootLayer.get()); | 1129 m_rootLayer.get()); |
| 815 | 1130 |
| 1131 Vector<PendingLayer, 0> pendingLayers; |
| 1132 GeometryMapper geometryMapper; |
| 1133 collectPendingLayers(paintArtifact, pendingLayers, geometryMapper); |
| 1134 |
| 816 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; | 1135 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; |
| 817 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 1136 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 818 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 1137 for (const PendingLayer& pendingLayer : pendingLayers) { |
| 819 gfx::Vector2dF layerOffset; | 1138 gfx::Vector2dF layerOffset; |
| 820 scoped_refptr<cc::Layer> layer = layerForPaintChunk( | 1139 scoped_refptr<cc::Layer> layer = compositedLayerForPendingLayer( |
| 821 paintArtifact, paintChunk, layerOffset, newContentLayerClients, | 1140 paintArtifact, pendingLayer, layerOffset, newContentLayerClients, |
| 822 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) | 1141 rasterChunkInvalidations, storeDebugInfo, geometryMapper); |
| 823 : nullptr, | |
| 824 storeDebugInfo); | |
| 825 | 1142 |
| 826 int transformId = propertyTreeManager.compositorIdForTransformNode( | 1143 int transformId = propertyTreeManager.compositorIdForTransformNode( |
| 827 paintChunk.properties.propertyTreeState.transform()); | 1144 pendingLayer.propertyTreeState.transform()); |
| 828 int scrollId = propertyTreeManager.compositorIdForScrollNode( | 1145 int scrollId = propertyTreeManager.compositorIdForScrollNode( |
| 829 paintChunk.properties.propertyTreeState.scroll()); | 1146 pendingLayer.propertyTreeState.scroll()); |
| 830 int clipId = propertyTreeManager.compositorIdForClipNode( | 1147 int clipId = propertyTreeManager.compositorIdForClipNode( |
| 831 paintChunk.properties.propertyTreeState.clip()); | 1148 pendingLayer.propertyTreeState.clip()); |
| 832 int effectId = propertyTreeManager.switchToEffectNode( | 1149 int effectId = propertyTreeManager.switchToEffectNode( |
| 833 *paintChunk.properties.propertyTreeState.effect()); | 1150 *pendingLayer.propertyTreeState.effect()); |
| 834 | 1151 |
| 835 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); | 1152 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 836 | 1153 |
| 837 layer->set_offset_to_transform_parent(layerOffset); | 1154 layer->set_offset_to_transform_parent(layerOffset); |
| 838 | 1155 |
| 839 m_rootLayer->AddChild(layer); | 1156 m_rootLayer->AddChild(layer); |
| 840 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1157 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 841 layer->SetTransformTreeIndex(transformId); | 1158 layer->SetTransformTreeIndex(transformId); |
| 842 layer->SetClipTreeIndex(clipId); | 1159 layer->SetClipTreeIndex(clipId); |
| 843 layer->SetEffectTreeIndex(effectId); | 1160 layer->SetEffectTreeIndex(effectId); |
| 844 layer->SetScrollTreeIndex(scrollId); | 1161 layer->SetScrollTreeIndex(scrollId); |
| 845 | 1162 |
| 846 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 1163 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 847 // queried by RenderSurfaceImpl. | 1164 // queried by RenderSurfaceImpl. |
| 848 layer->Set3dSortingContextId(layerTree->property_trees() | 1165 layer->Set3dSortingContextId(layerTree->property_trees() |
| 849 ->transform_tree.Node(transformId) | 1166 ->transform_tree.Node(transformId) |
| 850 ->sorting_context_id); | 1167 ->sorting_context_id); |
| 851 | 1168 |
| 852 layer->SetShouldCheckBackfaceVisibility( | 1169 layer->SetShouldCheckBackfaceVisibility(pendingLayer.backfaceHidden); |
| 853 paintChunk.properties.backfaceHidden); | |
| 854 | 1170 |
| 855 if (m_extraDataForTestingEnabled) | 1171 if (m_extraDataForTestingEnabled) |
| 856 m_extraDataForTesting->contentLayers.append(layer); | 1172 m_extraDataForTesting->contentLayers.append(layer); |
| 857 } | 1173 } |
| 858 m_contentLayerClients.clear(); | 1174 m_contentLayerClients.clear(); |
| 859 m_contentLayerClients.swap(newContentLayerClients); | 1175 m_contentLayerClients.swap(newContentLayerClients); |
| 860 | 1176 |
| 861 // Mark the property trees as having been rebuilt. | 1177 // Mark the property trees as having been rebuilt. |
| 862 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 1178 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 863 layerTree->property_trees()->needs_rebuild = false; | 1179 layerTree->property_trees()->needs_rebuild = false; |
| 864 layerTree->property_trees()->ResetCachedData(); | 1180 layerTree->property_trees()->ResetCachedData(); |
| 865 } | 1181 } |
| 866 | 1182 |
| 1183 #ifndef NDEBUG |
| 1184 void PaintArtifactCompositor::showDebugData() { |
| 1185 LOG(ERROR) << layersAsJSON(LayerTreeIncludesDebugInfo) |
| 1186 ->toPrettyJSONString() |
| 1187 .utf8() |
| 1188 .data(); |
| 1189 } |
| 1190 #endif |
| 1191 |
| 867 } // namespace blink | 1192 } // namespace blink |
| OLD | NEW |