| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 static_assert(TableCollapsedBorderBase >= TableCollapsedBorderUnalignedBase,
"TableCollapsedBorder types overlap with other types"); | 191 static_assert(TableCollapsedBorderBase >= TableCollapsedBorderUnalignedBase,
"TableCollapsedBorder types overlap with other types"); |
| 192 static_assert((TableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of T
ableCollapsedBorderBase should be zero"); | 192 static_assert((TableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of T
ableCollapsedBorderBase should be zero"); |
| 193 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps
ed border type. | 193 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps
ed border type. |
| 194 enum TableCollapsedBorderSides { | 194 enum TableCollapsedBorderSides { |
| 195 TableCollapsedBorderTop = 1 << 0, | 195 TableCollapsedBorderTop = 1 << 0, |
| 196 TableCollapsedBorderRight = 1 << 1, | 196 TableCollapsedBorderRight = 1 << 1, |
| 197 TableCollapsedBorderBottom = 1 << 2, | 197 TableCollapsedBorderBottom = 1 << 2, |
| 198 TableCollapsedBorderLeft = 1 << 3, | 198 TableCollapsedBorderLeft = 1 << 3, |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 DisplayItem(const DisplayItemClient& client, Type type, size_t derivedSize) | 201 DisplayItem(const DisplayItemClient& client, Type type, size_t derivedSize,
size_t derivedAlignment) |
| 202 : m_client(&client) | 202 : m_client(&client) |
| 203 , m_type(type) | 203 , m_type(type) |
| 204 , m_derivedSize(derivedSize) | 204 , m_derivedSize(derivedSize) |
| 205 , m_derivedAlignment(derivedAlignment) |
| 205 , m_skippedCache(false) | 206 , m_skippedCache(false) |
| 206 #ifndef NDEBUG | 207 #ifndef NDEBUG |
| 207 , m_clientDebugString(client.debugName()) | 208 , m_clientDebugString(client.debugName()) |
| 208 #endif | 209 #endif |
| 209 { | 210 { |
| 210 // derivedSize must fit in m_derivedSize. | 211 // derivedSize must fit in m_derivedSize. |
| 211 // If it doesn't, enlarge m_derivedSize and fix this assert. | 212 // If it doesn't, enlarge m_derivedSize and fix this assert. |
| 212 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize < (1 << 8)); | 213 SECURITY_CHECK(derivedSize == m_derivedSize); |
| 213 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize >= sizeof(*this)); | 214 SECURITY_CHECK(derivedSize >= sizeof(*this)); |
| 215 // derivedAlignment must fit in m_derivedAlignment. |
| 216 SECURITY_CHECK(derivedAlignment == m_derivedAlignment); |
| 214 } | 217 } |
| 215 | 218 |
| 216 virtual ~DisplayItem() { } | 219 virtual ~DisplayItem() { } |
| 217 | 220 |
| 218 // Ids are for matching new DisplayItems with existing DisplayItems. | 221 // Ids are for matching new DisplayItems with existing DisplayItems. |
| 219 struct Id { | 222 struct Id { |
| 220 STACK_ALLOCATED(); | 223 STACK_ALLOCATED(); |
| 221 Id(const DisplayItemClient& client, const Type type) | 224 Id(const DisplayItemClient& client, const Type type) |
| 222 : client(client) | 225 : client(client) |
| 223 , type(type) { } | 226 , type(type) { } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 254 | 257 |
| 255 const DisplayItemClient& client() const { ASSERT(m_client); return *m_client
; } | 258 const DisplayItemClient& client() const { ASSERT(m_client); return *m_client
; } |
| 256 Type getType() const { return m_type; } | 259 Type getType() const { return m_type; } |
| 257 | 260 |
| 258 // Size of this object in memory, used to move it with memcpy. | 261 // Size of this object in memory, used to move it with memcpy. |
| 259 // This is not sizeof(*this), because it needs to account for the size of | 262 // This is not sizeof(*this), because it needs to account for the size of |
| 260 // the derived class (i.e. runtime type). Derived classes are expected to | 263 // the derived class (i.e. runtime type). Derived classes are expected to |
| 261 // supply this to the DisplayItem constructor. | 264 // supply this to the DisplayItem constructor. |
| 262 size_t derivedSize() const { return m_derivedSize; } | 265 size_t derivedSize() const { return m_derivedSize; } |
| 263 | 266 |
| 267 // Alignment (in bytes) of this object when this object is allocated in memo
ry. |
| 268 size_t derivedAlignment() const { return m_derivedAlignment; } |
| 269 |
| 264 // For PaintController only. Painters should use DisplayItemCacheSkipper ins
tead. | 270 // For PaintController only. Painters should use DisplayItemCacheSkipper ins
tead. |
| 265 void setSkippedCache() { m_skippedCache = true; } | 271 void setSkippedCache() { m_skippedCache = true; } |
| 266 bool skippedCache() const { return m_skippedCache; } | 272 bool skippedCache() const { return m_skippedCache; } |
| 267 | 273 |
| 268 virtual void appendToWebDisplayItemList(const IntRect&, WebDisplayItemList*)
const { } | 274 virtual void appendToWebDisplayItemList(const IntRect&, WebDisplayItemList*)
const { } |
| 269 | 275 |
| 270 // See comments of enum Type for usage of the following macros. | 276 // See comments of enum Type for usage of the following macros. |
| 271 #define DEFINE_CATEGORY_METHODS(Category) \ | 277 #define DEFINE_CATEGORY_METHODS(Category) \ |
| 272 static bool is##Category##Type(Type type) { return type >= Category##First &
& type <= Category##Last; } \ | 278 static bool is##Category##Type(Type type) { return type >= Category##First &
& type <= Category##Last; } \ |
| 273 bool is##Category() const { return is##Category##Type(getType()); } | 279 bool is##Category() const { return is##Category##Type(getType()); } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 virtual bool isBegin() const { return false; } | 333 virtual bool isBegin() const { return false; } |
| 328 virtual bool isEnd() const { return false; } | 334 virtual bool isEnd() const { return false; } |
| 329 | 335 |
| 330 #if DCHECK_IS_ON() | 336 #if DCHECK_IS_ON() |
| 331 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return
false; } | 337 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return
false; } |
| 332 virtual bool equals(const DisplayItem& other) const | 338 virtual bool equals(const DisplayItem& other) const |
| 333 { | 339 { |
| 334 return m_client == other.m_client | 340 return m_client == other.m_client |
| 335 && m_type == other.m_type | 341 && m_type == other.m_type |
| 336 && m_derivedSize == other.m_derivedSize | 342 && m_derivedSize == other.m_derivedSize |
| 343 && m_derivedAlignment == other.m_derivedAlignment |
| 337 && m_skippedCache == other.m_skippedCache; | 344 && m_skippedCache == other.m_skippedCache; |
| 338 } | 345 } |
| 339 #endif | 346 #endif |
| 340 | 347 |
| 341 // True if the client is non-null. Because m_client is const, this should | 348 // True if the client is non-null. Because m_client is const, this should |
| 342 // never be false except when we explicitly create a tombstone/"dead display | 349 // never be false except when we explicitly create a tombstone/"dead display |
| 343 // item" as part of moving an item from one list to another (see: | 350 // item" as part of moving an item from one list to another (see: |
| 344 // DisplayItemList::appendByMoving). | 351 // DisplayItemList::appendByMoving). |
| 345 bool hasValidClient() const { return m_client; } | 352 bool hasValidClient() const { return m_client; } |
| 346 | 353 |
| 347 virtual bool drawsContent() const { return false; } | 354 virtual bool drawsContent() const { return false; } |
| 348 | 355 |
| 349 // Override to implement specific analysis strategies. | 356 // Override to implement specific analysis strategies. |
| 350 virtual void analyzeForGpuRasterization(SkPictureGpuAnalyzer&) const { } | 357 virtual void analyzeForGpuRasterization(SkPictureGpuAnalyzer&) const { } |
| 351 | 358 |
| 352 #ifndef NDEBUG | 359 #ifndef NDEBUG |
| 353 static WTF::String typeAsDebugString(DisplayItem::Type); | 360 static WTF::String typeAsDebugString(DisplayItem::Type); |
| 354 const WTF::String clientDebugString() const { return m_clientDebugString; } | 361 const WTF::String clientDebugString() const { return m_clientDebugString; } |
| 355 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } | 362 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } |
| 356 WTF::String asDebugString() const; | 363 WTF::String asDebugString() const; |
| 357 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; | 364 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; |
| 358 #endif | 365 #endif |
| 359 | 366 |
| 360 private: | 367 private: |
| 361 // The default DisplayItem constructor is only used by | 368 // The default DisplayItem constructor is only used by |
| 362 // ContiguousContainer::appendByMoving where an invalid DisplaItem is | 369 // ContiguousContainer::appendByMoving where an invalid DisplaItem is |
| 363 // constructed at the source location. | 370 // constructed at the source location. |
| 364 template <typename T, unsigned alignment> friend class ContiguousContainer; | 371 template <typename T> friend class ContiguousContainer; |
| 365 | 372 |
| 366 DisplayItem() | 373 DisplayItem() |
| 367 : m_client(nullptr) | 374 : m_client(nullptr) |
| 368 , m_type(UninitializedType) | 375 , m_type(UninitializedType) |
| 369 , m_derivedSize(sizeof(*this)) | 376 , m_derivedSize(sizeof(*this)) |
| 377 , m_derivedAlignment(WTF_ALIGN_OF(DisplayItem)) |
| 370 , m_skippedCache(false) | 378 , m_skippedCache(false) |
| 371 { } | 379 { } |
| 372 | 380 |
| 373 const DisplayItemClient* m_client; | 381 const DisplayItemClient* m_client; |
| 374 static_assert(TypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bits
"); | 382 static_assert(TypeLast < (1 << 11), "DisplayItem::Type should fit in 16 bits
"); |
| 375 const Type m_type : 16; | 383 const Type m_type : 11; |
| 376 const unsigned m_derivedSize : 8; // size of the actual derived class | 384 const unsigned m_derivedSize : 8; // size of the actual derived class |
| 385 const unsigned m_derivedAlignment : 5; // alignment of the actual derived cl
ass |
| 377 unsigned m_skippedCache : 1; | 386 unsigned m_skippedCache : 1; |
| 378 | 387 |
| 379 #ifndef NDEBUG | 388 #ifndef NDEBUG |
| 380 WTF::String m_clientDebugString; | 389 WTF::String m_clientDebugString; |
| 381 #endif | 390 #endif |
| 382 }; | 391 }; |
| 383 | 392 |
| 384 class PLATFORM_EXPORT PairedBeginDisplayItem : public DisplayItem { | 393 template <typename T> |
| 394 class DisplayItemBase : public DisplayItem { |
| 385 protected: | 395 protected: |
| 386 PairedBeginDisplayItem(const DisplayItemClient& client, Type type, size_t de
rivedSize) : DisplayItem(client, type, derivedSize) { } | 396 DisplayItemBase(const DisplayItemClient& client, Type type) |
| 397 : DisplayItem(client, type, sizeof(T), WTF_ALIGN_OF(T)) { } |
| 398 }; |
| 399 |
| 400 template <typename T> |
| 401 class PairedBeginDisplayItem : public DisplayItemBase<T> { |
| 402 protected: |
| 403 PairedBeginDisplayItem(const DisplayItemClient& client, DisplayItem::Type ty
pe) |
| 404 : DisplayItemBase<T>(client, type) { } |
| 387 | 405 |
| 388 private: | 406 private: |
| 389 bool isBegin() const final { return true; } | 407 bool isBegin() const final { return true; } |
| 390 }; | 408 }; |
| 391 | 409 |
| 392 class PLATFORM_EXPORT PairedEndDisplayItem : public DisplayItem { | 410 template <typename T> |
| 411 class PairedEndDisplayItem : public DisplayItemBase<T> { |
| 393 protected: | 412 protected: |
| 394 PairedEndDisplayItem(const DisplayItemClient& client, Type type, size_t deri
vedSize) : DisplayItem(client, type, derivedSize) { } | 413 PairedEndDisplayItem(const DisplayItemClient& client, DisplayItem::Type type
) |
| 414 : DisplayItemBase<T>(client, type) { } |
| 395 | 415 |
| 396 #if ENABLE(ASSERT) | 416 #if ENABLE(ASSERT) |
| 397 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; | 417 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; |
| 398 #endif | 418 #endif |
| 399 | 419 |
| 400 private: | 420 private: |
| 401 bool isEnd() const final { return true; } | 421 bool isEnd() const final { return true; } |
| 402 }; | 422 }; |
| 403 | 423 |
| 404 } // namespace blink | 424 } // namespace blink |
| 405 | 425 |
| 406 #endif // DisplayItem_h | 426 #endif // DisplayItem_h |
| OLD | NEW |