OLD | NEW |
---|---|
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/ContiguousContainer.h" | 9 #include "platform/graphics/ContiguousContainer.h" |
10 #include "platform/graphics/paint/DisplayItemClient.h" | 10 #include "platform/graphics/paint/DisplayItemClient.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 UninitializedType, | 177 UninitializedType, |
178 TypeLast = UninitializedType | 178 TypeLast = UninitializedType |
179 }; | 179 }; |
180 | 180 |
181 DisplayItem(const DisplayItemClientWrapper& client, Type type, size_t derive dSize) | 181 DisplayItem(const DisplayItemClientWrapper& client, Type type, size_t derive dSize) |
182 : m_client(client.displayItemClient()) | 182 : m_client(client.displayItemClient()) |
183 , m_scope(0) | 183 , m_scope(0) |
184 , m_type(type) | 184 , m_type(type) |
185 , m_derivedSize(derivedSize) | 185 , m_derivedSize(derivedSize) |
186 , m_skippedCache(false) | 186 , m_skippedCache(false) |
187 , m_ignoredFromList(false) | |
188 #ifndef NDEBUG | 187 #ifndef NDEBUG |
189 , m_clientDebugString(client.debugName()) | 188 , m_clientDebugString(client.debugName()) |
190 #endif | 189 #endif |
191 { | 190 { |
192 // derivedSize must fit in m_derivedSize. | 191 // derivedSize must fit in m_derivedSize. |
193 // If it doesn't, enlarge m_derivedSize and fix this assert. | 192 // If it doesn't, enlarge m_derivedSize and fix this assert. |
194 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize < (1 << 8)); | 193 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize < (1 << 8)); |
195 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize >= sizeof(*this)); | 194 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize >= sizeof(*this)); |
196 } | 195 } |
197 | 196 |
197 virtual ~DisplayItem() { } | |
198 | |
198 // Ids are for matching new DisplayItems with existing DisplayItems. | 199 // Ids are for matching new DisplayItems with existing DisplayItems. |
199 struct Id { | 200 struct Id { |
200 Id(const DisplayItemClient client, const Type type, const unsigned scope ) | 201 Id(const DisplayItemClient client, const Type type, const unsigned scope ) |
201 : client(client) | 202 : client(client) |
202 , type(type) | 203 , type(type) |
203 , scope(scope) { } | 204 , scope(scope) { } |
204 | 205 |
205 bool matches(const DisplayItem& item) const | 206 bool matches(const DisplayItem& item) const |
206 { | 207 { |
207 // We should always convert to non-cached types before matching. | 208 // We should always convert to non-cached types before matching. |
(...skipping 18 matching lines...) Expand all Loading... | |
226 return cachedSubtreeTypeToBeginSubtreeType(m_type); | 227 return cachedSubtreeTypeToBeginSubtreeType(m_type); |
227 return m_type; | 228 return m_type; |
228 } | 229 } |
229 | 230 |
230 // Return the Id with cached type converted to non-cached type. | 231 // Return the Id with cached type converted to non-cached type. |
231 Id nonCachedId() const | 232 Id nonCachedId() const |
232 { | 233 { |
233 return Id(m_client, nonCachedType(), m_scope); | 234 return Id(m_client, nonCachedType(), m_scope); |
234 } | 235 } |
235 | 236 |
236 virtual ~DisplayItem() { } | |
237 | |
238 virtual void replay(GraphicsContext&) { } | 237 virtual void replay(GraphicsContext&) { } |
239 | 238 |
240 DisplayItemClient client() const { return m_client; } | 239 DisplayItemClient client() const { return m_client; } |
241 Type type() const { return m_type; } | 240 Type type() const { return m_type; } |
242 | 241 |
243 void setScope(unsigned scope) { m_scope = scope; } | 242 void setScope(unsigned scope) { m_scope = scope; } |
244 unsigned scope() { return m_scope; } | 243 unsigned scope() { return m_scope; } |
245 | 244 |
246 // Size of this object in memory, used to move it with memcpy. | 245 // Size of this object in memory, used to move it with memcpy. |
247 // This is not sizeof(*this), because it needs to account for the size of | 246 // This is not sizeof(*this), because it needs to account for the size of |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 321 |
323 virtual bool isBegin() const { return false; } | 322 virtual bool isBegin() const { return false; } |
324 virtual bool isEnd() const { return false; } | 323 virtual bool isEnd() const { return false; } |
325 | 324 |
326 #if ENABLE(ASSERT) | 325 #if ENABLE(ASSERT) |
327 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return false; } | 326 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return false; } |
328 #endif | 327 #endif |
329 | 328 |
330 virtual bool drawsContent() const { return false; } | 329 virtual bool drawsContent() const { return false; } |
331 | 330 |
332 bool ignoreFromDisplayList() const { return m_ignoredFromList; } | 331 bool isValid() const { return m_client; } |
333 void setIgnoredFromDisplayList() { m_ignoredFromList = true; } | 332 // Re-construct this display item as a permanently invalid item with no clie nt set. |
333 void invalidate() | |
pdr.
2015/08/18 06:15:21
This looks correct now, but it's tricky. Because t
Xianzhu
2015/08/18 16:24:44
Acknowledged and Done.
| |
334 { | |
335 this->~DisplayItem(); | |
336 new (this) DisplayItem; | |
337 } | |
334 | 338 |
335 #ifndef NDEBUG | 339 #ifndef NDEBUG |
336 static WTF::String typeAsDebugString(DisplayItem::Type); | 340 static WTF::String typeAsDebugString(DisplayItem::Type); |
337 const WTF::String& clientDebugString() const { return m_clientDebugString; } | 341 const WTF::String& clientDebugString() const { return m_clientDebugString; } |
338 WTF::String asDebugString() const; | 342 WTF::String asDebugString() const; |
339 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; | 343 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; |
340 #endif | 344 #endif |
341 | 345 |
342 private: | 346 private: |
343 // The default DisplayItem constructor is only used by | 347 // The default DisplayItem constructor is only used by |
344 // ContiguousContainer::appendByMoving where an invalid DisplaItem is | 348 // ContiguousContainer::appendByMoving where an invalid DisplaItem is |
345 // constructed at the source location. | 349 // constructed at the source location. |
346 template <typename T, unsigned alignment> friend class ContiguousContainer; | 350 template <typename T, unsigned alignment> friend class ContiguousContainer; |
347 | 351 |
348 DisplayItem() | 352 DisplayItem() |
349 : m_client(nullptr) | 353 : m_client(nullptr) |
350 , m_scope(0) | 354 , m_scope(0) |
351 , m_type(UninitializedType) | 355 , m_type(UninitializedType) |
352 , m_derivedSize(sizeof(*this)) | 356 , m_derivedSize(sizeof(*this)) |
353 , m_skippedCache(false) | 357 , m_skippedCache(false) |
354 , m_ignoredFromList(true) | |
355 #ifndef NDEBUG | 358 #ifndef NDEBUG |
356 , m_clientDebugString("invalid") | 359 , m_clientDebugString("invalid") |
357 #endif | 360 #endif |
358 { } | 361 { } |
359 | 362 |
360 const DisplayItemClient m_client; | 363 const DisplayItemClient m_client; |
361 unsigned m_scope; | 364 unsigned m_scope; |
362 static_assert(TypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bits "); | 365 static_assert(TypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bits "); |
363 const Type m_type : 16; | 366 const Type m_type : 16; |
364 unsigned m_derivedSize : 8; // size of the actual derived class | 367 unsigned m_derivedSize : 8; // size of the actual derived class |
365 unsigned m_skippedCache : 1; | 368 unsigned m_skippedCache : 1; |
366 unsigned m_ignoredFromList : 1; | |
367 | 369 |
368 #ifndef NDEBUG | 370 #ifndef NDEBUG |
369 WTF::String m_clientDebugString; | 371 WTF::String m_clientDebugString; |
370 #endif | 372 #endif |
371 }; | 373 }; |
372 | 374 |
373 class PLATFORM_EXPORT PairedBeginDisplayItem : public DisplayItem { | 375 class PLATFORM_EXPORT PairedBeginDisplayItem : public DisplayItem { |
374 protected: | 376 protected: |
375 PairedBeginDisplayItem(const DisplayItemClientWrapper& client, Type type, si ze_t derivedSize) : DisplayItem(client, type, derivedSize) { } | 377 PairedBeginDisplayItem(const DisplayItemClientWrapper& client, Type type, si ze_t derivedSize) : DisplayItem(client, type, derivedSize) { } |
376 | 378 |
377 private: | 379 private: |
378 bool isBegin() const final { return true; } | 380 bool isBegin() const final { return true; } |
379 }; | 381 }; |
380 | 382 |
381 class PLATFORM_EXPORT PairedEndDisplayItem : public DisplayItem { | 383 class PLATFORM_EXPORT PairedEndDisplayItem : public DisplayItem { |
382 protected: | 384 protected: |
383 PairedEndDisplayItem(const DisplayItemClientWrapper& client, Type type, size _t derivedSize) : DisplayItem(client, type, derivedSize) { } | 385 PairedEndDisplayItem(const DisplayItemClientWrapper& client, Type type, size _t derivedSize) : DisplayItem(client, type, derivedSize) { } |
384 | 386 |
385 #if ENABLE(ASSERT) | 387 #if ENABLE(ASSERT) |
386 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; | 388 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; |
387 #endif | 389 #endif |
388 | 390 |
389 private: | 391 private: |
390 bool isEnd() const final { return true; } | 392 bool isEnd() const final { return true; } |
391 }; | 393 }; |
392 | 394 |
393 } // namespace blink | 395 } // namespace blink |
394 | 396 |
395 #endif // DisplayItem_h | 397 #endif // DisplayItem_h |
OLD | NEW |