| 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 24 matching lines...) Expand all Loading... |
| 35 #include "platform/geometry/LayoutRect.h" | 35 #include "platform/geometry/LayoutRect.h" |
| 36 #include "platform/geometry/Region.h" | 36 #include "platform/geometry/Region.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
| 38 #include "platform/graphics/CompositorFilterOperations.h" | 38 #include "platform/graphics/CompositorFilterOperations.h" |
| 39 #include "platform/graphics/FirstPaintInvalidationTracking.h" | 39 #include "platform/graphics/FirstPaintInvalidationTracking.h" |
| 40 #include "platform/graphics/GraphicsContext.h" | 40 #include "platform/graphics/GraphicsContext.h" |
| 41 #include "platform/graphics/Image.h" | 41 #include "platform/graphics/Image.h" |
| 42 #include "platform/graphics/LinkHighlight.h" | 42 #include "platform/graphics/LinkHighlight.h" |
| 43 #include "platform/graphics/paint/DrawingRecorder.h" | 43 #include "platform/graphics/paint/DrawingRecorder.h" |
| 44 #include "platform/graphics/paint/PaintController.h" | 44 #include "platform/graphics/paint/PaintController.h" |
| 45 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
| 45 #include "platform/json/JSONValues.h" | 46 #include "platform/json/JSONValues.h" |
| 46 #include "platform/scroll/ScrollableArea.h" | 47 #include "platform/scroll/ScrollableArea.h" |
| 47 #include "platform/text/TextStream.h" | 48 #include "platform/text/TextStream.h" |
| 48 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 49 #include "public/platform/WebCompositorSupport.h" | 50 #include "public/platform/WebCompositorSupport.h" |
| 50 #include "public/platform/WebFloatPoint.h" | 51 #include "public/platform/WebFloatPoint.h" |
| 51 #include "public/platform/WebFloatRect.h" | 52 #include "public/platform/WebFloatRect.h" |
| 52 #include "public/platform/WebLayer.h" | 53 #include "public/platform/WebLayer.h" |
| 53 #include "public/platform/WebPoint.h" | 54 #include "public/platform/WebPoint.h" |
| 54 #include "public/platform/WebSize.h" | 55 #include "public/platform/WebSize.h" |
| 55 #include "wtf/CurrentTime.h" | 56 #include "wtf/CurrentTime.h" |
| 56 #include "wtf/HashMap.h" | 57 #include "wtf/HashMap.h" |
| 57 #include "wtf/HashSet.h" | 58 #include "wtf/HashSet.h" |
| 58 #include "wtf/MathExtras.h" | 59 #include "wtf/MathExtras.h" |
| 59 #include "wtf/PtrUtil.h" | 60 #include "wtf/PtrUtil.h" |
| 60 #include "wtf/text/StringUTF8Adaptor.h" | 61 #include "wtf/text/StringUTF8Adaptor.h" |
| 61 #include "wtf/text/WTFString.h" | 62 #include "wtf/text/WTFString.h" |
| 62 #include <algorithm> | 63 #include <algorithm> |
| 63 #include <cmath> | 64 #include <cmath> |
| 64 #include <memory> | 65 #include <memory> |
| 65 #include <utility> | 66 #include <utility> |
| 66 | 67 |
| 67 #ifndef NDEBUG | 68 #ifndef NDEBUG |
| 68 #include <stdio.h> | 69 #include <stdio.h> |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 namespace blink { | 72 namespace blink { |
| 72 | 73 |
| 73 struct PaintInvalidationInfo { | 74 template class RasterInvalidationTrackingMap<const GraphicsLayer>; |
| 74 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 75 static RasterInvalidationTrackingMap<const GraphicsLayer>& |
| 75 // This is for comparison only. Don't dereference because the client may have
died. | 76 rasterInvalidationTrackingMap() { |
| 76 const DisplayItemClient* client; | 77 DEFINE_STATIC_LOCAL(RasterInvalidationTrackingMap<const GraphicsLayer>, map, |
| 77 String clientDebugName; | 78 ()); |
| 78 IntRect rect; | |
| 79 PaintInvalidationReason reason; | |
| 80 }; | |
| 81 | |
| 82 struct UnderPaintInvalidation { | |
| 83 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 84 int x; | |
| 85 int y; | |
| 86 SkColor oldPixel; | |
| 87 SkColor newPixel; | |
| 88 }; | |
| 89 | |
| 90 struct PaintInvalidationTracking { | |
| 91 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 92 Vector<PaintInvalidationInfo> trackedPaintInvalidations; | |
| 93 sk_sp<SkPicture> lastPaintedPicture; | |
| 94 IntRect lastInterestRect; | |
| 95 Region paintInvalidationRegionSinceLastPaint; | |
| 96 Vector<UnderPaintInvalidation> underPaintInvalidations; | |
| 97 }; | |
| 98 | |
| 99 typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> | |
| 100 PaintInvalidationTrackingMap; | |
| 101 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() { | |
| 102 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); | |
| 103 return map; | 79 return map; |
| 104 } | 80 } |
| 105 | 81 |
| 106 std::unique_ptr<GraphicsLayer> GraphicsLayer::create( | 82 std::unique_ptr<GraphicsLayer> GraphicsLayer::create( |
| 107 GraphicsLayerClient* client) { | 83 GraphicsLayerClient* client) { |
| 108 return wrapUnique(new GraphicsLayer(client)); | 84 return wrapUnique(new GraphicsLayer(client)); |
| 109 } | 85 } |
| 110 | 86 |
| 111 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) | 87 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) |
| 112 : m_client(client), | 88 : m_client(client), |
| 113 m_backgroundColor(Color::transparent), | 89 m_backgroundColor(Color::transparent), |
| 114 m_opacity(1), | 90 m_opacity(1), |
| 115 m_blendMode(WebBlendModeNormal), | 91 m_blendMode(WebBlendModeNormal), |
| 116 m_hasTransformOrigin(false), | 92 m_hasTransformOrigin(false), |
| 117 m_contentsOpaque(false), | 93 m_contentsOpaque(false), |
| 118 m_shouldFlattenTransform(true), | 94 m_shouldFlattenTransform(true), |
| 119 m_backfaceVisibility(true), | 95 m_backfaceVisibility(true), |
| 120 m_drawsContent(false), | 96 m_drawsContent(false), |
| 121 m_contentsVisible(true), | 97 m_contentsVisible(true), |
| 122 m_isRootForIsolatedGroup(false), | 98 m_isRootForIsolatedGroup(false), |
| 123 m_hasScrollParent(false), | 99 m_hasScrollParent(false), |
| 124 m_hasClipParent(false), | 100 m_hasClipParent(false), |
| 125 m_painted(false), | 101 m_painted(false), |
| 126 m_isTrackingPaintInvalidations(client && | 102 m_isTrackingRasterInvalidations(client && |
| 127 client->isTrackingPaintInvalidations()), | 103 client->isTrackingRasterInvalidations()), |
| 128 m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip), | 104 m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip), |
| 129 m_parent(0), | 105 m_parent(0), |
| 130 m_maskLayer(0), | 106 m_maskLayer(0), |
| 131 m_contentsClippingMaskLayer(0), | 107 m_contentsClippingMaskLayer(0), |
| 132 m_paintCount(0), | 108 m_paintCount(0), |
| 133 m_contentsLayer(0), | 109 m_contentsLayer(0), |
| 134 m_contentsLayerId(0), | 110 m_contentsLayerId(0), |
| 135 m_scrollableArea(nullptr), | 111 m_scrollableArea(nullptr), |
| 136 m_renderingContext3d(0) { | 112 m_renderingContext3d(0) { |
| 137 #if ENABLE(ASSERT) | 113 #if ENABLE(ASSERT) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 m_linkHighlights.clear(); | 129 m_linkHighlights.clear(); |
| 154 | 130 |
| 155 #if ENABLE(ASSERT) | 131 #if ENABLE(ASSERT) |
| 156 if (m_client) | 132 if (m_client) |
| 157 m_client->verifyNotPainting(); | 133 m_client->verifyNotPainting(); |
| 158 #endif | 134 #endif |
| 159 | 135 |
| 160 removeAllChildren(); | 136 removeAllChildren(); |
| 161 removeFromParent(); | 137 removeFromParent(); |
| 162 | 138 |
| 163 paintInvalidationTrackingMap().remove(this); | 139 rasterInvalidationTrackingMap().remove(this); |
| 164 ASSERT(!m_parent); | 140 ASSERT(!m_parent); |
| 165 } | 141 } |
| 166 | 142 |
| 167 LayoutRect GraphicsLayer::visualRect() const { | 143 LayoutRect GraphicsLayer::visualRect() const { |
| 168 LayoutRect bounds = LayoutRect(FloatPoint(), size()); | 144 LayoutRect bounds = LayoutRect(FloatPoint(), size()); |
| 169 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation()); | 145 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation()); |
| 170 return bounds; | 146 return bounds; |
| 171 } | 147 } |
| 172 | 148 |
| 173 void GraphicsLayer::setHasWillChangeTransformHint(bool hasWillChangeTransform) { | 149 void GraphicsLayer::setHasWillChangeTransformHint(bool hasWillChangeTransform) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 273 } |
| 298 | 274 |
| 299 void GraphicsLayer::paint(const IntRect* interestRect, | 275 void GraphicsLayer::paint(const IntRect* interestRect, |
| 300 GraphicsContext::DisabledMode disabledMode) { | 276 GraphicsContext::DisabledMode disabledMode) { |
| 301 if (paintWithoutCommit(interestRect, disabledMode)) { | 277 if (paintWithoutCommit(interestRect, disabledMode)) { |
| 302 getPaintController().commitNewDisplayItems( | 278 getPaintController().commitNewDisplayItems( |
| 303 offsetFromLayoutObjectWithSubpixelAccumulation()); | 279 offsetFromLayoutObjectWithSubpixelAccumulation()); |
| 304 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 280 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
| 305 sk_sp<SkPicture> newPicture = capturePicture(); | 281 sk_sp<SkPicture> newPicture = capturePicture(); |
| 306 checkPaintUnderInvalidations(*newPicture); | 282 checkPaintUnderInvalidations(*newPicture); |
| 307 PaintInvalidationTracking& tracking = | 283 RasterInvalidationTracking& tracking = |
| 308 paintInvalidationTrackingMap() | 284 rasterInvalidationTrackingMap().add(this); |
| 309 .add(this, PaintInvalidationTracking()) | |
| 310 .storedValue->value; | |
| 311 tracking.lastPaintedPicture = std::move(newPicture); | 285 tracking.lastPaintedPicture = std::move(newPicture); |
| 312 tracking.lastInterestRect = m_previousInterestRect; | 286 tracking.lastInterestRect = m_previousInterestRect; |
| 313 tracking.paintInvalidationRegionSinceLastPaint = Region(); | 287 tracking.rasterInvalidationRegionSinceLastPaint = Region(); |
| 314 } | 288 } |
| 315 } | 289 } |
| 316 } | 290 } |
| 317 | 291 |
| 318 bool GraphicsLayer::paintWithoutCommit( | 292 bool GraphicsLayer::paintWithoutCommit( |
| 319 const IntRect* interestRect, | 293 const IntRect* interestRect, |
| 320 GraphicsContext::DisabledMode disabledMode) { | 294 GraphicsContext::DisabledMode disabledMode) { |
| 321 ASSERT(drawsContent()); | 295 ASSERT(drawsContent()); |
| 322 | 296 |
| 323 if (!m_client) | 297 if (!m_client) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 475 |
| 502 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() { | 476 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() { |
| 503 return m_debugInfo; | 477 return m_debugInfo; |
| 504 } | 478 } |
| 505 | 479 |
| 506 WebLayer* GraphicsLayer::contentsLayerIfRegistered() { | 480 WebLayer* GraphicsLayer::contentsLayerIfRegistered() { |
| 507 clearContentsLayerIfUnregistered(); | 481 clearContentsLayerIfUnregistered(); |
| 508 return m_contentsLayer; | 482 return m_contentsLayer; |
| 509 } | 483 } |
| 510 | 484 |
| 511 void GraphicsLayer::setTracksPaintInvalidations(bool tracksPaintInvalidations) { | 485 void GraphicsLayer::setTracksRasterInvalidations( |
| 512 resetTrackedPaintInvalidations(); | 486 bool tracksRasterInvalidations) { |
| 513 m_isTrackingPaintInvalidations = tracksPaintInvalidations; | 487 resetTrackedRasterInvalidations(); |
| 488 m_isTrackingRasterInvalidations = tracksRasterInvalidations; |
| 514 } | 489 } |
| 515 | 490 |
| 516 void GraphicsLayer::resetTrackedPaintInvalidations() { | 491 void GraphicsLayer::resetTrackedRasterInvalidations() { |
| 517 auto it = paintInvalidationTrackingMap().find(this); | 492 RasterInvalidationTracking* tracking = |
| 518 if (it == paintInvalidationTrackingMap().end()) | 493 rasterInvalidationTrackingMap().find(this); |
| 494 if (!tracking) |
| 519 return; | 495 return; |
| 520 | 496 |
| 521 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) | 497 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) |
| 522 it->value.trackedPaintInvalidations.clear(); | 498 tracking->trackedRasterInvalidations.clear(); |
| 523 else | 499 else |
| 524 paintInvalidationTrackingMap().remove(it); | 500 rasterInvalidationTrackingMap().remove(this); |
| 525 } | 501 } |
| 526 | 502 |
| 527 bool GraphicsLayer::hasTrackedPaintInvalidations() const { | 503 bool GraphicsLayer::hasTrackedRasterInvalidations() const { |
| 528 PaintInvalidationTrackingMap::iterator it = | 504 RasterInvalidationTracking* tracking = |
| 529 paintInvalidationTrackingMap().find(this); | 505 rasterInvalidationTrackingMap().find(this); |
| 530 if (it != paintInvalidationTrackingMap().end()) | 506 if (tracking) |
| 531 return !it->value.trackedPaintInvalidations.isEmpty(); | 507 return !tracking->trackedRasterInvalidations.isEmpty(); |
| 532 return false; | 508 return false; |
| 533 } | 509 } |
| 534 | 510 |
| 535 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, | 511 void GraphicsLayer::trackRasterInvalidation(const DisplayItemClient& client, |
| 536 const IntRect& rect, | 512 const IntRect& rect, |
| 537 PaintInvalidationReason reason) { | 513 PaintInvalidationReason reason) { |
| 538 if (!isTrackingOrCheckingPaintInvalidations() || rect.isEmpty()) | 514 if (!isTrackingOrCheckingRasterInvalidations() || rect.isEmpty()) |
| 539 return; | 515 return; |
| 540 | 516 |
| 541 PaintInvalidationTracking& tracking = | 517 RasterInvalidationTracking& tracking = |
| 542 paintInvalidationTrackingMap() | 518 rasterInvalidationTrackingMap().add(this); |
| 543 .add(this, PaintInvalidationTracking()) | |
| 544 .storedValue->value; | |
| 545 | 519 |
| 546 if (m_isTrackingPaintInvalidations) { | 520 if (m_isTrackingRasterInvalidations) { |
| 547 PaintInvalidationInfo info = {&client, client.debugName(), rect, reason}; | 521 RasterInvalidationInfo info; |
| 548 tracking.trackedPaintInvalidations.append(info); | 522 info.client = &client; |
| 523 info.clientDebugName = client.debugName(); |
| 524 info.rect = rect; |
| 525 info.reason = reason; |
| 526 tracking.trackedRasterInvalidations.append(info); |
| 549 } | 527 } |
| 550 | 528 |
| 551 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 529 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
| 552 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint inv
alidation rect. | 530 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint inv
alidation rect. |
| 553 IntRect r = rect; | 531 IntRect r = rect; |
| 554 r.inflate(1); | 532 r.inflate(1); |
| 555 tracking.paintInvalidationRegionSinceLastPaint.unite(r); | 533 tracking.rasterInvalidationRegionSinceLastPaint.unite(r); |
| 556 } | 534 } |
| 557 } | 535 } |
| 558 | 536 |
| 559 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, | |
| 560 const PaintInvalidationInfo& b) { | |
| 561 // Sort by rect first, bigger rects before smaller ones. | |
| 562 if (a.rect.width() != b.rect.width()) | |
| 563 return a.rect.width() > b.rect.width(); | |
| 564 if (a.rect.height() != b.rect.height()) | |
| 565 return a.rect.height() > b.rect.height(); | |
| 566 if (a.rect.x() != b.rect.x()) | |
| 567 return a.rect.x() > b.rect.x(); | |
| 568 if (a.rect.y() != b.rect.y()) | |
| 569 return a.rect.y() > b.rect.y(); | |
| 570 | |
| 571 // Then compare clientDebugName, in alphabetic order. | |
| 572 int nameCompareResult = | |
| 573 codePointCompare(a.clientDebugName, b.clientDebugName); | |
| 574 if (nameCompareResult != 0) | |
| 575 return nameCompareResult < 0; | |
| 576 | |
| 577 return a.reason < b.reason; | |
| 578 } | |
| 579 | |
| 580 template <typename T> | 537 template <typename T> |
| 581 static std::unique_ptr<JSONArray> pointAsJSONArray(const T& point) { | 538 static std::unique_ptr<JSONArray> pointAsJSONArray(const T& point) { |
| 582 std::unique_ptr<JSONArray> array = JSONArray::create(); | 539 std::unique_ptr<JSONArray> array = JSONArray::create(); |
| 583 array->pushDouble(point.x()); | 540 array->pushDouble(point.x()); |
| 584 array->pushDouble(point.y()); | 541 array->pushDouble(point.y()); |
| 585 return array; | 542 return array; |
| 586 } | 543 } |
| 587 | 544 |
| 588 template <typename T> | 545 template <typename T> |
| 589 static std::unique_ptr<JSONArray> sizeAsJSONArray(const T& size) { | 546 static std::unique_ptr<JSONArray> sizeAsJSONArray(const T& size) { |
| 590 std::unique_ptr<JSONArray> array = JSONArray::create(); | 547 std::unique_ptr<JSONArray> array = JSONArray::create(); |
| 591 array->pushDouble(size.width()); | 548 array->pushDouble(size.width()); |
| 592 array->pushDouble(size.height()); | 549 array->pushDouble(size.height()); |
| 593 return array; | 550 return array; |
| 594 } | 551 } |
| 595 | 552 |
| 596 template <typename T> | |
| 597 static std::unique_ptr<JSONArray> rectAsJSONArray(const T& rect) { | |
| 598 std::unique_ptr<JSONArray> array = JSONArray::create(); | |
| 599 array->pushDouble(rect.x()); | |
| 600 array->pushDouble(rect.y()); | |
| 601 array->pushDouble(rect.width()); | |
| 602 array->pushDouble(rect.height()); | |
| 603 return array; | |
| 604 } | |
| 605 | |
| 606 static double roundCloseToZero(double number) { | 553 static double roundCloseToZero(double number) { |
| 607 return std::abs(number) < 1e-7 ? 0 : number; | 554 return std::abs(number) < 1e-7 ? 0 : number; |
| 608 } | 555 } |
| 609 | 556 |
| 610 static std::unique_ptr<JSONArray> transformAsJSONArray( | 557 static std::unique_ptr<JSONArray> transformAsJSONArray( |
| 611 const TransformationMatrix& t) { | 558 const TransformationMatrix& t) { |
| 612 std::unique_ptr<JSONArray> array = JSONArray::create(); | 559 std::unique_ptr<JSONArray> array = JSONArray::create(); |
| 613 { | 560 { |
| 614 std::unique_ptr<JSONArray> row = JSONArray::create(); | 561 std::unique_ptr<JSONArray> row = JSONArray::create(); |
| 615 row->pushDouble(roundCloseToZero(t.m11())); | 562 row->pushDouble(roundCloseToZero(t.m11())); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 if (flags & LayerTreeIncludesDebugInfo) | 666 if (flags & LayerTreeIncludesDebugInfo) |
| 720 json->setString("client", pointerAsString(m_client)); | 667 json->setString("client", pointerAsString(m_client)); |
| 721 | 668 |
| 722 if (m_backgroundColor.alpha()) | 669 if (m_backgroundColor.alpha()) |
| 723 json->setString("backgroundColor", | 670 json->setString("backgroundColor", |
| 724 m_backgroundColor.nameForLayoutTreeAsText()); | 671 m_backgroundColor.nameForLayoutTreeAsText()); |
| 725 | 672 |
| 726 if (!m_transform.isIdentity()) | 673 if (!m_transform.isIdentity()) |
| 727 json->setArray("transform", transformAsJSONArray(m_transform)); | 674 json->setArray("transform", transformAsJSONArray(m_transform)); |
| 728 | 675 |
| 729 PaintInvalidationTrackingMap::iterator it = | 676 if (flags & LayerTreeIncludesPaintInvalidations) |
| 730 paintInvalidationTrackingMap().find(this); | 677 rasterInvalidationTrackingMap().asJSON(this, json.get()); |
| 731 if (it != paintInvalidationTrackingMap().end()) { | |
| 732 if (flags & LayerTreeIncludesPaintInvalidations) { | |
| 733 Vector<PaintInvalidationInfo>& infos = | |
| 734 it->value.trackedPaintInvalidations; | |
| 735 if (!infos.isEmpty()) { | |
| 736 std::sort(infos.begin(), infos.end(), &comparePaintInvalidationInfo); | |
| 737 std::unique_ptr<JSONArray> paintInvalidationsJSON = JSONArray::create(); | |
| 738 for (auto& info : infos) { | |
| 739 std::unique_ptr<JSONObject> infoJSON = JSONObject::create(); | |
| 740 infoJSON->setString("object", info.clientDebugName); | |
| 741 if (!info.rect.isEmpty()) | |
| 742 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); | |
| 743 infoJSON->setString("reason", | |
| 744 paintInvalidationReasonToString(info.reason)); | |
| 745 paintInvalidationsJSON->pushObject(std::move(infoJSON)); | |
| 746 } | |
| 747 json->setArray("paintInvalidations", std::move(paintInvalidationsJSON)); | |
| 748 } | |
| 749 | |
| 750 Vector<UnderPaintInvalidation>& underPaintInvalidations = | |
| 751 it->value.underPaintInvalidations; | |
| 752 if (!underPaintInvalidations.isEmpty()) { | |
| 753 std::unique_ptr<JSONArray> underPaintInvalidationsJSON = | |
| 754 JSONArray::create(); | |
| 755 for (auto& underPaintInvalidation : underPaintInvalidations) { | |
| 756 std::unique_ptr<JSONObject> underPaintInvalidationJSON = | |
| 757 JSONObject::create(); | |
| 758 underPaintInvalidationJSON->setDouble("x", underPaintInvalidation.x); | |
| 759 underPaintInvalidationJSON->setDouble("y", underPaintInvalidation.y); | |
| 760 underPaintInvalidationJSON->setString( | |
| 761 "oldPixel", | |
| 762 Color(underPaintInvalidation.oldPixel).nameForLayoutTreeAsText()); | |
| 763 underPaintInvalidationJSON->setString( | |
| 764 "newPixel", | |
| 765 Color(underPaintInvalidation.newPixel).nameForLayoutTreeAsText()); | |
| 766 underPaintInvalidationsJSON->pushObject( | |
| 767 std::move(underPaintInvalidationJSON)); | |
| 768 } | |
| 769 json->setArray("underPaintInvalidations", | |
| 770 std::move(underPaintInvalidationsJSON)); | |
| 771 } | |
| 772 } | |
| 773 } | |
| 774 | 678 |
| 775 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { | 679 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { |
| 776 std::unique_ptr<JSONArray> paintingPhasesJSON = JSONArray::create(); | 680 std::unique_ptr<JSONArray> paintingPhasesJSON = JSONArray::create(); |
| 777 if (m_paintingPhase & GraphicsLayerPaintBackground) | 681 if (m_paintingPhase & GraphicsLayerPaintBackground) |
| 778 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); | 682 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); |
| 779 if (m_paintingPhase & GraphicsLayerPaintForeground) | 683 if (m_paintingPhase & GraphicsLayerPaintForeground) |
| 780 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); | 684 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); |
| 781 if (m_paintingPhase & GraphicsLayerPaintMask) | 685 if (m_paintingPhase & GraphicsLayerPaintMask) |
| 782 paintingPhasesJSON->pushString("GraphicsLayerPaintMask"); | 686 paintingPhasesJSON->pushString("GraphicsLayerPaintMask"); |
| 783 if (m_paintingPhase & GraphicsLayerPaintChildClippingMask) | 687 if (m_paintingPhase & GraphicsLayerPaintChildClippingMask) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 void GraphicsLayer::setIsRootForIsolatedGroup(bool isolated) { | 941 void GraphicsLayer::setIsRootForIsolatedGroup(bool isolated) { |
| 1038 if (m_isRootForIsolatedGroup == isolated) | 942 if (m_isRootForIsolatedGroup == isolated) |
| 1039 return; | 943 return; |
| 1040 m_isRootForIsolatedGroup = isolated; | 944 m_isRootForIsolatedGroup = isolated; |
| 1041 platformLayer()->setIsRootForIsolatedGroup(isolated); | 945 platformLayer()->setIsRootForIsolatedGroup(isolated); |
| 1042 } | 946 } |
| 1043 | 947 |
| 1044 void GraphicsLayer::setContentsNeedsDisplay() { | 948 void GraphicsLayer::setContentsNeedsDisplay() { |
| 1045 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { | 949 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { |
| 1046 contentsLayer->invalidate(); | 950 contentsLayer->invalidate(); |
| 1047 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull); | 951 trackRasterInvalidation(*this, m_contentsRect, PaintInvalidationFull); |
| 1048 } | 952 } |
| 1049 } | 953 } |
| 1050 | 954 |
| 1051 void GraphicsLayer::setNeedsDisplay() { | 955 void GraphicsLayer::setNeedsDisplay() { |
| 1052 if (!drawsContent()) | 956 if (!drawsContent()) |
| 1053 return; | 957 return; |
| 1054 | 958 |
| 1055 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursivel
y does so. | 959 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursivel
y does so. |
| 1056 m_layer->layer()->invalidate(); | 960 m_layer->layer()->invalidate(); |
| 1057 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 961 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
| 1058 m_linkHighlights[i]->invalidate(); | 962 m_linkHighlights[i]->invalidate(); |
| 1059 getPaintController().invalidateAll(); | 963 getPaintController().invalidateAll(); |
| 1060 | 964 |
| 1061 trackPaintInvalidation(*this, IntRect(IntPoint(), expandedIntSize(m_size)), | 965 trackRasterInvalidation(*this, IntRect(IntPoint(), expandedIntSize(m_size)), |
| 1062 PaintInvalidationFull); | 966 PaintInvalidationFull); |
| 1063 } | 967 } |
| 1064 | 968 |
| 1065 void GraphicsLayer::setNeedsDisplayInRect( | 969 void GraphicsLayer::setNeedsDisplayInRect( |
| 1066 const IntRect& rect, | 970 const IntRect& rect, |
| 1067 PaintInvalidationReason invalidationReason, | 971 PaintInvalidationReason invalidationReason, |
| 1068 const DisplayItemClient& client) { | 972 const DisplayItemClient& client) { |
| 1069 if (!drawsContent()) | 973 if (!drawsContent()) |
| 1070 return; | 974 return; |
| 1071 | 975 |
| 1072 m_layer->layer()->invalidateRect(rect); | 976 m_layer->layer()->invalidateRect(rect); |
| 1073 if (firstPaintInvalidationTrackingEnabled()) | 977 if (firstPaintInvalidationTrackingEnabled()) |
| 1074 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); | 978 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); |
| 1075 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 979 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
| 1076 m_linkHighlights[i]->invalidate(); | 980 m_linkHighlights[i]->invalidate(); |
| 1077 | 981 |
| 1078 trackPaintInvalidation(client, rect, invalidationReason); | 982 trackRasterInvalidation(client, rect, invalidationReason); |
| 1079 } | 983 } |
| 1080 | 984 |
| 1081 void GraphicsLayer::setContentsRect(const IntRect& rect) { | 985 void GraphicsLayer::setContentsRect(const IntRect& rect) { |
| 1082 if (rect == m_contentsRect) | 986 if (rect == m_contentsRect) |
| 1083 return; | 987 return; |
| 1084 | 988 |
| 1085 m_contentsRect = rect; | 989 m_contentsRect = rect; |
| 1086 updateContentsRect(); | 990 updateContentsRect(); |
| 1087 } | 991 } |
| 1088 | 992 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) || | 1147 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) || |
| 1244 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) || | 1148 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) || |
| 1245 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) || | 1149 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) || |
| 1246 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2)); | 1150 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2)); |
| 1247 } | 1151 } |
| 1248 | 1152 |
| 1249 void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture) { | 1153 void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture) { |
| 1250 if (!drawsContent()) | 1154 if (!drawsContent()) |
| 1251 return; | 1155 return; |
| 1252 | 1156 |
| 1253 auto it = paintInvalidationTrackingMap().find(this); | 1157 RasterInvalidationTracking* tracking = |
| 1254 if (it == paintInvalidationTrackingMap().end()) | 1158 rasterInvalidationTrackingMap().find(this); |
| 1255 return; | 1159 if (!tracking) |
| 1256 PaintInvalidationTracking& tracking = it->value; | |
| 1257 if (!tracking.lastPaintedPicture) | |
| 1258 return; | 1160 return; |
| 1259 | 1161 |
| 1260 IntRect rect = intersection(tracking.lastInterestRect, interestRect()); | 1162 if (!tracking->lastPaintedPicture) |
| 1163 return; |
| 1164 |
| 1165 IntRect rect = intersection(tracking->lastInterestRect, interestRect()); |
| 1261 if (rect.isEmpty()) | 1166 if (rect.isEmpty()) |
| 1262 return; | 1167 return; |
| 1263 | 1168 |
| 1264 SkBitmap oldBitmap; | 1169 SkBitmap oldBitmap; |
| 1265 oldBitmap.allocPixels( | 1170 oldBitmap.allocPixels( |
| 1266 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 1171 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |
| 1267 { | 1172 { |
| 1268 SkCanvas canvas(oldBitmap); | 1173 SkCanvas canvas(oldBitmap); |
| 1269 canvas.clear(SK_ColorTRANSPARENT); | 1174 canvas.clear(SK_ColorTRANSPARENT); |
| 1270 canvas.translate(-rect.x(), -rect.y()); | 1175 canvas.translate(-rect.x(), -rect.y()); |
| 1271 canvas.drawPicture(tracking.lastPaintedPicture.get()); | 1176 canvas.drawPicture(tracking->lastPaintedPicture.get()); |
| 1272 } | 1177 } |
| 1273 | 1178 |
| 1274 SkBitmap newBitmap; | 1179 SkBitmap newBitmap; |
| 1275 newBitmap.allocPixels( | 1180 newBitmap.allocPixels( |
| 1276 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 1181 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |
| 1277 { | 1182 { |
| 1278 SkCanvas canvas(newBitmap); | 1183 SkCanvas canvas(newBitmap); |
| 1279 canvas.clear(SK_ColorTRANSPARENT); | 1184 canvas.clear(SK_ColorTRANSPARENT); |
| 1280 canvas.translate(-rect.x(), -rect.y()); | 1185 canvas.translate(-rect.x(), -rect.y()); |
| 1281 canvas.drawPicture(&newPicture); | 1186 canvas.drawPicture(&newPicture); |
| 1282 } | 1187 } |
| 1283 | 1188 |
| 1284 oldBitmap.lockPixels(); | 1189 oldBitmap.lockPixels(); |
| 1285 newBitmap.lockPixels(); | 1190 newBitmap.lockPixels(); |
| 1286 int mismatchingPixels = 0; | 1191 int mismatchingPixels = 0; |
| 1287 static const int maxMismatchesToReport = 50; | 1192 static const int maxMismatchesToReport = 50; |
| 1288 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) { | 1193 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) { |
| 1289 int layerY = bitmapY + rect.y(); | 1194 int layerY = bitmapY + rect.y(); |
| 1290 for (int bitmapX = 0; bitmapX < rect.width(); ++bitmapX) { | 1195 for (int bitmapX = 0; bitmapX < rect.width(); ++bitmapX) { |
| 1291 int layerX = bitmapX + rect.x(); | 1196 int layerX = bitmapX + rect.x(); |
| 1292 SkColor oldPixel = oldBitmap.getColor(bitmapX, bitmapY); | 1197 SkColor oldPixel = oldBitmap.getColor(bitmapX, bitmapY); |
| 1293 SkColor newPixel = newBitmap.getColor(bitmapX, bitmapY); | 1198 SkColor newPixel = newBitmap.getColor(bitmapX, bitmapY); |
| 1294 if (pixelsDiffer(oldPixel, newPixel) && | 1199 if (pixelsDiffer(oldPixel, newPixel) && |
| 1295 !tracking.paintInvalidationRegionSinceLastPaint.contains( | 1200 !tracking->rasterInvalidationRegionSinceLastPaint.contains( |
| 1296 IntPoint(layerX, layerY))) { | 1201 IntPoint(layerX, layerY))) { |
| 1297 if (mismatchingPixels < maxMismatchesToReport) { | 1202 if (mismatchingPixels < maxMismatchesToReport) { |
| 1298 UnderPaintInvalidation underPaintInvalidation = {layerX, layerY, | 1203 UnderPaintInvalidation underPaintInvalidation = {layerX, layerY, |
| 1299 oldPixel, newPixel}; | 1204 oldPixel, newPixel}; |
| 1300 tracking.underPaintInvalidations.append(underPaintInvalidation); | 1205 tracking->underPaintInvalidations.append(underPaintInvalidation); |
| 1301 LOG(ERROR) << debugName() | 1206 LOG(ERROR) << debugName() |
| 1302 << " Uninvalidated old/new pixels mismatch at " << layerX | 1207 << " Uninvalidated old/new pixels mismatch at " << layerX |
| 1303 << "," << layerY << " old:" << std::hex << oldPixel | 1208 << "," << layerY << " old:" << std::hex << oldPixel |
| 1304 << " new:" << newPixel; | 1209 << " new:" << newPixel; |
| 1305 } else if (mismatchingPixels == maxMismatchesToReport) { | 1210 } else if (mismatchingPixels == maxMismatchesToReport) { |
| 1306 LOG(ERROR) << "and more..."; | 1211 LOG(ERROR) << "and more..."; |
| 1307 } | 1212 } |
| 1308 ++mismatchingPixels; | 1213 ++mismatchingPixels; |
| 1309 *newBitmap.getAddr32(bitmapX, bitmapY) = | 1214 *newBitmap.getAddr32(bitmapX, bitmapY) = |
| 1310 SkColorSetARGB(0xFF, 0xA0, 0, 0); // Dark red. | 1215 SkColorSetARGB(0xFF, 0xA0, 0, 0); // Dark red. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1332 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) { | 1237 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) { |
| 1333 if (!layer) { | 1238 if (!layer) { |
| 1334 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1239 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
| 1335 return; | 1240 return; |
| 1336 } | 1241 } |
| 1337 | 1242 |
| 1338 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1243 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
| 1339 fprintf(stderr, "%s\n", output.utf8().data()); | 1244 fprintf(stderr, "%s\n", output.utf8().data()); |
| 1340 } | 1245 } |
| 1341 #endif | 1246 #endif |
| OLD | NEW |