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

Unified Diff: third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp

Issue 2380683006: SPv2: Add support for tracking raster paint invalidations in testing. (Closed)
Patch Set: none Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
index 74a28a27082351a6a87d641b1bc86ce033775dcd..dd062a60324d6b9dc0f611f50dc1b65211a0c093 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
@@ -42,6 +42,7 @@
#include "platform/graphics/LinkHighlight.h"
#include "platform/graphics/paint/DrawingRecorder.h"
#include "platform/graphics/paint/PaintController.h"
+#include "platform/graphics/paint/PaintInvalidationTracking.h"
#include "platform/json/JSONValues.h"
#include "platform/scroll/ScrollableArea.h"
#include "platform/text/TextStream.h"
@@ -70,36 +71,10 @@
namespace blink {
-struct PaintInvalidationInfo {
- DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
- // This is for comparison only. Don't dereference because the client may have died.
- const DisplayItemClient* client;
- String clientDebugName;
- IntRect rect;
- PaintInvalidationReason reason;
-};
-
-struct UnderPaintInvalidation {
- DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
- int x;
- int y;
- SkColor oldPixel;
- SkColor newPixel;
-};
-
-struct PaintInvalidationTracking {
- DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
- Vector<PaintInvalidationInfo> trackedPaintInvalidations;
- sk_sp<SkPicture> lastPaintedPicture;
- IntRect lastInterestRect;
- Region paintInvalidationRegionSinceLastPaint;
- Vector<UnderPaintInvalidation> underPaintInvalidations;
-};
-
-typedef HashMap<const GraphicsLayer*, PaintInvalidationTracking> PaintInvalidationTrackingMap;
-static PaintInvalidationTrackingMap& paintInvalidationTrackingMap()
-{
- DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ());
+template class PaintInvalidationTrackingMap<const GraphicsLayer>;
+static PaintInvalidationTrackingMap<const GraphicsLayer>& paintInvalidationTrackingMap()
+{
+ DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap<const GraphicsLayer>, map, ());
return map;
}
@@ -334,7 +309,7 @@ void GraphicsLayer::paint(const IntRect* interestRect, GraphicsContext::Disabled
if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) {
sk_sp<SkPicture> newPicture = capturePicture();
checkPaintUnderInvalidations(*newPicture);
- PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(this, PaintInvalidationTracking()).storedValue->value;
+ PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(this);
tracking.lastPaintedPicture = std::move(newPicture);
tracking.lastInterestRect = m_previousInterestRect;
tracking.paintInvalidationRegionSinceLastPaint = Region();
@@ -544,21 +519,21 @@ void GraphicsLayer::setTracksPaintInvalidations(bool tracksPaintInvalidations)
void GraphicsLayer::resetTrackedPaintInvalidations()
{
- auto it = paintInvalidationTrackingMap().find(this);
- if (it == paintInvalidationTrackingMap().end())
+ PaintInvalidationTracking* tracking = paintInvalidationTrackingMap().find(this);
+ if (!tracking)
return;
if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled())
- it->value.trackedPaintInvalidations.clear();
+ tracking->trackedPaintInvalidations.clear();
else
- paintInvalidationTrackingMap().remove(it);
+ paintInvalidationTrackingMap().remove(this);
}
bool GraphicsLayer::hasTrackedPaintInvalidations() const
{
- PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().find(this);
- if (it != paintInvalidationTrackingMap().end())
- return !it->value.trackedPaintInvalidations.isEmpty();
+ PaintInvalidationTracking* tracking = paintInvalidationTrackingMap().find(this);
+ if (tracking)
+ return !tracking->trackedPaintInvalidations.isEmpty();
return false;
}
@@ -567,10 +542,14 @@ void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons
if (!isTrackingOrCheckingPaintInvalidations() || rect.isEmpty())
return;
- PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(this, PaintInvalidationTracking()).storedValue->value;
+ PaintInvalidationTracking& tracking = paintInvalidationTrackingMap().add(this);
if (m_isTrackingPaintInvalidations) {
- PaintInvalidationInfo info = { &client, client.debugName(), rect, reason };
+ PaintInvalidationInfo info;
+ info.client = &client;
+ info.clientDebugName = client.debugName();
+ info.rect = rect;
+ info.reason = reason;
tracking.trackedPaintInvalidations.append(info);
}
@@ -582,26 +561,6 @@ void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons
}
}
-static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const PaintInvalidationInfo& b)
-{
- // Sort by rect first, bigger rects before smaller ones.
- if (a.rect.width() != b.rect.width())
- return a.rect.width() > b.rect.width();
- if (a.rect.height() != b.rect.height())
- return a.rect.height() > b.rect.height();
- if (a.rect.x() != b.rect.x())
- return a.rect.x() > b.rect.x();
- if (a.rect.y() != b.rect.y())
- return a.rect.y() > b.rect.y();
-
- // Then compare clientDebugName, in alphabetic order.
- int nameCompareResult = codePointCompare(a.clientDebugName, b.clientDebugName);
- if (nameCompareResult != 0)
- return nameCompareResult < 0;
-
- return a.reason < b.reason;
-}
-
template <typename T>
static std::unique_ptr<JSONArray> pointAsJSONArray(const T& point)
{
@@ -620,17 +579,6 @@ static std::unique_ptr<JSONArray> sizeAsJSONArray(const T& size)
return array;
}
-template <typename T>
-static std::unique_ptr<JSONArray> rectAsJSONArray(const T& rect)
-{
- std::unique_ptr<JSONArray> array = JSONArray::create();
- array->pushDouble(rect.x());
- array->pushDouble(rect.y());
- array->pushDouble(rect.width());
- array->pushDouble(rect.height());
- return array;
-}
-
static double roundCloseToZero(double number)
{
return std::abs(number) < 1e-7 ? 0 : number;
@@ -755,39 +703,7 @@ std::unique_ptr<JSONObject> GraphicsLayer::layerTreeAsJSONInternal(LayerTreeFlag
if (m_replicatedLayer)
json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ? pointerAsString(m_replicatedLayer) : "");
- PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().find(this);
- if (it != paintInvalidationTrackingMap().end()) {
- if (flags & LayerTreeIncludesPaintInvalidations) {
- Vector<PaintInvalidationInfo>& infos = it->value.trackedPaintInvalidations;
- if (!infos.isEmpty()) {
- std::sort(infos.begin(), infos.end(), &comparePaintInvalidationInfo);
- std::unique_ptr<JSONArray> paintInvalidationsJSON = JSONArray::create();
- for (auto& info : infos) {
- std::unique_ptr<JSONObject> infoJSON = JSONObject::create();
- infoJSON->setString("object", info.clientDebugName);
- if (!info.rect.isEmpty())
- infoJSON->setArray("rect", rectAsJSONArray(info.rect));
- infoJSON->setString("reason", paintInvalidationReasonToString(info.reason));
- paintInvalidationsJSON->pushObject(std::move(infoJSON));
- }
- json->setArray("paintInvalidations", std::move(paintInvalidationsJSON));
- }
-
- Vector<UnderPaintInvalidation>& underPaintInvalidations = it->value.underPaintInvalidations;
- if (!underPaintInvalidations.isEmpty()) {
- std::unique_ptr<JSONArray> underPaintInvalidationsJSON = JSONArray::create();
- for (auto& underPaintInvalidation : underPaintInvalidations) {
- std::unique_ptr<JSONObject> underPaintInvalidationJSON = JSONObject::create();
- underPaintInvalidationJSON->setDouble("x", underPaintInvalidation.x);
- underPaintInvalidationJSON->setDouble("y", underPaintInvalidation.y);
- underPaintInvalidationJSON->setString("oldPixel", Color(underPaintInvalidation.oldPixel).nameForLayoutTreeAsText());
- underPaintInvalidationJSON->setString("newPixel", Color(underPaintInvalidation.newPixel).nameForLayoutTreeAsText());
- underPaintInvalidationsJSON->pushObject(std::move(underPaintInvalidationJSON));
- }
- json->setArray("underPaintInvalidations", std::move(underPaintInvalidationsJSON));
- }
- }
- }
+ paintInvalidationTrackingMap().asJSON(this, json.get());
if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) {
std::unique_ptr<JSONArray> paintingPhasesJSON = JSONArray::create();
@@ -1283,14 +1199,14 @@ void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture)
if (!drawsContent())
return;
- auto it = paintInvalidationTrackingMap().find(this);
- if (it == paintInvalidationTrackingMap().end())
+ PaintInvalidationTracking* tracking = paintInvalidationTrackingMap().find(this);
+ if (!tracking)
return;
- PaintInvalidationTracking& tracking = it->value;
- if (!tracking.lastPaintedPicture)
+
+ if (!tracking->lastPaintedPicture)
return;
- IntRect rect = intersection(tracking.lastInterestRect, interestRect());
+ IntRect rect = intersection(tracking->lastInterestRect, interestRect());
if (rect.isEmpty())
return;
@@ -1300,7 +1216,7 @@ void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture)
SkCanvas canvas(oldBitmap);
canvas.clear(SK_ColorTRANSPARENT);
canvas.translate(-rect.x(), -rect.y());
- canvas.drawPicture(tracking.lastPaintedPicture.get());
+ canvas.drawPicture(tracking->lastPaintedPicture.get());
}
SkBitmap newBitmap;
@@ -1322,10 +1238,10 @@ void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture)
int layerX = bitmapX + rect.x();
SkColor oldPixel = oldBitmap.getColor(bitmapX, bitmapY);
SkColor newPixel = newBitmap.getColor(bitmapX, bitmapY);
- if (pixelsDiffer(oldPixel, newPixel) && !tracking.paintInvalidationRegionSinceLastPaint.contains(IntPoint(layerX, layerY))) {
+ if (pixelsDiffer(oldPixel, newPixel) && !tracking->paintInvalidationRegionSinceLastPaint.contains(IntPoint(layerX, layerY))) {
if (mismatchingPixels < maxMismatchesToReport) {
UnderPaintInvalidation underPaintInvalidation = { layerX, layerY, oldPixel, newPixel };
- tracking.underPaintInvalidations.append(underPaintInvalidation);
+ tracking->underPaintInvalidations.append(underPaintInvalidation);
LOG(ERROR) << debugName() << " Uninvalidated old/new pixels mismatch at " << layerX << "," << layerY << " old:" << std::hex << oldPixel << " new:" << newPixel;
} else if (mismatchingPixels == maxMismatchesToReport) {
LOG(ERROR) << "and more...";

Powered by Google App Engine
This is Rietveld 408576698