Title: [275925] trunk
Revision
275925
Author
mmaxfi...@apple.com
Date
2021-04-13 19:57:52 -0700 (Tue, 13 Apr 2021)

Log Message

[GPU Process] Simplify DisplayList::Iterator part 4: Move DisplayList::Iterator to its own .h/.cpp files
https://bugs.webkit.org/show_bug.cgi?id=224146

Reviewed by Wenson Hsieh.

Source/WebCore:

This doesn't actually change any lines of code; it just moves code into different files.
This patch isn't strictly necessary, but I think it helps, because the iterator contains
a non-trivial amount of logic.

No new tests because there is no behavior change.

* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/displaylists/DisplayList.cpp:
(WebCore::DisplayList::DisplayList::begin const):
(WebCore::DisplayList::DisplayList::end const):
(WebCore::DisplayList::DisplayList::iterator::atEnd const): Deleted.
(WebCore::DisplayList::DisplayList::iterator::updateCurrentDrawingItemExtent): Deleted.
(WebCore::DisplayList::DisplayList::iterator::updateCurrentItem): Deleted.
(WebCore::DisplayList::DisplayList::iterator::advance): Deleted.
(WebCore::DisplayList::DisplayList::iterator::clearCurrentItem): Deleted.
(WebCore::DisplayList::DisplayList::iterator::moveToEnd): Deleted.
(WebCore::DisplayList::DisplayList::iterator::moveCursorToStartOfCurrentBuffer): Deleted.
* platform/graphics/displaylists/DisplayList.h:
(WebCore::DisplayList::DisplayList::iterator::iterator): Deleted.
(WebCore::DisplayList::DisplayList::iterator::~iterator): Deleted.
(WebCore::DisplayList::DisplayList::iterator::operator==): Deleted.
(WebCore::DisplayList::DisplayList::iterator::operator!=): Deleted.
(WebCore::DisplayList::DisplayList::iterator::operator++): Deleted.
(WebCore::DisplayList::DisplayList::iterator::operator* const): Deleted.
(WebCore::DisplayList::DisplayList::iterator::itemBuffer const): Deleted.
(WebCore::DisplayList::DisplayList::begin const): Deleted.
(WebCore::DisplayList::DisplayList::end const): Deleted.
* platform/graphics/displaylists/DisplayListIterator.cpp: Added.
(WebCore::DisplayList::DisplayList::Iterator::atEnd const):
(WebCore::DisplayList::DisplayList::Iterator::updateCurrentDrawingItemExtent):
(WebCore::DisplayList::DisplayList::Iterator::updateCurrentItem):
(WebCore::DisplayList::DisplayList::Iterator::advance):
(WebCore::DisplayList::DisplayList::Iterator::clearCurrentItem):
(WebCore::DisplayList::DisplayList::Iterator::moveToEnd):
(WebCore::DisplayList::DisplayList::Iterator::moveCursorToStartOfCurrentBuffer):
* platform/graphics/displaylists/DisplayListIterator.h: Added.
(WebCore::DisplayList::DisplayList::Iterator::Iterator):
(WebCore::DisplayList::DisplayList::Iterator::~Iterator):
(WebCore::DisplayList::DisplayList::Iterator::operator==):
(WebCore::DisplayList::DisplayList::Iterator::operator!=):
(WebCore::DisplayList::DisplayList::Iterator::operator++):
(WebCore::DisplayList::DisplayList::Iterator::operator* const):
(WebCore::DisplayList::DisplayList::Iterator::itemBuffer const):
* platform/graphics/displaylists/DisplayListReplayer.cpp:

Tools:

* TestWebKitAPI/Tests/WebCore/DisplayListTests.cpp:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275924 => 275925)


