2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
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
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "platform/graphics/GraphicsLayerDebugInfo.h"
23 #include "public/platform/WebGraphicsLayerDebugInfo.h"
24 #include "public/platform/WebVector.h"
25 #include "wtf/text/CString.h"
29 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo()
30 : m_compositingReasons(CompositingReasonNone)
35 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { }
37 void GraphicsLayerDebugInfo::appendAsTraceFormat(WebString* out) const
39 RefPtr<JSONObject> jsonObject = JSONObject::create();
40 appendLayoutRects(jsonObject.get());
41 appendAnnotatedInvalidateRects(jsonObject.get());
42 appendCompositingReasons(jsonObject.get());
43 appendDebugName(jsonObject.get());
44 appendOwnerNodeId(jsonObject.get());
45 *out = jsonObject->toJSONString();
48 GraphicsLayerDebugInfo* GraphicsLayerDebugInfo::clone() const
50 GraphicsLayerDebugInfo* toReturn = new GraphicsLayerDebugInfo();
51 for (size_t i = 0; i < m_currentLayoutRects.size(); ++i)
52 toReturn->currentLayoutRects().append(m_currentLayoutRects[i]);
53 toReturn->setCompositingReasons(m_compositingReasons);
54 toReturn->setOwnerNodeId(m_ownerNodeId);
55 toReturn->m_invalidations = m_invalidations;
56 toReturn->m_previousInvalidations = m_previousInvalidations;
60 void GraphicsLayerDebugInfo::appendLayoutRects(JSONObject* jsonObject) const
62 RefPtr<JSONArray> jsonArray = JSONArray::create();
63 for (size_t i = 0; i < m_currentLayoutRects.size(); i++) {
64 const LayoutRect& rect = m_currentLayoutRects[i];
65 RefPtr<JSONObject> rectContainer = JSONObject::create();
66 RefPtr<JSONArray> rectArray = JSONArray::create();
67 rectArray->pushNumber(rect.x().toFloat());
68 rectArray->pushNumber(rect.y().toFloat());
69 rectArray->pushNumber(rect.maxX().toFloat());
70 rectArray->pushNumber(rect.maxY().toFloat());
71 rectContainer->setArray("geometry_rect", rectArray);
72 jsonArray->pushObject(rectContainer);
74 jsonObject->setArray("layout_rects", jsonArray);
77 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(JSONObject* jsonObject) const
79 RefPtr<JSONArray> jsonArray = JSONArray::create();
80 for (const auto& annotatedRect : m_previousInvalidations) {
81 RefPtr<JSONObject> rectContainer = JSONObject::create();
82 RefPtr<JSONArray> rectArray = JSONArray::create();
83 const FloatRect& rect = annotatedRect.rect;
84 rectArray->pushNumber(rect.x());
85 rectArray->pushNumber(rect.y());
86 rectArray->pushNumber(rect.width());
87 rectArray->pushNumber(rect.height());
88 rectContainer->setArray("geometry_rect", rectArray);
89 rectContainer->setString("reason", paintInvalidationReasonToString(annotatedRect.reason));
90 jsonArray->pushObject(rectContainer);
92 jsonObject->setArray("annotated_invalidation_rects", jsonArray);
95 void GraphicsLayerDebugInfo::appendCompositingReasons(JSONObject* jsonObject) const
97 RefPtr<JSONArray> jsonArray = JSONArray::create();
98 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) {
99 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason))
101 jsonArray->pushString(kCompositingReasonStringMap[i].description);
103 jsonObject->setArray("compositing_reasons", jsonArray);
106 void GraphicsLayerDebugInfo::appendDebugName(JSONObject* jsonObject) const
108 if (m_debugName.isEmpty())
111 jsonObject->setString("layer_name", m_debugName);
114 void GraphicsLayerDebugInfo::appendOwnerNodeId(JSONObject* jsonObject) const
119 jsonObject->setNumber("owner_node", m_ownerNodeId);
122 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect, PaintInvalidationReason invalidationReason)
124 AnnotatedInvalidationRect annotatedRect = {
128 m_invalidations.append(annotatedRect);
131 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects()
133 m_previousInvalidations.clear();
134 m_previousInvalidations.swap(m_invalidations);