Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp

Issue 1956853002: [SPv2] Build trivial cc property trees in PaintArtifactCompositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix DCHECK in unit tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "cc/playback/display_item_list_settings.h" 11 #include "cc/playback/display_item_list_settings.h"
12 #include "cc/playback/drawing_display_item.h" 12 #include "cc/playback/drawing_display_item.h"
13 #include "cc/playback/transform_display_item.h" 13 #include "cc/playback/transform_display_item.h"
14 #include "cc/trees/layer_tree_host.h"
14 #include "platform/RuntimeEnabledFeatures.h" 15 #include "platform/RuntimeEnabledFeatures.h"
15 #include "platform/graphics/paint/ClipPaintPropertyNode.h" 16 #include "platform/graphics/paint/ClipPaintPropertyNode.h"
16 #include "platform/graphics/paint/DisplayItem.h" 17 #include "platform/graphics/paint/DisplayItem.h"
17 #include "platform/graphics/paint/DrawingDisplayItem.h" 18 #include "platform/graphics/paint/DrawingDisplayItem.h"
18 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" 19 #include "platform/graphics/paint/ForeignLayerDisplayItem.h"
19 #include "platform/graphics/paint/PaintArtifact.h" 20 #include "platform/graphics/paint/PaintArtifact.h"
20 #include "platform/graphics/paint/TransformPaintPropertyNode.h" 21 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
21 #include "public/platform/Platform.h" 22 #include "public/platform/Platform.h"
22 #include "public/platform/WebCompositorSupport.h" 23 #include "public/platform/WebCompositorSupport.h"
23 #include "public/platform/WebLayer.h" 24 #include "public/platform/WebLayer.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 251
251 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI tem&>(displayItem); 252 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI tem&>(displayItem);
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 transform.Translate(foreignLayerDisplayItem.location().x(), foreignLayerDisp layItem.location().y());
254 layer->SetTransform(transform); 255 layer->SetTransform(transform);
255 layer->SetBounds(foreignLayerDisplayItem.bounds()); 256 layer->SetBounds(foreignLayerDisplayItem.bounds());
256 layer->SetIsDrawable(true); 257 layer->SetIsDrawable(true);
257 return layer; 258 return layer;
258 } 259 }
259 260
261 static const int kInvalidNodeId = -1;
262 static const int kRealRootNodeId = 0;
263 static const int kSecondaryRootNodeId = 1;
264 static const int kPropertyTreeSequenceNumber = 1;
265
266 // Creates a minimal set of property trees for the compositor.
267 void setMinimalPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId)
268 {
269 // cc's property trees expect a child of the actual root to be used. So we
270 // need to create and populate an additional node for each type of tree.
271
272 cc::TransformTree& transformTree = propertyTrees->transform_tree;
273 if (transformTree.size() < 2) {
274 transformTree.Insert(cc::TransformNode(), kRealRootNodeId);
275 cc::TransformNode& transformNode = *transformTree.back();
276 transformNode.data.target_id = kRealRootNodeId;
277 transformNode.data.content_target_id = kSecondaryRootNodeId;
278 transformNode.data.source_node_id = kRealRootNodeId;
279 transformNode.data.needs_local_transform_update = true;
280 transformNode.owner_id = ownerId;
281 transformTree.set_needs_update(true);
282 }
283 DCHECK_EQ(transformTree.size(), 2u);
284
285 cc::ClipTree& clipTree = propertyTrees->clip_tree;
286 if (clipTree.size() < 2) {
287 clipTree.Insert(cc::ClipNode(), kRealRootNodeId);
288 cc::ClipNode& clipNode = *clipTree.back();
289 clipNode.data.transform_id = kSecondaryRootNodeId;
290 clipNode.data.target_id = kSecondaryRootNodeId;
291 clipNode.owner_id = ownerId;
292 clipTree.set_needs_update(true);
293 }
294 DCHECK_EQ(clipTree.size(), 2u);
295
296 cc::EffectTree& effectTree = propertyTrees->effect_tree;
297 if (effectTree.size() < 2) {
298 // This matches what cc does right now: the secondary root isn't a child
299 // of the first root (at index 0). This may not have been intentional.
300 effectTree.Insert(cc::EffectNode(), kInvalidNodeId);
301 cc::EffectNode& effectNode = *effectTree.back();
302 effectNode.data.has_render_surface = true;
303 effectNode.data.transform_id = kRealRootNodeId;
304 effectNode.data.clip_id = kRealRootNodeId;
305 effectNode.owner_id = ownerId;
306 effectTree.set_needs_update(true);
307 }
308 DCHECK_EQ(effectTree.size(), 2u);
309
310 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree;
311 if (scrollTree.size() < 2) {
312 scrollTree.Insert(cc::ScrollNode(), kRealRootNodeId);
313 cc::ScrollNode& scrollNode = *scrollTree.back();
314 scrollNode.data.scrollable = false;
315 scrollNode.data.transform_id = kSecondaryRootNodeId;
316 scrollNode.owner_id = ownerId;
317 scrollTree.set_needs_update(true);
318 }
319 DCHECK_EQ(scrollTree.size(), 2u);
320 }
321
260 } // namespace 322 } // namespace
261 323
262 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) 324 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact)
263 { 325 {
264 ASSERT(m_rootLayer); 326 ASSERT(m_rootLayer);
265 327
328 // If the compositor is configured to expect using flat layer lists plus
329 // property trees, then we should provide that format.
330 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host();
331 const bool useLayerLists = host && host->settings().use_layer_lists;
332
333 if (useLayerLists) {
334 // The root layer must be the owner so that the render surface
335 // validation works. It's expected to own at least the effect node.
336 setMinimalPropertyTrees(host->property_trees(), m_rootLayer->id());
337 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumb er);
338 m_rootLayer->SetTransformTreeIndex(kSecondaryRootNodeId);
339 m_rootLayer->SetClipTreeIndex(kSecondaryRootNodeId);
340 m_rootLayer->SetEffectTreeIndex(kSecondaryRootNodeId);
341 m_rootLayer->SetScrollTreeIndex(kSecondaryRootNodeId);
342 }
343
266 // TODO(jbroman): This should be incremental. 344 // TODO(jbroman): This should be incremental.
267 m_rootLayer->RemoveAllChildren(); 345 m_rootLayer->RemoveAllChildren();
268 m_contentLayerClients.clear(); 346 m_contentLayerClients.clear();
269 347
270 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); 348 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size());
271 ClipLayerManager clipLayerManager(m_rootLayer.get()); 349 ClipLayerManager clipLayerManager(m_rootLayer.get());
272 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { 350 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) {
273 cc::Layer* parent = clipLayerManager.switchToNewClipLayer(paintChunk.pro perties.clip.get()); 351 cc::Layer* parent;
274 // TODO(jbroman): Same as above. This assumes the transform space of the current clip is 352 gfx::Transform transform;
275 // an ancestor of the chunk. It is not necessarily true. crbug.com/59715 6 353 if (useLayerLists) {
276 gfx::Transform transform = transformToTransformSpace(paintChunk.properti es.transform.get(), localTransformSpace(paintChunk.properties.clip.get())); 354 parent = m_rootLayer.get();
355 } else {
356 parent = clipLayerManager.switchToNewClipLayer(paintChunk.properties .clip.get());
357 // TODO(jbroman): Same as above. This assumes the transform space of the current clip is
358 // an ancestor of the chunk. It is not necessarily true. crbug.com/5 97156
359 transform = transformToTransformSpace(paintChunk.properties.transfor m.get(), localTransformSpace(paintChunk.properties.clip.get()));
360 }
361
277 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint Chunk, transform); 362 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint Chunk, transform);
363 if (useLayerLists) {
364 // This is only good enough to get trivial 2D translations working.
365 // We'll need to actually create more cc transform nodes to do any
366 // more; then we'll express offset-to-transform-parent relative to
367 // that transform node.
368 // TODO(jbroman): ^ Do that.
369 layer->set_offset_to_transform_parent(
370 transformToTransformSpace(paintChunk.properties.transform.get(), nullptr).To2dTranslation()
371 + layer->transform().To2dTranslation());
372 }
278 layer->SetNeedsDisplay(); 373 layer->SetNeedsDisplay();
279 parent->AddChild(std::move(layer)); 374 parent->AddChild(layer);
375
376 if (useLayerLists) {
377 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber );
378 layer->SetTransformTreeIndex(kSecondaryRootNodeId);
379 layer->SetClipTreeIndex(kSecondaryRootNodeId);
380 layer->SetEffectTreeIndex(kSecondaryRootNodeId);
381 layer->SetScrollTreeIndex(kSecondaryRootNodeId);
382 }
383 }
384
385 if (useLayerLists) {
386 // Mark the property trees as having been rebuilt.
387 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber;
388 host->property_trees()->needs_rebuild = false;
280 } 389 }
281 } 390 }
282 391
283 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Transform transform) 392 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Transform transform)
284 { 393 {
285 // If the paint chunk is a foreign layer, just return that layer. 394 // If the paint chunk is a foreign layer, just return that layer.
286 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA rtifact, paintChunk, transform)) 395 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA rtifact, paintChunk, transform))
287 return foreignLayer; 396 return foreignLayer;
288 397
289 // The common case: create a layer for painted content. 398 // The common case: create a layer for painted content.
(...skipping 21 matching lines...) Expand all
311 layer->SetBounds(combinedBounds.size()); 420 layer->SetBounds(combinedBounds.size());
312 layer->SetTransform(transform); 421 layer->SetTransform(transform);
313 layer->SetIsDrawable(true); 422 layer->SetIsDrawable(true);
314 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden); 423 layer->SetDoubleSided(!paintChunk.properties.backfaceHidden);
315 if (paintChunk.knownToBeOpaque) 424 if (paintChunk.knownToBeOpaque)
316 layer->SetContentsOpaque(true); 425 layer->SetContentsOpaque(true);
317 m_contentLayerClients.append(contentLayerClient.release()); 426 m_contentLayerClients.append(contentLayerClient.release());
318 return layer; 427 return layer;
319 } 428 }
320 429
321
322 } // namespace blink 430 } // namespace blink
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698