--- trunk/Source/WebCore/ChangeLog	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/ChangeLog	2021-04-14 02:57:52 UTC (rev 275925)
@@ -1,3 +1,57 @@
+2021-04-13  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [GPU Process] Simplify DisplayList::Iterator part 4: Move DisplayList::Iterator to its own .h/.cpp files
+        https://bugs.webkit.org/show_bug.cgi?id=224146
+
+        Reviewed by Wenson Hsieh.
+
+        This doesn't actually change any lines of code; it just moves code into different files.
+        This patch isn't strictly necessary, but I think it helps, because the iterator contains
+        a non-trivial amount of logic.
+
+        No new tests because there is no behavior change.
+
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/displaylists/DisplayList.cpp:
+        (WebCore::DisplayList::DisplayList::begin const):
+        (WebCore::DisplayList::DisplayList::end const):
+        (WebCore::DisplayList::DisplayList::iterator::atEnd const): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::updateCurrentDrawingItemExtent): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::updateCurrentItem): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::advance): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::clearCurrentItem): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::moveToEnd): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::moveCursorToStartOfCurrentBuffer): Deleted.
+        * platform/graphics/displaylists/DisplayList.h:
+        (WebCore::DisplayList::DisplayList::iterator::iterator): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::~iterator): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::operator==): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::operator!=): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::operator++): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::operator* const): Deleted.
+        (WebCore::DisplayList::DisplayList::iterator::itemBuffer const): Deleted.
+        (WebCore::DisplayList::DisplayList::begin const): Deleted.
+        (WebCore::DisplayList::DisplayList::end const): Deleted.
+        * platform/graphics/displaylists/DisplayListIterator.cpp: Added.
+        (WebCore::DisplayList::DisplayList::Iterator::atEnd const):
+        (WebCore::DisplayList::DisplayList::Iterator::updateCurrentDrawingItemExtent):
+        (WebCore::DisplayList::DisplayList::Iterator::updateCurrentItem):
+        (WebCore::DisplayList::DisplayList::Iterator::advance):
+        (WebCore::DisplayList::DisplayList::Iterator::clearCurrentItem):
+        (WebCore::DisplayList::DisplayList::Iterator::moveToEnd):
+        (WebCore::DisplayList::DisplayList::Iterator::moveCursorToStartOfCurrentBuffer):
+        * platform/graphics/displaylists/DisplayListIterator.h: Added.
+        (WebCore::DisplayList::DisplayList::Iterator::Iterator):
+        (WebCore::DisplayList::DisplayList::Iterator::~Iterator):
+        (WebCore::DisplayList::DisplayList::Iterator::operator==):
+        (WebCore::DisplayList::DisplayList::Iterator::operator!=):
+        (WebCore::DisplayList::DisplayList::Iterator::operator++):
+        (WebCore::DisplayList::DisplayList::Iterator::operator* const):
+        (WebCore::DisplayList::DisplayList::Iterator::itemBuffer const):
+        * platform/graphics/displaylists/DisplayListReplayer.cpp:
+
 2021-04-13  Alex Christensen  <achristen...@webkit.org>
 
         Disable YouTube Flash and QuickTime plug in replacements on iOS

Modified: trunk/Source/WebCore/Headers.cmake (275924 => 275925)


--- trunk/Source/WebCore/Headers.cmake	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/Headers.cmake	2021-04-14 02:57:52 UTC (rev 275925)
@@ -1325,6 +1325,7 @@
     platform/graphics/displaylists/DisplayListItemBufferIdentifier.h
     platform/graphics/displaylists/DisplayListItemType.h
     platform/graphics/displaylists/DisplayListItems.h
+    platform/graphics/displaylists/DisplayListIterator.h
     platform/graphics/displaylists/DisplayListRecorder.h
     platform/graphics/displaylists/DisplayListReplayer.h
     platform/graphics/displaylists/InMemoryDisplayList.h

Modified: trunk/Source/WebCore/Sources.txt (275924 => 275925)


