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

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

Issue 2581843002: Implement merging non-composited paint property nodes in the PACompositor. (Closed)
Patch Set: none Created 3 years, 12 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/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
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 static FloatRect infinteFloatRect = FloatRect(LayoutRect::infiniteIntRect());
299 FloatRect combinedClip;
300 bool success = false;
301 combinedClip = geometryMapper.localToVisualRectInAncestorSpace(
302 infinteFloatRect, localState, ancestorState, success);
303 DCHECK(success);
304 if (combinedClip == infinteFloatRect)
305 return;
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 }
331 mappedClipDestinationSpace = *pairedState;
332 clipSpace = *pairedState;
333
334 gfx::Transform transform(gfx::Transform::kSkipInitialization);
335 transform.matrix() = TransformationMatrix::toSkMatrix44(
336 pairedState->transform()->matrix());
337
338 ccList.CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(
339 transform);
340 endDisplayItems.push_back(EndTransform);
341 break;
342 }
343 case PropertyTreeState::Clip: {
344 // Clips are handled in |applyClips| when ending the iterator, or
345 // transitioning between transform spaces. Here we store off the
346 // PropertyTreeState of the first found clip, under the transform of
347 // pairedState->transform(). All subsequent clips before applying the
348 // transform will be applied in applyClips.
349 clipSpace = *pairedState;
350 hasClip = true;
351 #ifdef DCHECK_IS_ON
352 if (pairedState->clip()->localTransformSpace() !=
353 pairedState->transform()) {
354 const TransformationMatrix& localTransformMatrix =
355 pairedState->effect()->localTransformSpace()->matrix();
356 // Clips are only in descendant spaces that are transformed by scroll.
357 DCHECK(localTransformMatrix.isIdentityOrTranslation());
358 }
359 #endif
360 break;
361 }
362 case PropertyTreeState::Effect: {
363 // TODO(chrishtr): skip effect and/or compositing display items if
364 // not necessary.
365
366 FloatRect clipRect =
367 pairedState->effect()->outputClip()->clipRect().rect();
368 // TODO(chrishtr): specify origin of the filter.
369 FloatPoint filterOrigin;
370 if (pairedState->effect()->localTransformSpace() !=
371 pairedState->transform()) {
372 bool success = false;
373 const TransformPaintPropertyNode* transformNode =
374 pairedState->effect()->localTransformSpace();
375 const TransformationMatrix& localToAncestorMatrix =
376 geometryMapper.localToAncestorMatrix(transformNode, *pairedState,
377 success);
378 DCHECK(success);
379 // Effects are only in descendant spaces that are transformed by one
380 // or more scrolls.
381 DCHECK(localToAncestorMatrix.isIdentityOrTranslation());
382
383 clipRect = localToAncestorMatrix.mapRect(clipRect);
384 filterOrigin = localToAncestorMatrix.mapPoint(filterOrigin);
385 }
386
387 ccList.CreateAndAppendPairedBeginItem<cc::FilterDisplayItem>(
388 pairedState->effect()->filter().asCcFilterOperations(),
389 pairedState->effect()->outputClip()->clipRect().rect(),
390 gfx::PointF(filterOrigin.x(), filterOrigin.y()));
391 const bool kLcdTextRequiresOpaqueLayer = true;
392 ccList.CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>(
393 static_cast<uint8_t>(
394 gfx::ToFlooredInt(255 * pairedState->effect()->opacity())),
395 pairedState->effect()->blendMode(),
396 // TODO(chrishtr): compute bounds as necessary.
397 nullptr, nullptr, kLcdTextRequiresOpaqueLayer);
398 endDisplayItems.push_back(EndEffect);
399 break;
400 }
401 case PropertyTreeState::None:
402 break;
403 }
404 }
405
406 if (hasClip) {
407 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, endDi splayItems,
408 geometryMapper);
409 }
410 }
411
412 static void recordPairedEndDisplayItems(
413 const Vector<EndDisplayItemType>& endDisplayItemTypes,
414 cc::DisplayItemList* ccList) {
415 for (Vector<EndDisplayItemType>::const_reverse_iterator endType =
416 endDisplayItemTypes.rbegin();
417 endType != endDisplayItemTypes.rend(); ++endType) {
418 switch (*endType) {
419 case EndTransform:
420 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>();
421 break;
422 case EndClip:
423 ccList->CreateAndAppendPairedEndItem<cc::EndFloatClipDisplayItem>();
424 break;
425 case EndEffect:
426 ccList->CreateAndAppendPairedEndItem<cc::EndCompositingDisplayItem>();
427 ccList->CreateAndAppendPairedEndItem<cc::EndFilterDisplayItem>();
428 break;
429 }
430 }
431 }
432
293 } // namespace 433 } // namespace
294 434
435 scoped_refptr<cc::DisplayItemList> PaintArtifactCompositor::recordPendingLayer(
436 const PaintArtifact& artifact,
437 const PendingLayer& pendingLayer,
438 const gfx::Rect& combinedBounds,
439 GeometryMapper& geometryMapper) {
440 cc::DisplayItemListSettings settings;
441 scoped_refptr<cc::DisplayItemList> ccList =
442 cc::DisplayItemList::Create(settings);
443
444 gfx::Transform translation;
445 translation.Translate(-combinedBounds.x(), -combinedBounds.y());
446 // Passing combinedBounds as the visual rect for the begin/end transform item
447 // would normally be the sensible thing to do, but see comment above re:
448 // visual rects for drawing items and further rework in flight.
449 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation);
450
451 const DisplayItemList& displayItems = artifact.getDisplayItemList();
452 for (const auto& paintChunk : pendingLayer.paintChunks) {
453 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState;
454 PropertyTreeStateIterator iterator(*state);
455 Vector<PropertyTreeState> pairedStates;
456 for (; state && *state != pendingLayer.propertyTreeState;
457 state = iterator.next()) {
458 if (state->innermostNode() != PropertyTreeState::None)
459 pairedStates.push_back(*state);
460 }
461
462 // TODO(chrishtr): we can avoid some extra paired display items if
463 // multiple PaintChunks share them. We can also collapse clips between
464 // transforms into single clips in the same way that PaintLayerClipper does.
trchen 2016/12/22 22:21:24 Sharing is required for effect node, otherwise gro
chrishtr 2016/12/22 22:28:45 Sure, but it's not always possible.
465 Vector<EndDisplayItemType> endDisplayItems;
466
467 recordPairedBeginDisplayItems(pairedStates, pendingLayer.propertyTreeState,
468 *ccList.get(), endDisplayItems,
469 geometryMapper);
470
471 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk))
472 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get());
473
474 recordPairedEndDisplayItems(endDisplayItems, ccList.get());
475 }
476
477 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>();
478
479 ccList->Finalize();
480 return ccList;
481 }
482
295 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl> 483 std::unique_ptr<PaintArtifactCompositor::ContentLayerClientImpl>
296 PaintArtifactCompositor::clientForPaintChunk( 484 PaintArtifactCompositor::clientForPaintChunk(
297 const PaintChunk& paintChunk, 485 const PaintChunk& paintChunk,
298 const PaintArtifact& paintArtifact) { 486 const PaintArtifact& paintArtifact) {
299 // TODO(chrishtr): for now, just using a linear walk. In the future we can 487 // 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 488 // optimize this by using the same techniques used in PaintController for
301 // display lists. 489 // display lists.
302 for (auto& client : m_contentLayerClients) { 490 for (auto& client : m_contentLayerClients) {
303 if (client && client->matches(paintChunk)) 491 if (client && client->matches(paintChunk))
304 return std::move(client); 492 return std::move(client);
305 } 493 }
306 494
307 return WTF::wrapUnique(new ContentLayerClientImpl( 495 return WTF::wrapUnique(new ContentLayerClientImpl(
308 paintChunk.id 496 paintChunk.id
309 ? *paintChunk.id 497 ? *paintChunk.id
310 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); 498 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId()));
311 } 499 }
312 500
313 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( 501 scoped_refptr<cc::Layer>
502 PaintArtifactCompositor::compositedLayerForPendingLayer(
314 const PaintArtifact& paintArtifact, 503 const PaintArtifact& paintArtifact,
315 const PaintChunk& paintChunk, 504 const PendingLayer& pendingLayer,
316 gfx::Vector2dF& layerOffset, 505 gfx::Vector2dF& layerOffset,
317 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, 506 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients,
318 RasterInvalidationTracking* tracking, 507 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap,
319 bool storeDebugInfo) { 508 bool storeDebugInfo,
320 DCHECK(paintChunk.size()); 509 GeometryMapper& geometryMapper) {
510 DCHECK(pendingLayer.paintChunks.size());
511 const PaintChunk& firstPaintChunk = *pendingLayer.paintChunks[0];
512 DCHECK(firstPaintChunk.size());
513 #if DCHECK_IS_ON
514 for (const auto& paintChunk : pendingLayer.paintChunks) {
515 DCHECK(paintChunk.properties == firstPaintChunk.properties);
516 }
517 #endif
321 518
322 // If the paint chunk is a foreign layer, just return that layer. 519 // If the paint chunk is a foreign layer, just return that layer.
323 if (scoped_refptr<cc::Layer> foreignLayer = 520 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(
324 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) 521 paintArtifact, firstPaintChunk, layerOffset)) {
522 DCHECK(pendingLayer.paintChunks.size() == 1);
325 return foreignLayer; 523 return foreignLayer;
524 }
326 525
327 // The common case: create or reuse a PictureLayer for painted content. 526 // The common case: create or reuse a PictureLayer for painted content.
328 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = 527 std::unique_ptr<ContentLayerClientImpl> contentLayerClient =
329 clientForPaintChunk(paintChunk, paintArtifact); 528 clientForPaintChunk(firstPaintChunk, paintArtifact);
330 529
331 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); 530 gfx::Rect ccCombinedBounds(enclosingIntRect(pendingLayer.bounds));
trchen 2016/12/22 22:21:24 In PendingLayer::add it seemed to me pendingLayer.
chrishtr 2016/12/22 22:28:45 It's in the space of the transform node of the fir
332 scoped_refptr<cc::DisplayItemList> displayList = 531
333 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); 532 scoped_refptr<cc::DisplayItemList> displayList = recordPendingLayer(
533 paintArtifact, pendingLayer, ccCombinedBounds, geometryMapper);
334 contentLayerClient->SetDisplayList(std::move(displayList)); 534 contentLayerClient->SetDisplayList(std::move(displayList));
335 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); 535 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size()));
336 536
337 layerOffset = combinedBounds.OffsetFromOrigin(); 537 layerOffset = ccCombinedBounds.OffsetFromOrigin();
538
338 scoped_refptr<cc::PictureLayer> ccPictureLayer = 539 scoped_refptr<cc::PictureLayer> ccPictureLayer =
339 contentLayerClient->ccPictureLayer(); 540 contentLayerClient->ccPictureLayer();
340 ccPictureLayer->SetBounds(combinedBounds.size()); 541 ccPictureLayer->SetBounds(ccCombinedBounds.size());
341 ccPictureLayer->SetIsDrawable(true); 542 ccPictureLayer->SetIsDrawable(true);
342 if (paintChunk.knownToBeOpaque) 543 ccPictureLayer->SetContentsOpaque(pendingLayer.knownToBeOpaque);
343 ccPictureLayer->SetContentsOpaque(true); 544 contentLayerClient->clearPaintChunkDebugData();
344 DCHECK(!tracking ||
345 tracking->trackedRasterInvalidations.size() ==
346 paintChunk.rasterInvalidationRects.size());
347 545
348 contentLayerClient->clearPaintChunkDebugData(); 546 for (const auto& paintChunk : pendingLayer.paintChunks) {
349 if (storeDebugInfo) { 547 RasterInvalidationTracking* rasterTracking =
350 contentLayerClient->addPaintChunkDebugData( 548 trackingMap ? trackingMap->find(paintChunk) : nullptr;
351 paintArtifact.getDisplayItemList().subsequenceAsJSON( 549 DCHECK(!rasterTracking ||
352 paintChunk.beginIndex, paintChunk.endIndex, 550 rasterTracking->trackedRasterInvalidations.size() ==
353 DisplayItemList::SkipNonDrawings | 551 paintChunk->rasterInvalidationRects.size());
354 DisplayItemList::ShownOnlyDisplayItemTypes));
355 }
356 552
357 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); 553 if (storeDebugInfo) {
358 ++index) { 554 contentLayerClient->addPaintChunkDebugData(
359 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); 555 paintArtifact.getDisplayItemList().subsequenceAsJSON(
360 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), 556 paintChunk->beginIndex, paintChunk->endIndex,
361 std::max(0, rect.height())); 557 DisplayItemList::SkipNonDrawings |
362 // Raster paintChunk.rasterInvalidationRects is in the space of the 558 DisplayItemList::ShownOnlyDisplayItemTypes));
363 // containing transform node, so need to subtract off the layer offset. 559 }
364 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); 560
365 contentLayerClient->setNeedsDisplayRect( 561 for (unsigned index = 0; index < paintChunk->rasterInvalidationRects.size();
366 ccInvalidationRect, 562 ++index) {
367 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); 563 IntRect rect(
564 enclosingIntRect(paintChunk->rasterInvalidationRects[index]));
565 gfx::Rect ccInvalidationRect(rect.x(), rect.y(),
566 std::max(0, rect.width()),
567 std::max(0, rect.height()));
568 if (ccInvalidationRect.IsEmpty())
569 continue;
570 // Raster paintChunk.rasterInvalidationRects is in the space of the
571 // containing transform node, so need to subtract off the layer offset.
572 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin());
573 contentLayerClient->setNeedsDisplayRect(
574 ccInvalidationRect,
575 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index]
576 : nullptr);
577 }
368 } 578 }
369 579
370 newContentLayerClients.append(std::move(contentLayerClient)); 580 newContentLayerClients.append(std::move(contentLayerClient));
371 return ccPictureLayer; 581 return ccPictureLayer;
372 } 582 }
373 583
374 namespace { 584 namespace {
375 585
376 class PropertyTreeManager { 586 class PropertyTreeManager {
377 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); 587 WTF_MAKE_NONCOPYABLE(PropertyTreeManager);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 scrollTree().set_needs_update(true); 880 scrollTree().set_needs_update(true);
671 } 881 }
672 882
673 unsigned depth(const EffectPaintPropertyNode* node) { 883 unsigned depth(const EffectPaintPropertyNode* node) {
674 unsigned result = 0; 884 unsigned result = 0;
675 for (; node; node = node->parent()) 885 for (; node; node = node->parent())
676 result++; 886 result++;
677 return result; 887 return result;
678 } 888 }
679 889
890 // TODO(chrishtr): templatize this to avoid duplication of
891 // GeometryMapper::leastCommonAncestor.
680 const EffectPaintPropertyNode* lowestCommonAncestor( 892 const EffectPaintPropertyNode* lowestCommonAncestor(
681 const EffectPaintPropertyNode* nodeA, 893 const EffectPaintPropertyNode* nodeA,
682 const EffectPaintPropertyNode* nodeB) { 894 const EffectPaintPropertyNode* nodeB) {
683 // Optimized common case. 895 // Optimized common case.
684 if (nodeA == nodeB) 896 if (nodeA == nodeB)
685 return nodeA; 897 return nodeA;
686 898
687 unsigned depthA = depth(nodeA), depthB = depth(nodeB); 899 unsigned depthA = depth(nodeA), depthB = depth(nodeB);
688 while (depthA > depthB) { 900 while (depthA > depthB) {
689 nodeA = nodeA->parent(); 901 nodeA = nodeA->parent();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 996
785 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); 997 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber);
786 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); 998 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId);
787 dummyLayer->SetClipTreeIndex(outputClipId); 999 dummyLayer->SetClipTreeIndex(outputClipId);
788 dummyLayer->SetEffectTreeIndex(effectNode.id); 1000 dummyLayer->SetEffectTreeIndex(effectNode.id);
789 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); 1001 dummyLayer->SetScrollTreeIndex(kRealRootNodeId);
790 } 1002 }
791 1003
792 } // namespace 1004 } // namespace
793 1005
1006 bool PaintArtifactCompositor::canMergeInto(
1007 const PaintChunk& newChunk,
1008 const PendingLayer& candidatePendingLayer) {
1009 DCHECK(candidatePendingLayer.paintChunks.size() >= 1);
1010 PropertyTreeStateIterator iterator(newChunk.properties.propertyTreeState);
1011 for (const PropertyTreeState* currentState =
1012 &newChunk.properties.propertyTreeState;
1013 currentState; currentState = iterator.next()) {
1014 if (currentState->hasDirectCompositingReasons())
1015 return false;
1016 if (*currentState == candidatePendingLayer.propertyTreeState)
1017 return true;
1018 }
1019 return false;
1020 }
1021
1022 bool PaintArtifactCompositor::overlaps(
trchen 2016/12/22 22:21:24 nits: I think it should be named "possiblyOverlap"
chrishtr 2016/12/22 22:28:45 Done.
1023 const PaintChunk& paintChunk,
1024 const PendingLayer& candidatePendingLayer,
1025 GeometryMapper& geometryMapper) {
1026 // TODO(chrishtr): implement
1027 return true;
1028 }
1029
1030 PaintArtifactCompositor::PendingLayer::PendingLayer(
1031 const PaintChunk& firstPaintChunk)
1032 : knownToBeOpaque(true),
1033 backfaceHidden(firstPaintChunk.properties.backfaceHidden),
1034 propertyTreeState(firstPaintChunk.properties.propertyTreeState) {
1035 add(firstPaintChunk);
1036 }
1037
1038 void PaintArtifactCompositor::PendingLayer::add(const PaintChunk& paintChunk) {
1039 DCHECK(paintChunk.properties.backfaceHidden == backfaceHidden);
1040 paintChunks.append(&paintChunk);
1041 bounds.unite(paintChunk.bounds);
1042 knownToBeOpaque = knownToBeOpaque && paintChunk.knownToBeOpaque;
trchen 2016/12/22 22:21:24 This looks wrong. A layer is opaque as long as the
chrishtr 2016/12/22 22:28:45 Good point, will fix.
1043 }
1044
1045 void PaintArtifactCompositor::collectPendingLayers(
1046 const Vector<PaintChunk>& paintChunks,
1047 Vector<PendingLayer>& pendingLayers,
1048 GeometryMapper& geometryMapper) {
1049 // n = # of paint chunks. Memoizing canMergeInto() can get it to O(n^2), and
1050 // other heuristics can make worst-case behavior better.
1051 for (const PaintChunk& paintChunk : paintChunks) {
1052 bool createNew = true;
1053 for (Vector<PendingLayer>::reverse_iterator candidatePendingLayer =
1054 pendingLayers.rbegin();
1055 candidatePendingLayer != pendingLayers.rend();
1056 ++candidatePendingLayer) {
1057 if (canMergeInto(paintChunk, *candidatePendingLayer)) {
1058 candidatePendingLayer->add(paintChunk);
1059 createNew = false;
1060 break;
1061 }
1062 if (overlaps(paintChunk, *candidatePendingLayer, geometryMapper)) {
1063 break;
1064 }
1065 }
1066 if (createNew)
1067 pendingLayers.append(PendingLayer(paintChunk));
1068 }
1069 }
1070
794 void PaintArtifactCompositor::update( 1071 void PaintArtifactCompositor::update(
795 const PaintArtifact& paintArtifact, 1072 const PaintArtifact& paintArtifact,
796 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, 1073 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations,
797 bool storeDebugInfo) { 1074 bool storeDebugInfo) {
798 DCHECK(m_rootLayer); 1075 DCHECK(m_rootLayer);
799 1076
800 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); 1077 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree();
801 1078
802 // The tree will be null after detaching and this update can be ignored. 1079 // The tree will be null after detaching and this update can be ignored.
803 // See: WebViewImpl::detachPaintArtifactCompositor(). 1080 // See: WebViewImpl::detachPaintArtifactCompositor().
804 if (!layerTree) 1081 if (!layerTree)
805 return; 1082 return;
806 1083
807 if (m_extraDataForTestingEnabled) 1084 if (m_extraDataForTestingEnabled)
808 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); 1085 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting);
809 1086
810 m_rootLayer->RemoveAllChildren(); 1087 m_rootLayer->RemoveAllChildren();
811 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); 1088 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber);
812 1089
813 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), 1090 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(),
814 m_rootLayer.get()); 1091 m_rootLayer.get());
815 1092
1093 Vector<PendingLayer, 0> pendingLayers;
1094 GeometryMapper geometryMapper;
1095 collectPendingLayers(paintArtifact.paintChunks(), pendingLayers,
1096 geometryMapper);
1097
816 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; 1098 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients;
817 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); 1099 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size());
818 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { 1100 for (const PendingLayer& pendingLayer : pendingLayers) {
819 gfx::Vector2dF layerOffset; 1101 gfx::Vector2dF layerOffset;
820 scoped_refptr<cc::Layer> layer = layerForPaintChunk( 1102 scoped_refptr<cc::Layer> layer = compositedLayerForPendingLayer(
821 paintArtifact, paintChunk, layerOffset, newContentLayerClients, 1103 paintArtifact, pendingLayer, layerOffset, newContentLayerClients,
822 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) 1104 rasterChunkInvalidations, storeDebugInfo, geometryMapper);
823 : nullptr,
824 storeDebugInfo);
825 1105
826 int transformId = propertyTreeManager.compositorIdForTransformNode( 1106 int transformId = propertyTreeManager.compositorIdForTransformNode(
827 paintChunk.properties.propertyTreeState.transform()); 1107 pendingLayer.propertyTreeState.transform());
828 int scrollId = propertyTreeManager.compositorIdForScrollNode( 1108 int scrollId = propertyTreeManager.compositorIdForScrollNode(
829 paintChunk.properties.propertyTreeState.scroll()); 1109 pendingLayer.propertyTreeState.scroll());
830 int clipId = propertyTreeManager.compositorIdForClipNode( 1110 int clipId = propertyTreeManager.compositorIdForClipNode(
831 paintChunk.properties.propertyTreeState.clip()); 1111 pendingLayer.propertyTreeState.clip());
832 int effectId = propertyTreeManager.switchToEffectNode( 1112 int effectId = propertyTreeManager.switchToEffectNode(
833 *paintChunk.properties.propertyTreeState.effect()); 1113 *pendingLayer.propertyTreeState.effect());
834 1114
835 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); 1115 propertyTreeManager.updateScrollOffset(layer->id(), scrollId);
836 1116
837 layer->set_offset_to_transform_parent(layerOffset); 1117 layer->set_offset_to_transform_parent(layerOffset);
838 1118
839 m_rootLayer->AddChild(layer); 1119 m_rootLayer->AddChild(layer);
840 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); 1120 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber);
841 layer->SetTransformTreeIndex(transformId); 1121 layer->SetTransformTreeIndex(transformId);
842 layer->SetClipTreeIndex(clipId); 1122 layer->SetClipTreeIndex(clipId);
843 layer->SetEffectTreeIndex(effectId); 1123 layer->SetEffectTreeIndex(effectId);
844 layer->SetScrollTreeIndex(scrollId); 1124 layer->SetScrollTreeIndex(scrollId);
845 1125
846 // TODO(jbroman): This probably shouldn't be necessary, but it is still 1126 // TODO(jbroman): This probably shouldn't be necessary, but it is still
847 // queried by RenderSurfaceImpl. 1127 // queried by RenderSurfaceImpl.
848 layer->Set3dSortingContextId(layerTree->property_trees() 1128 layer->Set3dSortingContextId(layerTree->property_trees()
849 ->transform_tree.Node(transformId) 1129 ->transform_tree.Node(transformId)
850 ->sorting_context_id); 1130 ->sorting_context_id);
851 1131
852 layer->SetShouldCheckBackfaceVisibility( 1132 layer->SetShouldCheckBackfaceVisibility(pendingLayer.backfaceHidden);
853 paintChunk.properties.backfaceHidden);
854 1133
855 if (m_extraDataForTestingEnabled) 1134 if (m_extraDataForTestingEnabled)
856 m_extraDataForTesting->contentLayers.append(layer); 1135 m_extraDataForTesting->contentLayers.append(layer);
857 } 1136 }
858 m_contentLayerClients.clear(); 1137 m_contentLayerClients.clear();
859 m_contentLayerClients.swap(newContentLayerClients); 1138 m_contentLayerClients.swap(newContentLayerClients);
860 1139
861 // Mark the property trees as having been rebuilt. 1140 // Mark the property trees as having been rebuilt.
862 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; 1141 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber;
863 layerTree->property_trees()->needs_rebuild = false; 1142 layerTree->property_trees()->needs_rebuild = false;
864 layerTree->property_trees()->ResetCachedData(); 1143 layerTree->property_trees()->ResetCachedData();
865 } 1144 }
866 1145
867 } // namespace blink 1146 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698