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 | |
6 #include "platform/graphics/paint/PaintInvalidationTracking.h" | |
7 | |
8 #include "platform/geometry/LayoutRect.h" | |
9 #include "platform/graphics/Color.h" | |
10 | |
11 namespace blink { | |
12 | |
13 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P aintInvalidationInfo& b) | |
14 { | |
15 // Sort by rect first, bigger rects before smaller ones. | |
16 if (a.rect.width() != b.rect.width()) | |
17 return a.rect.width() > b.rect.width(); | |
18 if (a.rect.height() != b.rect.height()) | |
19 return a.rect.height() > b.rect.height(); | |
20 if (a.rect.x() != b.rect.x()) | |
21 return a.rect.x() > b.rect.x(); | |
22 if (a.rect.y() != b.rect.y()) | |
23 return a.rect.y() > b.rect.y(); | |
24 | |
25 // Then compare clientDebugName, in alphabetic order. | |
26 int nameCompareResult = codePointCompare(a.clientDebugName, b.clientDebugNam e); | |
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 { | |
36 std::unique_ptr<JSONArray> array = JSONArray::create(); | |
37 array->pushDouble(rect.x()); | |
38 array->pushDouble(rect.y()); | |
39 array->pushDouble(rect.width()); | |
40 array->pushDouble(rect.height()); | |
41 return array; | |
42 } | |
43 | |
44 void PaintInvalidationTracking::asJSON(JSONObject* json) | |
45 { | |
46 if (!trackedPaintInvalidations.isEmpty()) { | |
47 std::sort(trackedPaintInvalidations.begin(), trackedPaintInvalidations.e nd(), &comparePaintInvalidationInfo); | |
48 std::unique_ptr<JSONArray> paintInvalidationsJSON = JSONArray::create(); | |
49 for (auto& info : trackedPaintInvalidations) { | |
50 std::unique_ptr<JSONObject> infoJSON = JSONObject::create(); | |
51 infoJSON->setString("object", info.clientDebugName); | |
52 if (!info.rect.isEmpty()) { | |
53 if (info.rect == LayoutRect::infiniteIntRect()) | |
54 infoJSON->setString("rect", "infinite"); | |
55 else | |
56 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); | |
57 } | |
58 infoJSON->setString("reason", paintInvalidationReasonToString(info.r eason)); | |
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 = JSONArray::crea te(); | |
66 for (auto& underPaintInvalidation : underPaintInvalidations) { | |
67 std::unique_ptr<JSONObject> underPaintInvalidationJSON = JSONObject: :create(); | |
68 underPaintInvalidationJSON->setDouble("x", underPaintInvalidation.x) ; | |
69 underPaintInvalidationJSON->setDouble("y", underPaintInvalidation.y) ; | |
70 underPaintInvalidationJSON->setString("oldPixel", Color(underPaintIn validation.oldPixel).nameForLayoutTreeAsText()); | |
71 underPaintInvalidationJSON->setString("newPixel", Color(underPaintIn validation.newPixel).nameForLayoutTreeAsText()); | |
72 underPaintInvalidationsJSON->pushObject(std::move(underPaintInvalida tionJSON)); | |
73 } | |
74 json->setArray("underPaintInvalidations", std::move(underPaintInvalidati onsJSON)); | |
75 } | |
76 } | |
77 | |
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.
| |
78 } // namespace blink | |
OLD | NEW |