--- trunk/Source/WebCore/Sources.txt	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/Sources.txt	2021-04-14 02:57:52 UTC (rev 275925)
@@ -2026,6 +2026,7 @@
 platform/graphics/displaylists/DisplayListItems.cpp
 platform/graphics/displaylists/DisplayListItemBuffer.cpp
 platform/graphics/displaylists/DisplayListItemType.cpp
+platform/graphics/displaylists/DisplayListIterator.cpp
 platform/graphics/displaylists/DisplayListRecorder.cpp
 platform/graphics/displaylists/DisplayListReplayer.cpp
 platform/graphics/displaylists/InMemoryDisplayList.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (275924 => 275925)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-04-14 02:57:52 UTC (rev 275925)
@@ -644,6 +644,7 @@
 		1CAF56DB25301AC80017B472 /* DisplayListDrawGlyphsRecorder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CAF56D8253014570017B472 /* DisplayListDrawGlyphsRecorder.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1CCD81502231F83E0065FC2B /* WebCoreResourceHandleAsOperationQueueDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = E152551416FD234F003D7ADB /* WebCoreResourceHandleAsOperationQueueDelegate.mm */; };
 		1CCDF5BE1990332400BCEBAD /* SVGToOTFFontConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */; };
+		1CE8D12E261861C400FC3AEF /* DisplayListIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CE8D12C2618616400FC3AEF /* DisplayListIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1CE8D12726185C0E00FC3AEF /* DisplayListItemBufferIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CE8D12526185BD800FC3AEF /* DisplayListItemBufferIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1CE8864126105BF2000C816C /* InMemoryDisplayList.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CE8863F26105A5F000C816C /* InMemoryDisplayList.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; };
@@ -6956,6 +6957,8 @@
 		1CE8863E26105A5F000C816C /* InMemoryDisplayList.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InMemoryDisplayList.cpp; sourceTree = "<group>"; };
 		1CE8863F26105A5F000C816C /* InMemoryDisplayList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InMemoryDisplayList.h; sourceTree = "<group>"; };
 		1CECB3A821F2B67300F44542 /* WHLSLStatementBehaviorChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLStatementBehaviorChecker.h; sourceTree = "<group>"; };
+		1CE8D12B2618616400FC3AEF /* DisplayListIterator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayListIterator.cpp; sourceTree = "<group>"; };
+		1CE8D12C2618616400FC3AEF /* DisplayListIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayListIterator.h; sourceTree = "<group>"; };
 		1CECB3A921F2B67300F44542 /* WHLSLStatementBehaviorChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLStatementBehaviorChecker.cpp; sourceTree = "<group>"; };
 		1CECB3AF21F2B98400F44542 /* WHLSLFunctionWriter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLFunctionWriter.cpp; sourceTree = "<group>"; };
 		1CECB3B021F2B98500F44542 /* WHLSLTypeNamer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLTypeNamer.h; sourceTree = "<group>"; };
@@ -18100,6 +18103,8 @@
 				0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */,
 				F4377D562551C9C60080ABFE /* DisplayListItemType.cpp */,
 				F4377D552551C9C60080ABFE /* DisplayListItemType.h */,
+				1CE8D12B2618616400FC3AEF /* DisplayListIterator.cpp */,
+				1CE8D12C2618616400FC3AEF /* DisplayListIterator.h */,
 				0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */,
 				0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */,
 				0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */,
@@ -32167,6 +32172,7 @@
 				1CE8D12726185C0E00FC3AEF /* DisplayListItemBufferIdentifier.h in Headers */,
 				0FE5FBD51C3DD51E0007A2CA /* DisplayListItems.h in Headers */,
 				F4377D572551C9C60080ABFE /* DisplayListItemType.h in Headers */,
