Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / GraphicsLayerDebugInfo.cpp
blob4c2c76e9bb716876b16b62554071a8ab5378f352
1 /*
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.
20 #include "config.h"
21 #include "platform/graphics/GraphicsLayerDebugInfo.h"
23 #include "public/platform/WebGraphicsLayerDebugInfo.h"
24 #include "wtf/text/CString.h"
26 namespace blink {
28 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo()
29 : m_compositingReasons(CompositingReasonNone)
30 , m_ownerNodeId(0)
34 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { }
36 void GraphicsLayerDebugInfo::appendAsTraceFormat(WebString* out) const
38 RefPtr<JSONObject> jsonObject = JSONObject::create();
39 appendAnnotatedInvalidateRects(jsonObject.get());
40 appendCompositingReasons(jsonObject.get());
41 appendDebugName(jsonObject.get());
42 appendOwnerNodeId(jsonObject.get());
43 *out = jsonObject->toJSONString();
46 GraphicsLayerDebugInfo* GraphicsLayerDebugInfo::clone() const
48 GraphicsLayerDebugInfo* toReturn = new GraphicsLayerDebugInfo();
49 toReturn->setCompositingReasons(m_compositingReasons);
50 toReturn->setOwnerNodeId(m_ownerNodeId);
51 toReturn->m_invalidations = m_invalidations;
52 toReturn->m_previousInvalidations = m_previousInvalidations;
53 return toReturn;
56 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRects(JSONObject* jsonObject) const
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(annotatedRect.reason));
69 jsonArray->pushObject(rectContainer);
71 jsonObject->setArray("annotated_invalidation_rects", jsonArray);
74 void GraphicsLayerDebugInfo::appendCompositingReasons(JSONObject* jsonObject) const
76 RefPtr<JSONArray> jsonArray = JSONArray::create();
77 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) {
78 if (!(m_compositingReasons & kCompositingReasonStringMap[i].reason))
79 continue;
80 jsonArray->pushString(kCompositingReasonStringMap[i].description);
82 jsonObject->setArray("compositing_reasons", jsonArray);
85 void GraphicsLayerDebugInfo::appendDebugName(JSONObject* jsonObject) const
87 if (m_debugName.isEmpty())
88 return;
90 jsonObject->setString("layer_name", m_debugName);
93 void GraphicsLayerDebugInfo::appendOwnerNodeId(JSONObject* jsonObject) const
95 if (!m_ownerNodeId)
96 return;
98 jsonObject->setNumber("owner_node", m_ownerNodeId);
101 void GraphicsLayerDebugInfo::appendAnnotatedInvalidateRect(const FloatRect& rect, PaintInvalidationReason invalidationReason)
103 AnnotatedInvalidationRect annotatedRect = {
104 rect,
105 invalidationReason
107 m_invalidations.append(annotatedRect);
110 void GraphicsLayerDebugInfo::clearAnnotatedInvalidateRects()
112 m_previousInvalidations.clear();
113 m_previousInvalidations.swap(m_invalidations);
116 } // namespace blink