Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef DisplayItems_h | |
| 6 #define DisplayItems_h | |
| 7 | |
| 8 #include "platform/PlatformExport.h" | |
| 9 #include "platform/graphics/paint/DisplayItem.h" | |
| 10 #include "platform/graphics/paint/DrawingDisplayItem.h" | |
| 11 #include "wtf/Forward.h" | |
| 12 #include "wtf/Noncopyable.h" | |
| 13 #include "wtf/OwnPtr.h" | |
| 14 #include "wtf/Vector.h" | |
| 15 | |
| 16 #include <iterator> | |
| 17 | |
| 18 class GraphicsContext; | |
| 19 class SkPicture; | |
| 20 | |
| 21 namespace blink { | |
| 22 | |
| 23 // Encapsulates logic for dealing with a simple list of display items, as | |
| 24 // opposed to DisplayItemList, which also manages the logic required for caching | |
| 25 // and updating them. | |
| 26 // | |
| 27 // This is presently implemented on top of a vector of pointers, but the | |
| 28 // implementation is intended to change in the future. | |
| 29 class PLATFORM_EXPORT DisplayItems { | |
| 30 WTF_MAKE_NONCOPYABLE(DisplayItems); | |
| 31 public: | |
| 32 // Holds a handle to an individual item, and provides restricted access to | |
| 33 // it. This limits what needs to be exposed by later implementations. | |
| 34 class PLATFORM_EXPORT ItemHandle { | |
| 35 public: | |
| 36 // Returns true if there is no item, because it was removed from the | |
| 37 // list for checking of cached items. | |
| 38 // TODO(jbroman): Clarify the purpose of this. | |
|
chrishtr
2015/06/08 23:03:05
I agree, this method is pretty weird as named. Wha
jbroman
2015/06/09 00:00:02
I think it's currently only used by the code that
| |
| 39 bool isGone() const { return !m_ptr; } | |
| 40 | |
| 41 DisplayItemClient client() const { return m_ptr->client(); } | |
| 42 DisplayItem::Type type() const { return m_ptr->type(); } | |
| 43 DisplayItem::Id id() const { return m_ptr->id(); } | |
| 44 | |
| 45 bool isBegin() const { return m_ptr->isBegin(); } | |
| 46 bool drawsContent() const { return m_ptr->drawsContent(); } | |
| 47 bool skippedCache() const { return m_ptr->skippedCache(); } | |
| 48 | |
| 49 void appendToWebDisplayItemList(WebDisplayItemList* list) const | |
| 50 { | |
| 51 m_ptr->appendToWebDisplayItemList(list); | |
| 52 } | |
| 53 | |
| 54 const SkPicture* picture() const | |
| 55 { | |
| 56 ASSERT_WITH_SECURITY_IMPLICATION(DisplayItem::isDrawingType(type())) ; | |
| 57 return static_cast<DrawingDisplayItem*>(m_ptr)->picture(); | |
| 58 } | |
| 59 | |
| 60 #if ENABLE(ASSERT) | |
| 61 DrawingDisplayItem::UnderInvalidationCheckingMode underInvalidationCheck ingMode() const | |
| 62 { | |
| 63 ASSERT_WITH_SECURITY_IMPLICATION(DisplayItem::isDrawingType(type())) ; | |
| 64 return static_cast<DrawingDisplayItem*>(m_ptr)->underInvalidationChe ckingMode(); | |
| 65 } | |
| 66 #endif | |
| 67 | |
| 68 #ifndef NDEBUG | |
| 69 String asDebugString() const { return m_ptr->asDebugString(); } | |
| 70 void dumpPropertiesAsDebugString(StringBuilder& builder) const { m_ptr-> dumpPropertiesAsDebugString(builder); } | |
| 71 #endif | |
| 72 | |
| 73 void replay(GraphicsContext& context) const { m_ptr->replay(context); } | |
| 74 | |
| 75 private: | |
| 76 ItemHandle() : m_ptr(nullptr) { } | |
| 77 explicit ItemHandle(DisplayItem* ptr) : m_ptr(ptr) { } | |
| 78 | |
| 79 DisplayItem* m_ptr; | |
| 80 friend class DisplayItems; | |
| 81 }; | |
| 82 | |
| 83 // Input iterators over the display items. | |
| 84 class Iterator : public std::iterator<std::input_iterator_tag, const ItemHan dle> { | |
| 85 public: | |
| 86 const ItemHandle& operator*() const { m_handle = ItemHandle(m_iterator-> get()); return m_handle; } | |
| 87 const ItemHandle* operator->() const { return &operator*(); } | |
| 88 Iterator& operator++() { ++m_iterator; return *this; } | |
| 89 Iterator operator++(int) { Iterator tmp(*this); operator++(); return tmp ; } | |
| 90 bool operator==(const Iterator& other) const { return m_iterator == othe r.m_iterator; } | |
| 91 bool operator!=(const Iterator& other) const { return !(*this == other); } | |
| 92 private: | |
| 93 using InternalIterator = Vector<OwnPtr<DisplayItem>>::iterator; | |
| 94 Iterator(const InternalIterator& it) : m_iterator(it) { } | |
| 95 InternalIterator m_iterator; | |
| 96 mutable ItemHandle m_handle; | |
| 97 friend class DisplayItems; | |
| 98 friend class ConstIterator; | |
| 99 }; | |
| 100 class ConstIterator : public std::iterator<std::input_iterator_tag, const It emHandle> { | |
| 101 public: | |
| 102 ConstIterator(const Iterator& it) : m_iterator(it.m_iterator) { } | |
| 103 const ItemHandle& operator*() const { m_handle = ItemHandle(m_iterator-> get()); return m_handle; } | |
| 104 const ItemHandle* operator->() const { return &operator*(); } | |
| 105 ConstIterator& operator++() { ++m_iterator; return *this; } | |
| 106 ConstIterator operator++(int) { ConstIterator tmp(*this); operator++(); return tmp; } | |
| 107 bool operator==(const ConstIterator& other) const { return m_iterator == other.m_iterator; } | |
| 108 bool operator!=(const ConstIterator& other) const { return !(*this == ot her); } | |
| 109 private: | |
| 110 using InternalIterator = Vector<OwnPtr<DisplayItem>>::const_iterator; | |
| 111 ConstIterator(const InternalIterator& it) : m_iterator(it) { } | |
| 112 InternalIterator m_iterator; | |
| 113 mutable ItemHandle m_handle; | |
| 114 friend class DisplayItems; | |
| 115 }; | |
| 116 | |
| 117 DisplayItems(); | |
| 118 ~DisplayItems(); | |
| 119 | |
| 120 bool isEmpty() const { return m_items.isEmpty(); } | |
| 121 size_t size() const { return m_items.size(); } | |
| 122 | |
| 123 // Random access may not remain O(1) in the future. | |
| 124 ItemHandle operator[](size_t index) const { return ItemHandle(m_items[index] .get()); } | |
| 125 Iterator iteratorAt(size_t index) { return Iterator(m_items.begin() + index) ; } | |
| 126 ConstIterator iteratorAt(size_t index) const { return ConstIterator(m_items. begin() + index); } | |
| 127 size_t indexForIterator(const Iterator& it) const { return it.m_iterator - m _items.begin(); } | |
| 128 size_t indexForIterator(const ConstIterator& it) const { return it.m_iterato r - m_items.begin(); } | |
| 129 | |
| 130 // Input iteration, however, should remain cheap. | |
| 131 Iterator begin() { return Iterator(m_items.begin()); } | |
| 132 Iterator end() { return Iterator(m_items.end()); } | |
| 133 ConstIterator begin() const { return ConstIterator(m_items.begin()); } | |
| 134 ConstIterator end() const { return ConstIterator(m_items.end()); } | |
| 135 | |
| 136 // Access to the end of the list should also be fast. | |
| 137 ItemHandle last() const { return ItemHandle(m_items.last().get()); } | |
| 138 | |
| 139 // TODO(jbroman): Replace this with something that doesn't first require | |
| 140 // heap allocation. | |
| 141 void append(PassOwnPtr<DisplayItem>); | |
| 142 | |
| 143 // Appends by moving from another list. The item in the list it's being | |
| 144 // removed from will become "gone" in this process, but can still be safely | |
| 145 // destroyed. | |
| 146 void appendByMoving(const Iterator&); | |
| 147 | |
| 148 void removeLast(); | |
| 149 void clear(); | |
| 150 | |
| 151 // TODO(jbroman): Is swap the right primitive? | |
| 152 void swap(DisplayItems&); | |
| 153 | |
| 154 // TODO(jbroman): This abstraction is odd and it would be nice to explain it | |
| 155 // more clearly. | |
| 156 void setGone(const Iterator&); | |
| 157 | |
| 158 private: | |
| 159 Vector<OwnPtr<DisplayItem>> m_items; | |
| 160 }; | |
| 161 | |
| 162 } // namespace blink | |
| 163 | |
| 164 #endif // DisplayItems_h | |
| OLD | NEW |