| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 static_assert(TableCollapsedBorderBase >= TableCollapsedBorderUnalignedBase,
"TableCollapsedBorder types overlap with other types"); | 185 static_assert(TableCollapsedBorderBase >= TableCollapsedBorderUnalignedBase,
"TableCollapsedBorder types overlap with other types"); |
| 186 static_assert((TableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of T
ableCollapsedBorderBase should be zero"); | 186 static_assert((TableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of T
ableCollapsedBorderBase should be zero"); |
| 187 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps
ed border type. | 187 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps
ed border type. |
| 188 enum TableCollapsedBorderSides { | 188 enum TableCollapsedBorderSides { |
| 189 TableCollapsedBorderTop = 1 << 0, | 189 TableCollapsedBorderTop = 1 << 0, |
| 190 TableCollapsedBorderRight = 1 << 1, | 190 TableCollapsedBorderRight = 1 << 1, |
| 191 TableCollapsedBorderBottom = 1 << 2, | 191 TableCollapsedBorderBottom = 1 << 2, |
| 192 TableCollapsedBorderLeft = 1 << 3, | 192 TableCollapsedBorderLeft = 1 << 3, |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 DisplayItem(const DisplayItemClientWrapper& client, Type type, size_t derive
dSize) | 195 DisplayItem(const DisplayItemClient& client, Type type, size_t derivedSize) |
| 196 : m_client(client.displayItemClient()) | 196 : m_client(&client) |
| 197 , m_scope(0) | 197 , m_scope(0) |
| 198 , m_type(type) | 198 , m_type(type) |
| 199 , m_derivedSize(derivedSize) | 199 , m_derivedSize(derivedSize) |
| 200 , m_skippedCache(false) | 200 , m_skippedCache(false) |
| 201 #ifndef NDEBUG | 201 #ifndef NDEBUG |
| 202 , m_clientDebugString(client.debugName()) | 202 , m_clientDebugString(client.debugName()) |
| 203 #endif | 203 #endif |
| 204 { | 204 { |
| 205 // derivedSize must fit in m_derivedSize. | 205 // derivedSize must fit in m_derivedSize. |
| 206 // If it doesn't, enlarge m_derivedSize and fix this assert. | 206 // If it doesn't, enlarge m_derivedSize and fix this assert. |
| 207 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize < (1 << 8)); | 207 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize < (1 << 8)); |
| 208 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize >= sizeof(*this)); | 208 ASSERT_WITH_SECURITY_IMPLICATION(derivedSize >= sizeof(*this)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 virtual ~DisplayItem() { } | 211 virtual ~DisplayItem() { } |
| 212 | 212 |
| 213 // Ids are for matching new DisplayItems with existing DisplayItems. | 213 // Ids are for matching new DisplayItems with existing DisplayItems. |
| 214 struct Id { | 214 struct Id { |
| 215 STACK_ALLOCATED(); | 215 STACK_ALLOCATED(); |
| 216 Id(const DisplayItemClient client, const Type type, const unsigned scope
) | 216 Id(const DisplayItemClient& client, const Type type, const unsigned scop
e) |
| 217 : client(client) | 217 : client(client) |
| 218 , type(type) | 218 , type(type) |
| 219 , scope(scope) { } | 219 , scope(scope) { } |
| 220 | 220 |
| 221 bool matches(const DisplayItem& item) const | 221 bool matches(const DisplayItem& item) const |
| 222 { | 222 { |
| 223 // We should always convert to non-cached types before matching. | 223 // We should always convert to non-cached types before matching. |
| 224 ASSERT(!isCachedType(item.m_type)); | 224 ASSERT(!isCachedType(item.m_type)); |
| 225 ASSERT(!isCachedType(type)); | 225 ASSERT(!isCachedType(type)); |
| 226 return client == item.m_client | 226 return &client == item.m_client |
| 227 && type == item.m_type | 227 && type == item.m_type |
| 228 && scope == item.m_scope; | 228 && scope == item.m_scope; |
| 229 } | 229 } |
| 230 | 230 |
| 231 const DisplayItemClient client; | 231 const DisplayItemClient& client; |
| 232 const Type type; | 232 const Type type; |
| 233 const unsigned scope; | 233 const unsigned scope; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 // Convert cached type to non-cached type (e.g., Type::CachedSVGImage -> Typ
e::SVGImage). | 236 // Convert cached type to non-cached type (e.g., Type::CachedSVGImage -> Typ
e::SVGImage). |
| 237 static Type nonCachedType(Type type) | 237 static Type nonCachedType(Type type) |
| 238 { | 238 { |
| 239 if (isCachedDrawingType(type)) | 239 if (isCachedDrawingType(type)) |
| 240 return cachedDrawingTypeToDrawingType(type); | 240 return cachedDrawingTypeToDrawingType(type); |
| 241 if (type == CachedSubsequence) | 241 if (type == CachedSubsequence) |
| 242 return Subsequence; | 242 return Subsequence; |
| 243 return type; | 243 return type; |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Return the Id with cached type converted to non-cached type. | 246 // Return the Id with cached type converted to non-cached type. |
| 247 Id nonCachedId() const | 247 Id nonCachedId() const |
| 248 { | 248 { |
| 249 return Id(m_client, nonCachedType(m_type), m_scope); | 249 return Id(*m_client, nonCachedType(m_type), m_scope); |
| 250 } | 250 } |
| 251 | 251 |
| 252 virtual void replay(GraphicsContext&) const { } | 252 virtual void replay(GraphicsContext&) const { } |
| 253 | 253 |
| 254 DisplayItemClient client() const { return m_client; } | 254 const DisplayItemClient& client() const { ASSERT(m_client); return *m_client
; } |
| 255 Type type() const { return m_type; } | 255 Type type() const { return m_type; } |
| 256 | 256 |
| 257 void setScope(unsigned scope) { m_scope = scope; } | 257 void setScope(unsigned scope) { m_scope = scope; } |
| 258 unsigned scope() { return m_scope; } | 258 unsigned scope() { return m_scope; } |
| 259 | 259 |
| 260 // Size of this object in memory, used to move it with memcpy. | 260 // Size of this object in memory, used to move it with memcpy. |
| 261 // This is not sizeof(*this), because it needs to account for the size of | 261 // This is not sizeof(*this), because it needs to account for the size of |
| 262 // the derived class (i.e. runtime type). Derived classes are expected to | 262 // the derived class (i.e. runtime type). Derived classes are expected to |
| 263 // supply this to the DisplayItem constructor. | 263 // supply this to the DisplayItem constructor. |
| 264 size_t derivedSize() const { return m_derivedSize; } | 264 size_t derivedSize() const { return m_derivedSize; } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 && m_skippedCache == other.m_skippedCache; | 338 && m_skippedCache == other.m_skippedCache; |
| 339 } | 339 } |
| 340 #endif | 340 #endif |
| 341 | 341 |
| 342 virtual bool drawsContent() const { return false; } | 342 virtual bool drawsContent() const { return false; } |
| 343 | 343 |
| 344 bool isValid() const { return m_client; } | 344 bool isValid() const { return m_client; } |
| 345 | 345 |
| 346 #ifndef NDEBUG | 346 #ifndef NDEBUG |
| 347 static WTF::String typeAsDebugString(DisplayItem::Type); | 347 static WTF::String typeAsDebugString(DisplayItem::Type); |
| 348 const WTF::String& clientDebugString() const { return m_clientDebugString; } | 348 const WTF::String clientDebugString() const { return m_clientDebugString; } |
| 349 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } | 349 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } |
| 350 WTF::String asDebugString() const; | 350 WTF::String asDebugString() const; |
| 351 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; | 351 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; |
| 352 #endif | 352 #endif |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 // The default DisplayItem constructor is only used by | 355 // The default DisplayItem constructor is only used by |
| 356 // ContiguousContainer::appendByMoving where an invalid DisplaItem is | 356 // ContiguousContainer::appendByMoving where an invalid DisplaItem is |
| 357 // constructed at the source location. | 357 // constructed at the source location. |
| 358 template <typename T, unsigned alignment> friend class ContiguousContainer; | 358 template <typename T, unsigned alignment> friend class ContiguousContainer; |
| 359 | 359 |
| 360 DisplayItem() | 360 DisplayItem() |
| 361 : m_client(nullptr) | 361 : m_client(nullptr) |
| 362 , m_scope(0) | 362 , m_scope(0) |
| 363 , m_type(UninitializedType) | 363 , m_type(UninitializedType) |
| 364 , m_derivedSize(sizeof(*this)) | 364 , m_derivedSize(sizeof(*this)) |
| 365 , m_skippedCache(false) | 365 , m_skippedCache(false) |
| 366 { } | 366 { } |
| 367 | 367 |
| 368 const DisplayItemClient m_client; | 368 const DisplayItemClient* m_client; |
| 369 unsigned m_scope; | 369 unsigned m_scope; |
| 370 static_assert(TypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bits
"); | 370 static_assert(TypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bits
"); |
| 371 const Type m_type : 16; | 371 const Type m_type : 16; |
| 372 const unsigned m_derivedSize : 8; // size of the actual derived class | 372 const unsigned m_derivedSize : 8; // size of the actual derived class |
| 373 unsigned m_skippedCache : 1; | 373 unsigned m_skippedCache : 1; |
| 374 | 374 |
| 375 #ifndef NDEBUG | 375 #ifndef NDEBUG |
| 376 WTF::String m_clientDebugString; | 376 WTF::String m_clientDebugString; |
| 377 #endif | 377 #endif |
| 378 }; | 378 }; |
| 379 | 379 |
| 380 class PLATFORM_EXPORT PairedBeginDisplayItem : public DisplayItem { | 380 class PLATFORM_EXPORT PairedBeginDisplayItem : public DisplayItem { |
| 381 protected: | 381 protected: |
| 382 PairedBeginDisplayItem(const DisplayItemClientWrapper& client, Type type, si
ze_t derivedSize) : DisplayItem(client, type, derivedSize) { } | 382 PairedBeginDisplayItem(const DisplayItemClient& client, Type type, size_t de
rivedSize) : DisplayItem(client, type, derivedSize) { } |
| 383 | 383 |
| 384 private: | 384 private: |
| 385 bool isBegin() const final { return true; } | 385 bool isBegin() const final { return true; } |
| 386 }; | 386 }; |
| 387 | 387 |
| 388 class PLATFORM_EXPORT PairedEndDisplayItem : public DisplayItem { | 388 class PLATFORM_EXPORT PairedEndDisplayItem : public DisplayItem { |
| 389 protected: | 389 protected: |
| 390 PairedEndDisplayItem(const DisplayItemClientWrapper& client, Type type, size
_t derivedSize) : DisplayItem(client, type, derivedSize) { } | 390 PairedEndDisplayItem(const DisplayItemClient& client, Type type, size_t deri
vedSize) : DisplayItem(client, type, derivedSize) { } |
| 391 | 391 |
| 392 #if ENABLE(ASSERT) | 392 #if ENABLE(ASSERT) |
| 393 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; | 393 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; |
| 394 #endif | 394 #endif |
| 395 | 395 |
| 396 private: | 396 private: |
| 397 bool isEnd() const final { return true; } | 397 bool isEnd() const final { return true; } |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 } // namespace blink | 400 } // namespace blink |
| 401 | 401 |
| 402 #endif // DisplayItem_h | 402 #endif // DisplayItem_h |
| OLD | NEW |