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, | |
| 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>( | |
|
chrishtr
2016/12/24 20:56:59
Switched these in order. Old one was wrong.
| |
| 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(), | |
| 400 clipRect, | |
| 401 gfx::PointF(filterOrigin.x(), filterOrigin.y())); | |
| 402 | |
| 403 endDisplayItems.push_back(EndEffect); | |
| 404 break; | |
| 405 } | |
| 406 case PropertyTreeState::None: | |
| 407 break; | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 if (hasClip) { | |
| 412 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, | |
| 413 endDisplayItems, geometryMapper); | |
| 414 } | |
| 415 } | |
| 416 | |
| 417 static void recordPairedEndDisplayItems( | |
| 418 const Vector<EndDisplayItemType>& endDisplayItemTypes, | |
| 419 cc::DisplayItemList* ccList) { | |
| 420 for (Vector<EndDisplayItemType>::const_reverse_iterator endType = | |
| 421 endDisplayItemTypes.rbegin(); | |
| 422 endType != endDisplayItemTypes.rend(); ++endType) { | |
| 423 switch (*endType) { | |
| 424 case EndTransform: | |
| 425 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 426 break; | |
| 427 case EndClip: | |
| 428 ccList->CreateAndAppendPairedEndItem<cc::EndFloatClipDisplayItem>(); | |
| 429 break; | |
| 430 case EndEffect: | |
| 431 ccList->CreateAndAppendPairedEndItem<cc::EndFilterDisplayItem>(); | |
| 432 ccList->CreateAndAppendPairedEndItem<cc::EndCompositingDisplayItem>(); | |
| 433 break; | |
| 434 } | |
| 435 } | |
| 436 } | |
| 437 | |
| 293 } // namespace | 438 } // namespace |
| 294 | 439 |
| 440 scoped_refptr<cc::DisplayItemList> PaintArtifactCompositor::recordPendingLayer( | |
| 441 const PaintArtifact& artifact, | |
| 442 const PendingLayer& pendingLayer, | |
| 443 const gfx::Rect& combinedBounds, | |
| 444 GeometryMapper& geometryMapper) { | |
| 445 cc::DisplayItemListSettings settings; | |
| 446 scoped_refptr<cc::DisplayItemList> ccList = | |
| 447 cc::DisplayItemList::Create(settings); | |
| 448 | |
| 449 gfx::Transform translation; | |
| 450 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | |
| 451 // Passing combinedBounds as the visual rect for the begin/end transform item | |
| 452 // would normally be the sensible thing to do, but see comment above re: | |
| 453 // visual rects for drawing items and further rework in flight. | |
| 454 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | |
| 455 | |
| 456 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | |
| 457 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 458 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; | |
| 459 PropertyTreeStateIterator iterator(*state); | |
| 460 Vector<PropertyTreeState> pairedStates; | |
| 461 for (; state && *state != pendingLayer.propertyTreeState; | |
| 462 state = iterator.next()) { | |
| 463 if (state->innermostNode() != PropertyTreeState::None) | |
| 464 pairedStates.push_back(*state); | |
| 465 } | |
| 466 | |
| 467 // TODO(chrishtr): we can avoid some extra paired display items if | |
| 468 // multiple PaintChunks share them. We can also collapse clips between | |
| 469 // transforms into single clips in the same way that PaintLayerClipper does. | |
| 470 Vector<EndDisplayItemType> endDisplayItems; | |
| 471 | |
| 472 recordPairedBeginDisplayItems(pairedStates, pendingLayer.propertyTreeState, | |
| 473 *ccList.get(), endDisplayItems, | |
| 474 geometryMapper); | |
| 475 | |
| 476 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) | |
| 477 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); | |
| 478 | |
| 479 recordPairedEndDisplayItems(endDisplayItems, ccList.get()); | |
| 480 } | |
| 481 | |
| 482 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 483 | |
| 484 ccList->Finalize(); | |
| 485 return ccList; | |
| 486 } | |
| 487 | |
| 295 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> | 488 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> |
| 296 PaintArtifactCompositor::clientForPaintChunk( | 489 PaintArtifactCompositor::clientForPaintChunk( |
| 297 const PaintChunk& paintChunk, | 490 const PaintChunk& paintChunk, |
| 298 const PaintArtifact& paintArtifact) { | 491 const PaintArtifact& paintArtifact) { |
| 299 // TODO(chrishtr): for now, just using a linear walk. In the future we can | 492 // 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 | 493 // optimize this by using the same techniques used in PaintController for |
| 301 // display lists. | 494 // display lists. |
| 302 for (auto& client : m_contentLayerClients) { | 495 for (auto& client : m_contentLayerClients) { |
| 303 if (client && client->matches(paintChunk)) | 496 if (client && client->matches(paintChunk)) |
| 304 return std::move(client); | 497 return std::move(client); |
| 305 } | 498 } |
| 306 | 499 |
| 307 return WTF::wrapUnique(new ContentLayerClientImpl( | 500 return WTF::wrapUnique(new ContentLayerClientImpl( |
| 308 paintChunk.id | 501 paintChunk.id |
| 309 ? *paintChunk.id | 502 ? *paintChunk.id |
| 310 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 503 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 311 } | 504 } |
| 312 | 505 |
| 313 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 506 scoped_refptr<cc::Layer> |
| 507 PaintArtifactCompositor::compositedLayerForPendingLayer( | |
| 314 const PaintArtifact& paintArtifact, | 508 const PaintArtifact& paintArtifact, |
| 315 const PaintChunk& paintChunk, | 509 const PendingLayer& pendingLayer, |
| 316 gfx::Vector2dF& layerOffset, | 510 gfx::Vector2dF& layerOffset, |
| 317 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 511 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 318 RasterInvalidationTracking* tracking, | 512 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap, |
| 319 bool storeDebugInfo) { | 513 bool storeDebugInfo, |
| 320 DCHECK(paintChunk.size()); | 514 GeometryMapper& geometryMapper) { |
| 515 DCHECK(pendingLayer.paintChunks.size()); | |
| 516 const PaintChunk& firstPaintChunk = *pendingLayer.paintChunks[0]; | |
| 517 DCHECK(firstPaintChunk.size()); | |
| 518 #if DCHECK_IS_ON | |
| 519 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 520 DCHECK(paintChunk.properties == firstPaintChunk.properties); | |
| 521 } | |
| 522 #endif | |
| 321 | 523 |
| 322 // If the paint chunk is a foreign layer, just return that layer. | 524 // If the paint chunk is a foreign layer, just return that layer. |
| 323 if (scoped_refptr<cc::Layer> foreignLayer = | 525 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk( |
| 324 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 526 paintArtifact, firstPaintChunk, layerOffset)) { |
| 527 DCHECK(pendingLayer.paintChunks.size() == 1); | |
| 325 return foreignLayer; | 528 return foreignLayer; |
| 529 } | |
| 326 | 530 |
| 327 // The common case: create or reuse a PictureLayer for painted content. | 531 // The common case: create or reuse a PictureLayer for painted content. |
| 328 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 532 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 329 clientForPaintChunk(paintChunk, paintArtifact); | 533 clientForPaintChunk(firstPaintChunk, paintArtifact); |
| 330 | 534 |
| 331 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 535 gfx::Rect ccCombinedBounds(enclosingIntRect(pendingLayer.bounds)); |
| 332 scoped_refptr<cc::DisplayItemList> displayList = | 536 |
| 333 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 537 scoped_refptr<cc::DisplayItemList> displayList = recordPendingLayer( |
| 538 paintArtifact, pendingLayer, ccCombinedBounds, geometryMapper); | |
| 334 contentLayerClient->SetDisplayList(std::move(displayList)); | 539 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 335 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 540 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size())); |
| 336 | 541 |
| 337 layerOffset = combinedBounds.OffsetFromOrigin(); | 542 layerOffset = ccCombinedBounds.OffsetFromOrigin(); |
| 543 | |
| 338 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 544 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 339 contentLayerClient->ccPictureLayer(); | 545 contentLayerClient->ccPictureLayer(); |
| 340 ccPictureLayer->SetBounds(combinedBounds.size()); | 546 ccPictureLayer->SetBounds(ccCombinedBounds.size()); |
| 341 ccPictureLayer->SetIsDrawable(true); | 547 ccPictureLayer->SetIsDrawable(true); |
| 342 if (paintChunk.knownToBeOpaque) | 548 ccPictureLayer->SetContentsOpaque(pendingLayer.knownToBeOpaque); |
| 343 ccPictureLayer->SetContentsOpaque(true); | 549 contentLayerClient->clearPaintChunkDebugData(); |
| 344 DCHECK(!tracking || | |
| 345 tracking->trackedRasterInvalidations.size() == | |
| 346 paintChunk.rasterInvalidationRects.size()); | |
| 347 | 550 |
| 348 contentLayerClient->clearPaintChunkDebugData(); | 551 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 349 if (storeDebugInfo) { | 552 RasterInvalidationTracking* rasterTracking = |
| 350 contentLayerClient->addPaintChunkDebugData( | 553 trackingMap ? trackingMap->find(paintChunk) : nullptr; |
| 351 paintArtifact.getDisplayItemList().subsequenceAsJSON( | 554 DCHECK(!rasterTracking || |
| 352 paintChunk.beginIndex, paintChunk.endIndex, | 555 rasterTracking->trackedRasterInvalidations.size() == |
| 353 DisplayItemList::SkipNonDrawings | | 556 paintChunk->rasterInvalidationRects.size()); |
| 354 DisplayItemList::ShownOnlyDisplayItemTypes)); | |
| 355 } | |
| 356 | 557 |
| 357 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 558 if (storeDebugInfo) { |
| 358 ++index) { | 559 contentLayerClient->addPaintChunkDebugData( |
| 359 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 560 paintArtifact.getDisplayItemList().subsequenceAsJSON( |
| 360 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 561 paintChunk->beginIndex, paintChunk->endIndex, |
| 361 std::max(0, rect.height())); | 562 DisplayItemList::SkipNonDrawings | |
| 362 // Raster paintChunk.rasterInvalidationRects is in the space of the | 563 DisplayItemList::ShownOnlyDisplayItemTypes)); |
| 363 // containing transform node, so need to subtract off the layer offset. | 564 } |
| 364 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 565 |
| 365 contentLayerClient->setNeedsDisplayRect( | 566 for (unsigned index = 0; index < paintChunk->rasterInvalidationRects.size(); |
| 366 ccInvalidationRect, | 567 ++index) { |
| 367 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); | 568 IntRect rect( |
| 569 enclosingIntRect(paintChunk->rasterInvalidationRects[index])); | |
| 570 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), | |
| 571 std::max(0, rect.width()), | |
| 572 std::max(0, rect.height())); | |
| 573 if (ccInvalidationRect.IsEmpty()) | |
| 574 continue; | |
| 575 // Raster paintChunk.rasterInvalidationRects is in the space of the | |
| 576 // containing transform node, so need to subtract off the layer offset. | |
| 577 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin()); | |
| 578 contentLayerClient->setNeedsDisplayRect( | |
| 579 ccInvalidationRect, | |
| 580 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index] | |
| 581 : nullptr); | |
| 582 } | |
| 368 } | 583 } |
| 369 | 584 |
| 370 newContentLayerClients.append(std::move(contentLayerClient)); | 585 newContentLayerClients.append(std::move(contentLayerClient)); |
| 371 return ccPictureLayer; | 586 return ccPictureLayer; |
| 372 } | 587 } |
| 373 | 588 |
| 374 namespace { | 589 namespace { |
| 375 | 590 |
| 376 class PropertyTreeManager { | 591 class PropertyTreeManager { |
| 377 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); | 592 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 scrollTree().set_needs_update(true); | 885 scrollTree().set_needs_update(true); |
| 671 } | 886 } |
| 672 | 887 |
| 673 unsigned depth(const EffectPaintPropertyNode* node) { | 888 unsigned depth(const EffectPaintPropertyNode* node) { |
| 674 unsigned result = 0; | 889 unsigned result = 0; |
| 675 for (; node; node = node->parent()) | 890 for (; node; node = node->parent()) |
| 676 result++; | 891 result++; |
| 677 return result; | 892 return result; |
| 678 } | 893 } |
| 679 | 894 |
| 895 // TODO(chrishtr): templatize this to avoid duplication of | |
| 896 // GeometryMapper::leastCommonAncestor. | |
| 680 const EffectPaintPropertyNode* lowestCommonAncestor( | 897 const EffectPaintPropertyNode* lowestCommonAncestor( |
| 681 const EffectPaintPropertyNode* nodeA, | 898 const EffectPaintPropertyNode* nodeA, |
| 682 const EffectPaintPropertyNode* nodeB) { | 899 const EffectPaintPropertyNode* nodeB) { |
| 683 // Optimized common case. | 900 // Optimized common case. |
| 684 if (nodeA == nodeB) | 901 if (nodeA == nodeB) |
| 685 return nodeA; | 902 return nodeA; |
| 686 | 903 |
| 687 unsigned depthA = depth(nodeA), depthB = depth(nodeB); | 904 unsigned depthA = depth(nodeA), depthB = depth(nodeB); |
| 688 while (depthA > depthB) { | 905 while (depthA > depthB) { |
| 689 nodeA = nodeA->parent(); | 906 nodeA = nodeA->parent(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 | 1001 |
| 785 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 1002 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 786 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 1003 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 787 dummyLayer->SetClipTreeIndex(outputClipId); | 1004 dummyLayer->SetClipTreeIndex(outputClipId); |
| 788 dummyLayer->SetEffectTreeIndex(effectNode.id); | 1005 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 789 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 1006 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 790 } | 1007 } |
| 791 | 1008 |
| 792 } // namespace | 1009 } // namespace |
| 793 | 1010 |
| 1011 bool PaintArtifactCompositor::canMergeInto( | |
| 1012 const PaintArtifact& paintArtifact, | |
| 1013 const PaintChunk& newChunk, | |
| 1014 const PendingLayer& candidatePendingLayer) { | |
| 1015 const PaintChunk& pendingLayerFirstChunk = *candidatePendingLayer.paintChunks[ 0]; | |
| 1016 if (paintArtifact.getDisplayItemList()[newChunk.beginIndex].isForeignLayer()) | |
| 1017 return false; | |
| 1018 | |
| 1019 if (paintArtifact | |
| 1020 .getDisplayItemList()[pendingLayerFirstChunk.beginIndex] | |
| 1021 .isForeignLayer()) | |
| 1022 return false; | |
| 1023 | |
| 1024 if (newChunk.properties.backfaceHidden != pendingLayerFirstChunk.properties.ba ckfaceHidden) | |
|
chrishtr
2016/12/24 20:56:59
Added this code to not merge with backface visibil
| |
| 1025 return false; | |
| 1026 | |
| 1027 DCHECK(candidatePendingLayer.paintChunks.size() >= 1); | |
| 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 |