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

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

Issue 2049263003: Check rect under-invalidations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ImageQuality
Patch Set: Tolerate invisible differences Created 4 years, 6 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 /* 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 16 matching lines...) Expand all
27 27
28 #include "SkImageFilter.h" 28 #include "SkImageFilter.h"
29 #include "SkMatrix44.h" 29 #include "SkMatrix44.h"
30 #include "base/trace_event/trace_event_argument.h" 30 #include "base/trace_event/trace_event_argument.h"
31 #include "cc/layers/layer.h" 31 #include "cc/layers/layer.h"
32 #include "platform/DragImage.h" 32 #include "platform/DragImage.h"
33 #include "platform/JSONValues.h" 33 #include "platform/JSONValues.h"
34 #include "platform/TraceEvent.h" 34 #include "platform/TraceEvent.h"
35 #include "platform/geometry/FloatRect.h" 35 #include "platform/geometry/FloatRect.h"
36 #include "platform/geometry/LayoutRect.h" 36 #include "platform/geometry/LayoutRect.h"
37 #include "platform/geometry/Region.h"
37 #include "platform/graphics/BitmapImage.h" 38 #include "platform/graphics/BitmapImage.h"
38 #include "platform/graphics/CompositorFactory.h" 39 #include "platform/graphics/CompositorFactory.h"
39 #include "platform/graphics/CompositorFilterOperations.h" 40 #include "platform/graphics/CompositorFilterOperations.h"
40 #include "platform/graphics/FirstPaintInvalidationTracking.h" 41 #include "platform/graphics/FirstPaintInvalidationTracking.h"
41 #include "platform/graphics/GraphicsContext.h" 42 #include "platform/graphics/GraphicsContext.h"
42 #include "platform/graphics/Image.h" 43 #include "platform/graphics/Image.h"
43 #include "platform/graphics/LinkHighlight.h" 44 #include "platform/graphics/LinkHighlight.h"
44 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" 45 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
45 #include "platform/graphics/paint/DrawingRecorder.h" 46 #include "platform/graphics/paint/DrawingRecorder.h"
46 #include "platform/graphics/paint/PaintController.h" 47 #include "platform/graphics/paint/PaintController.h"
(...skipping 22 matching lines...) Expand all
69 70
70 namespace blink { 71 namespace blink {
71 72
72 static bool s_drawDebugRedFill = true; 73 static bool s_drawDebugRedFill = true;
73 74
74 struct PaintInvalidationInfo { 75 struct PaintInvalidationInfo {
75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 76 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
76 // This is for comparison only. Don't dereference because the client may hav e died. 77 // This is for comparison only. Don't dereference because the client may hav e died.
77 const DisplayItemClient* client; 78 const DisplayItemClient* client;
78 String clientDebugName; 79 String clientDebugName;
79 FloatRect rect; 80 IntRect rect;
80 PaintInvalidationReason reason; 81 PaintInvalidationReason reason;
81 }; 82 };
82 83
83 typedef HashMap<const GraphicsLayer*, Vector<PaintInvalidationInfo>> PaintInvali dationTrackingMap; 84 #if DCHECK_IS_ON()
85 struct UnderPaintInvalidation {
86 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
87 int x;
88 int y;
89 SkColor oldPixel;
90 SkColor newPixel;
91 };
92 #endif
93
94 struct PaintInvalidationTracking {
95 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
96 Vector<PaintInvalidationInfo> trackedPaintInvalidations;
97 #if DCHECK_IS_ON()
98 RefPtr<SkPicture> lastPaintedPicture;
99 Region paintInvalidationRegionSinceLastPaint;
100 Vector<UnderPaintInvalidation> underPaintInvalidations;
101 #endif
102 };
103
104 typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> PaintInvalidati onTrackingMap;
84 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() 105 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap()
85 { 106 {
86 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); 107 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ());
87 return map; 108 return map;
88 } 109 }
89 110
90 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) 111 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
91 { 112 {
92 return adoptPtr(new GraphicsLayer(client)); 113 return adoptPtr(new GraphicsLayer(client));
93 } 114 }
94 115
95 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) 116 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client)
96 : m_client(client) 117 : m_client(client)
97 , m_backgroundColor(Color::transparent) 118 , m_backgroundColor(Color::transparent)
98 , m_opacity(1) 119 , m_opacity(1)
99 , m_blendMode(WebBlendModeNormal) 120 , m_blendMode(WebBlendModeNormal)
100 , m_hasTransformOrigin(false) 121 , m_hasTransformOrigin(false)
101 , m_contentsOpaque(false) 122 , m_contentsOpaque(false)
102 , m_shouldFlattenTransform(true) 123 , m_shouldFlattenTransform(true)
103 , m_backfaceVisibility(true) 124 , m_backfaceVisibility(true)
104 , m_masksToBounds(false) 125 , m_masksToBounds(false)
105 , m_drawsContent(false) 126 , m_drawsContent(false)
106 , m_contentsVisible(true) 127 , m_contentsVisible(true)
107 , m_isRootForIsolatedGroup(false) 128 , m_isRootForIsolatedGroup(false)
108 , m_hasScrollParent(false) 129 , m_hasScrollParent(false)
109 , m_hasClipParent(false) 130 , m_hasClipParent(false)
110 , m_painted(false) 131 , m_painted(false)
111 , m_textPainted(false) 132 , m_textPainted(false)
112 , m_imagePainted(false) 133 , m_imagePainted(false)
134 , m_isTrackingPaintInvalidations(client && client->isTrackingPaintInvalidati ons())
113 , m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip) 135 , m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip)
114 , m_parent(0) 136 , m_parent(0)
115 , m_maskLayer(0) 137 , m_maskLayer(0)
116 , m_contentsClippingMaskLayer(0) 138 , m_contentsClippingMaskLayer(0)
117 , m_replicaLayer(0) 139 , m_replicaLayer(0)
118 , m_replicatedLayer(0) 140 , m_replicatedLayer(0)
119 , m_paintCount(0) 141 , m_paintCount(0)
120 , m_contentsLayer(0) 142 , m_contentsLayer(0)
121 , m_contentsLayerId(0) 143 , m_contentsLayerId(0)
122 , m_scrollableArea(nullptr) 144 , m_scrollableArea(nullptr)
(...skipping 23 matching lines...) Expand all
146 168
147 if (m_replicaLayer) 169 if (m_replicaLayer)
148 m_replicaLayer->setReplicatedLayer(0); 170 m_replicaLayer->setReplicatedLayer(0);
149 171
150 if (m_replicatedLayer) 172 if (m_replicatedLayer)
151 m_replicatedLayer->setReplicatedByLayer(0); 173 m_replicatedLayer->setReplicatedByLayer(0);
152 174
153 removeAllChildren(); 175 removeAllChildren();
154 removeFromParent(); 176 removeFromParent();
155 177
156 resetTrackedPaintInvalidations(); 178 paintInvalidationTrackingMap().remove(this);
157 ASSERT(!m_parent); 179 ASSERT(!m_parent);
158 } 180 }
159 181
160 LayoutRect GraphicsLayer::visualRect() const 182 LayoutRect GraphicsLayer::visualRect() const
161 { 183 {
162 LayoutRect bounds = LayoutRect(FloatPoint(), size()); 184 LayoutRect bounds = LayoutRect(FloatPoint(), size());
163 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation()); 185 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation());
164 return bounds; 186 return bounds;
165 } 187 }
166 188
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return LayoutSize(offsetFromLayoutObject()) + client()->subpixelAccumulation (); 334 return LayoutSize(offsetFromLayoutObject()) + client()->subpixelAccumulation ();
313 } 335 }
314 336
315 IntRect GraphicsLayer::interestRect() 337 IntRect GraphicsLayer::interestRect()
316 { 338 {
317 return m_previousInterestRect; 339 return m_previousInterestRect;
318 } 340 }
319 341
320 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode) 342 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode)
321 { 343 {
322 if (paintWithoutCommit(interestRect, disabledMode)) 344 if (paintWithoutCommit(interestRect, disabledMode)) {
323 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation()); 345 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation());
346 #if DCHECK_IS_ON()
347 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnable d()) {
348 RefPtr<SkPicture> newPicture = capturePicture();
349 checkUnderPaintInvalidations(*newPicture);
350 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap() .add(this, PaintInvalidationTracking()).storedValue->value;
351 tracking.lastPaintedPicture = newPicture;
352 tracking.paintInvalidationRegionSinceLastPaint = Region();
353 }
354 #endif
355 }
324 } 356 }
325 357
326 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode) 358 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode)
327 { 359 {
328 ASSERT(drawsContent()); 360 ASSERT(drawsContent());
329 361
330 if (!m_client) 362 if (!m_client)
331 return false; 363 return false;
332 if (firstPaintInvalidationTrackingEnabled()) 364 if (firstPaintInvalidationTrackingEnabled())
333 m_debugInfo.clearAnnotatedInvalidateRects(); 365 m_debugInfo.clearAnnotatedInvalidateRects();
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 { 558 {
527 return m_debugInfo; 559 return m_debugInfo;
528 } 560 }
529 561
530 WebLayer* GraphicsLayer::contentsLayerIfRegistered() 562 WebLayer* GraphicsLayer::contentsLayerIfRegistered()
531 { 563 {
532 clearContentsLayerIfUnregistered(); 564 clearContentsLayerIfUnregistered();
533 return m_contentsLayer; 565 return m_contentsLayer;
534 } 566 }
535 567
568 void GraphicsLayer::setTracksPaintInvalidations(bool tracksPaintInvalidations)
569 {
570 resetTrackedPaintInvalidations();
571 m_isTrackingPaintInvalidations = tracksPaintInvalidations;
572 }
573
536 void GraphicsLayer::resetTrackedPaintInvalidations() 574 void GraphicsLayer::resetTrackedPaintInvalidations()
537 { 575 {
538 paintInvalidationTrackingMap().remove(this); 576 auto it = paintInvalidationTrackingMap().find(this);
577 if (it == paintInvalidationTrackingMap().end())
578 return;
579
580 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
581 it->value.trackedPaintInvalidations.clear();
582 else
583 paintInvalidationTrackingMap().remove(it);
539 } 584 }
540 585
541 bool GraphicsLayer::hasTrackedPaintInvalidations() const 586 bool GraphicsLayer::hasTrackedPaintInvalidations() const
542 { 587 {
543 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 588 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
544 if (it != paintInvalidationTrackingMap().end()) 589 if (it != paintInvalidationTrackingMap().end())
545 return !it->value.isEmpty(); 590 return !it->value.trackedPaintInvalidations.isEmpty();
546 return false; 591 return false;
547 } 592 }
548 593
549 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t FloatRect& rect, PaintInvalidationReason reason) 594 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t IntRect& rect, PaintInvalidationReason reason)
550 { 595 {
551 // The caller must check isTrackingPaintInvalidations() before calling this method 596 // The caller must check isTrackingOrCheckingPaintInvalidations() before cal ling this method
552 // to avoid constructing the rect unnecessarily. 597 // to avoid constructing the rect unnecessarily.
553 ASSERT(isTrackingPaintInvalidations()); 598 DCHECK(isTrackingOrCheckingPaintInvalidations());
554 599
555 Vector<PaintInvalidationInfo>& infos = paintInvalidationTrackingMap().add(th is, Vector<PaintInvalidationInfo>()).storedValue->value; 600 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(thi s, PaintInvalidationTracking()).storedValue->value;
556 // Omit the entry for trackObjectPaintInvalidation() if the last entry is fo r the same client. 601 // Omit the entry for trackObjectPaintInvalidation() if the last entry is fo r the same client.
557 // This is to avoid duplicated entries for setNeedsDisplayInRect() and track ObjectPaintInvalidation(). 602 // This is to avoid duplicated entries for setNeedsDisplayInRect() and track ObjectPaintInvalidation().
558 if (rect.isEmpty() && !infos.isEmpty() && infos.last().client == &client) 603 if (rect.isEmpty() && !tracking.trackedPaintInvalidations.isEmpty() && track ing.trackedPaintInvalidations.last().client == &client)
559 return; 604 return;
560 605
561 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason }; 606 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason };
562 infos.append(info); 607 tracking.trackedPaintInvalidations.append(info);
608
609 #if DCHECK_IS_ON()
610 if (!rect.isEmpty() && RuntimeEnabledFeatures::slimmingPaintUnderInvalidatio nCheckingEnabled()) {
611 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint invalidation rect.
612 IntRect r = rect;
613 r.inflate(1);
614 tracking.paintInvalidationRegionSinceLastPaint.unite(r);
615 }
616 #endif
563 } 617 }
564 618
565 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b) 619 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b)
566 { 620 {
567 // Sort by rect first, bigger rects before smaller ones. 621 // Sort by rect first, bigger rects before smaller ones.
568 if (a.rect.width() != b.rect.width()) 622 if (a.rect.width() != b.rect.width())
569 return a.rect.width() > b.rect.width(); 623 return a.rect.width() > b.rect.width();
570 if (a.rect.height() != b.rect.height()) 624 if (a.rect.height() != b.rect.height())
571 return a.rect.height() > b.rect.height(); 625 return a.rect.height() > b.rect.height();
572 if (a.rect.x() != b.rect.x()) 626 if (a.rect.x() != b.rect.x())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 779
726 if (m_replicaLayer) 780 if (m_replicaLayer)
727 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap)); 781 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap));
728 782
729 if (m_replicatedLayer) 783 if (m_replicatedLayer)
730 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : ""); 784 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : "");
731 785
732 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 786 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
733 if (it != paintInvalidationTrackingMap().end()) { 787 if (it != paintInvalidationTrackingMap().end()) {
734 if (flags & LayerTreeIncludesPaintInvalidations) { 788 if (flags & LayerTreeIncludesPaintInvalidations) {
735 Vector<PaintInvalidationInfo>& infos = it->value; 789 Vector<PaintInvalidationInfo>& infos = it->value.trackedPaintInvalid ations;
736 if (!infos.isEmpty()) { 790 if (!infos.isEmpty()) {
737 std::sort(infos.begin(), infos.end(), &comparePaintInvalidationI nfo); 791 std::sort(infos.begin(), infos.end(), &comparePaintInvalidationI nfo);
738 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create(); 792 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create();
739 for (auto& info : infos) { 793 for (auto& info : infos) {
740 RefPtr<JSONObject> infoJSON = JSONObject::create(); 794 RefPtr<JSONObject> infoJSON = JSONObject::create();
741 infoJSON->setString("object", info.clientDebugName); 795 infoJSON->setString("object", info.clientDebugName);
742 if (!info.rect.isEmpty()) 796 if (!info.rect.isEmpty())
743 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); 797 infoJSON->setArray("rect", rectAsJSONArray(info.rect));
744 infoJSON->setString("reason", paintInvalidationReasonToStrin g(info.reason)); 798 infoJSON->setString("reason", paintInvalidationReasonToStrin g(info.reason));
745 paintInvalidationsJSON->pushObject(infoJSON); 799 paintInvalidationsJSON->pushObject(infoJSON);
746 } 800 }
747 json->setArray("paintInvalidations", paintInvalidationsJSON); 801 json->setArray("paintInvalidations", paintInvalidationsJSON);
748 } 802 }
803 #if DCHECK_IS_ON()
804 Vector<UnderPaintInvalidation>& underPaintInvalidations = it->value. underPaintInvalidations;
805 if (!underPaintInvalidations.isEmpty()) {
806 RefPtr<JSONArray> underPaintInvalidationsJSON = JSONArray::creat e();
807 for (auto& underPaintInvalidation : underPaintInvalidations) {
808 RefPtr<JSONObject> underPaintInvalidationJSON = JSONObject:: create();
809 underPaintInvalidationJSON->setNumber("x", underPaintInvalid ation.x);
810 underPaintInvalidationJSON->setNumber("y", underPaintInvalid ation.x);
811 underPaintInvalidationJSON->setString("oldPixel", Color(unde rPaintInvalidation.oldPixel).nameForLayoutTreeAsText());
812 underPaintInvalidationJSON->setString("newPixel", Color(unde rPaintInvalidation.newPixel).nameForLayoutTreeAsText());
813 underPaintInvalidationsJSON->pushObject(underPaintInvalidati onJSON);
814 }
815 json->setArray("underPaintInvalidations", underPaintInvalidation sJSON);
816 }
817 #endif
749 } 818 }
750 } 819 }
751 820
752 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { 821 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) {
753 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create(); 822 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create();
754 if (m_paintingPhase & GraphicsLayerPaintBackground) 823 if (m_paintingPhase & GraphicsLayerPaintBackground)
755 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); 824 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground");
756 if (m_paintingPhase & GraphicsLayerPaintForeground) 825 if (m_paintingPhase & GraphicsLayerPaintForeground)
757 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); 826 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground");
758 if (m_paintingPhase & GraphicsLayerPaintMask) 827 if (m_paintingPhase & GraphicsLayerPaintMask)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 if (m_isRootForIsolatedGroup == isolated) 1097 if (m_isRootForIsolatedGroup == isolated)
1029 return; 1098 return;
1030 m_isRootForIsolatedGroup = isolated; 1099 m_isRootForIsolatedGroup = isolated;
1031 platformLayer()->setIsRootForIsolatedGroup(isolated); 1100 platformLayer()->setIsRootForIsolatedGroup(isolated);
1032 } 1101 }
1033 1102
1034 void GraphicsLayer::setContentsNeedsDisplay() 1103 void GraphicsLayer::setContentsNeedsDisplay()
1035 { 1104 {
1036 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { 1105 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) {
1037 contentsLayer->invalidate(); 1106 contentsLayer->invalidate();
1038 if (isTrackingPaintInvalidations()) 1107 if (isTrackingOrCheckingPaintInvalidations())
1039 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull) ; 1108 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull) ;
1040 } 1109 }
1041 } 1110 }
1042 1111
1043 void GraphicsLayer::setNeedsDisplay() 1112 void GraphicsLayer::setNeedsDisplay()
1044 { 1113 {
1045 if (!drawsContent()) 1114 if (!drawsContent())
1046 return; 1115 return;
1047 1116
1048 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so. 1117 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so.
1049 m_layer->layer()->invalidate(); 1118 m_layer->layer()->invalidate();
1050 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1119 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1051 m_linkHighlights[i]->invalidate(); 1120 m_linkHighlights[i]->invalidate();
1052 getPaintController().invalidateAll(); 1121 getPaintController().invalidateAll();
1053 1122
1054 if (isTrackingPaintInvalidations()) 1123 if (isTrackingOrCheckingPaintInvalidations())
1055 trackPaintInvalidation(*this, FloatRect(FloatPoint(), m_size), PaintInva lidationFull); 1124 trackPaintInvalidation(*this, IntRect(IntPoint(), expandedIntSize(m_size )), PaintInvalidationFull);
1056 } 1125 }
1057 1126
1058 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason, const DisplayItemClient& client) 1127 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason, const DisplayItemClient& client)
1059 { 1128 {
1060 if (!drawsContent()) 1129 if (!drawsContent())
1061 return; 1130 return;
1062 1131
1063 m_layer->layer()->invalidateRect(rect); 1132 m_layer->layer()->invalidateRect(rect);
1064 if (firstPaintInvalidationTrackingEnabled()) 1133 if (firstPaintInvalidationTrackingEnabled())
1065 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); 1134 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason);
1066 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1135 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1067 m_linkHighlights[i]->invalidate(); 1136 m_linkHighlights[i]->invalidate();
1068 1137
1069 if (isTrackingPaintInvalidations()) 1138 if (isTrackingOrCheckingPaintInvalidations())
1070 trackPaintInvalidation(client, rect, invalidationReason); 1139 trackPaintInvalidation(client, rect, invalidationReason);
1071 } 1140 }
1072 1141
1073 void GraphicsLayer::displayItemClientWasInvalidated(const DisplayItemClient& dis playItemClient, PaintInvalidationReason invalidationReason) 1142 void GraphicsLayer::displayItemClientWasInvalidated(const DisplayItemClient& dis playItemClient, PaintInvalidationReason invalidationReason)
1074 { 1143 {
1075 if (!drawsContent()) 1144 if (!drawsContent())
1076 return; 1145 return;
1077 1146
1078 getPaintController().displayItemClientWasInvalidated(displayItemClient); 1147 getPaintController().displayItemClientWasInvalidated(displayItemClient);
1079 1148
1080 if (isTrackingPaintInvalidations()) 1149 if (isTrackingOrCheckingPaintInvalidations())
1081 trackPaintInvalidation(displayItemClient, FloatRect(), invalidationReaso n); 1150 trackPaintInvalidation(displayItemClient, IntRect(), invalidationReason) ;
1082 } 1151 }
1083 1152
1084 void GraphicsLayer::setContentsRect(const IntRect& rect) 1153 void GraphicsLayer::setContentsRect(const IntRect& rect)
1085 { 1154 {
1086 if (rect == m_contentsRect) 1155 if (rect == m_contentsRect)
1087 return; 1156 return;
1088 1157
1089 m_contentsRect = rect; 1158 m_contentsRect = rect;
1090 updateContentsRect(); 1159 updateContentsRect();
1091 } 1160 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (WebLayer* layer = platformLayer()) 1281 if (WebLayer* layer = platformLayer())
1213 layer->setElementId(id); 1282 layer->setElementId(id);
1214 } 1283 }
1215 1284
1216 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) 1285 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties)
1217 { 1286 {
1218 if (WebLayer* layer = platformLayer()) 1287 if (WebLayer* layer = platformLayer())
1219 layer->setCompositorMutableProperties(properties); 1288 layer->setCompositorMutableProperties(properties);
1220 } 1289 }
1221 1290
1291 #if DCHECK_IS_ON()
1292
1293 PassRefPtr<SkPicture> GraphicsLayer::capturePicture()
1294 {
1295 if (!drawsContent())
1296 return nullptr;
1297
1298 IntSize intSize = expandedIntSize(size());
1299 GraphicsContext graphicsContext(getPaintController());
1300 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize));
1301 getPaintController().paintArtifact().replay(graphicsContext);
1302 return graphicsContext.endRecording();
1303 }
1304
1305 static bool pixelComponentsDiffer(int c1, int c2)
Xianzhu 2016/06/10 18:42:58 Modified the pixel verification algorithm by toler
1306 {
1307 // Compare strictly for saturated values.
1308 if (c1 == 0 || c1 == 255 || c2 == 0 || c2 == 255)
1309 return c1 != c2;
1310 // Tolerate invisible differences that may occur in gradients etc.
1311 return abs(c1 - c2) > 2;
1312 }
1313
1314 static bool pixelsDiffer(SkColor p1, SkColor p2)
1315 {
1316 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2))
1317 || pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2))
1318 || pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2))
1319 || pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2));
1320 }
1321
1322 void GraphicsLayer::checkUnderPaintInvalidations(const SkPicture& newPicture)
1323 {
1324 if (!drawsContent())
1325 return;
1326
1327 auto it = paintInvalidationTrackingMap().find(this);
1328 if (it == paintInvalidationTrackingMap().end())
1329 return;
1330 PaintInvalidationTracking& tracking = it->value;
1331 if (!tracking.lastPaintedPicture)
1332 return;
1333
1334 SkBitmap oldBitmap;
1335 int width = static_cast<int>(ceilf(std::min(tracking.lastPaintedPicture->cul lRect().width(), newPicture.cullRect().width())));
1336 int height = static_cast<int>(ceilf(std::min(tracking.lastPaintedPicture->cu llRect().height(), newPicture.cullRect().height())));
1337 oldBitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
1338 SkCanvas(oldBitmap).drawPicture(tracking.lastPaintedPicture.get());
1339
1340 SkBitmap newBitmap;
1341 newBitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
1342 SkCanvas(newBitmap).drawPicture(&newPicture);
1343
1344 oldBitmap.lockPixels();
1345 newBitmap.lockPixels();
1346 int mismatchingPixels = 0;
1347 static const int maxMismatchesToReport = 50;
1348 for (int y = 0; y < height; ++y) {
1349 for (int x = 0; x < width; ++x) {
1350 SkColor oldPixel = oldBitmap.getColor(x, y);
1351 SkColor newPixel = newBitmap.getColor(x, y);
1352 if (pixelsDiffer(oldPixel, newPixel) && !tracking.paintInvalidationR egionSinceLastPaint.contains(IntPoint(x, y))) {
1353 if (mismatchingPixels < maxMismatchesToReport) {
1354 UnderPaintInvalidation underPaintInvalidation = { x, y, oldP ixel, newPixel };
1355 tracking.underPaintInvalidations.append(underPaintInvalidati on);
1356 LOG(ERROR) << debugName() << " Uninvalidated old/new pixels mismatch at " << x << "," << y << " old:" << std::hex << oldPixel << " new:" << newPixel;
1357 } else if (mismatchingPixels == maxMismatchesToReport) {
1358 LOG(ERROR) << "and more...";
1359 }
1360 ++mismatchingPixels;
1361 *newBitmap.getAddr32(x, y) = SK_ColorRED;
1362 } else {
1363 *newBitmap.getAddr32(x, y) = SK_ColorTRANSPARENT;
1364 }
1365 }
1366 }
1367
1368 oldBitmap.unlockPixels();
1369 newBitmap.unlockPixels();
1370
1371 // Visualize under-invalidations by overlaying the new bitmap (containing re d pixels indicating under-invalidations,
1372 // and transparent pixels otherwise) onto the painting.
1373 SkPictureRecorder recorder;
1374 recorder.beginRecording(width, height);
1375 recorder.getRecordingCanvas()->drawBitmap(newBitmap, 0, 0);
1376 RefPtr<SkPicture> picture = fromSkSp(recorder.finishRecordingAsPicture());
1377 getPaintController().appendDebugDrawingAfterCommit(*this, picture, offsetFro mLayoutObjectWithSubpixelAccumulation());
1378 }
1379
1380 #endif // DCHECK_IS_ON()
1381
1222 } // namespace blink 1382 } // namespace blink
1223 1383
1224 #ifndef NDEBUG 1384 #ifndef NDEBUG
1225 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) 1385 void showGraphicsLayerTree(const blink::GraphicsLayer* layer)
1226 { 1386 {
1227 if (!layer) { 1387 if (!layer) {
1228 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); 1388 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n");
1229 return; 1389 return;
1230 } 1390 }
1231 1391
1232 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); 1392 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
1233 fprintf(stderr, "%s\n", output.utf8().data()); 1393 fprintf(stderr, "%s\n", output.utf8().data());
1234 } 1394 }
1235 #endif 1395 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698