| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 scrollNode.owner_id = ownerId; | 314 scrollNode.owner_id = ownerId; |
| 315 scrollTree.set_needs_update(true); | 315 scrollTree.set_needs_update(true); |
| 316 } | 316 } |
| 317 DCHECK_EQ(scrollTree.size(), 2u); | 317 DCHECK_EQ(scrollTree.size(), 2u); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) | 322 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) |
| 323 { | 323 { |
| 324 ASSERT(m_rootLayer); | 324 DCHECK(m_rootLayer); |
| 325 | 325 |
| 326 // If the compositor is configured to expect using flat layer lists plus | 326 // If the compositor is configured to expect using flat layer lists plus |
| 327 // property trees, then we should provide that format. | 327 // property trees, then we should provide that format. |
| 328 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); | 328 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); |
| 329 const bool useLayerLists = host && host->settings().use_layer_lists; | 329 const bool useLayerLists = host && host->settings().use_layer_lists; |
| 330 | |
| 331 if (useLayerLists) { | 330 if (useLayerLists) { |
| 332 // The root layer must be the owner so that the render surface | 331 updateInLayerListMode(paintArtifact); |
| 333 // validation works. It's expected to own at least the effect node. | 332 return; |
| 334 setMinimalPropertyTrees(host->property_trees(), m_rootLayer->id()); | |
| 335 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumb
er); | |
| 336 m_rootLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | |
| 337 m_rootLayer->SetClipTreeIndex(kSecondaryRootNodeId); | |
| 338 m_rootLayer->SetEffectTreeIndex(kSecondaryRootNodeId); | |
| 339 m_rootLayer->SetScrollTreeIndex(kSecondaryRootNodeId); | |
| 340 } | 333 } |
| 341 | 334 |
| 342 // TODO(jbroman): This should be incremental. | 335 // TODO(jbroman): This should be incremental. |
| 343 m_rootLayer->RemoveAllChildren(); | 336 m_rootLayer->RemoveAllChildren(); |
| 344 m_contentLayerClients.clear(); | 337 m_contentLayerClients.clear(); |
| 345 | 338 |
| 346 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 339 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 347 ClipLayerManager clipLayerManager(m_rootLayer.get()); | 340 ClipLayerManager clipLayerManager(m_rootLayer.get()); |
| 348 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 341 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 349 cc::Layer* parent; | 342 cc::Layer* parent = clipLayerManager.switchToNewClipLayer(paintChunk.pro
perties.clip.get()); |
| 350 if (useLayerLists) | |
| 351 parent = m_rootLayer.get(); | |
| 352 else | |
| 353 parent = clipLayerManager.switchToNewClipLayer(paintChunk.properties
.clip.get()); | |
| 354 | 343 |
| 355 gfx::Vector2dF layerOffset; | 344 gfx::Vector2dF layerOffset; |
| 356 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); | 345 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); |
| 357 if (useLayerLists) { | 346 // TODO(jbroman): Same as above. This assumes the transform space of the
current clip is |
| 358 // This is only good enough to get trivial 2D translations working. | 347 // an ancestor of the chunk. It is not necessarily true. crbug.com/59715
6 |
| 359 // We'll need to actually create more cc transform nodes to do any | 348 gfx::Transform transform = transformToTransformSpace(paintChunk.properti
es.transform.get(), localTransformSpace(paintChunk.properties.clip.get())); |
| 360 // more; then we'll express offset-to-transform-parent relative to | 349 transform.Translate(layerOffset.x(), layerOffset.y()); |
| 361 // that transform node. | 350 // If a clip was applied, its origin needs to be cancelled out in |
| 362 // TODO(jbroman): ^ Do that. | 351 // this transform. |
| 363 layer->set_offset_to_transform_parent( | 352 if (const auto* clip = paintChunk.properties.clip.get()) { |
| 364 transformToTransformSpace(paintChunk.properties.transform.get(),
nullptr).To2dTranslation() | 353 FloatPoint offsetDueToClipOffset = clip->clipRect().rect().location(
); |
| 365 + layerOffset); | 354 gfx::Transform undoClipOffset; |
| 366 } else { | 355 undoClipOffset.Translate(-offsetDueToClipOffset.x(), -offsetDueToCli
pOffset.y()); |
| 367 // TODO(jbroman): Same as above. This assumes the transform space of
the current clip is | 356 transform.ConcatTransform(undoClipOffset); |
| 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); | |
| 380 } | 357 } |
| 358 layer->SetTransform(transform); |
| 381 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden); | 359 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden); |
| 382 layer->SetNeedsDisplay(); | 360 layer->SetNeedsDisplay(); |
| 383 parent->AddChild(layer); | 361 parent->AddChild(layer); |
| 384 | |
| 385 if (useLayerLists) { | |
| 386 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber
); | |
| 387 layer->SetTransformTreeIndex(kSecondaryRootNodeId); | |
| 388 layer->SetClipTreeIndex(kSecondaryRootNodeId); | |
| 389 layer->SetEffectTreeIndex(kSecondaryRootNodeId); | |
| 390 layer->SetScrollTreeIndex(kSecondaryRootNodeId); | |
| 391 } | |
| 392 } | |
| 393 | |
| 394 if (useLayerLists) { | |
| 395 // Mark the property trees as having been rebuilt. | |
| 396 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | |
| 397 host->property_trees()->needs_rebuild = false; | |
| 398 } | 362 } |
| 399 } | 363 } |
| 400 | 364 |
| 401 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffs
et) | 365 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffs
et) |
| 402 { | 366 { |
| 403 DCHECK(paintChunk.size()); | 367 DCHECK(paintChunk.size()); |
| 404 | 368 |
| 405 // If the paint chunk is a foreign layer, just return that layer. | 369 // If the paint chunk is a foreign layer, just return that layer. |
| 406 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, layerOffset)) | 370 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, layerOffset)) |
| 407 return foreignLayer; | 371 return foreignLayer; |
| 408 | 372 |
| 409 // The common case: create a layer for painted content. | 373 // The common case: create a layer for painted content. |
| 410 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 374 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); |
| 411 scoped_refptr<cc::DisplayItemList> displayList = recordPaintChunk(paintArtif
act, paintChunk, combinedBounds); | 375 scoped_refptr<cc::DisplayItemList> displayList = recordPaintChunk(paintArtif
act, paintChunk, combinedBounds); |
| 412 OwnPtr<ContentLayerClientImpl> contentLayerClient = adoptPtr( | 376 OwnPtr<ContentLayerClientImpl> contentLayerClient = adoptPtr( |
| 413 new ContentLayerClientImpl(std::move(displayList), gfx::Rect(combinedBou
nds.size()))); | 377 new ContentLayerClientImpl(std::move(displayList), gfx::Rect(combinedBou
nds.size()))); |
| 414 | 378 |
| 415 layerOffset = combinedBounds.OffsetFromOrigin(); | 379 layerOffset = combinedBounds.OffsetFromOrigin(); |
| 416 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye
rClient.get()); | 380 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye
rClient.get()); |
| 417 layer->SetBounds(combinedBounds.size()); | 381 layer->SetBounds(combinedBounds.size()); |
| 418 layer->SetIsDrawable(true); | 382 layer->SetIsDrawable(true); |
| 419 if (paintChunk.knownToBeOpaque) | 383 if (paintChunk.knownToBeOpaque) |
| 420 layer->SetContentsOpaque(true); | 384 layer->SetContentsOpaque(true); |
| 421 m_contentLayerClients.append(std::move(contentLayerClient)); | 385 m_contentLayerClients.append(std::move(contentLayerClient)); |
| 422 return layer; | 386 return layer; |
| 423 } | 387 } |
| 424 | 388 |
| 389 void PaintArtifactCompositor::updateInLayerListMode(const PaintArtifact& paintAr
tifact) |
| 390 { |
| 391 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); |
| 392 |
| 393 // The root layer must be the owner so that the render surface |
| 394 // validation works. It's expected to own at least the effect node. |
| 395 setMinimalPropertyTrees(host->property_trees(), m_rootLayer->id()); |
| 396 m_rootLayer->RemoveAllChildren(); |
| 397 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 398 m_rootLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 399 m_rootLayer->SetClipTreeIndex(kSecondaryRootNodeId); |
| 400 m_rootLayer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 401 m_rootLayer->SetScrollTreeIndex(kSecondaryRootNodeId); |
| 402 |
| 403 m_contentLayerClients.clear(); |
| 404 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 405 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 406 gfx::Vector2dF layerOffset; |
| 407 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); |
| 408 // This is only good enough to get trivial 2D translations working. |
| 409 // We'll need to actually create more cc transform nodes to do any |
| 410 // more; then we'll express offset-to-transform-parent relative to |
| 411 // that transform node. |
| 412 // TODO(jbroman): ^ Do that. |
| 413 layer->set_offset_to_transform_parent( |
| 414 transformToTransformSpace(paintChunk.properties.transform.get(), nul
lptr).To2dTranslation() |
| 415 + layerOffset); |
| 416 |
| 417 m_rootLayer->AddChild(layer); |
| 418 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 419 layer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 420 layer->SetClipTreeIndex(kSecondaryRootNodeId); |
| 421 layer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 422 layer->SetScrollTreeIndex(kSecondaryRootNodeId); |
| 423 } |
| 424 |
| 425 // Mark the property trees as having been rebuilt. |
| 426 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 427 host->property_trees()->needs_rebuild = false; |
| 428 } |
| 429 |
| 425 } // namespace blink | 430 } // namespace blink |
| OLD | NEW |