Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / paint / DisplayItem.cpp
blob59fd0fec4bc8a868591277e109e2bb0eac4c5448
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "platform/graphics/paint/DisplayItem.h"
8 namespace blink {
10 struct SameSizeAsDisplayItem {
11 virtual ~SameSizeAsDisplayItem() { } // Allocate vtable pointer.
12 void* pointer;
13 int ints[2]; // Make sure other fields are packed into two ints.
14 #ifndef NDEBUG
15 WTF::String m_debugString;
16 #endif
18 static_assert(sizeof(DisplayItem) == sizeof(SameSizeAsDisplayItem), "DisplayItem should stay small");
20 #ifndef NDEBUG
22 static WTF::String paintPhaseAsDebugString(int paintPhase)
24 // Must be kept in sync with PaintPhase.
25 switch (paintPhase) {
26 case 0: return "PaintPhaseBlockBackground";
27 case 1: return "PaintPhaseChildBlockBackground";
28 case 2: return "PaintPhaseChildBlockBackgrounds";
29 case 3: return "PaintPhaseFloat";
30 case 4: return "PaintPhaseForeground";
31 case 5: return "PaintPhaseOutline";
32 case 6: return "PaintPhaseChildOutlines";
33 case 7: return "PaintPhaseSelfOutline";
34 case 8: return "PaintPhaseSelection";
35 case 9: return "PaintPhaseCollapsedTableBorders";
36 case 10: return "PaintPhaseTextClip";
37 case 11: return "PaintPhaseMask";
38 case DisplayItem::PaintPhaseMax: return "PaintPhaseClippingMask";
39 default:
40 ASSERT_NOT_REACHED();
41 return "Unknown";
45 #define PAINT_PHASE_BASED_DEBUG_STRINGS(Category) \
46 if (type >= DisplayItem::Category##PaintPhaseFirst && type <= DisplayItem::Category##PaintPhaseLast) \
47 return #Category + paintPhaseAsDebugString(type - DisplayItem::Category##PaintPhaseFirst);
49 #define DEBUG_STRING_CASE(DisplayItemName) \
50 case DisplayItem::DisplayItemName: return #DisplayItemName
52 #define DEFAULT_CASE default: ASSERT_NOT_REACHED(); return "Unknown"
54 static WTF::String specialDrawingTypeAsDebugString(DisplayItem::Type type)
56 if (type >= DisplayItem::TableCollapsedBorderUnalignedBase) {
57 if (type <= DisplayItem::TableCollapsedBorderBase)
58 return "TableCollapsedBorderAlignment";
59 if (type <= DisplayItem::TableCollapsedBorderLast) {
60 StringBuilder sb;
61 sb.append("TableCollapsedBorder");
62 if (type & DisplayItem::TableCollapsedBorderTop)
63 sb.append("Top");
64 if (type & DisplayItem::TableCollapsedBorderRight)
65 sb.append("Right");
66 if (type & DisplayItem::TableCollapsedBorderBottom)
67 sb.append("Bottom");
68 if (type & DisplayItem::TableCollapsedBorderLeft)
69 sb.append("Left");
70 return sb.toString();
73 switch (type) {
74 DEBUG_STRING_CASE(BoxDecorationBackground);
75 DEBUG_STRING_CASE(Caret);
76 DEBUG_STRING_CASE(ColumnRules);
77 DEBUG_STRING_CASE(DebugRedFill);
78 DEBUG_STRING_CASE(DragImage);
79 DEBUG_STRING_CASE(SVGImage);
80 DEBUG_STRING_CASE(LinkHighlight);
81 DEBUG_STRING_CASE(PageOverlay);
82 DEBUG_STRING_CASE(PageWidgetDelegateBackgroundFallback);
83 DEBUG_STRING_CASE(PopupContainerBorder);
84 DEBUG_STRING_CASE(PopupListBoxBackground);
85 DEBUG_STRING_CASE(PopupListBoxRow);
86 DEBUG_STRING_CASE(PrintedContentBackground);
87 DEBUG_STRING_CASE(PrintedContentLineBoundary);
88 DEBUG_STRING_CASE(PrintedContentPDFURLRect);
89 DEBUG_STRING_CASE(Resizer);
90 DEBUG_STRING_CASE(SVGClip);
91 DEBUG_STRING_CASE(SVGFilter);
92 DEBUG_STRING_CASE(SVGMask);
93 DEBUG_STRING_CASE(ScrollbarBackButtonEnd);
94 DEBUG_STRING_CASE(ScrollbarBackButtonStart);
95 DEBUG_STRING_CASE(ScrollbarBackground);
96 DEBUG_STRING_CASE(ScrollbarBackTrack);
97 DEBUG_STRING_CASE(ScrollbarCorner);
98 DEBUG_STRING_CASE(ScrollbarForwardButtonEnd);
99 DEBUG_STRING_CASE(ScrollbarForwardButtonStart);
100 DEBUG_STRING_CASE(ScrollbarForwardTrack);
101 DEBUG_STRING_CASE(ScrollbarHorizontal);
102 DEBUG_STRING_CASE(ScrollbarThumb);
103 DEBUG_STRING_CASE(ScrollbarTickmarks);
104 DEBUG_STRING_CASE(ScrollbarTrackBackground);
105 DEBUG_STRING_CASE(ScrollbarVertical);
106 DEBUG_STRING_CASE(SelectionGap);
107 DEBUG_STRING_CASE(SelectionTint);
108 DEBUG_STRING_CASE(TableCellBackgroundFromContainers);
109 DEBUG_STRING_CASE(TableCellBackgroundFromSelfPaintingRow);
110 DEBUG_STRING_CASE(VideoBitmap);
111 DEBUG_STRING_CASE(WebPlugin);
112 DEBUG_STRING_CASE(WebFont);
114 DEFAULT_CASE;
118 static WTF::String drawingTypeAsDebugString(DisplayItem::Type type)
120 PAINT_PHASE_BASED_DEBUG_STRINGS(Drawing);
121 return "Drawing" + specialDrawingTypeAsDebugString(type);
124 static WTF::String clipTypeAsDebugString(DisplayItem::Type type)
126 PAINT_PHASE_BASED_DEBUG_STRINGS(ClipBox);
127 PAINT_PHASE_BASED_DEBUG_STRINGS(ClipColumnBounds);
128 PAINT_PHASE_BASED_DEBUG_STRINGS(ClipLayerFragment);
130 switch (type) {
131 DEBUG_STRING_CASE(ClipFileUploadControlRect);
132 DEBUG_STRING_CASE(ClipFrameToVisibleContentRect);
133 DEBUG_STRING_CASE(ClipFrameScrollbars);
134 DEBUG_STRING_CASE(ClipLayerBackground);
135 DEBUG_STRING_CASE(ClipLayerColumnBounds);
136 DEBUG_STRING_CASE(ClipLayerFilter);
137 DEBUG_STRING_CASE(ClipLayerForeground);
138 DEBUG_STRING_CASE(ClipLayerParent);
139 DEBUG_STRING_CASE(ClipLayerOverflowControls);
140 DEBUG_STRING_CASE(ClipNodeImage);
141 DEBUG_STRING_CASE(ClipPopupListBoxFrame);
142 DEBUG_STRING_CASE(ClipSelectionImage);
143 DEBUG_STRING_CASE(PageWidgetDelegateClip);
144 DEBUG_STRING_CASE(ClipPrintedPage);
145 DEFAULT_CASE;
149 static String transform3DTypeAsDebugString(DisplayItem::Type type)
151 switch (type) {
152 DEBUG_STRING_CASE(Transform3DElementTransform);
153 DEFAULT_CASE;
157 WTF::String DisplayItem::typeAsDebugString(Type type)
159 if (isDrawingType(type))
160 return drawingTypeAsDebugString(type);
161 if (isCachedDrawingType(type))
162 return "Cached" + drawingTypeAsDebugString(cachedDrawingTypeToDrawingType(type));
163 if (isClipType(type))
164 return clipTypeAsDebugString(type);
165 if (isEndClipType(type))
166 return "End" + clipTypeAsDebugString(endClipTypeToClipType(type));
168 if (type == UninitializedType)
169 return "UninitializedType";
171 PAINT_PHASE_BASED_DEBUG_STRINGS(FloatClip);
172 if (isEndFloatClipType(type))
173 return "End" + typeAsDebugString(endFloatClipTypeToFloatClipType(type));
175 PAINT_PHASE_BASED_DEBUG_STRINGS(Scroll);
176 if (isEndScrollType(type))
177 return "End" + typeAsDebugString(endScrollTypeToScrollType(type));
179 if (isTransform3DType(type))
180 return transform3DTypeAsDebugString(type);
181 if (isEndTransform3DType(type))
182 return "End" + transform3DTypeAsDebugString(endTransform3DTypeToTransform3DType(type));
184 switch (type) {
185 DEBUG_STRING_CASE(BeginFilter);
186 DEBUG_STRING_CASE(EndFilter);
187 DEBUG_STRING_CASE(BeginCompositing);
188 DEBUG_STRING_CASE(EndCompositing);
189 DEBUG_STRING_CASE(BeginTransform);
190 DEBUG_STRING_CASE(EndTransform);
191 DEBUG_STRING_CASE(BeginClipPath);
192 DEBUG_STRING_CASE(EndClipPath);
193 DEBUG_STRING_CASE(BeginFixedPosition);
194 DEBUG_STRING_CASE(EndFixedPosition);
195 DEBUG_STRING_CASE(BeginFixedPositionContainer);
196 DEBUG_STRING_CASE(EndFixedPositionContainer);
197 DEBUG_STRING_CASE(BeginSubsequence);
198 DEBUG_STRING_CASE(EndSubsequence);
199 DEBUG_STRING_CASE(CachedSubsequence);
200 DEBUG_STRING_CASE(UninitializedType);
201 DEFAULT_CASE;
205 WTF::String DisplayItem::asDebugString() const
207 WTF::StringBuilder stringBuilder;
208 stringBuilder.append('{');
209 dumpPropertiesAsDebugString(stringBuilder);
210 stringBuilder.append('}');
211 return stringBuilder.toString();
214 void DisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuilder) const
216 if (!isValid()) {
217 stringBuilder.append("valid: false, originalDebugString: ");
218 // This is the original debug string which is in json format.
219 stringBuilder.append(clientDebugString());
220 return;
223 stringBuilder.append(String::format("client: \"%p", client()));
224 if (!clientDebugString().isEmpty()) {
225 stringBuilder.append(' ');
226 stringBuilder.append(clientDebugString());
228 stringBuilder.append("\", type: \"");
229 stringBuilder.append(typeAsDebugString(type()));
230 stringBuilder.append('"');
231 if (m_skippedCache)
232 stringBuilder.append(", skippedCache: true");
233 if (m_scope)
234 stringBuilder.append(String::format(", scope: %d", m_scope));
237 #endif
239 } // namespace blink