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

Unified Diff: third_party/WebKit/Source/platform/graphics/paint/PaintInvalidationTracking.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/paint/PaintInvalidationTracking.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/PaintInvalidationTracking.cpp b/third_party/WebKit/Source/platform/graphics/paint/PaintInvalidationTracking.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fbb4d231dd0632b8ea6233c5fdc656368af7b2fb
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/paint/PaintInvalidationTracking.cpp
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+#include "platform/graphics/paint/PaintInvalidationTracking.h"
+
+#include "platform/geometry/LayoutRect.h"
+#include "platform/graphics/Color.h"
+
+namespace blink {
+
+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> 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;
+}
+
+void PaintInvalidationTracking::asJSON(JSONObject* json)
+{
+ if (!trackedPaintInvalidations.isEmpty()) {
+ std::sort(trackedPaintInvalidations.begin(), trackedPaintInvalidations.end(), &comparePaintInvalidationInfo);
+ std::unique_ptr<JSONArray> paintInvalidationsJSON = JSONArray::create();
+ for (auto& info : trackedPaintInvalidations) {
+ std::unique_ptr<JSONObject> infoJSON = JSONObject::create();
+ infoJSON->setString("object", info.clientDebugName);
+ if (!info.rect.isEmpty()) {
+ if (info.rect == LayoutRect::infiniteIntRect())
+ infoJSON->setString("rect", "infinite");
+ else
+ infoJSON->setArray("rect", rectAsJSONArray(info.rect));
+ }
+ infoJSON->setString("reason", paintInvalidationReasonToString(info.reason));
+ paintInvalidationsJSON->pushObject(std::move(infoJSON));
+ }
+ json->setArray("paintInvalidations", std::move(paintInvalidationsJSON));
+ }
+
+ 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));
+ }
+}
+
Xianzhu 2016/09/30 00:47:01 Can we move rect under-invalidation checking from
chrishtr 2016/09/30 18:19:10 Ok will do that in a followup.
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698