OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "platform/graphics/GraphicsLayerDebugInfo.h" | 21 #include "platform/graphics/GraphicsLayerDebugInfo.h" |
22 | 22 |
23 #include "public/platform/WebGraphicsLayerDebugInfo.h" | 23 #include "base/trace_event/trace_event_argument.h" |
24 #include "wtf/text/CString.h" | |
25 | 24 |
26 namespace blink { | 25 namespace blink { |
27 | 26 |
28 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo() | 27 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo() |
29 : m_compositingReasons(CompositingReasonNone) | 28 : m_compositingReasons(CompositingReasonNone) |
30 , m_ownerNodeId(0) | 29 , m_ownerNodeId(0) |
31 { | 30 { |
32 } | 31 } |
33 | 32 |
34 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { } | 33 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { } |
35 | 34 |
36 void GraphicsLayerDebugInfo::appendAsTraceFormat(WebString* out) const | 35 scoped_refptr<base::trace_event::TracedValue> GraphicsLayerDebugInfo::asTracedVa
lue() const |
37 { | 36 { |
38 RefPtr<JSONObject> jsonObject = JSONObject::create(); | 37 scoped_refptr<base::trace_event::TracedValue> tracedValue = new base::trace_
event::TracedValue; |
39 appendAnnotatedInvalidateRects(jsonObject.get()); | 38 appendAnnotatedInvalidateRects(tracedValue.get()); |
40 appendCompositingReasons(jsonObject.get()); | 39 appendCompositingReasons(tracedValue.get()); |
41 appendDebugName(jsonObject.get()); | 40 appendOwnerNodeId(tracedValue.get()); |
42 appendOwnerNodeId(jsonObject.get()); | 41 return tracedValue; |
43 *out = jsonObject->toJSONString(); | |
44 } | 42 } |
45 | 43 |
46 GraphicsLayerDebugInfo* GraphicsLayerDebugInfo::clone() const | 44 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(base::trace_event::T
racedValue* tracedValue) const |
47 { | 45 { |
48 GraphicsLayerDebugInfo* toReturn = new GraphicsLayerDebugInfo(); | 46 tracedValue->BeginArray("annotated_invalidation_rects"); |
49 toReturn->setCompositingReasons(m_compositingReasons); | 47 for (const auto& annotatedRect : m_previousInvalidations) { |
50 toReturn->setOwnerNodeId(m_ownerNodeId); | 48 const FloatRect& rect = annotatedRect.rect; |
51 toReturn->m_invalidations = m_invalidations; | 49 tracedValue->BeginDictionary(); |
52 toReturn->m_previousInvalidations = m_previousInvalidations; | 50 tracedValue->BeginArray("geometry_rect"); |
53 return toReturn; | 51 tracedValue->AppendDouble(rect.x()); |
| 52 tracedValue->AppendDouble(rect.y()); |
| 53 tracedValue->AppendDouble(rect.width()); |
| 54 tracedValue->AppendDouble(rect.height()); |
| 55 tracedValue->EndArray(); |
| 56 tracedValue->SetString("reason", paintInvalidationReasonToString(annotat
edRect.reason)); |
| 57 tracedValue->EndDictionary(); |
| 58 } |
| 59 tracedValue->EndArray(); |
54 } | 60 } |
55 | 61 |
56 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(JSONObject* jsonObje
ct) const | 62 void GraphicsLayerDebugInfo::appendCompositingReasons(base::trace_event::TracedV
alue* tracedValue) const |
57 { | 63 { |
58 RefPtr<JSONArray> jsonArray = JSONArray::create(); | 64 tracedValue->BeginArray("compositing_reasons"); |
59 for (const auto& annotatedRect : m_previousInvalidations) { | |
60 RefPtr<JSONObject> rectContainer = JSONObject::create(); | |
61 RefPtr<JSONArray> rectArray = JSONArray::create(); | |
62 const FloatRect& rect = annotatedRect.rect; | |
63 rectArray->pushNumber(rect.x()); | |
64 rectArray->pushNumber(rect.y()); | |
65 rectArray->pushNumber(rect.width()); | |
66 rectArray->pushNumber(rect.height()); | |
67 rectContainer->setArray("geometry_rect", rectArray); | |
68 rectContainer->setString("reason", paintInvalidationReasonToString(annot
atedRect.reason)); | |
69 jsonArray->pushObject(rectContainer); | |
70 } | |
71 jsonObject->setArray("annotated_invalidation_rects", jsonArray); | |
72 } | |
73 | |
74 void GraphicsLayerDebugInfo::appendCompositingReasons(JSONObject* jsonObject) co
nst | |
75 { | |
76 RefPtr<JSONArray> jsonArray = JSONArray::create(); | |
77 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) { | 65 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) { |
78 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason)) | 66 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason)) |
79 continue; | 67 continue; |
80 jsonArray->pushString(kCompositingReasonStringMap[i].description); | 68 tracedValue->AppendString(kCompositingReasonStringMap[i].description); |
81 } | 69 } |
82 jsonObject->setArray("compositing_reasons", jsonArray); | 70 tracedValue->EndArray(); |
83 } | 71 } |
84 | 72 |
85 void GraphicsLayerDebugInfo::appendDebugName(JSONObject* jsonObject) const | 73 void GraphicsLayerDebugInfo::appendOwnerNodeId(base::trace_event::TracedValue* t
racedValue) const |
86 { | |
87 if (m_debugName.isEmpty()) | |
88 return; | |
89 | |
90 jsonObject->setString("layer_name", m_debugName); | |
91 } | |
92 | |
93 void GraphicsLayerDebugInfo::appendOwnerNodeId(JSONObject* jsonObject) const | |
94 { | 74 { |
95 if (!m_ownerNodeId) | 75 if (!m_ownerNodeId) |
96 return; | 76 return; |
97 | 77 |
98 jsonObject->setNumber("owner_node", m_ownerNodeId); | 78 tracedValue->SetInteger("owner_node", m_ownerNodeId); |
99 } | 79 } |
100 | 80 |
101 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect
, PaintInvalidationReason invalidationReason) | 81 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect
, PaintInvalidationReason invalidationReason) |
102 { | 82 { |
103 AnnotatedInvalidationRect annotatedRect = { | 83 AnnotatedInvalidationRect annotatedRect = { |
104 rect, | 84 rect, |
105 invalidationReason | 85 invalidationReason |
106 }; | 86 }; |
107 m_invalidations.append(annotatedRect); | 87 m_invalidations.append(annotatedRect); |
108 } | 88 } |
109 | 89 |
110 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects() | 90 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects() |
111 { | 91 { |
112 m_previousInvalidations.clear(); | 92 m_previousInvalidations.clear(); |
113 m_previousInvalidations.swap(m_invalidations); | 93 m_previousInvalidations.swap(m_invalidations); |
114 } | 94 } |
115 | 95 |
116 } // namespace blink | 96 } // namespace blink |
OLD | NEW |