• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 Google Inc. All rights reserved.
3  *
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.
8  *
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.
13  *
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.
18  */
19 
20 #include "config.h"
21 
22 #include "platform/graphics/GraphicsLayerDebugInfo.h"
23 
24 #include "wtf/text/CString.h"
25 
26 namespace WebCore {
27 
GraphicsLayerDebugInfo()28 GraphicsLayerDebugInfo::GraphicsLayerDebugInfo()
29     : m_compositingReasons(CompositingReasonNone)
30 {
31 }
32 
~GraphicsLayerDebugInfo()33 GraphicsLayerDebugInfo::~GraphicsLayerDebugInfo() { }
34 
appendAsTraceFormat(blink::WebString * out) const35 void GraphicsLayerDebugInfo::appendAsTraceFormat(blink::WebString* out) const
36 {
37     RefPtr<JSONObject> jsonObject = JSONObject::create();
38     appendLayoutRects(jsonObject.get());
39     appendCompositingReasons(jsonObject.get());
40     appendDebugName(jsonObject.get());
41     appendOwnerNodeId(jsonObject.get());
42     *out = jsonObject->toJSONString();
43 }
44 
clone() const45 GraphicsLayerDebugInfo* GraphicsLayerDebugInfo::clone() const
46 {
47     GraphicsLayerDebugInfo* toReturn = new GraphicsLayerDebugInfo();
48     for (size_t i = 0; i < m_currentLayoutRects.size(); ++i)
49         toReturn->currentLayoutRects().append(m_currentLayoutRects[i]);
50     toReturn->setCompositingReasons(m_compositingReasons);
51     toReturn->setOwnerNodeId(m_ownerNodeId);
52     return toReturn;
53 }
54 
appendLayoutRects(JSONObject * jsonObject) const55 void GraphicsLayerDebugInfo::appendLayoutRects(JSONObject* jsonObject) const
56 {
57     RefPtr<JSONArray> jsonArray = JSONArray::create();
58     for (size_t i = 0; i < m_currentLayoutRects.size(); i++) {
59         const LayoutRect& rect = m_currentLayoutRects[i];
60         RefPtr<JSONObject> rectContainer = JSONObject::create();
61         RefPtr<JSONArray> rectArray = JSONArray::create();
62         rectArray->pushNumber(rect.x().toFloat());
63         rectArray->pushNumber(rect.y().toFloat());
64         rectArray->pushNumber(rect.maxX().toFloat());
65         rectArray->pushNumber(rect.maxY().toFloat());
66         rectContainer->setArray("geometry_rect", rectArray);
67         jsonArray->pushObject(rectContainer);
68     }
69     jsonObject->setArray("layout_rects", jsonArray);
70 }
71 
appendCompositingReasons(JSONObject * jsonObject) const72 void GraphicsLayerDebugInfo::appendCompositingReasons(JSONObject* jsonObject) const
73 {
74     RefPtr<JSONArray> jsonArray = JSONArray::create();
75     for (size_t i = 0; i < WTF_ARRAY_LENGTH(compositingReasonStringMap); ++i) {
76         if (!(m_compositingReasons & compositingReasonStringMap[i].reason))
77             continue;
78         jsonArray->pushString(compositingReasonStringMap[i].description);
79     }
80     jsonObject->setArray("compositing_reasons", jsonArray);
81 }
82 
appendDebugName(JSONObject * jsonObject) const83 void GraphicsLayerDebugInfo::appendDebugName(JSONObject* jsonObject) const
84 {
85     if (m_debugName.isEmpty())
86         return;
87 
88     jsonObject->setString("layer_name", m_debugName);
89 }
90 
appendOwnerNodeId(JSONObject * jsonObject) const91 void GraphicsLayerDebugInfo::appendOwnerNodeId(JSONObject* jsonObject) const
92 {
93     if (!m_ownerNodeId)
94         return;
95 
96     jsonObject->setNumber("owner_node", m_ownerNodeId);
97 }
98 
99 } // namespace WebCore
100