OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 73 |
74 struct PaintInvalidationInfo { | 74 struct PaintInvalidationInfo { |
75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
76 // This is for comparison only. Don't dereference because the client may hav e died. | 76 // This is for comparison only. Don't dereference because the client may hav e died. |
77 const DisplayItemClient* client; | 77 const DisplayItemClient* client; |
78 String clientDebugName; | 78 String clientDebugName; |
79 IntRect rect; | 79 IntRect rect; |
80 PaintInvalidationReason reason; | 80 PaintInvalidationReason reason; |
81 }; | 81 }; |
82 | 82 |
83 #if DCHECK_IS_ON() | |
84 struct UnderPaintInvalidation { | 83 struct UnderPaintInvalidation { |
85 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 84 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
86 int x; | 85 int x; |
87 int y; | 86 int y; |
88 SkColor oldPixel; | 87 SkColor oldPixel; |
89 SkColor newPixel; | 88 SkColor newPixel; |
90 }; | 89 }; |
91 #endif | |
92 | 90 |
93 struct PaintInvalidationTracking { | 91 struct PaintInvalidationTracking { |
94 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 92 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
95 Vector<PaintInvalidationInfo> trackedPaintInvalidations; | 93 Vector<PaintInvalidationInfo> trackedPaintInvalidations; |
96 #if DCHECK_IS_ON() | |
97 RefPtr<SkPicture> lastPaintedPicture; | 94 RefPtr<SkPicture> lastPaintedPicture; |
98 Region paintInvalidationRegionSinceLastPaint; | 95 Region paintInvalidationRegionSinceLastPaint; |
pdr.
2016/09/01 16:48:52
Region is a huge datastructure. Do we need to worr
Xianzhu
2016/09/01 17:00:03
I don't think we need to worry memory because the
| |
99 Vector<UnderPaintInvalidation> underPaintInvalidations; | 96 Vector<UnderPaintInvalidation> underPaintInvalidations; |
pdr.
2016/09/01 16:48:52
To save memory can you make this vector small by d
| |
100 #endif | |
101 }; | 97 }; |
102 | 98 |
103 typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> PaintInvalidati onTrackingMap; | 99 typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> PaintInvalidati onTrackingMap; |
104 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() | 100 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() |
105 { | 101 { |
106 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); | 102 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); |
107 return map; | 103 return map; |
108 } | 104 } |
109 | 105 |
110 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client ) | 106 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client ) |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 | 325 |
330 IntRect GraphicsLayer::interestRect() | 326 IntRect GraphicsLayer::interestRect() |
331 { | 327 { |
332 return m_previousInterestRect; | 328 return m_previousInterestRect; |
333 } | 329 } |
334 | 330 |
335 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode) | 331 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode) |
336 { | 332 { |
337 if (paintWithoutCommit(interestRect, disabledMode)) { | 333 if (paintWithoutCommit(interestRect, disabledMode)) { |
338 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation()); | 334 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation()); |
339 #if DCHECK_IS_ON() | 335 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
340 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnable d()) { | |
341 RefPtr<SkPicture> newPicture = capturePicture(); | 336 RefPtr<SkPicture> newPicture = capturePicture(); |
342 checkPaintUnderInvalidations(*newPicture); | 337 checkPaintUnderInvalidations(*newPicture); |
343 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap() .add(this, PaintInvalidationTracking()).storedValue->value; | 338 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap() .add(this, PaintInvalidationTracking()).storedValue->value; |
344 tracking.lastPaintedPicture = newPicture; | 339 tracking.lastPaintedPicture = newPicture; |
345 tracking.paintInvalidationRegionSinceLastPaint = Region(); | 340 tracking.paintInvalidationRegionSinceLastPaint = Region(); |
346 } | 341 } |
347 #endif | |
348 } | 342 } |
349 } | 343 } |
350 | 344 |
351 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode) | 345 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode) |
352 { | 346 { |
353 ASSERT(drawsContent()); | 347 ASSERT(drawsContent()); |
354 | 348 |
355 if (!m_client) | 349 if (!m_client) |
356 return false; | 350 return false; |
357 if (firstPaintInvalidationTrackingEnabled()) | 351 if (firstPaintInvalidationTrackingEnabled()) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 resetTrackedPaintInvalidations(); | 541 resetTrackedPaintInvalidations(); |
548 m_isTrackingPaintInvalidations = tracksPaintInvalidations; | 542 m_isTrackingPaintInvalidations = tracksPaintInvalidations; |
549 } | 543 } |
550 | 544 |
551 void GraphicsLayer::resetTrackedPaintInvalidations() | 545 void GraphicsLayer::resetTrackedPaintInvalidations() |
552 { | 546 { |
553 auto it = paintInvalidationTrackingMap().find(this); | 547 auto it = paintInvalidationTrackingMap().find(this); |
554 if (it == paintInvalidationTrackingMap().end()) | 548 if (it == paintInvalidationTrackingMap().end()) |
555 return; | 549 return; |
556 | 550 |
557 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) | 551 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) |
558 it->value.trackedPaintInvalidations.clear(); | 552 it->value.trackedPaintInvalidations.clear(); |
559 else | 553 else |
560 paintInvalidationTrackingMap().remove(it); | 554 paintInvalidationTrackingMap().remove(it); |
561 } | 555 } |
562 | 556 |
563 bool GraphicsLayer::hasTrackedPaintInvalidations() const | 557 bool GraphicsLayer::hasTrackedPaintInvalidations() const |
564 { | 558 { |
565 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); | 559 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); |
566 if (it != paintInvalidationTrackingMap().end()) | 560 if (it != paintInvalidationTrackingMap().end()) |
567 return !it->value.trackedPaintInvalidations.isEmpty(); | 561 return !it->value.trackedPaintInvalidations.isEmpty(); |
568 return false; | 562 return false; |
569 } | 563 } |
570 | 564 |
571 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t IntRect& rect, PaintInvalidationReason reason) | 565 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t IntRect& rect, PaintInvalidationReason reason) |
572 { | 566 { |
573 if (!isTrackingOrCheckingPaintInvalidations() || rect.isEmpty()) | 567 if (!isTrackingOrCheckingPaintInvalidations() || rect.isEmpty()) |
574 return; | 568 return; |
575 | 569 |
576 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(thi s, PaintInvalidationTracking()).storedValue->value; | 570 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(thi s, PaintInvalidationTracking()).storedValue->value; |
577 | 571 |
578 if (m_isTrackingPaintInvalidations) { | 572 if (m_isTrackingPaintInvalidations) { |
579 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason }; | 573 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason }; |
580 tracking.trackedPaintInvalidations.append(info); | 574 tracking.trackedPaintInvalidations.append(info); |
581 } | 575 } |
582 | 576 |
583 #if DCHECK_IS_ON() | 577 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
584 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) { | |
585 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint invalidation rect. | 578 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint invalidation rect. |
586 IntRect r = rect; | 579 IntRect r = rect; |
587 r.inflate(1); | 580 r.inflate(1); |
588 tracking.paintInvalidationRegionSinceLastPaint.unite(r); | 581 tracking.paintInvalidationRegionSinceLastPaint.unite(r); |
589 } | 582 } |
590 #endif | |
591 } | 583 } |
592 | 584 |
593 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b) | 585 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b) |
594 { | 586 { |
595 // Sort by rect first, bigger rects before smaller ones. | 587 // Sort by rect first, bigger rects before smaller ones. |
596 if (a.rect.width() != b.rect.width()) | 588 if (a.rect.width() != b.rect.width()) |
597 return a.rect.width() > b.rect.width(); | 589 return a.rect.width() > b.rect.width(); |
598 if (a.rect.height() != b.rect.height()) | 590 if (a.rect.height() != b.rect.height()) |
599 return a.rect.height() > b.rect.height(); | 591 return a.rect.height() > b.rect.height(); |
600 if (a.rect.x() != b.rect.x()) | 592 if (a.rect.x() != b.rect.x()) |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1246 if (WebLayer* layer = platformLayer()) | 1238 if (WebLayer* layer = platformLayer()) |
1247 layer->setElementId(id); | 1239 layer->setElementId(id); |
1248 } | 1240 } |
1249 | 1241 |
1250 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) | 1242 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) |
1251 { | 1243 { |
1252 if (WebLayer* layer = platformLayer()) | 1244 if (WebLayer* layer = platformLayer()) |
1253 layer->setCompositorMutableProperties(properties); | 1245 layer->setCompositorMutableProperties(properties); |
1254 } | 1246 } |
1255 | 1247 |
1256 #if DCHECK_IS_ON() | |
1257 | |
1258 PassRefPtr<SkPicture> GraphicsLayer::capturePicture() | 1248 PassRefPtr<SkPicture> GraphicsLayer::capturePicture() |
1259 { | 1249 { |
1260 if (!drawsContent()) | 1250 if (!drawsContent()) |
1261 return nullptr; | 1251 return nullptr; |
1262 | 1252 |
1263 IntSize intSize = expandedIntSize(size()); | 1253 IntSize intSize = expandedIntSize(size()); |
1264 GraphicsContext graphicsContext(getPaintController()); | 1254 GraphicsContext graphicsContext(getPaintController()); |
1265 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize)); | 1255 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize)); |
1266 getPaintController().paintArtifact().replay(graphicsContext); | 1256 getPaintController().paintArtifact().replay(graphicsContext); |
1267 return graphicsContext.endRecording(); | 1257 return graphicsContext.endRecording(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 | 1325 |
1336 // Visualize under-invalidations by overlaying the new bitmap (containing re d pixels indicating under-invalidations, | 1326 // Visualize under-invalidations by overlaying the new bitmap (containing re d pixels indicating under-invalidations, |
1337 // and transparent pixels otherwise) onto the painting. | 1327 // and transparent pixels otherwise) onto the painting. |
1338 SkPictureRecorder recorder; | 1328 SkPictureRecorder recorder; |
1339 recorder.beginRecording(width, height); | 1329 recorder.beginRecording(width, height); |
1340 recorder.getRecordingCanvas()->drawBitmap(newBitmap, 0, 0); | 1330 recorder.getRecordingCanvas()->drawBitmap(newBitmap, 0, 0); |
1341 RefPtr<SkPicture> picture = fromSkSp(recorder.finishRecordingAsPicture()); | 1331 RefPtr<SkPicture> picture = fromSkSp(recorder.finishRecordingAsPicture()); |
1342 getPaintController().appendDebugDrawingAfterCommit(*this, picture, offsetFro mLayoutObjectWithSubpixelAccumulation()); | 1332 getPaintController().appendDebugDrawingAfterCommit(*this, picture, offsetFro mLayoutObjectWithSubpixelAccumulation()); |
1343 } | 1333 } |
1344 | 1334 |
1345 #endif // DCHECK_IS_ON() | |
1346 | |
1347 } // namespace blink | 1335 } // namespace blink |
1348 | 1336 |
1349 #ifndef NDEBUG | 1337 #ifndef NDEBUG |
1350 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) | 1338 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) |
1351 { | 1339 { |
1352 if (!layer) { | 1340 if (!layer) { |
1353 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1341 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
1354 return; | 1342 return; |
1355 } | 1343 } |
1356 | 1344 |
1357 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1345 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
1358 fprintf(stderr, "%s\n", output.utf8().data()); | 1346 fprintf(stderr, "%s\n", output.utf8().data()); |
1359 } | 1347 } |
1360 #endif | 1348 #endif |
OLD | NEW |