Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: Source/platform/graphics/paint/DisplayItem.h

Issue 892293002: First version of new merge algorithm (not enabled yet) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove scope-related code (accidentally mixed in this CL) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DisplayItem_h 5 #ifndef DisplayItem_h
6 #define DisplayItem_h 6 #define DisplayItem_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/graphics/paint/DisplayItemClient.h" 9 #include "platform/graphics/paint/DisplayItemClient.h"
10 #include "wtf/Assertions.h" 10 #include "wtf/Assertions.h"
11 #include "wtf/HashTraits.h"
11 #include "wtf/PassOwnPtr.h" 12 #include "wtf/PassOwnPtr.h"
12 13
13 #ifndef NDEBUG 14 #ifndef NDEBUG
14 #include "wtf/text/StringBuilder.h" 15 #include "wtf/text/StringBuilder.h"
15 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
16 #endif 17 #endif
17 18
18 19
19 namespace blink { 20 namespace blink {
20 21
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 EndScrollLast = EndScrollFirst + ScrollLast - ScrollFirst, 112 EndScrollLast = EndScrollFirst + ScrollLast - ScrollFirst,
112 113
113 BeginFilter, 114 BeginFilter,
114 EndFilter, 115 EndFilter,
115 BeginCompositing, 116 BeginCompositing,
116 EndCompositing, 117 EndCompositing,
117 BeginTransform, 118 BeginTransform,
118 EndTransform, 119 EndTransform,
119 BeginClipPath, 120 BeginClipPath,
120 EndClipPath, 121 EndClipPath,
122
123 SubtreeCachedFirst,
124 SubtreeCachedPaintPhaseFirst = SubtreeCachedFirst,
125 SubtreeCachedPaintPhaseLast = SubtreeCachedPaintPhaseFirst + PaintPhaseM ax,
126 SubtreeCachedLast = SubtreeCachedPaintPhaseLast,
127
128 BeginSubtreeFirst,
129 BeginSubtreePaintPhaseFirst = BeginSubtreeFirst,
130 BeginSubtreePaintPhaseLast = BeginSubtreePaintPhaseFirst + PaintPhaseMax ,
131 BeginSubtreeLast = BeginSubtreePaintPhaseLast,
132
133 EndSubtreeFirst,
134 EndSubtreePaintPhaseFirst = EndSubtreeFirst,
135 EndSubtreePaintPhaseLast = EndSubtreePaintPhaseFirst + PaintPhaseMax,
136 EndSubtreeLast = EndSubtreePaintPhaseLast,
137 };
138
139 struct Id {
140 Id(DisplayItemClient c, Type t) : client(c), type(t) { }
141
142 bool operator==(const Id& other) const { return client == other.client & & type == other.type; }
143 bool operator!=(const Id& other) const { return !(*this == other); }
144
145 DisplayItemClient client;
146 Type type;
121 }; 147 };
122 148
123 // Create a dummy display item which just holds the id but has no display op eration. 149 // Create a dummy display item which just holds the id but has no display op eration.
124 // It helps a CachedDisplayItem to match the corresponding original empty di splay item. 150 // It helps a CachedDisplayItem to match the corresponding original empty di splay item.
125 static PassOwnPtr<DisplayItem> create(DisplayItemClient client, Type type) { return adoptPtr(new DisplayItem(client, type)); } 151 static PassOwnPtr<DisplayItem> create(DisplayItemClient client, Type type) { return adoptPtr(new DisplayItem(client, type)); }
126 152
127 virtual ~DisplayItem() { } 153 virtual ~DisplayItem() { }
128 154
129 virtual void replay(GraphicsContext*) { } 155 virtual void replay(GraphicsContext*) { }
130 156
131 DisplayItemClient client() const { return m_id.client; } 157 DisplayItemClient client() const { return m_id.client; }
132 Type type() const { return m_id.type; } 158 Type type() const { return m_id.type; }
133 bool idsEqual(const DisplayItem& other) const { return m_id.client == other. m_id.client && m_id.type == other.m_id.type; } 159 const Id& id() const { return m_id; }
160 bool idsEqual(const DisplayItem& other) const { return m_id == other.m_id; }
134 161
135 virtual void appendToWebDisplayItemList(WebDisplayItemList*) const { } 162 virtual void appendToWebDisplayItemList(WebDisplayItemList*) const { }
136 163
137 // See comments of enum Type for usage of the following macros. 164 // See comments of enum Type for usage of the following macros.
138 #define DEFINE_CATEGORY_METHODS(Category) \ 165 #define DEFINE_CATEGORY_METHODS(Category) \
139 static bool is##Category##Type(Type type) { return type >= Category##First & & type <= Category##Last; } \ 166 static bool is##Category##Type(Type type) { return type >= Category##First & & type <= Category##Last; } \
140 bool is##Category() const { return is##Category##Type(type()); } 167 bool is##Category() const { return is##Category##Type(type()); }
141 168
142 #define DEFINE_CONVERSION_METHODS(Category1, category1, Category2, category2) \ 169 #define DEFINE_CONVERSION_METHODS(Category1, category1, Category2, category2) \
143 static Type category1##TypeTo##Category2##Type(Type type) \ 170 static Type category1##TypeTo##Category2##Type(Type type) \
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipLayerFragment) 202 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipLayerFragment)
176 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipBox) 203 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipBox)
177 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipColumnBounds) 204 DEFINE_PAINT_PHASE_CONVERSION_METHOD(ClipColumnBounds)
178 205
179 DEFINE_PAIRED_CATEGORY_METHODS(FloatClip, floatClip) 206 DEFINE_PAIRED_CATEGORY_METHODS(FloatClip, floatClip)
180 DEFINE_PAINT_PHASE_CONVERSION_METHOD(FloatClip) 207 DEFINE_PAINT_PHASE_CONVERSION_METHOD(FloatClip)
181 208
182 DEFINE_PAIRED_CATEGORY_METHODS(Scroll, scroll) 209 DEFINE_PAIRED_CATEGORY_METHODS(Scroll, scroll)
183 DEFINE_PAINT_PHASE_CONVERSION_METHOD(Scroll) 210 DEFINE_PAINT_PHASE_CONVERSION_METHOD(Scroll)
184 211
212 DEFINE_CATEGORY_METHODS(SubtreeCached)
213 DEFINE_PAINT_PHASE_CONVERSION_METHOD(SubtreeCached)
214 DEFINE_CATEGORY_METHODS(BeginSubtree)
215 DEFINE_PAINT_PHASE_CONVERSION_METHOD(BeginSubtree)
216 DEFINE_CATEGORY_METHODS(EndSubtree)
217 DEFINE_PAINT_PHASE_CONVERSION_METHOD(EndSubtree)
218 DEFINE_CONVERSION_METHODS(SubtreeCached, subtreeCached, BeginSubtree, beginS ubtree)
219 DEFINE_CONVERSION_METHODS(SubtreeCached, subtreeCached, EndSubtree, endSubtr ee)
220 DEFINE_CONVERSION_METHODS(BeginSubtree, beginSubtree, EndSubtree, endSubtree )
221
222 bool isBegin() const { return isClip() || isFloatClip() || isScroll() || isB eginSubtree() || type() == BeginFilter || type() == BeginCompositing || type() = = BeginTransform || type() == BeginClipPath; }
pdr. 2015/02/04 05:19:58 Can we introduce a subclass of paired display item
Xianzhu 2015/02/04 20:46:32 Done and separated into https://codereview.chromiu
223 bool isEnd() const { return isEndClip() || isEndFloatClip() || isEndScroll() || isEndSubtree() || type() == EndFilter || type() == EndCompositing || type() == EndTransform || type() == EndClipPath; }
224
225 #if ENABLE(ASSERT)
226 bool isEndAndPairedWith(DisplayItem& other) const
227 {
228 return client() == other.client()
229 && ((isEndClip() && other.isClip() && type() == clipTypeToEndClipTyp e(other.type()))
230 || (isEndFloatClip() && other.isFloatClip() && type() == floatCl ipTypeToEndFloatClipType(other.type()))
231 || (isEndScroll() && other.isScroll() && type() == scrollTypeToE ndScrollType(other.type()))
232 || (isEndSubtree() && other.isBeginSubtree() && type() == beginS ubtreeTypeToEndSubtreeType(other.type()))
233 || (type() == EndFilter && other.type() == BeginFilter)
234 || (type() == EndCompositing && other.type() == BeginCompositing )
235 || (type() == EndTransform && other.type() == BeginTransform)
236 || (type() == EndClipPath && other.type() == BeginClipPath));
237 }
238 #endif
239
185 #ifndef NDEBUG 240 #ifndef NDEBUG
186 static WTF::String typeAsDebugString(DisplayItem::Type); 241 static WTF::String typeAsDebugString(DisplayItem::Type);
187 242
188 void setClientDebugString(const WTF::String& clientDebugString) { m_clientDe bugString = clientDebugString; } 243 void setClientDebugString(const WTF::String& clientDebugString) { m_clientDe bugString = clientDebugString; }
189 const WTF::String& clientDebugString() const { return m_clientDebugString; } 244 const WTF::String& clientDebugString() const { return m_clientDebugString; }
190 245
191 WTF::String asDebugString() const; 246 WTF::String asDebugString() const;
192 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; 247 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const;
193 #endif 248 #endif
194 249
195 protected: 250 protected:
196 DisplayItem(DisplayItemClient client, Type type) 251 DisplayItem(DisplayItemClient client, Type type)
197 : m_id(client, type) 252 : m_id(client, type)
198 { 253 {
199 ASSERT(client); 254 ASSERT(client);
200 } 255 }
201 256
202 private: 257 private:
203 struct Id { 258 const Id m_id;
204 Id(DisplayItemClient c, Type t)
205 : client(c)
206 , type(t)
207 {
208 ASSERT(client);
209 }
210
211 const DisplayItemClient client;
212 const Type type;
213 } m_id;
214 #ifndef NDEBUG 259 #ifndef NDEBUG
215 WTF::String m_clientDebugString; 260 WTF::String m_clientDebugString;
216 #endif 261 #endif
217 }; 262 };
218 263
219 } 264 } // namespace blink
265
266 // Allow DisplayItem::Id to be hash key.
267 namespace WTF {
268
269 template<> struct DefaultHash<blink::DisplayItem::Id> {
270 struct Hash {
271 static unsigned hash(const blink::DisplayItem::Id& id) { return pairIntH ash(PtrHash<blink::DisplayItemClient>::hash(id.client), static_cast<unsigned>(id .type)); }
272 static bool equal(const blink::DisplayItem::Id& a, const blink::DisplayI tem::Id& b) { return a == b; }
273 static const bool safeToCompareToEmptyOrDeleted = true;
274 };
275 };
276 template<> struct HashTraits<blink::DisplayItem::Id> : GenericHashTraits<blink:: DisplayItem::Id> {
277 static const bool emptyValueIsZero = true;
278 static const bool needsDestruction = false;
279 static blink::DisplayItem::Id emptyValue() { return blink::DisplayItem::Id(n ullptr, static_cast<blink::DisplayItem::Type>(0)); }
280 static void constructDeletedValue(blink::DisplayItem::Id& slot, bool) { new (NotNull, &slot) blink::DisplayItem::Id(nullptr, static_cast<blink::DisplayItem: :Type>(-1)); }
281 static bool isDeletedValue(const blink::DisplayItem::Id& id) { return id.typ e == static_cast<blink::DisplayItem::Type>(-1); }
282 };
283
284 } // namespace WTF
220 285
221 #endif // DisplayItem_h 286 #endif // DisplayItem_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698