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

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

Powered by Google App Engine
This is Rietveld 408576698