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

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

Issue 1880763002: Merge repaintRects and paintInvalidationObjects in text-based-repaint test results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include <utility> 64 #include <utility>
65 65
66 #ifndef NDEBUG 66 #ifndef NDEBUG
67 #include <stdio.h> 67 #include <stdio.h>
68 #endif 68 #endif
69 69
70 namespace blink { 70 namespace blink {
71 71
72 static bool s_drawDebugRedFill = true; 72 static bool s_drawDebugRedFill = true;
73 73
74 // TODO(wangxianzhu): Remove this when we no longer invalidate rects. 74 struct PaintInvalidationInfo {
75 struct PaintInvalidationTrackingInfo {
76 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
77 Vector<FloatRect> invalidationRects; 76 String object;
pdr. 2016/04/12 00:20:06 Why pass a string instead of a DisplayItemClient?
Xianzhu 2016/04/12 01:14:26 Another case is LinkHighlightImpl which is not a D
78 Vector<String> invalidationObjects; 77 FloatRect rect;
78 const char* reason;
pdr. 2016/04/12 00:20:06 Could we use PaintInvalidationReason directly here
Xianzhu 2016/04/12 01:14:26 Changed to PaintInvalidationReason. Used const ch
79 }; 79 };
80 80
81 typedef HashMap<const GraphicsLayer*, PaintInvalidationTrackingInfo> PaintInvali dationTrackingMap; 81 typedef HashMap<const GraphicsLayer*, Vector<PaintInvalidationInfo>> PaintInvali dationTrackingMap;
82 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() 82 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap()
83 { 83 {
84 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); 84 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ());
85 return map; 85 return map;
86 } 86 }
87 87
88 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) 88 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
89 { 89 {
90 OwnPtr<GraphicsLayer> layer = adoptPtr(new GraphicsLayer(client)); 90 OwnPtr<GraphicsLayer> layer = adoptPtr(new GraphicsLayer(client));
91 return layer.release(); 91 return layer.release();
(...skipping 21 matching lines...) Expand all
113 , m_parent(0) 113 , m_parent(0)
114 , m_maskLayer(0) 114 , m_maskLayer(0)
115 , m_contentsClippingMaskLayer(0) 115 , m_contentsClippingMaskLayer(0)
116 , m_replicaLayer(0) 116 , m_replicaLayer(0)
117 , m_replicatedLayer(0) 117 , m_replicatedLayer(0)
118 , m_paintCount(0) 118 , m_paintCount(0)
119 , m_contentsLayer(0) 119 , m_contentsLayer(0)
120 , m_contentsLayerId(0) 120 , m_contentsLayerId(0)
121 , m_scrollableArea(nullptr) 121 , m_scrollableArea(nullptr)
122 , m_3dRenderingContext(0) 122 , m_3dRenderingContext(0)
123 , m_lastSetNeedsDisplayInRectDisplayItemClient(nullptr)
123 { 124 {
124 #if ENABLE(ASSERT) 125 #if ENABLE(ASSERT)
125 if (m_client) 126 if (m_client)
126 m_client->verifyNotPainting(); 127 m_client->verifyNotPainting();
127 #endif 128 #endif
128 129
129 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this)); 130 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this));
130 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa yer(m_contentLayerDelegate.get())); 131 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa yer(m_contentLayerDelegate.get()));
131 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible); 132 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible);
132 m_layer->layer()->setLayerClient(this); 133 m_layer->layer()->setLayerClient(this);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 531
531 void GraphicsLayer::resetTrackedPaintInvalidations() 532 void GraphicsLayer::resetTrackedPaintInvalidations()
532 { 533 {
533 paintInvalidationTrackingMap().remove(this); 534 paintInvalidationTrackingMap().remove(this);
534 } 535 }
535 536
536 bool GraphicsLayer::hasTrackedPaintInvalidations() const 537 bool GraphicsLayer::hasTrackedPaintInvalidations() const
537 { 538 {
538 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 539 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
539 if (it != paintInvalidationTrackingMap().end()) 540 if (it != paintInvalidationTrackingMap().end())
540 return !it->value.invalidationRects.isEmpty(); 541 return !it->value.isEmpty();
541 return false; 542 return false;
542 } 543 }
543 544
544 void GraphicsLayer::trackPaintInvalidationRect(const FloatRect& rect) 545 void GraphicsLayer::trackPaintInvalidation(const String& object, const FloatRect & rect, const char* reason)
545 { 546 {
546 if (rect.isEmpty())
547 return;
548
549 // The caller must check isTrackingPaintInvalidations() before calling this method 547 // The caller must check isTrackingPaintInvalidations() before calling this method
550 // to avoid constructing the rect unnecessarily. 548 // to avoid constructing the rect unnecessarily.
551 ASSERT(isTrackingPaintInvalidations()); 549 ASSERT(isTrackingPaintInvalidations());
552 550
553 paintInvalidationTrackingMap().add(this, PaintInvalidationTrackingInfo()).st oredValue->value.invalidationRects.append(rect); 551 PaintInvalidationInfo info = { object, rect, reason };
552 paintInvalidationTrackingMap().add(this, Vector<PaintInvalidationInfo>()).st oredValue->value.append(info);
554 } 553 }
555 554
556 void GraphicsLayer::trackPaintInvalidationObject(const String& objectDebugString ) 555 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b)
557 { 556 {
558 if (objectDebugString.isEmpty()) 557 return codePointCompareLessThan(a.object, b.object);
559 return;
560
561 // The caller must check isTrackingPaintInvalidations() before calling this method
562 // because constructing the debug string will be costly.
563 ASSERT(isTrackingPaintInvalidations());
564
565 paintInvalidationTrackingMap().add(this, PaintInvalidationTrackingInfo()).st oredValue->value.invalidationObjects.append(objectDebugString);
566 }
567
568 static bool compareFloatRects(const FloatRect& a, const FloatRect& b)
569 {
570 if (a.x() != b.x())
571 return a.x() > b.x();
572 if (a.y() != b.y())
573 return a.y() > b.y();
574 if (a.width() != b.width())
575 return a.width() > b.width();
576 return a.height() > b.height();
577 } 558 }
578 559
579 template <typename T> 560 template <typename T>
580 static PassRefPtr<JSONArray> pointAsJSONArray(const T& point) 561 static PassRefPtr<JSONArray> pointAsJSONArray(const T& point)
581 { 562 {
582 RefPtr<JSONArray> array = JSONArray::create(); 563 RefPtr<JSONArray> array = JSONArray::create();
583 array->pushNumber(point.x()); 564 array->pushNumber(point.x());
584 array->pushNumber(point.y()); 565 array->pushNumber(point.y());
585 return array; 566 return array;
586 } 567 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 json->setArray("transform", transformAsJSONArray(m_transform)); 699 json->setArray("transform", transformAsJSONArray(m_transform));
719 700
720 if (m_replicaLayer) 701 if (m_replicaLayer)
721 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap)); 702 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r enderingContextMap));
722 703
723 if (m_replicatedLayer) 704 if (m_replicatedLayer)
724 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : ""); 705 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : "");
725 706
726 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this); 707 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f ind(this);
727 if (it != paintInvalidationTrackingMap().end()) { 708 if (it != paintInvalidationTrackingMap().end()) {
728 if (flags & LayerTreeIncludesPaintInvalidationRects) { 709 if (flags & LayerTreeIncludesPaintInvalidations) {
729 Vector<FloatRect>& rects = it->value.invalidationRects; 710 Vector<PaintInvalidationInfo>& infos = it->value;
730 if (!rects.isEmpty()) { 711 if (!infos.isEmpty()) {
731 std::sort(rects.begin(), rects.end(), &compareFloatRects); 712 std::stable_sort(infos.begin(), infos.end(), &comparePaintInvali dationInfo);
732 RefPtr<JSONArray> rectsJSON = JSONArray::create(); 713 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create();
733 for (auto& rect : rects) { 714 for (auto& info : infos) {
734 if (rect.isEmpty()) 715 RefPtr<JSONObject> infoJSON = JSONObject::create();
735 continue; 716 infoJSON->setString("object", info.object);
736 rectsJSON->pushArray(rectAsJSONArray(rect)); 717 infoJSON->setArray("rect", rectAsJSONArray(info.rect));
718 infoJSON->setString("reason", info.reason);
719 paintInvalidationsJSON->pushObject(infoJSON);
737 } 720 }
738 json->setArray("repaintRects", rectsJSON); 721 json->setArray("paintInvalidations", paintInvalidationsJSON);
739 }
740 }
741
742 if (flags & LayerTreeIncludesPaintInvalidationObjects) {
743 Vector<String>& clients = it->value.invalidationObjects;
744 if (!clients.isEmpty()) {
745 RefPtr<JSONArray> clientsJSON = JSONArray::create();
746 for (auto& clientString : clients)
747 clientsJSON->pushString(clientString);
748 json->setArray("paintInvalidationClients", clientsJSON);
749 } 722 }
750 } 723 }
751 } 724 }
752 725
753 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { 726 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) {
754 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create(); 727 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create();
755 if (m_paintingPhase & GraphicsLayerPaintBackground) 728 if (m_paintingPhase & GraphicsLayerPaintBackground)
756 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); 729 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground");
757 if (m_paintingPhase & GraphicsLayerPaintForeground) 730 if (m_paintingPhase & GraphicsLayerPaintForeground)
758 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); 731 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground");
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 return; 1004 return;
1032 m_isRootForIsolatedGroup = isolated; 1005 m_isRootForIsolatedGroup = isolated;
1033 platformLayer()->setIsRootForIsolatedGroup(isolated); 1006 platformLayer()->setIsRootForIsolatedGroup(isolated);
1034 } 1007 }
1035 1008
1036 void GraphicsLayer::setContentsNeedsDisplay() 1009 void GraphicsLayer::setContentsNeedsDisplay()
1037 { 1010 {
1038 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { 1011 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) {
1039 contentsLayer->invalidate(); 1012 contentsLayer->invalidate();
1040 if (isTrackingPaintInvalidations()) 1013 if (isTrackingPaintInvalidations())
1041 trackPaintInvalidationRect(m_contentsRect); 1014 trackPaintInvalidation("GraphicsLayerContents", m_contentsRect, "");
1042 } 1015 }
1043 } 1016 }
1044 1017
1045 void GraphicsLayer::setNeedsDisplay() 1018 void GraphicsLayer::setNeedsDisplay()
1046 { 1019 {
1047 if (!drawsContent()) 1020 if (!drawsContent())
1048 return; 1021 return;
1049 1022
1050 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so. 1023 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv ely does so.
1051 m_layer->layer()->invalidate(); 1024 m_layer->layer()->invalidate();
1052 if (isTrackingPaintInvalidations())
1053 trackPaintInvalidationRect(FloatRect(FloatPoint(), m_size));
1054 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1025 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1055 m_linkHighlights[i]->invalidate(); 1026 m_linkHighlights[i]->invalidate();
1027 getPaintController().invalidateAll();
1056 1028
1057 getPaintController().invalidateAll();
1058 if (isTrackingPaintInvalidations()) 1029 if (isTrackingPaintInvalidations())
1059 trackPaintInvalidationObject("##ALL##"); 1030 trackPaintInvalidation("##ALL##", FloatRect(FloatPoint(), m_size), "");
pdr. 2016/04/12 00:20:06 I only see this output in 4 tests, but there are 1
Xianzhu 2016/04/12 01:14:26 We may have test coverage for the other setNeedsDi
1060 } 1031 }
1061 1032
1062 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason) 1033 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation Reason invalidationReason, const DisplayItemClient& client)
1063 { 1034 {
1064 if (!drawsContent()) 1035 if (!drawsContent())
1065 return; 1036 return;
1066 1037
1067 m_layer->layer()->invalidateRect(rect); 1038 m_layer->layer()->invalidateRect(rect);
1068 if (firstPaintInvalidationTrackingEnabled()) 1039 if (firstPaintInvalidationTrackingEnabled())
1069 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); 1040 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason);
1070 if (isTrackingPaintInvalidations())
1071 trackPaintInvalidationRect(rect);
1072 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 1041 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
1073 m_linkHighlights[i]->invalidate(); 1042 m_linkHighlights[i]->invalidate();
1043
1044 if (isTrackingPaintInvalidations()) {
1045 m_lastSetNeedsDisplayInRectDisplayItemClient = &client;
1046 trackPaintInvalidation(client.debugName(), rect, paintInvalidationReason ToString(invalidationReason));
1047 }
1074 } 1048 }
1075 1049
1076 void GraphicsLayer::invalidateDisplayItemClient(const DisplayItemClient& display ItemClient, PaintInvalidationReason) 1050 void GraphicsLayer::invalidateDisplayItemClient(const DisplayItemClient& display ItemClient, PaintInvalidationReason invalidationReason)
1077 { 1051 {
1078 if (!drawsContent()) 1052 if (!drawsContent())
1079 return; 1053 return;
1080 1054
1081 getPaintController().invalidate(displayItemClient); 1055 getPaintController().invalidate(displayItemClient);
1082 if (isTrackingPaintInvalidations()) 1056
1083 trackPaintInvalidationObject(displayItemClient.debugName()); 1057 if (isTrackingPaintInvalidations() && m_lastSetNeedsDisplayInRectDisplayItem Client != &displayItemClient)
1058 trackPaintInvalidation(displayItemClient.debugName(), FloatRect(), paint InvalidationReasonToString(invalidationReason));
1084 } 1059 }
1085 1060
1086 void GraphicsLayer::setContentsRect(const IntRect& rect) 1061 void GraphicsLayer::setContentsRect(const IntRect& rect)
1087 { 1062 {
1088 if (rect == m_contentsRect) 1063 if (rect == m_contentsRect)
1089 return; 1064 return;
1090 1065
1091 m_contentsRect = rect; 1066 m_contentsRect = rect;
1092 updateContentsRect(); 1067 updateContentsRect();
1093 } 1068 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 { 1205 {
1231 if (!layer) { 1206 if (!layer) {
1232 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); 1207 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n");
1233 return; 1208 return;
1234 } 1209 }
1235 1210
1236 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); 1211 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
1237 fprintf(stderr, "%s\n", output.utf8().data()); 1212 fprintf(stderr, "%s\n", output.utf8().data());
1238 } 1213 }
1239 #endif 1214 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698