OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
| 6 |
| 7 #include "platform/geometry/LayoutRect.h" |
| 8 #include "platform/graphics/Color.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 static bool compareRasterInvalidationInfo(const RasterInvalidationInfo& a, |
| 13 const RasterInvalidationInfo& b) { |
| 14 // Sort by rect first, bigger rects before smaller ones. |
| 15 if (a.rect.width() != b.rect.width()) |
| 16 return a.rect.width() > b.rect.width(); |
| 17 if (a.rect.height() != b.rect.height()) |
| 18 return a.rect.height() > b.rect.height(); |
| 19 if (a.rect.x() != b.rect.x()) |
| 20 return a.rect.x() > b.rect.x(); |
| 21 if (a.rect.y() != b.rect.y()) |
| 22 return a.rect.y() > b.rect.y(); |
| 23 |
| 24 // Then compare clientDebugName, in alphabetic order. |
| 25 int nameCompareResult = |
| 26 codePointCompare(a.clientDebugName, b.clientDebugName); |
| 27 if (nameCompareResult != 0) |
| 28 return nameCompareResult < 0; |
| 29 |
| 30 return a.reason < b.reason; |
| 31 } |
| 32 |
| 33 template <typename T> |
| 34 static std::unique_ptr<JSONArray> rectAsJSONArray(const T& rect) { |
| 35 std::unique_ptr<JSONArray> array = JSONArray::create(); |
| 36 array->pushDouble(rect.x()); |
| 37 array->pushDouble(rect.y()); |
| 38 array->pushDouble(rect.width()); |
| 39 array->pushDouble(rect.height()); |
| 40 return array; |
| 41 } |
| 42 |
| 43 void RasterInvalidationTracking::asJSON(JSONObject* json) { |
| 44 if (!trackedRasterInvalidations.isEmpty()) { |
| 45 std::sort(trackedRasterInvalidations.begin(), |
| 46 trackedRasterInvalidations.end(), &compareRasterInvalidationInfo); |
| 47 std::unique_ptr<JSONArray> paintInvalidationsJSON = JSONArray::create(); |
| 48 for (auto& info : trackedRasterInvalidations) { |
| 49 std::unique_ptr<JSONObject> infoJSON = JSONObject::create(); |
| 50 infoJSON->setString("object", info.clientDebugName); |
| 51 if (!info.rect.isEmpty()) { |
| 52 if (info.rect == LayoutRect::infiniteIntRect()) |
| 53 infoJSON->setString("rect", "infinite"); |
| 54 else |
| 55 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); |
| 56 } |
| 57 infoJSON->setString("reason", |
| 58 paintInvalidationReasonToString(info.reason)); |
| 59 paintInvalidationsJSON->pushObject(std::move(infoJSON)); |
| 60 } |
| 61 json->setArray("paintInvalidations", std::move(paintInvalidationsJSON)); |
| 62 } |
| 63 |
| 64 if (!underPaintInvalidations.isEmpty()) { |
| 65 std::unique_ptr<JSONArray> underPaintInvalidationsJSON = |
| 66 JSONArray::create(); |
| 67 for (auto& underPaintInvalidation : underPaintInvalidations) { |
| 68 std::unique_ptr<JSONObject> underPaintInvalidationJSON = |
| 69 JSONObject::create(); |
| 70 underPaintInvalidationJSON->setDouble("x", underPaintInvalidation.x); |
| 71 underPaintInvalidationJSON->setDouble("y", underPaintInvalidation.y); |
| 72 underPaintInvalidationJSON->setString( |
| 73 "oldPixel", |
| 74 Color(underPaintInvalidation.oldPixel).nameForLayoutTreeAsText()); |
| 75 underPaintInvalidationJSON->setString( |
| 76 "newPixel", |
| 77 Color(underPaintInvalidation.newPixel).nameForLayoutTreeAsText()); |
| 78 underPaintInvalidationsJSON->pushObject( |
| 79 std::move(underPaintInvalidationJSON)); |
| 80 } |
| 81 json->setArray("underPaintInvalidations", |
| 82 std::move(underPaintInvalidationsJSON)); |
| 83 } |
| 84 } |
| 85 |
| 86 } // namespace blink |
OLD | NEW |