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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // gfx::Rect bounds = gfx::SkIRectToRect(picture->cullRect().roundOut()); | 220 // gfx::Rect bounds = gfx::SkIRectToRect(picture->cullRect().roundOut()); |
| 216 // or use the visual rect directly. However, clip content layers attempt | 221 // or use the visual rect directly. However, clip content layers attempt |
| 217 // to raster in a different space than that of the visual rects. We'll be | 222 // to raster in a different space than that of the visual rects. We'll be |
| 218 // reworking visual rects further for SPv2, so for now we just pass a | 223 // reworking visual rects further for SPv2, so for now we just pass a |
| 219 // visual rect large enough to make sure items raster. | 224 // visual rect large enough to make sure items raster. |
| 220 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( | 225 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( |
| 221 largeRect, sk_ref_sp(picture)); | 226 largeRect, sk_ref_sp(picture)); |
| 222 } | 227 } |
| 223 } | 228 } |
| 224 | 229 |
| 225 static scoped_refptr<cc::DisplayItemList> recordPaintChunk( | |
| 226 const PaintArtifact& artifact, | |
| 227 const PaintChunk& chunk, | |
| 228 const gfx::Rect& combinedBounds) { | |
| 229 cc::DisplayItemListSettings settings; | |
| 230 scoped_refptr<cc::DisplayItemList> list = | |
| 231 cc::DisplayItemList::Create(settings); | |
| 232 | |
| 233 gfx::Transform translation; | |
| 234 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | |
| 235 // Passing combinedBounds as the visual rect for the begin/end transform item | |
| 236 // would normally be the sensible thing to do, but see comment above re: | |
| 237 // visual rects for drawing items and further rework in flight. | |
| 238 list->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | |
| 239 | |
| 240 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | |
| 241 for (const auto& displayItem : displayItems.itemsInPaintChunk(chunk)) | |
| 242 appendDisplayItemToCcDisplayItemList(displayItem, list.get()); | |
| 243 | |
| 244 list->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 245 | |
| 246 list->Finalize(); | |
| 247 return list; | |
| 248 } | |
| 249 | |
| 250 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( | 230 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( |
| 251 const PaintArtifact& paintArtifact, | 231 const PaintArtifact& paintArtifact, |
| 252 const PaintChunk& paintChunk, | 232 const PaintChunk& paintChunk, |
| 253 gfx::Vector2dF& layerOffset) { | 233 gfx::Vector2dF& layerOffset) { |
| 254 if (paintChunk.size() != 1) | 234 if (paintChunk.size() != 1) |
| 255 return nullptr; | 235 return nullptr; |
| 256 | 236 |
| 257 const auto& displayItem = | 237 const auto& displayItem = |
| 258 paintArtifact.getDisplayItemList()[paintChunk.beginIndex]; | 238 paintArtifact.getDisplayItemList()[paintChunk.beginIndex]; |
| 259 if (!displayItem.isForeignLayer()) | 239 if (!displayItem.isForeignLayer()) |
| 260 return nullptr; | 240 return nullptr; |
| 261 | 241 |
| 262 const auto& foreignLayerDisplayItem = | 242 const auto& foreignLayerDisplayItem = |
| 263 static_cast<const ForeignLayerDisplayItem&>(displayItem); | 243 static_cast<const ForeignLayerDisplayItem&>(displayItem); |
| 264 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), | 244 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), |
| 265 foreignLayerDisplayItem.location().y()); | 245 foreignLayerDisplayItem.location().y()); |
| 266 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); | 246 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); |
| 267 layer->SetBounds(foreignLayerDisplayItem.bounds()); | 247 layer->SetBounds(foreignLayerDisplayItem.bounds()); |
| 268 layer->SetIsDrawable(true); | 248 layer->SetIsDrawable(true); |
| 269 return layer; | 249 return layer; |
| 270 } | 250 } |
| 271 | 251 |
| 272 constexpr int kInvalidNodeId = -1; | 252 constexpr int kInvalidNodeId = -1; |
| 273 // cc's property trees use 0 for the root node (always non-null). | 253 // cc's property trees use 0 for the root node (always non-null). |
| 274 constexpr int kRealRootNodeId = 0; | 254 constexpr int kRealRootNodeId = 0; |
| 275 // cc allocates special nodes for root effects such as the device scale. | 255 // cc allocates special nodes for root effects such as the device scale. |
| 276 constexpr int kSecondaryRootNodeId = 1; | 256 constexpr int kSecondaryRootNodeId = 1; |
| 277 constexpr int kPropertyTreeSequenceNumber = 1; | 257 constexpr int kPropertyTreeSequenceNumber = 1; |
| 278 | 258 |
| 259 static void recordPairedBeginDisplayItems( | |
|
pdr.
2016/12/20 22:50:58
Can you add a todo(chrishtr) comment about the gro
chrishtr
2016/12/20 23:48:31
Done. Added in recordPendingLayer.
| |
| 260 const Vector<PropertyTreeState>& pairedStates, | |
| 261 cc::DisplayItemList* ccList) { | |
| 262 for (Vector<PropertyTreeState>::const_reverse_iterator pairedState = | |
| 263 pairedStates.rbegin(); | |
| 264 pairedState != pairedStates.rend(); ++pairedState) { | |
| 265 switch (pairedState->innermostNode()) { | |
| 266 case PropertyTreeState::Transform: { | |
| 267 gfx::Transform transform(gfx::Transform::kSkipInitialization); | |
| 268 transform.matrix() = TransformationMatrix::toSkMatrix44( | |
| 269 pairedState->transform()->matrix()); | |
| 270 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>( | |
| 271 transform); | |
| 272 break; | |
| 273 } | |
| 274 case PropertyTreeState::Clip: { | |
| 275 const FloatRect& rect(pairedState->clip()->clipRect().rect()); | |
| 276 ccList->CreateAndAppendPairedBeginItem<cc::FloatClipDisplayItem>( | |
| 277 gfx::RectF(rect)); | |
| 278 break; | |
| 279 } | |
| 280 case PropertyTreeState::Effect: { | |
| 281 // TODO(chrishtr): skip effect and/or compositing display items if | |
| 282 // not necessary. | |
| 283 ccList->CreateAndAppendPairedBeginItem<cc::FilterDisplayItem>( | |
| 284 pairedState->effect()->filter().asCcFilterOperations(), | |
| 285 pairedState->effect()->outputClip()->clipRect().rect(), | |
| 286 // TODO(chrishtr): specify origin of the filter. | |
| 287 gfx::PointF()); | |
| 288 const bool kLcdTextRequiresOpaqueLayer = true; | |
| 289 ccList->CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>( | |
| 290 static_cast<uint8_t>( | |
| 291 gfx::ToFlooredInt(255 * pairedState->effect()->opacity())), | |
| 292 pairedState->effect()->blendMode(), | |
| 293 // TODO(chrishtr): compute bounds as necessary. | |
| 294 nullptr, nullptr, kLcdTextRequiresOpaqueLayer); | |
| 295 break; | |
| 296 } | |
| 297 case PropertyTreeState::None: | |
| 298 break; | |
| 299 } | |
| 300 } | |
| 301 } | |
| 302 | |
| 303 static void recordPairedEndDisplayItems( | |
| 304 const Vector<PropertyTreeState>& pairedStates, | |
| 305 cc::DisplayItemList* ccList) { | |
| 306 for (Vector<PropertyTreeState>::const_iterator pairedState = | |
| 307 pairedStates.begin(); | |
| 308 pairedState != pairedStates.end(); ++pairedState) { | |
| 309 switch (pairedState->innermostNode()) { | |
| 310 case PropertyTreeState::Transform: | |
| 311 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 312 break; | |
| 313 case PropertyTreeState::Clip: | |
| 314 ccList->CreateAndAppendPairedEndItem<cc::EndFloatClipDisplayItem>(); | |
| 315 break; | |
| 316 case PropertyTreeState::Effect: | |
| 317 ccList->CreateAndAppendPairedEndItem<cc::EndCompositingDisplayItem>(); | |
| 318 ccList->CreateAndAppendPairedEndItem<cc::EndFilterDisplayItem>(); | |
| 319 | |
|
wkorman
2016/12/20 00:28:56
extra line
chrishtr
2016/12/20 23:36:32
Fixed.
| |
| 320 break; | |
| 321 case PropertyTreeState::None: | |
| 322 break; | |
| 323 } | |
| 324 } | |
| 325 } | |
| 326 | |
| 279 } // namespace | 327 } // namespace |
| 280 | 328 |
| 329 scoped_refptr<cc::DisplayItemList> PaintArtifactCompositor::recordPendingLayer( | |
| 330 const PaintArtifact& artifact, | |
| 331 const PendingLayer& pendingLayer, | |
| 332 const gfx::Rect& combinedBounds) { | |
| 333 cc::DisplayItemListSettings settings; | |
| 334 scoped_refptr<cc::DisplayItemList> ccList = | |
| 335 cc::DisplayItemList::Create(settings); | |
| 336 | |
| 337 gfx::Transform translation; | |
|
pdr.
2016/12/20 06:46:30
I don't understand the paired begin/end display it
pdr.
2016/12/20 22:50:58
After discussion, I now get this. It's just the co
chrishtr
2016/12/20 23:36:32
Explained in person.
The tests MergeSimpleChunks,
chrishtr
2016/12/20 23:48:31
Agreed offline no extra test needed.
| |
| 338 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | |
| 339 // Passing combinedBounds as the visual rect for the begin/end transform item | |
| 340 // would normally be the sensible thing to do, but see comment above re: | |
| 341 // visual rects for drawing items and further rework in flight. | |
| 342 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | |
| 343 | |
| 344 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | |
| 345 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 346 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; | |
| 347 PropertyTreeStateIterator iterator(*state); | |
| 348 Vector<PropertyTreeState> pairedStates; | |
| 349 for (; state && *state != pendingLayer.propertyTreeState; | |
| 350 state = iterator.next()) { | |
| 351 if (state->innermostNode() != PropertyTreeState::None) | |
| 352 pairedStates.push_back(*state); | |
| 353 } | |
| 354 | |
| 355 recordPairedBeginDisplayItems(pairedStates, ccList.get()); | |
| 356 | |
| 357 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) | |
| 358 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); | |
| 359 | |
| 360 recordPairedEndDisplayItems(pairedStates, ccList.get()); | |
| 361 } | |
| 362 | |
| 363 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | |
| 364 | |
| 365 ccList->Finalize(); | |
| 366 return ccList; | |
| 367 } | |
| 368 | |
| 281 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> | 369 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> |
| 282 PaintArtifactCompositor::clientForPaintChunk( | 370 PaintArtifactCompositor::clientForPaintChunk( |
| 283 const PaintChunk& paintChunk, | 371 const PaintChunk& paintChunk, |
| 284 const PaintArtifact& paintArtifact) { | 372 const PaintArtifact& paintArtifact) { |
| 285 // TODO(chrishtr): for now, just using a linear walk. In the future we can | 373 // TODO(chrishtr): for now, just using a linear walk. In the future we can |
| 286 // optimize this by using the same techniques used in PaintController for | 374 // optimize this by using the same techniques used in PaintController for |
| 287 // display lists. | 375 // display lists. |
| 288 for (auto& client : m_contentLayerClients) { | 376 for (auto& client : m_contentLayerClients) { |
| 289 if (client && client->matches(paintChunk)) | 377 if (client && client->matches(paintChunk)) |
| 290 return std::move(client); | 378 return std::move(client); |
| 291 } | 379 } |
| 292 | 380 |
| 293 return WTF::wrapUnique(new ContentLayerClientImpl( | 381 return WTF::wrapUnique(new ContentLayerClientImpl( |
| 294 paintChunk.id | 382 paintChunk.id |
| 295 ? *paintChunk.id | 383 ? *paintChunk.id |
| 296 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 384 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 297 } | 385 } |
| 298 | 386 |
| 299 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 387 scoped_refptr<cc::Layer> |
| 388 PaintArtifactCompositor::compositedLayerForPendingLayer( | |
| 300 const PaintArtifact& paintArtifact, | 389 const PaintArtifact& paintArtifact, |
| 301 const PaintChunk& paintChunk, | 390 const PendingLayer& pendingLayer, |
| 302 gfx::Vector2dF& layerOffset, | 391 gfx::Vector2dF& layerOffset, |
| 303 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 392 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 304 RasterInvalidationTracking* tracking) { | 393 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap) { |
| 305 DCHECK(paintChunk.size()); | 394 DCHECK(pendingLayer.paintChunks.size()); |
| 395 const PaintChunk& firstPaintChunk = *pendingLayer.paintChunks[0]; | |
| 396 DCHECK(firstPaintChunk.size()); | |
| 397 #if DCHECK_IS_ON | |
| 398 for (const auto& paintChunk : pendingLayer.paintChunks) { | |
| 399 DCHECK(paintChunk.properties == firstPaintChunk.properties); | |
| 400 } | |
| 401 #endif | |
| 306 | 402 |
| 307 // If the paint chunk is a foreign layer, just return that layer. | 403 // If the paint chunk is a foreign layer, just return that layer. |
| 308 if (scoped_refptr<cc::Layer> foreignLayer = | 404 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk( |
| 309 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 405 paintArtifact, firstPaintChunk, layerOffset)) { |
| 406 DCHECK(pendingLayer.paintChunks.size() == 1); | |
| 310 return foreignLayer; | 407 return foreignLayer; |
| 408 } | |
| 311 | 409 |
| 312 // The common case: create or reuse a PictureLayer for painted content. | 410 // The common case: create or reuse a PictureLayer for painted content. |
| 313 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 411 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 314 clientForPaintChunk(paintChunk, paintArtifact); | 412 clientForPaintChunk(firstPaintChunk, paintArtifact); |
| 315 | 413 |
| 316 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 414 gfx::Rect ccCombinedBounds(enclosingIntRect(pendingLayer.bounds)); |
| 415 | |
| 317 scoped_refptr<cc::DisplayItemList> displayList = | 416 scoped_refptr<cc::DisplayItemList> displayList = |
| 318 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 417 recordPendingLayer(paintArtifact, pendingLayer, ccCombinedBounds); |
|
wkorman
2016/12/20 00:28:56
Possible to have ccCombinedBounds be an empty rect
chrishtr
2016/12/20 23:36:31
It could, but that seems a premature optimization
| |
| 319 contentLayerClient->SetDisplayList(std::move(displayList)); | 418 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 320 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 419 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size())); |
| 321 | 420 |
| 322 layerOffset = combinedBounds.OffsetFromOrigin(); | 421 layerOffset = ccCombinedBounds.OffsetFromOrigin(); |
| 422 | |
| 323 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 423 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 324 contentLayerClient->ccPictureLayer(); | 424 contentLayerClient->ccPictureLayer(); |
| 325 ccPictureLayer->SetBounds(combinedBounds.size()); | 425 ccPictureLayer->SetBounds(ccCombinedBounds.size()); |
| 326 ccPictureLayer->SetIsDrawable(true); | 426 ccPictureLayer->SetIsDrawable(true); |
| 327 if (paintChunk.knownToBeOpaque) | 427 ccPictureLayer->SetContentsOpaque(pendingLayer.knownToBeOpaque); |
| 328 ccPictureLayer->SetContentsOpaque(true); | 428 |
| 329 DCHECK(!tracking || | 429 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 330 tracking->trackedRasterInvalidations.size() == | 430 RasterInvalidationTracking* rasterTracking = |
| 331 paintChunk.rasterInvalidationRects.size()); | 431 trackingMap ? trackingMap->find(paintChunk) : nullptr; |
| 332 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 432 DCHECK(!rasterTracking || |
| 333 ++index) { | 433 rasterTracking->trackedRasterInvalidations.size() == |
| 334 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 434 paintChunk->rasterInvalidationRects.size()); |
| 335 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 435 |
| 336 std::max(0, rect.height())); | 436 for (unsigned index = 0; index < paintChunk->rasterInvalidationRects.size(); |
| 337 // Raster paintChunk.rasterInvalidationRects is in the space of the | 437 ++index) { |
| 338 // containing transform node, so need to subtract off the layer offset. | 438 IntRect rect( |
| 339 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 439 enclosingIntRect(paintChunk->rasterInvalidationRects[index])); |
| 340 contentLayerClient->setNeedsDisplayRect( | 440 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), |
| 341 ccInvalidationRect, | 441 std::max(0, rect.width()), |
|
wkorman
2016/12/20 00:28:56
Edge cases we're guarding against with max() here
chrishtr
2016/12/20 23:36:31
Optimized.
| |
| 342 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); | 442 std::max(0, rect.height())); |
| 443 // Raster paintChunk.rasterInvalidationRects is in the space of the | |
| 444 // containing transform node, so need to subtract off the layer offset. | |
| 445 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin()); | |
| 446 contentLayerClient->setNeedsDisplayRect( | |
| 447 ccInvalidationRect, | |
| 448 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index] | |
| 449 : nullptr); | |
| 450 } | |
| 343 } | 451 } |
| 344 | 452 |
| 345 newContentLayerClients.append(std::move(contentLayerClient)); | 453 newContentLayerClients.append(std::move(contentLayerClient)); |
| 346 return ccPictureLayer; | 454 return ccPictureLayer; |
| 347 } | 455 } |
| 348 | 456 |
| 349 namespace { | 457 namespace { |
| 350 | 458 |
| 351 class PropertyTreeManager { | 459 class PropertyTreeManager { |
| 352 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); | 460 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 | 867 |
| 760 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 868 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 761 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 869 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 762 dummyLayer->SetClipTreeIndex(outputClipId); | 870 dummyLayer->SetClipTreeIndex(outputClipId); |
| 763 dummyLayer->SetEffectTreeIndex(effectNode.id); | 871 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 764 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 872 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 765 } | 873 } |
| 766 | 874 |
| 767 } // namespace | 875 } // namespace |
| 768 | 876 |
| 877 bool PaintArtifactCompositor::canMergeInto( | |
| 878 const PaintChunk& newChunk, | |
| 879 const PendingLayer& candidatePendingLayer) { | |
| 880 DCHECK(candidatePendingLayer.paintChunks.size() >= 1); | |
| 881 PropertyTreeStateIterator iterator(newChunk.properties.propertyTreeState); | |
| 882 for (const PropertyTreeState* currentState = | |
| 883 &newChunk.properties.propertyTreeState; | |
| 884 currentState; currentState = iterator.next()) { | |
| 885 if (currentState->hasDirectCompositingReasons()) | |
| 886 return false; | |
| 887 if (*currentState == candidatePendingLayer.propertyTreeState) | |
| 888 return true; | |
| 889 } | |
| 890 return false; | |
| 891 } | |
| 892 | |
| 893 bool PaintArtifactCompositor::overlaps( | |
| 894 const PaintChunk& paintChunk, | |
| 895 const PendingLayer& candidatePendingLayer, | |
| 896 GeometryMapper& geometryMapper) { | |
| 897 // TODO(chrishtr): implement | |
|
wkorman
2016/12/20 00:28:56
Mentioned to pdr@ already, we should consider how
| |
| 898 return true; | |
| 899 } | |
| 900 | |
| 901 void PaintArtifactCompositor::collectPendingLayers( | |
| 902 const Vector<PaintChunk>& paintChunks, | |
| 903 Vector<PendingLayer>& pendingLayers) { | |
| 904 GeometryMapper geometryMapper; | |
| 905 for (const PaintChunk& paintChunk : paintChunks) { | |
|
pdr.
2016/12/20 06:46:30
What do you think about the performance of this fu
pdr.
2016/12/20 22:50:58
We discussed this offline and other folks were awa
chrishtr
2016/12/20 23:36:31
Added a comment about n^3 etc.
| |
| 906 bool createNew = true; | |
| 907 for (Vector<PendingLayer>::reverse_iterator candidatePendingLayer = | |
|
pdr.
2016/12/20 06:46:30
Could this candidate layer loop could be skipped i
| |
| 908 pendingLayers.rbegin(); | |
| 909 candidatePendingLayer != pendingLayers.rend(); | |
| 910 ++candidatePendingLayer) { | |
| 911 if (canMergeInto(paintChunk, *candidatePendingLayer)) { | |
| 912 candidatePendingLayer->add(paintChunk); | |
| 913 createNew = false; | |
| 914 break; | |
| 915 } | |
| 916 if (overlaps(paintChunk, *candidatePendingLayer, geometryMapper)) { | |
| 917 break; | |
| 918 } | |
| 919 } | |
| 920 if (createNew) | |
| 921 pendingLayers.append(PendingLayer(paintChunk)); | |
|
wkorman
2016/12/20 00:28:56
Does this move, or copy, the new PendingLayer inst
chrishtr
2016/12/20 23:36:31
Copies. I ran into some complications when attempt
| |
| 922 } | |
| 923 } | |
| 924 | |
| 769 void PaintArtifactCompositor::update( | 925 void PaintArtifactCompositor::update( |
| 770 const PaintArtifact& paintArtifact, | 926 const PaintArtifact& paintArtifact, |
| 771 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations) { | 927 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations) { |
| 772 DCHECK(m_rootLayer); | 928 DCHECK(m_rootLayer); |
| 773 | 929 |
| 774 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); | 930 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); |
| 775 | 931 |
| 776 // The tree will be null after detaching and this update can be ignored. | 932 // The tree will be null after detaching and this update can be ignored. |
| 777 // See: WebViewImpl::detachPaintArtifactCompositor(). | 933 // See: WebViewImpl::detachPaintArtifactCompositor(). |
| 778 if (!layerTree) | 934 if (!layerTree) |
| 779 return; | 935 return; |
| 780 | 936 |
| 781 if (m_extraDataForTestingEnabled) | 937 if (m_extraDataForTestingEnabled) |
| 782 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); | 938 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); |
| 783 | 939 |
| 784 m_rootLayer->RemoveAllChildren(); | 940 m_rootLayer->RemoveAllChildren(); |
| 785 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 941 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 786 | 942 |
| 787 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), | 943 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), |
| 788 m_rootLayer.get()); | 944 m_rootLayer.get()); |
| 789 | 945 |
| 946 Vector<PendingLayer> pendingLayers; | |
|
wkorman
2016/12/20 00:28:56
Wondered whether there is optimization value to no
chrishtr
2016/12/20 23:36:31
Done.
| |
| 947 collectPendingLayers(paintArtifact.paintChunks(), pendingLayers); | |
| 948 | |
| 790 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; | 949 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; |
| 791 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 950 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 792 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 951 for (const PendingLayer& pendingLayer : pendingLayers) { |
| 793 gfx::Vector2dF layerOffset; | 952 gfx::Vector2dF layerOffset; |
| 794 scoped_refptr<cc::Layer> layer = layerForPaintChunk( | 953 scoped_refptr<cc::Layer> layer = compositedLayerForPendingLayer( |
| 795 paintArtifact, paintChunk, layerOffset, newContentLayerClients, | 954 paintArtifact, pendingLayer, layerOffset, newContentLayerClients, |
| 796 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) | 955 rasterChunkInvalidations); |
| 797 : nullptr); | |
| 798 | 956 |
| 799 int transformId = propertyTreeManager.compositorIdForTransformNode( | 957 int transformId = propertyTreeManager.compositorIdForTransformNode( |
| 800 paintChunk.properties.propertyTreeState.transform()); | 958 pendingLayer.propertyTreeState.transform()); |
| 801 int scrollId = propertyTreeManager.compositorIdForScrollNode( | 959 int scrollId = propertyTreeManager.compositorIdForScrollNode( |
| 802 paintChunk.properties.propertyTreeState.scroll()); | 960 pendingLayer.propertyTreeState.scroll()); |
| 803 int clipId = propertyTreeManager.compositorIdForClipNode( | 961 int clipId = propertyTreeManager.compositorIdForClipNode( |
| 804 paintChunk.properties.propertyTreeState.clip()); | 962 pendingLayer.propertyTreeState.clip()); |
| 805 int effectId = propertyTreeManager.switchToEffectNode( | 963 int effectId = propertyTreeManager.switchToEffectNode( |
| 806 *paintChunk.properties.propertyTreeState.effect()); | 964 *pendingLayer.propertyTreeState.effect()); |
| 807 | 965 |
| 808 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); | 966 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 809 | 967 |
| 810 layer->set_offset_to_transform_parent(layerOffset); | 968 layer->set_offset_to_transform_parent(layerOffset); |
| 811 | 969 |
| 812 m_rootLayer->AddChild(layer); | 970 m_rootLayer->AddChild(layer); |
| 813 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 971 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 814 layer->SetTransformTreeIndex(transformId); | 972 layer->SetTransformTreeIndex(transformId); |
| 815 layer->SetClipTreeIndex(clipId); | 973 layer->SetClipTreeIndex(clipId); |
| 816 layer->SetEffectTreeIndex(effectId); | 974 layer->SetEffectTreeIndex(effectId); |
| 817 layer->SetScrollTreeIndex(scrollId); | 975 layer->SetScrollTreeIndex(scrollId); |
| 818 | 976 |
| 819 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 977 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 820 // queried by RenderSurfaceImpl. | 978 // queried by RenderSurfaceImpl. |
| 821 layer->Set3dSortingContextId(layerTree->property_trees() | 979 layer->Set3dSortingContextId(layerTree->property_trees() |
| 822 ->transform_tree.Node(transformId) | 980 ->transform_tree.Node(transformId) |
| 823 ->sorting_context_id); | 981 ->sorting_context_id); |
| 824 | 982 |
| 825 layer->SetShouldCheckBackfaceVisibility( | 983 layer->SetShouldCheckBackfaceVisibility(pendingLayer.backfaceHidden); |
| 826 paintChunk.properties.backfaceHidden); | |
| 827 | 984 |
| 828 if (m_extraDataForTestingEnabled) | 985 if (m_extraDataForTestingEnabled) |
| 829 m_extraDataForTesting->contentLayers.append(layer); | 986 m_extraDataForTesting->contentLayers.append(layer); |
| 830 } | 987 } |
| 831 m_contentLayerClients.clear(); | 988 m_contentLayerClients.clear(); |
| 832 m_contentLayerClients.swap(newContentLayerClients); | 989 m_contentLayerClients.swap(newContentLayerClients); |
| 833 | 990 |
| 834 // Mark the property trees as having been rebuilt. | 991 // Mark the property trees as having been rebuilt. |
| 835 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 992 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 836 layerTree->property_trees()->needs_rebuild = false; | 993 layerTree->property_trees()->needs_rebuild = false; |
| 837 layerTree->property_trees()->ResetCachedData(); | 994 layerTree->property_trees()->ResetCachedData(); |
| 838 } | 995 } |
| 839 | 996 |
| 840 } // namespace blink | 997 } // namespace blink |
| OLD | NEW |