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 "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, succe ss); | |
| 303 | |
| 304 DCHECK(success); | |
| 305 | |
| 306 ccList.CreateAndAppendPairedBeginItem<cc::FloatClipDisplayItem>( | |
| 307 gfx::RectF(combinedClip)); | |
| 308 endDisplayItems.push_back(EndClip); | |
| 309 } | |
| 310 | |
| 311 static void recordPairedBeginDisplayItems( | |
| 312 const Vector<PropertyTreeState>& pairedStates, | |
| 313 const PropertyTreeState& pendingLayerState, | |
| 314 cc::DisplayItemList& ccList, | |
| 315 Vector<EndDisplayItemType>& endDisplayItems, | |
| 316 GeometryMapper& geometryMapper) { | |
| 317 PropertyTreeState mappedClipDestinationSpace = pendingLayerState; | |
| 318 PropertyTreeState clipSpace = pendingLayerState; | |
| 319 bool hasClip = false; | |
| 320 | |
| 321 for (Vector<PropertyTreeState>::const_reverse_iterator pairedState = | |
| 322 pairedStates.rbegin(); | |
| 323 pairedState != pairedStates.rend(); ++pairedState) { | |
| 324 switch (pairedState->innermostNode()) { | |
| 325 case PropertyTreeState::Transform: { | |
| 326 if (hasClip) { | |
| 327 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, | |
| 328 endDisplayItems, geometryMapper); | |
| 329 hasClip = false; | |
|
chrishtr
2016/12/24 00:19:18
In an earlier patch set, I neglected to reset this
| |
| 330 } | |
| 331 mappedClipDestinationSpace = *pairedState; | |
| 332 clipSpace = *pairedState; | |
| 333 | |
| 334 TransformationMatrix matrix = pairedState->transform()->matrix(); | |
| 335 matrix.applyTransformOrigin(pairedState->transform()->origin()); | |
|
chrishtr
2016/12/24 00:19:18
In an earlier patchset I neglected to apply the tr
| |
| 336 | |
| 337 gfx::Transform transform(gfx::Transform::kSkipInitialization); | |
| 338 transform.matrix() = TransformationMatrix::toSkMatrix44( | |
| 339 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 ccList.CreateAndAppendPairedBeginItem<cc::FilterDisplayItem>( | |
| 391 pairedState->effect()->filter().asCcFilterOperations(), | |
| 392 pairedState->effect()->outputClip()->clipRect().rect(), | |
| 393 gfx::PointF(filterOrigin.x(), filterOrigin.y())); | |
| 394 const bool kLcdTextRequiresOpaqueLayer = true; | |
| 395 ccList.CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>( | |
| 396 static_cast<uint8_t>( | |
| 397 gfx::ToFlooredInt(255 * pairedState->effect()->opacity())), | |
| 398 pairedState->effect()->blendMode(), | |
| 399 // TODO(chrishtr): compute bounds as necessary. | |
| 400 nullptr, nullptr, kLcdTextRequiresOpaqueLayer); | |
| 401 endDisplayItems.push_back(EndEffect); | |
| 402 break; | |
| 403 } | |
| 404 case PropertyTreeState::None: | |
| 405 break; | |
| 406 } | |
| 407 } | |
| 408 | |
| 409 if (hasClip) { | |
| 410 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, endDi splayItems, | |
| 411 geometryMapper); | |
| 412 } | |
| 413 } | |
| 414 | |
| 415 static void recordPairedEndDisplayItems( | |
| 416 const Vector<EndDisplayItemType>& endDisplayItemTypes, | |
| 417 cc::DisplayItemList* ccList) { | |
| 418 for (Vector<EndDisplayItemType>::const_reverse_iterator endType = | |
| 419 endDisplayItemTypes.rbegin(); | |
| 420 endType != endDisplayItemTypes.rend(); ++endType) { | |
| 421 switch (*endType) { | |
| 422 case EndTransform: | |
| 423 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 424 break; | |
| 425 case EndClip: | |
| 426 ccList->CreateAndAppendPairedEndItem<cc::EndFloatClipDisplayItem>(); | |
| 427 break; | |
| 428 case EndEffect: | |
| 429 ccList->CreateAndAppendPairedEndItem<cc::EndCompositingDisplayItem>(); | |
| 430 ccList->CreateAndAppendPairedEndItem<cc::EndFilterDisplayItem>(); | |
| 431 break; | |
| 432 } | |
| 433 } | |
| 434 } | |
| 435 | |
| 293 } // namespace | 436 } // namespace |
| 294 | 437 |
| 438 scoped_refptr<cc::DisplayItemList> PaintArtifactCompositor::recordPendingLayer( | |
| 439 const PaintArtifact& artifact, | |
| 440 const PendingLayer& pendingLayer, | |
| 441 const gfx::Rect& combinedBounds, | |
| 442 GeometryMapper& geometryMapper) { | |
| 443 cc::DisplayItemListSettings settings; | |
| 444 scoped_refptr<cc::DisplayItemList> ccList = | |
| 445 cc::DisplayItemList::Create(settings); | |
| 446 | |
| 447 gfx::Transform translation; | |
| 448 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | |
| 449 // Passing combinedBounds as the visual rect for the begin/end transform item | |
| 450 // would normally be the sensible thing to do, but see comment above re: | |
| 451 // visual rects for drawing items and further rework in flight. | |
| 452 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | |
| 453 | |
| 454 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | |
| 455 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 456 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; | |
| 457 PropertyTreeStateIterator iterator(*state); | |
| 458 Vector<PropertyTreeState> pairedStates; | |
| 459 for (; state && *state != pendingLayer.propertyTreeState; | |
| 460 state = iterator.next()) { | |
| 461 if (state->innermostNode() != PropertyTreeState::None) | |
| 462 pairedStates.push_back(*state); | |
| 463 } | |
| 464 | |
| 465 // TODO(chrishtr): we can avoid some extra paired display items if | |
| 466 // multiple PaintChunks share them. We can also collapse clips between | |
| 467 // transforms into single clips in the same way that PaintLayerClipper does. | |
| 468 Vector<EndDisplayItemType> endDisplayItems; | |
| 469 | |
| 470 recordPairedBeginDisplayItems(pairedStates, pendingLayer.propertyTreeState, | |
| 471 *ccList.get(), endDisplayItems, | |
| 472 geometryMapper); | |
| 473 | |
| 474 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) | |
| 475 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); | |
| 476 | |
| 477 recordPairedEndDisplayItems(endDisplayItems, ccList.get()); | |
| 478 } | |
| 479 | |
| 480 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 481 | |
| 482 ccList->Finalize(); | |
| 483 return ccList; | |
| 484 } | |
| 485 | |
| 295 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> | 486 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> |
| 296 PaintArtifactCompositor::clientForPaintChunk( | 487 PaintArtifactCompositor::clientForPaintChunk( |
| 297 const PaintChunk& paintChunk, | 488 const PaintChunk& paintChunk, |
| 298 const PaintArtifact& paintArtifact) { | 489 const PaintArtifact& paintArtifact) { |
| 299 // TODO(chrishtr): for now, just using a linear walk. In the future we can | 490 // 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 | 491 // optimize this by using the same techniques used in PaintController for |
| 301 // display lists. | 492 // display lists. |
| 302 for (auto& client : m_contentLayerClients) { | 493 for (auto& client : m_contentLayerClients) { |
| 303 if (client && client->matches(paintChunk)) | 494 if (client && client->matches(paintChunk)) |
| 304 return std::move(client); | 495 return std::move(client); |
| 305 } | 496 } |
| 306 | 497 |
| 307 return WTF::wrapUnique(new ContentLayerClientImpl( | 498 return WTF::wrapUnique(new ContentLayerClientImpl( |
| 308 paintChunk.id | 499 paintChunk.id |
| 309 ? *paintChunk.id | 500 ? *paintChunk.id |
| 310 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 501 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 311 } | 502 } |
| 312 | 503 |
| 313 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 504 scoped_refptr<cc::Layer> |
| 505 PaintArtifactCompositor::compositedLayerForPendingLayer( | |
| 314 const PaintArtifact& paintArtifact, | 506 const PaintArtifact& paintArtifact, |
| 315 const PaintChunk& paintChunk, | 507 const PendingLayer& pendingLayer, |
| 316 gfx::Vector2dF& layerOffset, | 508 gfx::Vector2dF& layerOffset, |
| 317 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 509 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 318 RasterInvalidationTracking* tracking, | 510 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap, |
| 319 bool storeDebugInfo) { | 511 bool storeDebugInfo, |
| 320 DCHECK(paintChunk.size()); | 512 GeometryMapper& geometryMapper) { |
| 513 DCHECK(pendingLayer.paintChunks.size()); | |
| 514 const PaintChunk& firstPaintChunk = *pendingLayer.paintChunks[0]; | |
| 515 DCHECK(firstPaintChunk.size()); | |
| 516 #if DCHECK_IS_ON | |
| 517 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 518 DCHECK(paintChunk.properties == firstPaintChunk.properties); | |
| 519 } | |
| 520 #endif | |
| 321 | 521 |
| 322 // If the paint chunk is a foreign layer, just return that layer. | 522 // If the paint chunk is a foreign layer, just return that layer. |
| 323 if (scoped_refptr<cc::Layer> foreignLayer = | 523 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk( |
| 324 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 524 paintArtifact, firstPaintChunk, layerOffset)) { |
| 525 DCHECK(pendingLayer.paintChunks.size() == 1); | |
| 325 return foreignLayer; | 526 return foreignLayer; |
| 527 } | |
| 326 | 528 |
| 327 // The common case: create or reuse a PictureLayer for painted content. | 529 // The common case: create or reuse a PictureLayer for painted content. |
| 328 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 530 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 329 clientForPaintChunk(paintChunk, paintArtifact); | 531 clientForPaintChunk(firstPaintChunk, paintArtifact); |
| 330 | 532 |
| 331 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 533 gfx::Rect ccCombinedBounds(enclosingIntRect(pendingLayer.bounds)); |
| 332 scoped_refptr<cc::DisplayItemList> displayList = | 534 |
| 333 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 535 scoped_refptr<cc::DisplayItemList> displayList = recordPendingLayer( |
| 536 paintArtifact, pendingLayer, ccCombinedBounds, geometryMapper); | |
| 334 contentLayerClient->SetDisplayList(std::move(displayList)); | 537 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 335 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 538 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size())); |
| 336 | 539 |
| 337 layerOffset = combinedBounds.OffsetFromOrigin(); | 540 layerOffset = ccCombinedBounds.OffsetFromOrigin(); |
| 541 | |
| 338 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 542 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 339 contentLayerClient->ccPictureLayer(); | 543 contentLayerClient->ccPictureLayer(); |
| 340 ccPictureLayer->SetBounds(combinedBounds.size()); | 544 ccPictureLayer->SetBounds(ccCombinedBounds.size()); |
| 341 ccPictureLayer->SetIsDrawable(true); | 545 ccPictureLayer->SetIsDrawable(true); |
| 342 if (paintChunk.knownToBeOpaque) | 546 ccPictureLayer->SetContentsOpaque(pendingLayer.knownToBeOpaque); |
| 343 ccPictureLayer->SetContentsOpaque(true); | 547 contentLayerClient->clearPaintChunkDebugData(); |
| 344 DCHECK(!tracking || | |
| 345 tracking->trackedRasterInvalidations.size() == | |
| 346 paintChunk.rasterInvalidationRects.size()); | |
| 347 | 548 |
| 348 contentLayerClient->clearPaintChunkDebugData(); | 549 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 349 if (storeDebugInfo) { | 550 RasterInvalidationTracking* rasterTracking = |
| 350 contentLayerClient->addPaintChunkDebugData( | 551 trackingMap ? trackingMap->find(paintChunk) : nullptr; |
| 351 paintArtifact.getDisplayItemList().subsequenceAsJSON( | 552 DCHECK(!rasterTracking || |
| 352 paintChunk.beginIndex, paintChunk.endIndex, | 553 rasterTracking->trackedRasterInvalidations.size() == |
| 353 DisplayItemList::SkipNonDrawings | | 554 paintChunk->rasterInvalidationRects.size()); |
| 354 DisplayItemList::ShownOnlyDisplayItemTypes)); | |
| 355 } | |
| 356 | 555 |
| 357 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 556 if (storeDebugInfo) { |
| 358 ++index) { | 557 contentLayerClient->addPaintChunkDebugData( |
| 359 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 558 paintArtifact.getDisplayItemList().subsequenceAsJSON( |
| 360 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 559 paintChunk->beginIndex, paintChunk->endIndex, |
| 361 std::max(0, rect.height())); | 560 DisplayItemList::SkipNonDrawings | |
| 362 // Raster paintChunk.rasterInvalidationRects is in the space of the | 561 DisplayItemList::ShownOnlyDisplayItemTypes)); |
| 363 // containing transform node, so need to subtract off the layer offset. | 562 } |
| 364 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 563 |
| 365 contentLayerClient->setNeedsDisplayRect( | 564 for (unsigned index = 0; index < paintChunk->rasterInvalidationRects.size(); |
| 366 ccInvalidationRect, | 565 ++index) { |
| 367 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); | 566 IntRect rect( |
| 567 enclosingIntRect(paintChunk->rasterInvalidationRects[index])); | |
| 568 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), | |
| 569 std::max(0, rect.width()), | |
| 570 std::max(0, rect.height())); | |
| 571 if (ccInvalidationRect.IsEmpty()) | |
| 572 continue; | |
| 573 // Raster paintChunk.rasterInvalidationRects is in the space of the | |
| 574 // containing transform node, so need to subtract off the layer offset. | |
| 575 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin()); | |
| 576 contentLayerClient->setNeedsDisplayRect( | |
| 577 ccInvalidationRect, | |
| 578 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index] | |
| 579 : nullptr); | |
| 580 } | |
| 368 } | 581 } |
| 369 | 582 |
| 370 newContentLayerClients.append(std::move(contentLayerClient)); | 583 newContentLayerClients.append(std::move(contentLayerClient)); |
| 371 return ccPictureLayer; | 584 return ccPictureLayer; |
| 372 } | 585 } |
| 373 | 586 |
| 374 namespace { | 587 namespace { |
| 375 | 588 |
| 376 class PropertyTreeManager { | 589 class PropertyTreeManager { |
| 377 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); | 590 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 scrollTree().set_needs_update(true); | 883 scrollTree().set_needs_update(true); |
| 671 } | 884 } |
| 672 | 885 |
| 673 unsigned depth(const EffectPaintPropertyNode* node) { | 886 unsigned depth(const EffectPaintPropertyNode* node) { |
| 674 unsigned result = 0; | 887 unsigned result = 0; |
| 675 for (; node; node = node->parent()) | 888 for (; node; node = node->parent()) |
| 676 result++; | 889 result++; |
| 677 return result; | 890 return result; |
| 678 } | 891 } |
| 679 | 892 |
| 893 // TODO(chrishtr): templatize this to avoid duplication of | |
| 894 // GeometryMapper::leastCommonAncestor. | |
| 680 const EffectPaintPropertyNode* lowestCommonAncestor( | 895 const EffectPaintPropertyNode* lowestCommonAncestor( |
| 681 const EffectPaintPropertyNode* nodeA, | 896 const EffectPaintPropertyNode* nodeA, |
| 682 const EffectPaintPropertyNode* nodeB) { | 897 const EffectPaintPropertyNode* nodeB) { |
| 683 // Optimized common case. | 898 // Optimized common case. |
| 684 if (nodeA == nodeB) | 899 if (nodeA == nodeB) |
| 685 return nodeA; | 900 return nodeA; |
| 686 | 901 |
| 687 unsigned depthA = depth(nodeA), depthB = depth(nodeB); | 902 unsigned depthA = depth(nodeA), depthB = depth(nodeB); |
| 688 while (depthA > depthB) { | 903 while (depthA > depthB) { |
| 689 nodeA = nodeA->parent(); | 904 nodeA = nodeA->parent(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 | 999 |
| 785 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1000 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 786 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 1001 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 787 dummyLayer->SetClipTreeIndex(outputClipId); | 1002 dummyLayer->SetClipTreeIndex(outputClipId); |
| 788 dummyLayer->SetEffectTreeIndex(effectNode.id); | 1003 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 789 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 1004 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 790 } | 1005 } |
| 791 | 1006 |
| 792 } // namespace | 1007 } // namespace |
| 793 | 1008 |
| 1009 bool PaintArtifactCompositor::canMergeInto( | |
| 1010 const PaintArtifact& paintArtifact, | |
| 1011 const PaintChunk& newChunk, | |
| 1012 const PendingLayer& candidatePendingLayer) { | |
| 1013 if (paintArtifact.getDisplayItemList()[newChunk.beginIndex].isForeignLayer()) | |
| 1014 return false; | |
| 1015 | |
| 1016 if (paintArtifact.getDisplayItemList()[candidatePendingLayer.paintChunks[0]->b eginIndex].isForeignLayer()) | |
| 1017 return false; | |
| 1018 | |
| 1019 DCHECK(candidatePendingLayer.paintChunks.size() >= 1); | |
| 1020 PropertyTreeStateIterator iterator(newChunk.properties.propertyTreeState); | |
| 1021 for (const PropertyTreeState* currentState = | |
| 1022 &newChunk.properties.propertyTreeState; | |
| 1023 currentState; currentState = iterator.next()) { | |
| 1024 if (currentState->hasDirectCompositingReasons()) | |
| 1025 return false; | |
| 1026 if (*currentState == candidatePendingLayer.propertyTreeState) | |
| 1027 return true; | |
| 1028 } | |
| 1029 return false; | |
| 1030 } | |
| 1031 | |
| 1032 bool PaintArtifactCompositor::mightOverlap( | |
| 1033 const PaintChunk& paintChunk, | |
| 1034 const PendingLayer& candidatePendingLayer, | |
| 1035 GeometryMapper& geometryMapper) { | |
| 1036 // TODO(chrishtr): implement | |
| 1037 return true; | |
| 1038 } | |
| 1039 | |
| 1040 PaintArtifactCompositor::PendingLayer::PendingLayer( | |
| 1041 const PaintChunk& firstPaintChunk) | |
| 1042 : bounds(firstPaintChunk.bounds), | |
| 1043 knownToBeOpaque(firstPaintChunk.knownToBeOpaque), | |
|
chrishtr
2016/12/24 00:19:18
In an earlier patchset I got the business logic wr
| |
| 1044 backfaceHidden(firstPaintChunk.properties.backfaceHidden), | |
| 1045 propertyTreeState(firstPaintChunk.properties.propertyTreeState) { | |
| 1046 paintChunks.append(&firstPaintChunk); | |
| 1047 } | |
| 1048 | |
| 1049 void PaintArtifactCompositor::PendingLayer::add(const PaintChunk& paintChunk, | |
| 1050 GeometryMapper* geometryMapper) { | |
| 1051 DCHECK(paintChunk.properties.backfaceHidden == backfaceHidden); | |
| 1052 paintChunks.append(&paintChunk); | |
| 1053 FloatRect mappedBounds = paintChunk.bounds; | |
| 1054 if (geometryMapper) { | |
| 1055 bool success = false; | |
| 1056 mappedBounds = geometryMapper->localToAncestorRect( | |
| 1057 mappedBounds, | |
| 1058 paintChunk.properties.propertyTreeState, | |
| 1059 propertyTreeState, success); | |
| 1060 DCHECK(success); | |
| 1061 } | |
| 1062 bounds.unite(mappedBounds); | |
| 1063 if (bounds.size() != paintChunks[0]->bounds.size()) { | |
| 1064 if (bounds.size() != paintChunk.bounds.size()) | |
| 1065 knownToBeOpaque = false; | |
| 1066 else | |
| 1067 knownToBeOpaque = paintChunk.knownToBeOpaque; | |
| 1068 } | |
| 1069 } | |
| 1070 | |
| 1071 void PaintArtifactCompositor::collectPendingLayers( | |
| 1072 const PaintArtifact& paintArtifact, | |
| 1073 Vector<PendingLayer>& pendingLayers, | |
| 1074 GeometryMapper& geometryMapper) { | |
| 1075 // n = # of paint chunks. Memoizing canMergeInto() can get it to O(n^2), and | |
| 1076 // other heuristics can make worst-case behavior better. | |
| 1077 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | |
| 1078 bool createNew = true; | |
| 1079 for (Vector<PendingLayer>::reverse_iterator candidatePendingLayer = | |
| 1080 pendingLayers.rbegin(); | |
| 1081 candidatePendingLayer != pendingLayers.rend(); | |
| 1082 ++candidatePendingLayer) { | |
| 1083 if (canMergeInto(paintArtifact, paintChunk, *candidatePendingLayer)) { | |
| 1084 candidatePendingLayer->add(paintChunk, &geometryMapper); | |
| 1085 createNew = false; | |
| 1086 break; | |
| 1087 } | |
| 1088 if (mightOverlap(paintChunk, *candidatePendingLayer, geometryMapper)) { | |
| 1089 break; | |
| 1090 } | |
| 1091 } | |
| 1092 if (createNew) | |
| 1093 pendingLayers.append(PendingLayer(paintChunk)); | |
| 1094 } | |
| 1095 } | |
| 1096 | |
| 794 void PaintArtifactCompositor::update( | 1097 void PaintArtifactCompositor::update( |
| 795 const PaintArtifact& paintArtifact, | 1098 const PaintArtifact& paintArtifact, |
| 796 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, | 1099 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, |
| 797 bool storeDebugInfo) { | 1100 bool storeDebugInfo) { |
| 798 DCHECK(m_rootLayer); | 1101 DCHECK(m_rootLayer); |
| 799 | 1102 |
| 800 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); | 1103 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); |
| 801 | 1104 |
| 802 // The tree will be null after detaching and this update can be ignored. | 1105 // The tree will be null after detaching and this update can be ignored. |
| 803 // See: WebViewImpl::detachPaintArtifactCompositor(). | 1106 // See: WebViewImpl::detachPaintArtifactCompositor(). |
| 804 if (!layerTree) | 1107 if (!layerTree) |
| 805 return; | 1108 return; |
| 806 | 1109 |
| 807 if (m_extraDataForTestingEnabled) | 1110 if (m_extraDataForTestingEnabled) |
| 808 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); | 1111 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); |
| 809 | 1112 |
| 810 m_rootLayer->RemoveAllChildren(); | 1113 m_rootLayer->RemoveAllChildren(); |
| 811 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1114 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 812 | 1115 |
| 813 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), | 1116 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), |
| 814 m_rootLayer.get()); | 1117 m_rootLayer.get()); |
| 815 | 1118 |
| 1119 Vector<PendingLayer, 0> pendingLayers; | |
| 1120 GeometryMapper geometryMapper; | |
| 1121 collectPendingLayers(paintArtifact, pendingLayers, | |
| 1122 geometryMapper); | |
| 1123 | |
| 816 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; | 1124 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; |
| 817 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 1125 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 818 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 1126 for (const PendingLayer& pendingLayer : pendingLayers) { |
| 819 gfx::Vector2dF layerOffset; | 1127 gfx::Vector2dF layerOffset; |
| 820 scoped_refptr<cc::Layer> layer = layerForPaintChunk( | 1128 scoped_refptr<cc::Layer> layer = compositedLayerForPendingLayer( |
| 821 paintArtifact, paintChunk, layerOffset, newContentLayerClients, | 1129 paintArtifact, pendingLayer, layerOffset, newContentLayerClients, |
| 822 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) | 1130 rasterChunkInvalidations, storeDebugInfo, geometryMapper); |
| 823 : nullptr, | |
| 824 storeDebugInfo); | |
| 825 | 1131 |
| 826 int transformId = propertyTreeManager.compositorIdForTransformNode( | 1132 int transformId = propertyTreeManager.compositorIdForTransformNode( |
| 827 paintChunk.properties.propertyTreeState.transform()); | 1133 pendingLayer.propertyTreeState.transform()); |
| 828 int scrollId = propertyTreeManager.compositorIdForScrollNode( | 1134 int scrollId = propertyTreeManager.compositorIdForScrollNode( |
| 829 paintChunk.properties.propertyTreeState.scroll()); | 1135 pendingLayer.propertyTreeState.scroll()); |
| 830 int clipId = propertyTreeManager.compositorIdForClipNode( | 1136 int clipId = propertyTreeManager.compositorIdForClipNode( |
| 831 paintChunk.properties.propertyTreeState.clip()); | 1137 pendingLayer.propertyTreeState.clip()); |
| 832 int effectId = propertyTreeManager.switchToEffectNode( | 1138 int effectId = propertyTreeManager.switchToEffectNode( |
| 833 *paintChunk.properties.propertyTreeState.effect()); | 1139 *pendingLayer.propertyTreeState.effect()); |
| 834 | 1140 |
| 835 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); | 1141 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 836 | 1142 |
| 837 layer->set_offset_to_transform_parent(layerOffset); | 1143 layer->set_offset_to_transform_parent(layerOffset); |
| 838 | 1144 |
| 839 m_rootLayer->AddChild(layer); | 1145 m_rootLayer->AddChild(layer); |
| 840 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1146 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 841 layer->SetTransformTreeIndex(transformId); | 1147 layer->SetTransformTreeIndex(transformId); |
| 842 layer->SetClipTreeIndex(clipId); | 1148 layer->SetClipTreeIndex(clipId); |
| 843 layer->SetEffectTreeIndex(effectId); | 1149 layer->SetEffectTreeIndex(effectId); |
| 844 layer->SetScrollTreeIndex(scrollId); | 1150 layer->SetScrollTreeIndex(scrollId); |
| 845 | 1151 |
| 846 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 1152 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 847 // queried by RenderSurfaceImpl. | 1153 // queried by RenderSurfaceImpl. |
| 848 layer->Set3dSortingContextId(layerTree->property_trees() | 1154 layer->Set3dSortingContextId(layerTree->property_trees() |
| 849 ->transform_tree.Node(transformId) | 1155 ->transform_tree.Node(transformId) |
| 850 ->sorting_context_id); | 1156 ->sorting_context_id); |
| 851 | 1157 |
| 852 layer->SetShouldCheckBackfaceVisibility( | 1158 layer->SetShouldCheckBackfaceVisibility(pendingLayer.backfaceHidden); |
| 853 paintChunk.properties.backfaceHidden); | |
| 854 | 1159 |
| 855 if (m_extraDataForTestingEnabled) | 1160 if (m_extraDataForTestingEnabled) |
| 856 m_extraDataForTesting->contentLayers.append(layer); | 1161 m_extraDataForTesting->contentLayers.append(layer); |
| 857 } | 1162 } |
| 858 m_contentLayerClients.clear(); | 1163 m_contentLayerClients.clear(); |
| 859 m_contentLayerClients.swap(newContentLayerClients); | 1164 m_contentLayerClients.swap(newContentLayerClients); |
| 860 | 1165 |
| 861 // Mark the property trees as having been rebuilt. | 1166 // Mark the property trees as having been rebuilt. |
| 862 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 1167 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 863 layerTree->property_trees()->needs_rebuild = false; | 1168 layerTree->property_trees()->needs_rebuild = false; |
| 864 layerTree->property_trees()->ResetCachedData(); | 1169 layerTree->property_trees()->ResetCachedData(); |
| 865 } | 1170 } |
| 866 | 1171 |
| 867 } // namespace blink | 1172 } // namespace blink |
| OLD | NEW |