+				1CE8D12E261861C400FC3AEF /* DisplayListIterator.h in Headers */,
 				0FE5FBD71C3DD51E0007A2CA /* DisplayListRecorder.h in Headers */,
 				0FE5FBD91C3DD51E0007A2CA /* DisplayListReplayer.h in Headers */,
 				49AF2D6914435D050016A784 /* DisplayRefreshMonitor.h in Headers */,

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp (275924 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp	2021-04-14 02:57:52 UTC (rev 275925)
@@ -28,6 +28,7 @@
 
 #include "DisplayListItemBuffer.h"
 #include "DisplayListItems.h"
+#include "DisplayListIterator.h"
 #include "Logging.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/StdLibExtras.h>
@@ -334,128 +335,16 @@
     }
 }
 
-bool DisplayList::iterator::atEnd() const
+auto DisplayList::begin() const -> Iterator
 {
-    if (m_displayList.isEmpty() || !m_isValid)
-        return true;
-
-    auto& items = *itemBuffer();
-    auto endCursor = items.m_writableBuffer.data + items.m_writtenNumberOfBytes;
-    return m_cursor == endCursor;
+    return { *this };
 }
 
-DisplayList::iterator::ExtentUpdateResult DisplayList::iterator::updateCurrentDrawingItemExtent(ItemType itemType)
+auto DisplayList::end() const -> Iterator
 {
-    auto& extents = m_displayList.m_drawingItemExtents;
-    if (extents.isEmpty())
-        return ExtentUpdateResult::Success;
-
-    if (!isDrawingItem(itemType)) {
-        m_currentExtent = WTF::nullopt;
-        return ExtentUpdateResult::Success;
-    }
-
-    if (m_drawingItemIndex >= extents.size())
-        return ExtentUpdateResult::Failure;
-
-    m_currentExtent = extents[m_drawingItemIndex];
-    m_drawingItemIndex++;
-    return ExtentUpdateResult::Success;
+    return { *this, Iterator::ImmediatelyMoveToEnd::Yes };
 }
 
