| 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/display_item_list.h" | 10 #include "cc/playback/display_item_list.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 // Return the last (bottom-most) clip layer. | 233 // Return the last (bottom-most) clip layer. |
| 234 return m_clipLayers.last().second; | 234 return m_clipLayers.last().second; |
| 235 } | 235 } |
| 236 | 236 |
| 237 private: | 237 private: |
| 238 using NodeLayerPair = std::pair<const ClipPaintPropertyNode*, cc::Layer*>; | 238 using NodeLayerPair = std::pair<const ClipPaintPropertyNode*, cc::Layer*>; |
| 239 Vector<NodeLayerPair, 16> m_clipLayers; | 239 Vector<NodeLayerPair, 16> m_clipLayers; |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 scoped_refptr<cc::Layer> foreignLayerForPaintChunk(const PaintArtifact& paintArt
ifact, const PaintChunk& paintChunk, gfx::Transform transform) | 242 scoped_refptr<cc::Layer> foreignLayerForPaintChunk(const PaintArtifact& paintArt
ifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffset) |
| 243 { | 243 { |
| 244 if (paintChunk.size() != 1) | 244 if (paintChunk.size() != 1) |
| 245 return nullptr; | 245 return nullptr; |
| 246 | 246 |
| 247 const auto& displayItem = paintArtifact.getDisplayItemList()[paintChunk.begi
nIndex]; | 247 const auto& displayItem = paintArtifact.getDisplayItemList()[paintChunk.begi
nIndex]; |
| 248 if (!displayItem.isForeignLayer()) | 248 if (!displayItem.isForeignLayer()) |
| 249 return nullptr; | 249 return nullptr; |
| 250 | 250 |
| 251 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI
tem&>(displayItem); | 251 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI
tem&>(displayItem); |
| 252 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), foreign
LayerDisplayItem.location().y()); |
| 252 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); | 253 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); |
| 253 transform.Translate(foreignLayerDisplayItem.location().x(), foreignLayerDisp
layItem.location().y()); | |
| 254 layer->SetTransform(transform); | |
| 255 layer->SetBounds(foreignLayerDisplayItem.bounds()); | 254 layer->SetBounds(foreignLayerDisplayItem.bounds()); |
| 256 layer->SetIsDrawable(true); | 255 layer->SetIsDrawable(true); |
| 257 return layer; | 256 return layer; |
| 258 } | 257 } |
| 259 | 258 |
| 260 static const int kInvalidNodeId = -1; | 259 static const int kInvalidNodeId = -1; |
| 261 static const int kRealRootNodeId = 0; | 260 static const int kRealRootNodeId = 0; |
| 262 static const int kSecondaryRootNodeId = 1; | 261 static const int kSecondaryRootNodeId = 1; |
| 263 static const int kPropertyTreeSequenceNumber = 1; | 262 static const int kPropertyTreeSequenceNumber = 1; |
| 264 | 263 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 340 } |
| 342 | 341 |
| 343 // TODO(jbroman): This should be incremental. | 342 // TODO(jbroman): This should be incremental. |
| 344 m_rootLayer->RemoveAllChildren(); | 343 m_rootLayer->RemoveAllChildren(); |
| 345 m_contentLayerClients.clear(); | 344 m_contentLayerClients.clear(); |
| 346 | 345 |
| 347 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 346 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 348 ClipLayerManager clipLayerManager(m_rootLayer.get()); | 347 ClipLayerManager clipLayerManager(m_rootLayer.get()); |
| 349 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 348 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 350 cc::Layer* parent; | 349 cc::Layer* parent; |
| 351 gfx::Transform transform; | 350 if (useLayerLists) |
| 352 if (useLayerLists) { | |
| 353 parent = m_rootLayer.get(); | 351 parent = m_rootLayer.get(); |
| 354 } else { | 352 else |
| 355 parent = clipLayerManager.switchToNewClipLayer(paintChunk.properties
.clip.get()); | 353 parent = clipLayerManager.switchToNewClipLayer(paintChunk.properties
.clip.get()); |
| 356 // TODO(jbroman): Same as above. This assumes the transform space of
the current clip is | |
| 357 // an ancestor of the chunk. It is not necessarily true. crbug.com/5
97156 | |
| 358 transform = transformToTransformSpace(paintChunk.properties.transfor
m.get(), localTransformSpace(paintChunk.properties.clip.get())); | |
| 359 } | |
| 360 | 354 |
| 361 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, transform); | 355 gfx::Vector2dF layerOffset; |
| 356 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); |
| 362 if (useLayerLists) { | 357 if (useLayerLists) { |
| 363 // This is only good enough to get trivial 2D translations working. | 358 // This is only good enough to get trivial 2D translations working. |
| 364 // We'll need to actually create more cc transform nodes to do any | 359 // We'll need to actually create more cc transform nodes to do any |
| 365 // more; then we'll express offset-to-transform-parent relative to | 360 // more; then we'll express offset-to-transform-parent relative to |
| 366 // that transform node. | 361 // that transform node. |
| 367 // TODO(jbroman): ^ Do that. | 362 // TODO(jbroman): ^ Do that. |
| 368 layer->set_offset_to_transform_parent( | 363 layer->set_offset_to_transform_parent( |
| 369 transformToTransformSpace(paintChunk.properties.transform.get(),
nullptr).To2dTranslation() | 364 transformToTransformSpace(paintChunk.properties.transform.get(),
nullptr).To2dTranslation() |
| 370 + layer->transform().To2dTranslation()); | 365 + layerOffset); |
| 366 } else { |
| 367 // TODO(jbroman): Same as above. This assumes the transform space of
the current clip is |
| 368 // an ancestor of the chunk. It is not necessarily true. crbug.com/5
97156 |
| 369 gfx::Transform transform = transformToTransformSpace(paintChunk.prop
erties.transform.get(), localTransformSpace(paintChunk.properties.clip.get())); |
| 370 transform.Translate(layerOffset.x(), layerOffset.y()); |
| 371 // If a clip was applied, its origin needs to be cancelled out in |
| 372 // this transform. |
| 373 if (const auto* clip = paintChunk.properties.clip.get()) { |
| 374 FloatPoint offsetDueToClipOffset = clip->clipRect().rect().locat
ion(); |
| 375 gfx::Transform undoClipOffset; |
| 376 undoClipOffset.Translate(-offsetDueToClipOffset.x(), -offsetDueT
oClipOffset.y()); |
| 377 transform.ConcatTransform(undoClipOffset); |
| 378 } |
| 379 layer->SetTransform(transform); |
| 371 } | 380 } |
| 381 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden); |
| 372 layer->SetNeedsDisplay(); | 382 layer->SetNeedsDisplay(); |
| 373 parent->AddChild(layer); | 383 parent->AddChild(layer); |
| 374 | 384 |
| 375 if (useLayerLists) { | 385 if (useLayerLists) { |
| 376 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber
); | 386 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber
); |
| 377 layer->SetTransformTreeIndex(kSecondaryRootNodeId); | 387 layer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 378 layer->SetClipTreeIndex(kSecondaryRootNodeId); | 388 layer->SetClipTreeIndex(kSecondaryRootNodeId); |
| 379 layer->SetEffectTreeIndex(kSecondaryRootNodeId); | 389 layer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 380 layer->SetScrollTreeIndex(kSecondaryRootNodeId); | 390 layer->SetScrollTreeIndex(kSecondaryRootNodeId); |
| 381 } | 391 } |
| 382 } | 392 } |
| 383 | 393 |
| 384 if (useLayerLists) { | 394 if (useLayerLists) { |
| 385 // Mark the property trees as having been rebuilt. | 395 // Mark the property trees as having been rebuilt. |
| 386 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 396 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 387 host->property_trees()->needs_rebuild = false; | 397 host->property_trees()->needs_rebuild = false; |
| 388 } | 398 } |
| 389 } | 399 } |
| 390 | 400 |
| 391 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Transform transform) | 401 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffs
et) |
| 392 { | 402 { |
| 403 DCHECK(paintChunk.size()); |
| 404 |
| 393 // If the paint chunk is a foreign layer, just return that layer. | 405 // If the paint chunk is a foreign layer, just return that layer. |
| 394 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, transform)) | 406 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, layerOffset)) |
| 395 return foreignLayer; | 407 return foreignLayer; |
| 396 | 408 |
| 397 // The common case: create a layer for painted content. | 409 // The common case: create a layer for painted content. |
| 398 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 410 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); |
| 399 scoped_refptr<cc::DisplayItemList> displayList = recordPaintChunk(paintArtif
act, paintChunk, combinedBounds); | 411 scoped_refptr<cc::DisplayItemList> displayList = recordPaintChunk(paintArtif
act, paintChunk, combinedBounds); |
| 400 OwnPtr<ContentLayerClientImpl> contentLayerClient = adoptPtr( | 412 OwnPtr<ContentLayerClientImpl> contentLayerClient = adoptPtr( |
| 401 new ContentLayerClientImpl(std::move(displayList), gfx::Rect(combinedBou
nds.size()))); | 413 new ContentLayerClientImpl(std::move(displayList), gfx::Rect(combinedBou
nds.size()))); |
| 402 | 414 |
| 403 // Include the offset in the transform, because it needs to apply in | 415 layerOffset = combinedBounds.OffsetFromOrigin(); |
| 404 // this layer's transform space (whereas layer position applies in its | |
| 405 // parent's transform space). | |
| 406 gfx::Vector2dF offset = gfx::PointF(combinedBounds.origin()).OffsetFromOrigi
n(); | |
| 407 transform.Translate(offset.x(), offset.y()); | |
| 408 | |
| 409 // If a clip was applied, its origin needs to be cancelled out in | |
| 410 // this transform. | |
| 411 if (const auto* clip = paintChunk.properties.clip.get()) { | |
| 412 FloatPoint offsetDueToClipOffset = clip->clipRect().rect().location(); | |
| 413 gfx::Transform undoClipOffset; | |
| 414 undoClipOffset.Translate(-offsetDueToClipOffset.x(), -offsetDueToClipOff
set.y()); | |
| 415 transform.ConcatTransform(undoClipOffset); | |
| 416 } | |
| 417 | |
| 418 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye
rClient.get()); | 416 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye
rClient.get()); |
| 419 layer->SetBounds(combinedBounds.size()); | 417 layer->SetBounds(combinedBounds.size()); |
| 420 layer->SetTransform(transform); | |
| 421 layer->SetIsDrawable(true); | 418 layer->SetIsDrawable(true); |
| 422 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden); | |
| 423 if (paintChunk.knownToBeOpaque) | 419 if (paintChunk.knownToBeOpaque) |
| 424 layer->SetContentsOpaque(true); | 420 layer->SetContentsOpaque(true); |
| 425 m_contentLayerClients.append(std::move(contentLayerClient)); | 421 m_contentLayerClients.append(std::move(contentLayerClient)); |
| 426 return layer; | 422 return layer; |
| 427 } | 423 } |
| 428 | 424 |
| 429 } // namespace blink | 425 } // namespace blink |
| OLD | NEW |