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

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: Only DCHECK_IS_ON() 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"
46 #include "platform/graphics/paint/DisplayItemCacheSkipper.h"
45 #include "platform/graphics/paint/DrawingRecorder.h" 47 #include "platform/graphics/paint/DrawingRecorder.h"
46 #include "platform/graphics/paint/PaintController.h" 48 #include "platform/graphics/paint/PaintController.h"
47 #include "platform/scroll/ScrollableArea.h" 49 #include "platform/scroll/ScrollableArea.h"
48 #include "platform/text/TextStream.h" 50 #include "platform/text/TextStream.h"
49 #include "public/platform/Platform.h" 51 #include "public/platform/Platform.h"
50 #include "public/platform/WebCompositorSupport.h" 52 #include "public/platform/WebCompositorSupport.h"
51 #include "public/platform/WebFloatPoint.h" 53 #include "public/platform/WebFloatPoint.h"
52 #include "public/platform/WebFloatRect.h" 54 #include "public/platform/WebFloatRect.h"
53 #include "public/platform/WebLayer.h" 55 #include "public/platform/WebLayer.h"
54 #include "public/platform/WebPoint.h" 56 #include "public/platform/WebPoint.h"
(...skipping 14 matching lines...) Expand all
69 71
70 namespace blink { 72 namespace blink {
71 73
72 static bool s_drawDebugRedFill = true; 74 static bool s_drawDebugRedFill = true;
73 75
74 struct PaintInvalidationInfo { 76 struct PaintInvalidationInfo {
75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 77 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
76 // This is for comparison only. Don't dereference because the client may hav e died. 78 // This is for comparison only. Don't dereference because the client may hav e died.
77 const DisplayItemClient* client; 79 const DisplayItemClient* client;
78 String clientDebugName; 80 String clientDebugName;
79 FloatRect rect; 81 IntRect rect;
80 PaintInvalidationReason reason; 82 PaintInvalidationReason reason;
81 }; 83 };
82 84
83 typedef HashMap<const GraphicsLayer*, Vector<PaintInvalidationInfo>> PaintInvali dationTrackingMap; 85 struct PaintInvalidationTracking {
86 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
87 Vector<PaintInvalidationInfo> trackedPaintInvalidations;
88 #if DCHECK_IS_ON()
89 RefPtr<SkPicture> lastPaintedPicture;
90 Region paintInvalidationRegionSinceLastPaint;
91 #endif
92 };
93
94 typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> PaintInvalidati onTrackingMap;
84 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() 95 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap()
85 { 96 {
86 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); 97 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ());
87 return map; 98 return map;
88 } 99 }
89 100
90 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) 101 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
91 { 102 {
92 return adoptPtr(new GraphicsLayer(client)); 103 return adoptPtr(new GraphicsLayer(client));
93 } 104 }
94 105
95 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) 106 GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client)
96 : m_client(client) 107 : m_client(client)
97 , m_backgroundColor(Color::transparent) 108 , m_backgroundColor(Color::transparent)
98 , m_opacity(1) 109 , m_opacity(1)
99 , m_blendMode(WebBlendModeNormal) 110 , m_blendMode(WebBlendModeNormal)
100 , m_hasTransformOrigin(false) 111 , m_hasTransformOrigin(false)
101 , m_contentsOpaque(false) 112 , m_contentsOpaque(false)
102 , m_shouldFlattenTransform(true) 113 , m_shouldFlattenTransform(true)
103 , m_backfaceVisibility(true) 114 , m_backfaceVisibility(true)
104 , m_masksToBounds(false) 115 , m_masksToBounds(false)
105 , m_drawsContent(false) 116 , m_drawsContent(false)
106 , m_contentsVisible(true) 117 , m_contentsVisible(true)
107 , m_isRootForIsolatedGroup(false) 118 , m_isRootForIsolatedGroup(false)
108 , m_hasScrollParent(false) 119 , m_hasScrollParent(false)
109 , m_hasClipParent(false) 120 , m_hasClipParent(false)
110 , m_painted(false) 121 , m_painted(false)
111 , m_textPainted(false) 122 , m_textPainted(false)
112 , m_imagePainted(false) 123 , m_imagePainted(false)
124 , m_isTrackingPaintInvalidations(client && client->isTrackingPaintInvalidati ons())
113 , m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip) 125 , m_paintingPhase(GraphicsLayerPaintAllWithOverflowClip)
114 , m_parent(0) 126 , m_parent(0)
115 , m_maskLayer(0) 127 , m_maskLayer(0)
116 , m_contentsClippingMaskLayer(0) 128 , m_contentsClippingMaskLayer(0)
117 , m_replicaLayer(0) 129 , m_replicaLayer(0)
118 , m_replicatedLayer(0) 130 , m_replicatedLayer(0)
119 , m_paintCount(0) 131 , m_paintCount(0)
120 , m_contentsLayer(0) 132 , m_contentsLayer(0)
121 , m_contentsLayerId(0) 133 , m_contentsLayerId(0)
122 , m_scrollableArea(nullptr) 134 , m_scrollableArea(nullptr)
(...skipping 23 matching lines...) Expand all
146 158
147 if (m_replicaLayer) 159 if (m_replicaLayer)
148 m_replicaLayer->setReplicatedLayer(0); 160 m_replicaLayer->setReplicatedLayer(0);
149 161
150 if (m_replicatedLayer) 162 if (m_replicatedLayer)
151 m_replicatedLayer->setReplicatedByLayer(0); 163 m_replicatedLayer->setReplicatedByLayer(0);
152 164
153 removeAllChildren(); 165 removeAllChildren();
154 removeFromParent(); 166 removeFromParent();
155 167
156 resetTrackedPaintInvalidations(); 168 paintInvalidationTrackingMap().remove(this);
157 ASSERT(!m_parent); 169 ASSERT(!m_parent);
158 } 170 }
159 171
160 LayoutRect GraphicsLayer::visualRect() const 172 LayoutRect GraphicsLayer::visualRect() const
161 { 173 {
162 LayoutRect bounds = LayoutRect(FloatPoint(), size()); 174 LayoutRect bounds = LayoutRect(FloatPoint(), size());
163 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation()); 175 bounds.move(offsetFromLayoutObjectWithSubpixelAccumulation());
164 return bounds; 176 return bounds;
165 } 177 }
166 178
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return LayoutSize(offsetFromLayoutObject()) + client()->subpixelAccumulation (); 324 return LayoutSize(offsetFromLayoutObject()) + client()->subpixelAccumulation ();
313 } 325 }
314 326
315 IntRect GraphicsLayer::interestRect() 327 IntRect GraphicsLayer::interestRect()
316 { 328 {
317 return m_previousInterestRect; 329 return m_previousInterestRect;
318 } 330 }
319 331
320 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode) 332 void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled Mode disabledMode)
321 { 333 {
322 if (paintWithoutCommit(interestRect, disabledMode)) 334 if (paintWithoutCommit(interestRect, disabledMode)) {
323 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation()); 335 getPaintController().commitNewDisplayItems(offsetFromLayoutObjectWithSub pixelAccumulation());
336 #if DCHECK_IS_ON()
337 if (isTrackingOrCheckingPaintInvalidations()) {
338 RefPtr<SkPicture> newPicture = capturePicture();
339 checkUnderPaintInvalidations(*newPicture);
340 PaintInvalidationTracking& tracking = paintInvalidationTrackingMap() .add(this, PaintInvalidationTracking()).storedValue->value;
341 tracking.lastPaintedPicture = newPicture;
342 tracking.paintInvalidationRegionSinceLastPaint = Region();
343 }
344 #endif
345 }
324 } 346 }
325 347
326 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode) 348 bool GraphicsLayer::paintWithoutCommit(const IntRect* interestRect, GraphicsCont ext::DisabledMode disabledMode)
327 { 349 {
328 ASSERT(drawsContent()); 350 ASSERT(drawsContent());
329 351
330 if (!m_client) 352 if (!m_client)
331 return false; 353 return false;
332 if (firstPaintInvalidationTrackingEnabled()) 354 if (firstPaintInvalidationTrackingEnabled())
333 m_debugInfo.clearAnnotatedInvalidateRects(); 355 m_debugInfo.clearAnnotatedInvalidateRects();
(...skipping 10 matching lines...) Expand all
344 && !getPaintController().cacheIsEmpty() 366 && !getPaintController().cacheIsEmpty()
345 && m_previousInterestRect == *interestRect) { 367 && m_previousInterestRect == *interestRect) {
346 return false; 368 return false;
347 } 369 }
348 370
349 GraphicsContext context(getPaintController(), disabledMode); 371 GraphicsContext context(getPaintController(), disabledMode);
350 372
351 #ifndef NDEBUG 373 #ifndef NDEBUG
352 if (contentsOpaque() && s_drawDebugRedFill) { 374 if (contentsOpaque() && s_drawDebugRedFill) {
353 FloatRect rect(FloatPoint(), size()); 375 FloatRect rect(FloatPoint(), size());
354 if (!DrawingRecorder::useCachedDrawingIfPossible(context, *this, Display Item::DebugRedFill)) { 376 DisplayItemCacheSkipper cacheSkipper(context);
pdr. 2016/06/09 19:21:44 This change makes sense, but why was it needed for
Xianzhu 2016/06/09 20:47:44 This is not needed for this patch. Reverted.
355 DrawingRecorder recorder(context, *this, DisplayItem::DebugRedFill, rect); 377 DrawingRecorder recorder(context, *this, DisplayItem::DebugRedFill, rect );
356 context.fillRect(rect, SK_ColorRED); 378 context.fillRect(rect, SK_ColorRED);
357 }
358 } 379 }
359 #endif 380 #endif
360 381
361 m_previousInterestRect = *interestRect; 382 m_previousInterestRect = *interestRect;
362 m_client->paintContents(this, context, m_paintingPhase, *interestRect); 383 m_client->paintContents(this, context, m_paintingPhase, *interestRect);
363 notifyFirstPaintToClient(); 384 notifyFirstPaintToClient();
364 return true; 385 return true;
365 } 386 }
366 387
367 void GraphicsLayer::notifyFirstPaintToClient() 388 void GraphicsLayer::notifyFirstPaintToClient()
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 { 547 {
527 return m_debugInfo; 548 return m_debugInfo;
528 } 549 }
529 550
530 WebLayer* GraphicsLayer::contentsLayerIfRegistered() 551 WebLayer* GraphicsLayer::contentsLayerIfRegistered()
531 { 552 {
532 clearContentsLayerIfUnregistered(); 553 clearContentsLayerIfUnregistered();
533 return m_contentsLayer; 554 return m_contentsLayer;
534 } 555 }
535 556
557 void GraphicsLayer::setTracksPaintInvalidations(bool tracksPaintInvalidations)
558 {
559 resetTrackedPaintInvalidations();
560 m_isTrackingPaintInvalidations = tracksPaintInvalidations;
561 }
562
536 void GraphicsLayer::resetTrackedPaintInvalidations() 563 void GraphicsLayer::resetTrackedPaintInvalidations()
537 { 564 {
538 paintInvalidationTrackingMap().remove(this); 565 auto it = paintInvalidationTrackingMap().find(this);
566 if (it == paintInvalidationTrackingMap().end())
567 return;
568
569 if (!RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled() )
570 paintInvalidationTrackingMap().remove(it);
571 else
572 it->value.trackedPaintInvalidations.clear();
539 } 573 }
540 574
541 bool GraphicsLayer::hasTrackedPaintInvalidations() const 575 bool GraphicsLayer::hasTrackedPaintInvalidations() const
542 { 576 {
543 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 577 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
544 if (it != paintInvalidationTrackingMap().end()) 578 if (it != paintInvalidationTrackingMap().end())
545 return !it->value.isEmpty(); 579 return !it->value.trackedPaintInvalidations.isEmpty();
546 return false; 580 return false;
547 } 581 }
548 582
549 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t FloatRect& rect, PaintInvalidationReason reason) 583 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons t IntRect& rect, PaintInvalidationReason reason)
550 { 584 {
551 // The caller must check isTrackingPaintInvalidations() before calling this method 585 // The caller must check isTrackingOrCheckingPaintInvalidations() before cal ling this method
552 // to avoid constructing the rect unnecessarily. 586 // to avoid constructing the rect unnecessarily.
553 ASSERT(isTrackingPaintInvalidations()); 587 DCHECK(isTrackingOrCheckingPaintInvalidations());
554 588
555 Vector<PaintInvalidationInfo>& infos = paintInvalidationTrackingMap().add(th is, Vector<PaintInvalidationInfo>()).storedValue->value; 589 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. 590 // 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(). 591 // This is to avoid duplicated entries for setNeedsDisplayInRect() and track ObjectPaintInvalidation().
558 if (rect.isEmpty() && !infos.isEmpty() && infos.last().client == &client) 592 if (rect.isEmpty() && !tracking.trackedPaintInvalidations.isEmpty() && track ing.trackedPaintInvalidations.last().client == &client)
559 return; 593 return;
560 594
561 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason }; 595 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason };
562 infos.append(info); 596 tracking.trackedPaintInvalidations.append(info);
597
598 #if DCHECK_IS_ON()
599 if (!rect.isEmpty()) {
600 // TODO(crbug.com/496260): Some antialiasing effects overflows the paint invalidation rect.
601 IntRect r = rect;
602 r.inflate(1);
603 tracking.paintInvalidationRegionSinceLastPaint.unite(r);
604 }
605 #endif
563 } 606 }
564 607
565 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b) 608 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b)
566 { 609 {
567 // Sort by rect first, bigger rects before smaller ones. 610 // Sort by rect first, bigger rects before smaller ones.
568 if (a.rect.width() != b.rect.width()) 611 if (a.rect.width() != b.rect.width())
569 return a.rect.width() > b.rect.width(); 612 return a.rect.width() > b.rect.width();
570 if (a.rect.height() != b.rect.height()) 613 if (a.rect.height() != b.rect.height())
571 return a.rect.height() > b.rect.height(); 614 return a.rect.height() > b.rect.height();
572 if (a.rect.x() != b.rect.x()) 615 if (a.rect.x() != b.rect.x())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 768
726 if (m_replicaLayer) 769 if (m_replicaLayer)
727 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap)); 770 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap));
728 771
729 if (m_replicatedLayer) 772 if (m_replicatedLayer)
730 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : ""); 773 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : "");
731 774
732 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 775 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
733 if (it != paintInvalidationTrackingMap().end()) { 776 if (it != paintInvalidationTrackingMap().end()) {
734 if (flags & LayerTreeIncludesPaintInvalidations) { 777 if (flags & LayerTreeIncludesPaintInvalidations) {
735 Vector<PaintInvalidationInfo>& infos = it->value; 778 Vector<PaintInvalidationInfo>& infos = it->value.trackedPaintInvalid ations;
736 if (!infos.isEmpty()) { 779 if (!infos.isEmpty()) {
737 std::sort(infos.begin(), infos.end(), &comparePaintInvalidationI nfo); 780 std::sort(infos.begin(), infos.end(), &comparePaintInvalidationI nfo);
738 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create(); 781 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create();
739 for (auto& info : infos) { 782 for (auto& info : infos) {
740 RefPtr<JSONObject> infoJSON = JSONObject::create(); 783 RefPtr<JSONObject> infoJSON = JSONObject::create();
741 infoJSON->setString("object", info.clientDebugName); 784 infoJSON->setString("object", info.clientDebugName);
742 if (!info.rect.isEmpty()) 785 if (!info.rect.isEmpty())
743 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); 786 infoJSON->setArray("rect", rectAsJSONArray(info.rect));
744 infoJSON->setString("reason", paintInvalidationReasonToStrin g(info.reason)); 787 infoJSON->setString("reason", paintInvalidationReasonToStrin g(info.reason));
745 paintInvalidationsJSON->pushObject(infoJSON); 788 paintInvalidationsJSON->pushObject(infoJSON);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 if (clampedSize.width() < 0 || clampedSize.height() < 0) 911 if (clampedSize.width() < 0 || clampedSize.height() < 0)
869 clampedSize = FloatSize(); 912 clampedSize = FloatSize();
870 913
871 if (clampedSize == m_size) 914 if (clampedSize == m_size)
872 return; 915 return;
873 916
874 m_size = clampedSize; 917 m_size = clampedSize;
875 918
876 m_layer->layer()->setBounds(flooredIntSize(m_size)); 919 m_layer->layer()->setBounds(flooredIntSize(m_size));
877 // Note that we don't resize m_contentsLayer. It's up the caller to do that. 920 // Note that we don't resize m_contentsLayer. It's up the caller to do that.
878
879 #ifndef NDEBUG
880 // The red debug fill and needs to be invalidated if the layer resizes.
881 setDisplayItemsUncached();
882 #endif
883 } 921 }
884 922
885 void GraphicsLayer::setTransform(const TransformationMatrix& transform) 923 void GraphicsLayer::setTransform(const TransformationMatrix& transform)
886 { 924 {
887 m_transform = transform; 925 m_transform = transform;
888 platformLayer()->setTransform(TransformationMatrix::toSkMatrix44(m_transform )); 926 platformLayer()->setTransform(TransformationMatrix::toSkMatrix44(m_transform ));
889 } 927 }
890 928
891 void GraphicsLayer::setTransformOrigin(const FloatPoint3D& transformOrigin) 929 void GraphicsLayer::setTransformOrigin(const FloatPoint3D& transformOrigin)
892 { 930 {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 if (m_isRootForIsolatedGroup == isolated) 1066 if (m_isRootForIsolatedGroup == isolated)
1029 return; 1067 return;
1030 m_isRootForIsolatedGroup = isolated; 1068 m_isRootForIsolatedGroup = isolated;
1031 platformLayer()->setIsRootForIsolatedGroup(isolated); 1069 platformLayer()->setIsRootForIsolatedGroup(isolated);
1032 } 1070 }
1033 1071
1034 void GraphicsLayer::setContentsNeedsDisplay() 1072 void GraphicsLayer::setContentsNeedsDisplay()
1035 { 1073 {
1036 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { 1074 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) {
1037 contentsLayer->invalidate(); 1075 contentsLayer->invalidate();
1038 if (isTrackingPaintInvalidations()) 1076 if (isTrackingOrCheckingPaintInvalidations())
1039 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull) ; 1077 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull) ;
1040 } 1078 }
1041 } 1079 }
1042 1080
1043 void GraphicsLayer::setNeedsDisplay() 1081 void GraphicsLayer::setNeedsDisplay()
1044 { 1082 {
1045 if (!drawsContent()) 1083 if (!drawsContent())
1046 return; 1084 return;
1047 1085
1048 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so. 1086 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so.
1049 m_layer->layer()->invalidate(); 1087 m_layer->layer()->invalidate();
1050 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1088 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1051 m_linkHighlights[i]->invalidate(); 1089 m_linkHighlights[i]->invalidate();
1052 getPaintController().invalidateAll(); 1090 getPaintController().invalidateAll();
1053 1091
1054 if (isTrackingPaintInvalidations()) 1092 if (isTrackingOrCheckingPaintInvalidations())
1055 trackPaintInvalidation(*this, FloatRect(FloatPoint(), m_size), PaintInva lidationFull); 1093 trackPaintInvalidation(*this, IntRect(IntPoint(), expandedIntSize(m_size )), PaintInvalidationFull);
1056 } 1094 }
1057 1095
1058 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason, const DisplayItemClient& client) 1096 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason, const DisplayItemClient& client)
1059 { 1097 {
1060 if (!drawsContent()) 1098 if (!drawsContent())
1061 return; 1099 return;
1062 1100
1063 m_layer->layer()->invalidateRect(rect); 1101 m_layer->layer()->invalidateRect(rect);
1064 if (firstPaintInvalidationTrackingEnabled()) 1102 if (firstPaintInvalidationTrackingEnabled())
1065 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); 1103 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason);
1066 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1104 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1067 m_linkHighlights[i]->invalidate(); 1105 m_linkHighlights[i]->invalidate();
1068 1106
1069 if (isTrackingPaintInvalidations()) 1107 if (isTrackingOrCheckingPaintInvalidations())
1070 trackPaintInvalidation(client, rect, invalidationReason); 1108 trackPaintInvalidation(client, rect, invalidationReason);
1071 } 1109 }
1072 1110
1073 void GraphicsLayer::displayItemClientWasInvalidated(const DisplayItemClient& dis playItemClient, PaintInvalidationReason invalidationReason) 1111 void GraphicsLayer::displayItemClientWasInvalidated(const DisplayItemClient& dis playItemClient, PaintInvalidationReason invalidationReason)
1074 { 1112 {
1075 if (!drawsContent()) 1113 if (!drawsContent())
1076 return; 1114 return;
1077 1115
1078 getPaintController().displayItemClientWasInvalidated(displayItemClient); 1116 getPaintController().displayItemClientWasInvalidated(displayItemClient);
1079 1117
1080 if (isTrackingPaintInvalidations()) 1118 if (isTrackingOrCheckingPaintInvalidations())
1081 trackPaintInvalidation(displayItemClient, FloatRect(), invalidationReaso n); 1119 trackPaintInvalidation(displayItemClient, IntRect(), invalidationReason) ;
1082 } 1120 }
1083 1121
1084 void GraphicsLayer::setContentsRect(const IntRect& rect) 1122 void GraphicsLayer::setContentsRect(const IntRect& rect)
1085 { 1123 {
1086 if (rect == m_contentsRect) 1124 if (rect == m_contentsRect)
1087 return; 1125 return;
1088 1126
1089 m_contentsRect = rect; 1127 m_contentsRect = rect;
1090 updateContentsRect(); 1128 updateContentsRect();
1091 } 1129 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (WebLayer* layer = platformLayer()) 1250 if (WebLayer* layer = platformLayer())
1213 layer->setElementId(id); 1251 layer->setElementId(id);
1214 } 1252 }
1215 1253
1216 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) 1254 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties)
1217 { 1255 {
1218 if (WebLayer* layer = platformLayer()) 1256 if (WebLayer* layer = platformLayer())
1219 layer->setCompositorMutableProperties(properties); 1257 layer->setCompositorMutableProperties(properties);
1220 } 1258 }
1221 1259
1260 #if DCHECK_IS_ON()
1261
1262 PassRefPtr<SkPicture> GraphicsLayer::capturePicture()
1263 {
1264 if (!drawsContent())
1265 return nullptr;
1266
1267 IntSize intSize = expandedIntSize(size());
1268 GraphicsContext graphicsContext(getPaintController());
1269 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize));
1270 getPaintController().paintArtifact().replay(graphicsContext);
pdr. 2016/06/09 19:21:44 Why look at the pixels instead of just comparing t
Xianzhu 2016/06/09 20:47:44 Several reasons: 1. For incremental invalidation
1271 return graphicsContext.endRecording();
1272 }
1273
1274 void GraphicsLayer::checkUnderPaintInvalidations(const SkPicture& newPicture)
1275 {
1276 if (!drawsContent())
1277 return;
1278
1279 auto it = paintInvalidationTrackingMap().find(this);
1280 if (it == paintInvalidationTrackingMap().end())
1281 return;
1282 const PaintInvalidationTracking& tracking = it->value;
1283 if (!tracking.lastPaintedPicture)
1284 return;
1285
1286 SkBitmap oldBitmap;
1287 int width = static_cast<int>(ceilf(std::min(tracking.lastPaintedPicture->cul lRect().width(), newPicture.cullRect().width())));
1288 int height = static_cast<int>(ceilf(std::min(tracking.lastPaintedPicture->cu llRect().height(), newPicture.cullRect().height())));
1289 oldBitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
1290 SkCanvas(oldBitmap).drawPicture(tracking.lastPaintedPicture.get());
1291
1292 SkBitmap newBitmap;
1293 newBitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
1294 SkCanvas(newBitmap).drawPicture(&newPicture);
1295
1296 oldBitmap.lockPixels();
1297 newBitmap.lockPixels();
1298 int mismatchingPixels = 0;
1299 for (int y = 0; y < height; ++y) {
1300 for (int x = 0; x < width; ++x) {
1301 SkColor oldPixel = oldBitmap.getColor(x, y);
1302 SkColor newPixel = newBitmap.getColor(x, y);
1303 if (oldPixel != newPixel && !tracking.paintInvalidationRegionSinceLa stPaint.contains(IntPoint(x, y))) {
1304 if (mismatchingPixels < 50)
1305 LOG(ERROR) << debugName() << " Uninvalidated old/new pixels mismatch at " << x << "," << y << " old:" << std::hex << oldPixel << " new:" << newPixel;
1306 else if (mismatchingPixels == 50)
1307 LOG(ERROR) << "and more...";
1308 ++mismatchingPixels;
1309 *newBitmap.getAddr32(x, y) = SK_ColorRED;
1310 } else {
1311 *newBitmap.getAddr32(x, y) = SK_ColorTRANSPARENT;
1312 }
1313 }
1314 }
1315
1316 oldBitmap.unlockPixels();
1317 newBitmap.unlockPixels();
1318
1319 // Crash in layout test paint invalidation tracking mode if slimmingPaintUnd erInvalidationChecking is not enabled.
1320 if (!RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled() )
1321 CHECK(!mismatchingPixels) << "Run chrome/content_shell with --enable-bli nk-features=slimmingPaintUnderInvalidationChecking to visualize under-invalidati ons";
1322
1323 // Visualize under-invalidations by overlaying the new bitmap (containing re d pixels indicating under-invalidations,
1324 // and transparent pixels otherwise) onto the painting.
1325 SkPictureRecorder recorder;
1326 recorder.beginRecording(width, height);
1327 recorder.getRecordingCanvas()->drawBitmap(newBitmap, 0, 0);
1328 RefPtr<SkPicture> picture = fromSkSp(recorder.finishRecordingAsPicture());
1329 getPaintController().appendDebugDrawingAfterCommit(*this, picture, offsetFro mLayoutObjectWithSubpixelAccumulation());
1330 }
1331
1332 #endif // DCHECK_IS_ON()
1333
1222 } // namespace blink 1334 } // namespace blink
1223 1335
1224 #ifndef NDEBUG 1336 #ifndef NDEBUG
1225 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) 1337 void showGraphicsLayerTree(const blink::GraphicsLayer* layer)
1226 { 1338 {
1227 if (!layer) { 1339 if (!layer) {
1228 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); 1340 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n");
1229 return; 1341 return;
1230 } 1342 }
1231 1343
1232 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); 1344 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
1233 fprintf(stderr, "%s\n", output.utf8().data()); 1345 fprintf(stderr, "%s\n", output.utf8().data());
1234 } 1346 }
1235 #endif 1347 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698