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 "base/trace_event/trace_event_argument.h" | 23 #include "public/platform/WebGraphicsLayerDebugInfo.h" |
| 24 #include "wtf/text/CString.h" |
24 | 25 |
25 namespace blink { | 26 namespace blink { |
26 | 27 |
27 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo() | 28 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo() |
28 : m_compositingReasons(CompositingReasonNone) | 29 : m_compositingReasons(CompositingReasonNone) |
29 , m_ownerNodeId(0) | 30 , m_ownerNodeId(0) |
30 { | 31 { |
31 } | 32 } |
32 | 33 |
33 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { } | 34 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { } |
34 | 35 |
35 scoped_refptr<base::trace_event::TracedValue> GraphicsLayerDebugInfo::asTracedVa
lue() const | 36 void GraphicsLayerDebugInfo::appendAsTraceFormat(WebString* out) const |
36 { | 37 { |
37 scoped_refptr<base::trace_event::TracedValue> tracedValue = new base::trace_
event::TracedValue; | 38 RefPtr<JSONObject> jsonObject = JSONObject::create(); |
38 appendAnnotatedInvalidateRects(tracedValue.get()); | 39 appendAnnotatedInvalidateRects(jsonObject.get()); |
39 appendCompositingReasons(tracedValue.get()); | 40 appendCompositingReasons(jsonObject.get()); |
40 appendOwnerNodeId(tracedValue.get()); | 41 appendDebugName(jsonObject.get()); |
41 return tracedValue; | 42 appendOwnerNodeId(jsonObject.get()); |
| 43 *out = jsonObject->toJSONString(); |
42 } | 44 } |
43 | 45 |
44 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(base::trace_event::T
racedValue* tracedValue) const | 46 GraphicsLayerDebugInfo* GraphicsLayerDebugInfo::clone() const |
45 { | 47 { |
46 tracedValue->BeginArray("annotated_invalidation_rects"); | 48 GraphicsLayerDebugInfo* toReturn = new GraphicsLayerDebugInfo(); |
47 for (const auto& annotatedRect : m_previousInvalidations) { | 49 toReturn->setCompositingReasons(m_compositingReasons); |
48 const FloatRect& rect = annotatedRect.rect; | 50 toReturn->setOwnerNodeId(m_ownerNodeId); |
49 tracedValue->BeginDictionary(); | 51 toReturn->m_invalidations = m_invalidations; |
50 tracedValue->BeginArray("geometry_rect"); | 52 toReturn->m_previousInvalidations = m_previousInvalidations; |
51 tracedValue->AppendDouble(rect.x()); | 53 return toReturn; |
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(); | |
60 } | 54 } |
61 | 55 |
62 void GraphicsLayerDebugInfo::appendCompositingReasons(base::trace_event::TracedV
alue* tracedValue) const | 56 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(JSONObject* jsonObje
ct) const |
63 { | 57 { |
64 tracedValue->BeginArray("compositing_reasons"); | 58 RefPtr<JSONArray> jsonArray = JSONArray::create(); |
| 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(); |
65 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) { | 77 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) { |
66 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason)) | 78 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason)) |
67 continue; | 79 continue; |
68 tracedValue->AppendString(kCompositingReasonStringMap[i].description); | 80 jsonArray->pushString(kCompositingReasonStringMap[i].description); |
69 } | 81 } |
70 tracedValue->EndArray(); | 82 jsonObject->setArray("compositing_reasons", jsonArray); |
71 } | 83 } |
72 | 84 |
73 void GraphicsLayerDebugInfo::appendOwnerNodeId(base::trace_event::TracedValue* t
racedValue) const | 85 void GraphicsLayerDebugInfo::appendDebugName(JSONObject* jsonObject) 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 |
74 { | 94 { |
75 if (!m_ownerNodeId) | 95 if (!m_ownerNodeId) |
76 return; | 96 return; |
77 | 97 |
78 tracedValue->SetInteger("owner_node", m_ownerNodeId); | 98 jsonObject->setNumber("owner_node", m_ownerNodeId); |
79 } | 99 } |
80 | 100 |
81 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect
, PaintInvalidationReason invalidationReason) | 101 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect
, PaintInvalidationReason invalidationReason) |
82 { | 102 { |
83 AnnotatedInvalidationRect annotatedRect = { | 103 AnnotatedInvalidationRect annotatedRect = { |
84 rect, | 104 rect, |
85 invalidationReason | 105 invalidationReason |
86 }; | 106 }; |
87 m_invalidations.append(annotatedRect); | 107 m_invalidations.append(annotatedRect); |
88 } | 108 } |
89 | 109 |
90 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects() | 110 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects() |
91 { | 111 { |
92 m_previousInvalidations.clear(); | 112 m_previousInvalidations.clear(); |
93 m_previousInvalidations.swap(m_invalidations); | 113 m_previousInvalidations.swap(m_invalidations); |
94 } | 114 } |
95 | 115 |
96 } // namespace blink | 116 } // namespace blink |
OLD | NEW |