Chromium Code Reviews| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 kBeginCompositing, | 175 kBeginCompositing, |
| 176 kEndCompositing, | 176 kEndCompositing, |
| 177 kBeginTransform, | 177 kBeginTransform, |
| 178 kEndTransform, | 178 kEndTransform, |
| 179 kBeginClipPath, | 179 kBeginClipPath, |
| 180 kEndClipPath, | 180 kEndClipPath, |
| 181 | 181 |
| 182 kSubsequence, | 182 kSubsequence, |
| 183 kEndSubsequence, | 183 kEndSubsequence, |
| 184 | 184 |
| 185 kHasBeenMoved, | |
| 185 kUninitializedType, | 186 kUninitializedType, |
| 186 kTypeLast = kUninitializedType | 187 kTypeLast = kUninitializedType |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 static_assert(kTableCollapsedBorderBase >= kTableCollapsedBorderUnalignedBas e, "TableCollapsedBorder types overlap with other types"); | 190 static_assert(kTableCollapsedBorderBase >= kTableCollapsedBorderUnalignedBas e, "TableCollapsedBorder types overlap with other types"); |
| 190 static_assert((kTableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of TableCollapsedBorderBase should be zero"); | 191 static_assert((kTableCollapsedBorderBase & 0xf) == 0, "The lowest 4 bits of TableCollapsedBorderBase should be zero"); |
| 191 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps ed border type. | 192 // Bits or'ed onto TableCollapsedBorderBase to generate a real table collaps ed border type. |
| 192 enum TableCollapsedBorderSides { | 193 enum TableCollapsedBorderSides { |
| 193 TableCollapsedBorderTop = 1 << 0, | 194 TableCollapsedBorderTop = 1 << 0, |
| 194 TableCollapsedBorderRight = 1 << 1, | 195 TableCollapsedBorderRight = 1 << 1, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 217 struct Id { | 218 struct Id { |
| 218 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 219 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 219 Id(const DisplayItemClient& client, const Type type) | 220 Id(const DisplayItemClient& client, const Type type) |
| 220 : client(client) | 221 : client(client) |
| 221 , type(type) { } | 222 , type(type) { } |
| 222 | 223 |
| 223 const DisplayItemClient& client; | 224 const DisplayItemClient& client; |
| 224 const Type type; | 225 const Type type; |
| 225 }; | 226 }; |
| 226 | 227 |
| 227 Id getId() const { return Id(*m_client, m_type); } | 228 Id getId() const { return Id(client(), getType()); } |
| 228 | 229 |
| 229 virtual void replay(GraphicsContext&) const { } | 230 virtual void replay(GraphicsContext&) const { } |
| 230 | 231 |
| 231 const DisplayItemClient& client() const { ASSERT(m_client); return *m_client ; } | 232 const DisplayItemClient& client() const |
| 233 { | |
| 234 DCHECK(!hasBeenMoved()); | |
| 235 DCHECK(m_client); | |
| 236 return *m_client; | |
| 237 } | |
| 238 | |
| 232 Type getType() const { return m_type; } | 239 Type getType() const { return m_type; } |
| 233 | 240 |
| 234 // Size of this object in memory, used to move it with memcpy. | 241 // Size of this object in memory, used to move it with memcpy. |
| 235 // This is not sizeof(*this), because it needs to account for the size of | 242 // This is not sizeof(*this), because it needs to account for the size of |
| 236 // the derived class (i.e. runtime type). Derived classes are expected to | 243 // the derived class (i.e. runtime type). Derived classes are expected to |
| 237 // supply this to the DisplayItem constructor. | 244 // supply this to the DisplayItem constructor. |
| 238 size_t derivedSize() const { return m_derivedSize; } | 245 size_t derivedSize() const { return m_derivedSize; } |
| 239 | 246 |
| 240 // For PaintController only. Painters should use DisplayItemCacheSkipper ins tead. | 247 // For PaintController only. Painters should use DisplayItemCacheSkipper ins tead. |
| 241 void setSkippedCache() { m_skippedCache = true; } | 248 void setSkippedCache() { m_skippedCache = true; } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return false; } | 312 virtual bool isEndAndPairedWith(DisplayItem::Type otherType) const { return false; } |
| 306 virtual bool equals(const DisplayItem& other) const | 313 virtual bool equals(const DisplayItem& other) const |
| 307 { | 314 { |
| 308 return m_client == other.m_client | 315 return m_client == other.m_client |
| 309 && m_type == other.m_type | 316 && m_type == other.m_type |
| 310 && m_derivedSize == other.m_derivedSize | 317 && m_derivedSize == other.m_derivedSize |
| 311 && m_skippedCache == other.m_skippedCache; | 318 && m_skippedCache == other.m_skippedCache; |
| 312 } | 319 } |
| 313 #endif | 320 #endif |
| 314 | 321 |
| 315 // True if the client is non-null. Because m_client is const, this should | 322 // True if the item is a placeholder at the place of the original item that |
| 316 // never be false except when we explicitly create a tombstone/"dead display | 323 // has been moved by DisplayItemList::appendByMoving(). |
| 317 // item" as part of moving an item from one list to another (see: | 324 bool hasBeenMoved() const { return m_type == kHasBeenMoved; } |
| 318 // DisplayItemList::appendByMoving). | 325 size_t movedToIndex() const { DCHECK(hasBeenMoved()); return m_movedToIndex; } |
| 319 bool hasValidClient() const { return m_client; } | |
| 320 | 326 |
| 321 virtual bool drawsContent() const { return false; } | 327 virtual bool drawsContent() const { return false; } |
| 322 | 328 |
| 323 // Override to implement specific analysis strategies. | 329 // Override to implement specific analysis strategies. |
| 324 virtual void analyzeForGpuRasterization(SkPictureGpuAnalyzer&) const { } | 330 virtual void analyzeForGpuRasterization(SkPictureGpuAnalyzer&) const { } |
| 325 | 331 |
| 326 #ifndef NDEBUG | 332 #ifndef NDEBUG |
| 327 static WTF::String typeAsDebugString(DisplayItem::Type); | 333 static WTF::String typeAsDebugString(DisplayItem::Type); |
| 328 const WTF::String clientDebugString() const { return m_clientDebugString; } | 334 const WTF::String clientDebugString() const { return m_clientDebugString; } |
| 329 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } | 335 void setClientDebugString(const WTF::String& s) { m_clientDebugString = s; } |
| 330 WTF::String asDebugString() const; | 336 WTF::String asDebugString() const; |
| 331 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; | 337 virtual void dumpPropertiesAsDebugString(WTF::StringBuilder&) const; |
| 332 #endif | 338 #endif |
| 333 | 339 |
| 334 private: | 340 private: |
| 335 // The default DisplayItem constructor is only used by | 341 // The DisplayItem(size_t) constructor is only used by |
| 336 // ContiguousContainer::appendByMoving where an invalid DisplaItem is | 342 // ContiguousContainer::appendByMoving() where a placeholder DisplayItem is |
| 337 // constructed at the source location. | 343 // constructed at the source location. |
| 338 template <typename T, unsigned alignment> friend class ContiguousContainer; | 344 template <typename T, unsigned alignment> friend class ContiguousContainer; |
| 339 | 345 DisplayItem(size_t movedToIndex) |
| 340 DisplayItem() | 346 : m_movedToIndex(movedToIndex) |
| 341 : m_client(nullptr) | 347 , m_type(kHasBeenMoved) |
| 342 , m_type(kUninitializedType) | |
| 343 , m_derivedSize(sizeof(*this)) | 348 , m_derivedSize(sizeof(*this)) |
| 344 , m_skippedCache(false) | 349 , m_skippedCache(false) |
| 345 { } | 350 { } |
| 346 | 351 |
| 347 const DisplayItemClient* m_client; | 352 union { |
|
pdr.
2016/09/08 01:36:23
This approach of using a union is very efficient b
Xianzhu
2016/09/08 03:01:42
Done.
| |
| 353 const DisplayItemClient* m_client; // For m_type != HasBeenMoved. | |
| 354 size_t m_movedToIndex; // For m_type == HasBeenMoved. | |
| 355 }; | |
| 348 static_assert(kTypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bit s"); | 356 static_assert(kTypeLast < (1 << 16), "DisplayItem::Type should fit in 16 bit s"); |
| 349 const Type m_type : 16; | 357 const Type m_type : 16; |
| 350 const unsigned m_derivedSize : 8; // size of the actual derived class | 358 const unsigned m_derivedSize : 8; // size of the actual derived class |
| 351 unsigned m_skippedCache : 1; | 359 unsigned m_skippedCache : 1; |
| 352 | 360 |
| 353 #ifndef NDEBUG | 361 #ifndef NDEBUG |
| 354 WTF::String m_clientDebugString; | 362 WTF::String m_clientDebugString; |
| 355 #endif | 363 #endif |
| 356 }; | 364 }; |
| 357 | 365 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 381 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; | 389 bool isEndAndPairedWith(DisplayItem::Type otherType) const override = 0; |
| 382 #endif | 390 #endif |
| 383 | 391 |
| 384 private: | 392 private: |
| 385 bool isEnd() const final { return true; } | 393 bool isEnd() const final { return true; } |
| 386 }; | 394 }; |
| 387 | 395 |
| 388 } // namespace blink | 396 } // namespace blink |
| 389 | 397 |
| 390 #endif // DisplayItem_h | 398 #endif // DisplayItem_h |
| OLD | NEW |