-void DisplayList::iterator::updateCurrentItem()
-{
-    clearCurrentItem();
-
-    if (atEnd())
-        return;
-
-    auto& items = *itemBuffer();
-    auto itemType = static_cast<ItemType>(m_cursor[0]);
-
-    if (updateCurrentDrawingItemExtent(itemType) == ExtentUpdateResult::Failure) {
-        m_isValid = false;
-        return;
-    }
-
-    auto paddedSizeOfTypeAndItem = paddedSizeOfTypeAndItemInBytes(itemType);
-    m_currentBufferForItem = paddedSizeOfTypeAndItem <= sizeOfFixedBufferForCurrentItem ? m_fixedBufferForCurrentItem : reinterpret_cast<uint8_t*>(fastMalloc(paddedSizeOfTypeAndItem));
-    if (isInlineItem(itemType)) {
-        if (UNLIKELY(!ItemHandle { m_cursor }.safeCopy({ m_currentBufferForItem })))
-            m_isValid = false;
-
-        m_currentItemSizeInBuffer = paddedSizeOfTypeAndItem;
-    } else {
-        auto* client = items.m_readingClient;
-        RELEASE_ASSERT(client);
-        auto dataLength = reinterpret_cast<uint64_t*>(m_cursor)[1];
-        auto* startOfData = m_cursor + 2 * sizeof(uint64_t);
-        auto decodedItemHandle = client->decodeItem(startOfData, dataLength, itemType, m_currentBufferForItem);
-        if (UNLIKELY(!decodedItemHandle))
-            m_isValid = false;
-
-        m_currentBufferForItem[0] = static_cast<uint8_t>(itemType);
-        m_currentItemSizeInBuffer = 2 * sizeof(uint64_t) + roundUpToMultipleOf(alignof(uint64_t), dataLength);
-    }
-}
-
-void DisplayList::iterator::advance()
-{
-    if (atEnd())
-        return;
-
-    m_cursor += m_currentItemSizeInBuffer;
-
-    if (m_cursor == m_currentEndOfBuffer && m_readOnlyBufferIndex < itemBuffer()->m_readOnlyBuffers.size()) {
-        m_readOnlyBufferIndex++;
-        moveCursorToStartOfCurrentBuffer();
-    }
-
-    updateCurrentItem();
-}
-
-void DisplayList::iterator::clearCurrentItem()
-{
-    auto items = itemBuffer();
-    if (items && items->m_readingClient && m_currentBufferForItem) {
-        if (LIKELY(m_isValid))
-            ItemHandle { m_currentBufferForItem }.destroy();
-
-        if (UNLIKELY(m_currentBufferForItem != m_fixedBufferForCurrentItem))
-            fastFree(m_currentBufferForItem);
-    }
-
-    m_currentItemSizeInBuffer = 0;
-    m_currentBufferForItem = nullptr;
-}
-
-void DisplayList::iterator::moveToEnd()
-{
-    if (auto items = itemBuffer()) {
-        m_cursor = items->m_writableBuffer.data + items->m_writtenNumberOfBytes;
-        m_currentEndOfBuffer = m_cursor;
-        m_readOnlyBufferIndex = items->m_readOnlyBuffers.size();
-    }
-}
-
-void DisplayList::iterator::moveCursorToStartOfCurrentBuffer()
-{
-    auto items = itemBuffer();
-    if (!items)
-        return;
-
-    auto numberOfReadOnlyBuffers = items->m_readOnlyBuffers.size();
-    if (m_readOnlyBufferIndex < numberOfReadOnlyBuffers) {
-        auto& nextBufferHandle = items->m_readOnlyBuffers[m_readOnlyBufferIndex];
-        m_cursor = nextBufferHandle.data;
-        m_currentEndOfBuffer = m_cursor + nextBufferHandle.capacity;
-    } else if (m_readOnlyBufferIndex == numberOfReadOnlyBuffers) {
-        m_cursor = items->m_writableBuffer.data;
-        m_currentEndOfBuffer = m_cursor + items->m_writtenNumberOfBytes;
-    }
-}
-
-
 } // namespace DisplayList
 
 TextStream& operator<<(TextStream& ts, const DisplayList::DisplayList& displayList)

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h (275924 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2021-04-14 02:57:52 UTC (rev 275925)
@@ -96,78 +96,11 @@
     bool tracksDrawingItemExtents() const { return m_tracksDrawingItemExtents; }
     WEBCORE_EXPORT void setTracksDrawingItemExtents(bool);
 
-    class iterator {
-    public:
-        enum class ImmediatelyMoveToEnd { No, Yes };
-        iterator(const DisplayList& displayList, ImmediatelyMoveToEnd immediatelyMoveToEnd = ImmediatelyMoveToEnd::No)
-            : m_displayList(displayList)
-        {
-            if (immediatelyMoveToEnd == ImmediatelyMoveToEnd::Yes)
-                moveToEnd();
-            else {
-                moveCursorToStartOfCurrentBuffer();
-                updateCurrentItem();
-            }
-        }
+    class Iterator;
 
-        ~iterator()
-        {
-            clearCurrentItem();
-        }
+    WEBCORE_EXPORT Iterator begin() const;
+    WEBCORE_EXPORT Iterator end() const;
 
-        bool operator==(const iterator& other) { return &m_displayList == &other.m_displayList && m_cursor == other.m_cursor; }
-        bool operator!=(const iterator& other) { return !(*this == other); }
-        void operator++() { advance(); }
-
-        struct Value {
-            ItemHandle item;
-            Optional<FloatRect> extent;
-            size_t itemSizeInBuffer { 0 };
-        };
-
-        Optional<Value> operator*() const
-        {
-            if (!m_isValid)
-                return WTF::nullopt;
-            return {{
-                ItemHandle { m_currentBufferForItem },
-                m_currentExtent,
-                m_currentItemSizeInBuffer,
-            }};
-        }
-
-    private:
-        static constexpr size_t sizeOfFixedBufferForCurrentItem = 256;
-
-        WEBCORE_EXPORT void moveCursorToStartOfCurrentBuffer();
-        WEBCORE_EXPORT void moveToEnd();
-        WEBCORE_EXPORT void clearCurrentItem();
-        WEBCORE_EXPORT void updateCurrentItem();
-        WEBCORE_EXPORT void advance();
-
-        enum class ExtentUpdateResult : bool { Failure, Success };
-        ExtentUpdateResult updateCurrentDrawingItemExtent(ItemType);
-
-        bool atEnd() const;
-
-        ItemBuffer* itemBuffer() const { return m_displayList.itemBufferIfExists(); }
-
-        const DisplayList& m_displayList;
-        uint8_t* m_cursor { nullptr };
-        size_t m_readOnlyBufferIndex { 0 };
-        size_t m_drawingItemIndex { 0 };
-        uint8_t* m_currentEndOfBuffer { nullptr };
-
-        uint8_t m_fixedBufferForCurrentItem[sizeOfFixedBufferForCurrentItem] { 0 };
-        uint8_t* m_currentBufferForItem { nullptr };
-        Optional<FloatRect> m_currentExtent;
-        size_t m_currentItemSizeInBuffer { 0 };
-        bool m_isValid { true };
-    };
-
-    iterator begin() const { return { *this }; }
-    iterator end() const { return { *this, iterator::ImmediatelyMoveToEnd::Yes }; }
-
 private:
     ItemBuffer* itemBufferIfExists() const { return m_items.get(); }
     WEBCORE_EXPORT ItemBuffer& itemBuffer();

Added: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.cpp (0 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.cpp	2021-04-14 02:57:52 UTC (rev 275925)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DisplayListIterator.h"
+
+namespace WebCore {
+namespace DisplayList {
+
+bool DisplayList::Iterator::atEnd() const
+{
+    if (m_displayList.isEmpty() || !m_isValid)
+        return true;
+
+    auto& items = *itemBuffer();
+    auto endCursor = items.m_writableBuffer.data + items.m_writtenNumberOfBytes;
+    return m_cursor == endCursor;
+}
+
+auto DisplayList::Iterator::updateCurrentDrawingItemExtent(ItemType itemType) -> ExtentUpdateResult
+{
+    auto& extents = m_displayList.m_drawingItemExtents;
+    if (extents.isEmpty())
+        return ExtentUpdateResult::Success;
+
+    if (!isDrawingItem(itemType)) {
+        m_currentExtent = WTF::nullopt;
+        return ExtentUpdateResult::Success;
+    }
+
+    if (m_drawingItemIndex >= extents.size())
+        return ExtentUpdateResult::Failure;
+
+    m_currentExtent = extents[m_drawingItemIndex];
+    m_drawingItemIndex++;
+    return ExtentUpdateResult::Success;
+}
+
+void DisplayList::Iterator::updateCurrentItem()
+{
+    clearCurrentItem();
+
+    if (atEnd())
+        return;
+
+    auto& items = *itemBuffer();
+    auto itemType = static_cast<ItemType>(m_cursor[0]);
+
+    if (updateCurrentDrawingItemExtent(itemType) == ExtentUpdateResult::Failure) {
+        m_isValid = false;
+        return;
+    }
+
+    auto paddedSizeOfTypeAndItem = paddedSizeOfTypeAndItemInBytes(itemType);
+    m_currentBufferForItem = paddedSizeOfTypeAndItem <= sizeOfFixedBufferForCurrentItem ? m_fixedBufferForCurrentItem : reinterpret_cast<uint8_t*>(fastMalloc(paddedSizeOfTypeAndItem));
+    if (isInlineItem(itemType)) {
+        if (UNLIKELY(!ItemHandle { m_cursor }.safeCopy({ m_currentBufferForItem })))
+            m_isValid = false;
+
+        m_currentItemSizeInBuffer = paddedSizeOfTypeAndItem;
+    } else {
+        auto* client = items.m_readingClient;
+        RELEASE_ASSERT(client);
+        auto dataLength = reinterpret_cast<uint64_t*>(m_cursor)[1];
+        auto* startOfData = m_cursor + 2 * sizeof(uint64_t);
+        auto decodedItemHandle = client->decodeItem(startOfData, dataLength, itemType, m_currentBufferForItem);
+        if (UNLIKELY(!decodedItemHandle))
+            m_isValid = false;
+
+        m_currentBufferForItem[0] = static_cast<uint8_t>(itemType);
+        m_currentItemSizeInBuffer = 2 * sizeof(uint64_t) + roundUpToMultipleOf(alignof(uint64_t), dataLength);
+    }
+}
+
+void DisplayList::Iterator::advance()
+{
+    if (atEnd())
+        return;
+
+    m_cursor += m_currentItemSizeInBuffer;
+
+    if (m_cursor == m_currentEndOfBuffer && m_readOnlyBufferIndex < itemBuffer()->m_readOnlyBuffers.size()) {
+        m_readOnlyBufferIndex++;
+        moveCursorToStartOfCurrentBuffer();
+    }
+
+    updateCurrentItem();
+}
+
+void DisplayList::Iterator::clearCurrentItem()
+{
+    auto items = itemBuffer();
+    if (items && items->m_readingClient && m_currentBufferForItem) {
+        if (LIKELY(m_isValid))
+            ItemHandle { m_currentBufferForItem }.destroy();
+
+        if (UNLIKELY(m_currentBufferForItem != m_fixedBufferForCurrentItem))
+            fastFree(m_currentBufferForItem);
+    }
+
+    m_currentItemSizeInBuffer = 0;
+    m_currentBufferForItem = nullptr;
+}
+
+void DisplayList::Iterator::moveToEnd()
+{
+    if (auto items = itemBuffer()) {
+        m_cursor = items->m_writableBuffer.data + items->m_writtenNumberOfBytes;
+        m_currentEndOfBuffer = m_cursor;
+        m_readOnlyBufferIndex = items->m_readOnlyBuffers.size();
+    }
+}
+
+void DisplayList::Iterator::moveCursorToStartOfCurrentBuffer()
+{
+    auto items = itemBuffer();
+    if (!items)
+        return;
+
+    auto numberOfReadOnlyBuffers = items->m_readOnlyBuffers.size();
+    if (m_readOnlyBufferIndex < numberOfReadOnlyBuffers) {
+        auto& nextBufferHandle = items->m_readOnlyBuffers[m_readOnlyBufferIndex];
+        m_cursor = nextBufferHandle.data;
+        m_currentEndOfBuffer = m_cursor + nextBufferHandle.capacity;
+    } else if (m_readOnlyBufferIndex == numberOfReadOnlyBuffers) {
+        m_cursor = items->m_writableBuffer.data;
+        m_currentEndOfBuffer = m_cursor + items->m_writtenNumberOfBytes;
+    }
+}
+
+}
+}

Added: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.h (0 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListIterator.h	2021-04-14 02:57:52 UTC (rev 275925)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "DisplayList.h"
+#include <wtf/Optional.h>
+
+namespace WebCore {
+namespace DisplayList {
+
+class DisplayList::Iterator {
+public:
+    enum class ImmediatelyMoveToEnd { No, Yes };
+    Iterator(const DisplayList& displayList, ImmediatelyMoveToEnd immediatelyMoveToEnd = ImmediatelyMoveToEnd::No)
+        : m_displayList(displayList)
+    {
+        if (immediatelyMoveToEnd == ImmediatelyMoveToEnd::Yes)
+            moveToEnd();
+        else {
+            moveCursorToStartOfCurrentBuffer();
+            updateCurrentItem();
+        }
+    }
+
+    ~Iterator()
+    {
+        clearCurrentItem();
+    }
+
+    bool operator==(const Iterator& other) { return &m_displayList == &other.m_displayList && m_cursor == other.m_cursor; }
+    bool operator!=(const Iterator& other) { return !(*this == other); }
+    void operator++() { advance(); }
+
+    struct Value {
+        ItemHandle item;
+        Optional<FloatRect> extent;
+        size_t itemSizeInBuffer { 0 };
+    };
+
+    Optional<Value> operator*() const
+    {
+        if (!m_isValid)
+            return WTF::nullopt;
+        return {{
+            ItemHandle { m_currentBufferForItem },
+            m_currentExtent,
+            m_currentItemSizeInBuffer,
+        }};
+    }
+
+private:
+    static constexpr size_t sizeOfFixedBufferForCurrentItem = 256;
+
+    WEBCORE_EXPORT void moveCursorToStartOfCurrentBuffer();
+    WEBCORE_EXPORT void moveToEnd();
+    WEBCORE_EXPORT void clearCurrentItem();
+    WEBCORE_EXPORT void updateCurrentItem();
+    WEBCORE_EXPORT void advance();
+
+    enum class ExtentUpdateResult : bool { Failure, Success };
+    ExtentUpdateResult updateCurrentDrawingItemExtent(ItemType);
+
+    bool atEnd() const;
+
+    ItemBuffer* itemBuffer() const { return m_displayList.itemBufferIfExists(); }
+
+    const DisplayList& m_displayList;
+    uint8_t* m_cursor { nullptr };
+    size_t m_readOnlyBufferIndex { 0 };
+    size_t m_drawingItemIndex { 0 };
+    uint8_t* m_currentEndOfBuffer { nullptr };
+
+    uint8_t m_fixedBufferForCurrentItem[sizeOfFixedBufferForCurrentItem] { 0 };
+    uint8_t* m_currentBufferForItem { nullptr };
+    Optional<FloatRect> m_currentExtent;
+    size_t m_currentItemSizeInBuffer { 0 };
+    bool m_isValid { true };
+};
+
+}
+}

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp (275924 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2021-04-14 02:57:52 UTC (rev 275925)
@@ -27,6 +27,7 @@
 #include "DisplayListReplayer.h"
 
 #include "DisplayListItems.h"
+#include "DisplayListIterator.h"
 #include "GraphicsContext.h"
 #include "InMemoryDisplayList.h"
 #include "Logging.h"

Modified: trunk/Source/WebCore/platform/graphics/displaylists/InMemoryDisplayList.cpp (275924 => 275925)


--- trunk/Source/WebCore/platform/graphics/displaylists/InMemoryDisplayList.cpp	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Source/WebCore/platform/graphics/displaylists/InMemoryDisplayList.cpp	2021-04-14 02:57:52 UTC (rev 275925)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "InMemoryDisplayList.h"
 
+#include "DisplayListIterator.h"
+
 namespace WebCore {
 namespace DisplayList {
 

Modified: trunk/Tools/ChangeLog (275924 => 275925)


--- trunk/Tools/ChangeLog	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Tools/ChangeLog	2021-04-14 02:57:52 UTC (rev 275925)
@@ -1,3 +1,12 @@
+2021-04-13  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [GPU Process] Simplify DisplayList::Iterator part 4: Move DisplayList::Iterator to its own .h/.cpp files
+        https://bugs.webkit.org/show_bug.cgi?id=224146
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebCore/DisplayListTests.cpp:
+
 2021-04-13  Alex Christensen  <achristen...@webkit.org>
 
         Remove support for NPAPI plugins in WebView

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/DisplayListTests.cpp (275924 => 275925)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/DisplayListTests.cpp	2021-04-14 02:19:29 UTC (rev 275924)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/DisplayListTests.cpp	2021-04-14 02:57:52 UTC (rev 275925)
@@ -27,6 +27,7 @@
 
 #include <WebCore/DisplayList.h>
 #include <WebCore/DisplayListItems.h>
+#include <WebCore/DisplayListIterator.h>
 #include <WebCore/Gradient.h>
 #include <WebCore/InMemoryDisplayList.h>
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to