Title: [225773] trunk/Source
Revision
225773
Author
[email protected]
Date
2017-12-11 23:04:44 -0800 (Mon, 11 Dec 2017)

Log Message

[CoordGraphics] Move UpdateAtlas, AreaAllocator into the platform layer
https://bugs.webkit.org/show_bug.cgi?id=180641

Reviewed by Michael Catanzaro.

Source/WebCore:

Move the UpdateAtlas and AreaAllocator classes and their source files
into the platform layer. This still means using the WebCore namespace,
but apart from that these two classes have no dependency on anything in
the WebKit layer, so they can be moved from there.

No new tests -- no change in functionality.

* platform/TextureMapper.cmake:
* platform/graphics/texmap/coordinated/AreaAllocator.cpp: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp.
(WebCore::AreaAllocator::AreaAllocator):
(WebCore::AreaAllocator::~AreaAllocator):
(WebCore::AreaAllocator::expand):
(WebCore::AreaAllocator::expandBy):
(WebCore::AreaAllocator::release):
(WebCore::AreaAllocator::overhead const):
(WebCore::AreaAllocator::roundAllocation const):
(WebCore::GeneralAreaAllocator::GeneralAreaAllocator):
(WebCore::GeneralAreaAllocator::~GeneralAreaAllocator):
(WebCore::GeneralAreaAllocator::freeNode):
(WebCore::GeneralAreaAllocator::expand):
(WebCore::fitsWithin):
(WebCore::GeneralAreaAllocator::allocate):
(WebCore::GeneralAreaAllocator::allocateFromNode):
(WebCore::GeneralAreaAllocator::splitNode):
(WebCore::GeneralAreaAllocator::updateLargestFree):
(WebCore::GeneralAreaAllocator::release):
(WebCore::GeneralAreaAllocator::overhead const):
* platform/graphics/texmap/coordinated/AreaAllocator.h: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h.
(WebCore::nextPowerOfTwo):
(WebCore::AreaAllocator::size const):
(WebCore::AreaAllocator::minimumAllocation const):
(WebCore::AreaAllocator::setMinimumAllocation):
(WebCore::AreaAllocator::margin const):
(WebCore::AreaAllocator::setMargin):
* platform/graphics/texmap/coordinated/UpdateAtlas.cpp: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp.
(WebCore::UpdateAtlas::UpdateAtlas):
(WebCore::UpdateAtlas::~UpdateAtlas):
(WebCore::UpdateAtlas::buildLayoutIfNeeded):
(WebCore::UpdateAtlas::didSwapBuffers):
(WebCore::UpdateAtlas::getCoordinatedBuffer):
* platform/graphics/texmap/coordinated/UpdateAtlas.h: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h.
(WebCore::UpdateAtlas::size const):
(WebCore::UpdateAtlas::supportsAlpha const):
(WebCore::UpdateAtlas::addTimeInactive):
(WebCore::UpdateAtlas::isInactive const):
(WebCore::UpdateAtlas::isInUse const):

Source/WebKit:

Move the UpdateAtlas and AreaAllocator classes into the platform layer,
moving over build targets and adjust UpdateAtlas class references in
CompositingCoordinator.

* PlatformGTK.cmake:
* PlatformWPE.cmake:
* PlatformWin.cmake:
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225772 => 225773)


--- trunk/Source/WebCore/ChangeLog	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebCore/ChangeLog	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,3 +1,57 @@
+2017-12-11  Zan Dobersek  <[email protected]>
+
+        [CoordGraphics] Move UpdateAtlas, AreaAllocator into the platform layer
+        https://bugs.webkit.org/show_bug.cgi?id=180641
+
+        Reviewed by Michael Catanzaro.
+
+        Move the UpdateAtlas and AreaAllocator classes and their source files
+        into the platform layer. This still means using the WebCore namespace,
+        but apart from that these two classes have no dependency on anything in
+        the WebKit layer, so they can be moved from there.
+
+        No new tests -- no change in functionality.
+
+        * platform/TextureMapper.cmake:
+        * platform/graphics/texmap/coordinated/AreaAllocator.cpp: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp.
+        (WebCore::AreaAllocator::AreaAllocator):
+        (WebCore::AreaAllocator::~AreaAllocator):
+        (WebCore::AreaAllocator::expand):
+        (WebCore::AreaAllocator::expandBy):
+        (WebCore::AreaAllocator::release):
+        (WebCore::AreaAllocator::overhead const):
+        (WebCore::AreaAllocator::roundAllocation const):
+        (WebCore::GeneralAreaAllocator::GeneralAreaAllocator):
+        (WebCore::GeneralAreaAllocator::~GeneralAreaAllocator):
+        (WebCore::GeneralAreaAllocator::freeNode):
+        (WebCore::GeneralAreaAllocator::expand):
+        (WebCore::fitsWithin):
+        (WebCore::GeneralAreaAllocator::allocate):
+        (WebCore::GeneralAreaAllocator::allocateFromNode):
+        (WebCore::GeneralAreaAllocator::splitNode):
+        (WebCore::GeneralAreaAllocator::updateLargestFree):
+        (WebCore::GeneralAreaAllocator::release):
+        (WebCore::GeneralAreaAllocator::overhead const):
+        * platform/graphics/texmap/coordinated/AreaAllocator.h: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h.
+        (WebCore::nextPowerOfTwo):
+        (WebCore::AreaAllocator::size const):
+        (WebCore::AreaAllocator::minimumAllocation const):
+        (WebCore::AreaAllocator::setMinimumAllocation):
+        (WebCore::AreaAllocator::margin const):
+        (WebCore::AreaAllocator::setMargin):
+        * platform/graphics/texmap/coordinated/UpdateAtlas.cpp: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp.
+        (WebCore::UpdateAtlas::UpdateAtlas):
+        (WebCore::UpdateAtlas::~UpdateAtlas):
+        (WebCore::UpdateAtlas::buildLayoutIfNeeded):
+        (WebCore::UpdateAtlas::didSwapBuffers):
+        (WebCore::UpdateAtlas::getCoordinatedBuffer):
+        * platform/graphics/texmap/coordinated/UpdateAtlas.h: Renamed from Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h.
+        (WebCore::UpdateAtlas::size const):
+        (WebCore::UpdateAtlas::supportsAlpha const):
+        (WebCore::UpdateAtlas::addTimeInactive):
+        (WebCore::UpdateAtlas::isInactive const):
+        (WebCore::UpdateAtlas::isInUse const):
+
 2017-12-11  Ryosuke Niwa  <[email protected]>
 
         Disable NoEventDispatchAssertion release assertion in WebKit1

Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (225772 => 225773)


--- trunk/Source/WebCore/platform/TextureMapper.cmake	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake	2017-12-12 07:04:44 UTC (rev 225773)
@@ -35,10 +35,12 @@
         platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
         platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
 
+        platform/graphics/texmap/coordinated/AreaAllocator.cpp
         platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
         platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp
         platform/graphics/texmap/coordinated/Tile.cpp
         platform/graphics/texmap/coordinated/TiledBackingStore.cpp
+        platform/graphics/texmap/coordinated/UpdateAtlas.cpp
     )
 
     # FIXME: Move this into Nicosia.cmake once the component is set for long-term use.

Added: trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp (0 => 225773)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp	2017-12-12 07:04:44 UTC (rev 225773)
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "config.h"
+#include "AreaAllocator.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+namespace WebCore {
+
+AreaAllocator::AreaAllocator(const IntSize& size)
+    : m_size(size)
+    , m_minAlloc(1, 1)
+    , m_margin(0, 0)
+{
+}
+
+AreaAllocator::~AreaAllocator()
+{
+}
+
+void AreaAllocator::expand(const IntSize& size)
+{
+    m_size = m_size.expandedTo(size);
+}
+
+void AreaAllocator::expandBy(const IntSize& size)
+{
+    m_size += size;
+}
+
+void AreaAllocator::release(const IntRect&)
+{
+}
+
+int AreaAllocator::overhead() const
+{
+    return 0;
+}
+
+IntSize AreaAllocator::roundAllocation(const IntSize& size) const
+{
+    int width = size.width() + m_margin.width();
+    int height = size.height() + m_margin.height();
+    int extra = width % m_minAlloc.width();
+    if (extra)
+        width += m_minAlloc.width() - extra;
+    extra = height % m_minAlloc.height();
+    if (extra)
+        height += m_minAlloc.height() - extra;
+
+    return IntSize(width, height);
+}
+
+GeneralAreaAllocator::GeneralAreaAllocator(const IntSize& size)
+    : AreaAllocator(nextPowerOfTwo(size))
+{
+    m_root = new Node();
+    m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
+    m_root->largestFree = m_size;
+    m_nodeCount = 1;
+    setMinimumAllocation(IntSize(8, 8));
+}
+
+GeneralAreaAllocator::~GeneralAreaAllocator()
+{
+    freeNode(m_root);
+}
+
+void GeneralAreaAllocator::freeNode(Node* node)
+{
+    if (node) {
+        freeNode(node->left);
+        freeNode(node->right);
+    }
+    delete node;
+}
+
+void GeneralAreaAllocator::expand(const IntSize& size)
+{
+    AreaAllocator::expand(nextPowerOfTwo(size));
+
+    if (m_root->rect.size() == m_size)
+        return; // No change.
+
+    if (!m_root->left && m_root->largestFree.width() > 0) {
+        // No allocations have occurred, so just adjust the root size.
+        m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
+        m_root->largestFree = m_size;
+        return;
+    }
+
+    // Add extra nodes above the current root to expand the tree.
+    Node* oldRoot = m_root;
+    Split split;
+    if (m_size.width() >= m_size.height())
+        split = SplitOnX;
+    else
+        split = SplitOnY;
+
+    while (m_root->rect.size() != m_size) {
+        if (m_root->rect.width() == m_size.width())
+            split = SplitOnY;
+        else if (m_root->rect.height() == m_size.height())
+            split = SplitOnX;
+        Node* parent = new Node();
+        Node* right = new Node();
+        m_nodeCount += 2;
+        m_root->parent = parent;
+        parent->parent = nullptr;
+        parent->left = m_root;
+        parent->right = right;
+        parent->largestFree = m_root->rect.size();
+        right->parent = parent;
+        right->left = nullptr;
+        right->right = nullptr;
+        right->largestFree = m_root->rect.size();
+        if (split == SplitOnX) {
+            parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
+                m_root->rect.width() * 2, m_root->rect.height());
+            right->rect = IntRect(m_root->rect.x() + m_root->rect.width(), m_root->rect.y(),
+                m_root->rect.width(), m_root->rect.height());
+        } else {
+            parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
+                m_root->rect.width(), m_root->rect.height() * 2);
+            right->rect = IntRect(m_root->rect.x(), m_root->rect.y() + m_root->rect.width(),
+                m_root->rect.width(), m_root->rect.height());
+        }
+        split = (split == SplitOnX ? SplitOnY : SplitOnX);
+        m_root = parent;
+    }
+    updateLargestFree(oldRoot);
+}
+
+static inline bool fitsWithin(const IntSize& size1, const IntSize& size2)
+{
+    return size1.width() <= size2.width() && size1.height() <= size2.height();
+}
+
+IntRect GeneralAreaAllocator::allocate(const IntSize& size)
+{
+    IntSize rounded = roundAllocation(size);
+    rounded = nextPowerOfTwo(rounded);
+    if (rounded.width() <= 0 || rounded.width() > m_size.width()
+        || rounded.height() <= 0 || rounded.height() > m_size.height())
+        return IntRect();
+
+    IntPoint point = allocateFromNode(rounded, m_root);
+    if (point.x() >= 0)
+        return IntRect(point, size);
+    return IntRect();
+}
+
+IntPoint GeneralAreaAllocator::allocateFromNode(const IntSize& size, Node* node)
+{
+    // Find the best node to insert into, which should be
+    // a node with the least amount of unused space that is
+    // big enough to contain the requested size.
+    while (node) {
+        // Go down a level and determine if the left or right
+        // sub-tree contains the best chance of allocation.
+        Node* left = node->left;
+        Node* right = node->right;
+        if (left && fitsWithin(size, left->largestFree)) {
+            if (right && fitsWithin(size, right->largestFree)) {
+                if (left->largestFree.width() < right->largestFree.width()
+                    || left->largestFree.height() < right->largestFree.height()) {
+                    // The largestFree values may be a little oversized,
+                    // so try the left sub-tree and then the right sub-tree.
+                    IntPoint point = allocateFromNode(size, left);
+                    if (point.x() >= 0)
+                        return point;
+                    return allocateFromNode(size, right);
+                }
+                node = right;
+            } else
+                node = left;
+        } else if (right && fitsWithin(size, right->largestFree))
+            node = right;
+        else if (left || right) {
+            // Neither sub-node has enough space to allocate from.
+            return IntPoint(-1, -1);
+        } else if (fitsWithin(size, node->largestFree)) {
+            // Do we need to split this node into smaller pieces?
+            Split split;
+            if (fitsWithin(IntSize(size.width() * 2, size.height() * 2), node->largestFree)) {
+                // Split in either direction: choose the inverse of
+                // the parent node's split direction to try to balance
+                // out the wasted space as further subdivisions happen.
+                if (node->parent
+                    && node->parent->left->rect.x() == node->parent->right->rect.x())
+                    split = SplitOnX;
+                else if (node->parent)
+                    split = SplitOnY;
+                else if (node->rect.width() >= node->rect.height())
+                    split = SplitOnX;
+                else
+                    split = SplitOnY;
+            } else if (fitsWithin(IntSize(size.width() * 2, size.height()), node->largestFree)) {
+                // Split along the X direction.
+                split = SplitOnX;
+            } else if (fitsWithin(IntSize(size.width(), size.height() * 2), node->largestFree)) {
+                // Split along the Y direction.
+                split = SplitOnY;
+            } else {
+                // Cannot split further - allocate this node.
+                node->largestFree = IntSize(0, 0);
+                updateLargestFree(node);
+                return node->rect.location();
+            }
+
+            // Split the node, then go around again using the left sub-tree.
+            node = splitNode(node, split);
+        } else {
+            // Cannot possibly fit into this node.
+            break;
+        }
+    }
+    return IntPoint(-1, -1);
+}
+
+GeneralAreaAllocator::Node* GeneralAreaAllocator::splitNode(Node* node, Split split)
+{
+    Node* left = new Node();
+    left->parent = node;
+    Node* right = new Node();
+    right->parent = node;
+    node->left = left;
+    node->right = right;
+    m_nodeCount += 2;
+
+    if (split == SplitOnX) {
+        left->rect = IntRect(node->rect.x(), node->rect.y(),
+            node->rect.width() / 2, node->rect.height());
+        right->rect = IntRect(left->rect.maxX(), node->rect.y(),
+            node->rect.width() / 2, node->rect.height());
+    } else {
+        left->rect = IntRect(node->rect.x(), node->rect.y(),
+            node->rect.width(), node->rect.height() / 2);
+        right->rect = IntRect(node->rect.x(), left->rect.maxY(),
+            node->rect.width(), node->rect.height() / 2);
+    }
+
+    left->largestFree = left->rect.size();
+    right->largestFree = right->rect.size();
+    node->largestFree = right->largestFree;
+    return left;
+}
+
+void GeneralAreaAllocator::updateLargestFree(Node* node)
+{
+    while ((node = node->parent)) {
+        node->largestFree = IntSize(
+            std::max(node->left->largestFree.width(), node->right->largestFree.width()),
+            std::max(node->left->largestFree.height(), node->right->largestFree.height())
+            );
+    }
+}
+
+void GeneralAreaAllocator::release(const IntRect& rect)
+{
+    // Locate the node that contains the allocated region.
+    Node* node = m_root;
+    IntPoint point = rect.location();
+    while (node) {
+        if (node->left && node->left->rect.contains(point))
+            node = node->left;
+        else if (node->right && node->right->rect.contains(point))
+            node = node->right;
+        else if (node->rect.contains(point))
+            break;
+        else
+            return; // Point is completely outside the tree.
+    }
+    if (!node)
+        return;
+
+    // Mark the node as free and then work upwards through the tree
+    // recombining and deleting nodes until we reach a sibling
+    // that is still allocated.
+    node->largestFree = node->rect.size();
+    while (node->parent) {
+        if (node->parent->left == node) {
+            if (node->parent->right->largestFree != node->parent->right->rect.size())
+                break;
+        } else {
+            if (node->parent->left->largestFree != node->parent->left->rect.size())
+                break;
+        }
+        node = node->parent;
+        freeNode(node->left);
+        freeNode(node->right);
+        m_nodeCount -= 2;
+        node->left = nullptr;
+        node->right = nullptr;
+        node->largestFree = node->rect.size();
+    }
+
+    // Make the rest of our ancestors have the correct "largest free size".
+    updateLargestFree(node);
+}
+
+int GeneralAreaAllocator::overhead() const
+{
+    return m_nodeCount * sizeof(Node);
+}
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)

Added: trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h (0 => 225773)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h	2017-12-12 07:04:44 UTC (rev 225773)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#pragma once
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include "IntPoint.h"
+#include "IntRect.h"
+#include "IntSize.h"
+
+namespace WebCore {
+
+inline int nextPowerOfTwo(int number)
+{
+    // This is a fast trick to get nextPowerOfTwo for an integer.
+    --number;
+    number |= number >> 1;
+    number |= number >> 2;
+    number |= number >> 4;
+    number |= number >> 8;
+    number |= number >> 16;
+    number++;
+    return number;
+}
+
+inline IntSize nextPowerOfTwo(const IntSize& size)
+{
+    return IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));
+}
+
+class AreaAllocator {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit AreaAllocator(const IntSize&);
+    virtual ~AreaAllocator();
+
+    IntSize size() const { return m_size; }
+
+    IntSize minimumAllocation() const { return m_minAlloc; }
+    void setMinimumAllocation(const IntSize& size) { m_minAlloc = size; }
+
+    IntSize margin() const { return m_margin; }
+    void setMargin(const IntSize &margin) { m_margin = margin; }
+
+    virtual void expand(const IntSize&);
+    void expandBy(const IntSize&);
+
+    virtual IntRect allocate(const IntSize&) = 0;
+    virtual void release(const IntRect&);
+
+    virtual int overhead() const;
+
+protected:
+    IntSize m_size;
+    IntSize m_minAlloc;
+    IntSize m_margin;
+
+    IntSize roundAllocation(const IntSize&) const;
+};
+
+class GeneralAreaAllocator final : public AreaAllocator {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit GeneralAreaAllocator(const IntSize&);
+    virtual ~GeneralAreaAllocator();
+
+    void expand(const IntSize&) override;
+    IntRect allocate(const IntSize&) override;
+    void release(const IntRect&) override;
+    int overhead() const override;
+
+private:
+    enum Split { SplitOnX, SplitOnY };
+
+    struct Node {
+        WTF_MAKE_FAST_ALLOCATED;
+    public:
+        IntRect rect;
+        IntSize largestFree;
+        Node* parent { nullptr };
+        Node* left { nullptr };
+        Node* right { nullptr };
+    };
+
+    Node* m_root;
+    int m_nodeCount;
+
+    static void freeNode(Node*);
+    IntPoint allocateFromNode(const IntSize&, Node*);
+    Node* splitNode(Node*, Split);
+    static void updateLargestFree(Node*);
+};
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS)

Added: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp (0 => 225773)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp	2017-12-12 07:04:44 UTC (rev 225773)
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2012 Company 100, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "UpdateAtlas.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include "CoordinatedGraphicsState.h"
+#include "IntRect.h"
+
+namespace WebCore {
+
+UpdateAtlas::UpdateAtlas(Client& client, const IntSize& size, Nicosia::Buffer::Flags flags)
+    : m_client(client)
+    , m_buffer(Nicosia::Buffer::create(size, flags))
+{
+    static ID s_nextID { 0 };
+    m_id = ++s_nextID;
+
+    m_client.createUpdateAtlas(m_id, m_buffer.copyRef());
+}
+
+UpdateAtlas::~UpdateAtlas()
+{
+    m_client.removeUpdateAtlas(m_id);
+}
+
+void UpdateAtlas::buildLayoutIfNeeded()
+{
+    if (m_areaAllocator)
+        return;
+    m_areaAllocator = std::make_unique<GeneralAreaAllocator>(size());
+    m_areaAllocator->setMinimumAllocation(IntSize(32, 32));
+}
+
+void UpdateAtlas::didSwapBuffers()
+{
+    m_areaAllocator = nullptr;
+}
+
+RefPtr<Nicosia::Buffer> UpdateAtlas::getCoordinatedBuffer(const IntSize& size, uint32_t& atlasID, IntRect& allocatedRect)
+{
+    m_inactivityInSeconds = 0;
+    buildLayoutIfNeeded();
+    allocatedRect = m_areaAllocator->allocate(size);
+
+    if (allocatedRect.isEmpty())
+        return nullptr;
+
+    atlasID = m_id;
+    return m_buffer.copyRef();
+}
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS)

Added: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h (0 => 225773)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h	2017-12-12 07:04:44 UTC (rev 225773)
@@ -0,0 +1,79 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2012 Company 100, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "AreaAllocator.h"
+#include "NicosiaBuffer.h"
+#include <wtf/RefPtr.h>
+
+#if USE(COORDINATED_GRAPHICS)
+
+namespace WebCore {
+
+class IntRect;
+class IntSize;
+
+class UpdateAtlas {
+    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(UpdateAtlas);
+public:
+    using ID = uint32_t;
+
+    class Client {
+    public:
+        virtual void createUpdateAtlas(ID, Ref<Nicosia::Buffer>&&) = 0;
+        virtual void removeUpdateAtlas(ID) = 0;
+    };
+
+    UpdateAtlas(Client&, const IntSize&, Nicosia::Buffer::Flags);
+    ~UpdateAtlas();
+
+    const IntSize& size() const { return m_buffer->size(); }
+
+    RefPtr<Nicosia::Buffer> getCoordinatedBuffer(const IntSize&, uint32_t&, IntRect&);
+    void didSwapBuffers();
+    bool supportsAlpha() const { return m_buffer->supportsAlpha(); }
+
+    void addTimeInactive(double seconds)
+    {
+        ASSERT(!isInUse());
+        m_inactivityInSeconds += seconds;
+    }
+    bool isInactive() const
+    {
+        const double inactiveSecondsTolerance = 3;
+        return m_inactivityInSeconds > inactiveSecondsTolerance;
+    }
+    bool isInUse() const { return !!m_areaAllocator; }
+
+private:
+    void buildLayoutIfNeeded();
+
+    ID m_id { 0 };
+    Client& m_client;
+    std::unique_ptr<GeneralAreaAllocator> m_areaAllocator;
+    Ref<Nicosia::Buffer> m_buffer;
+    double m_inactivityInSeconds { 0 };
+};
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS)

Modified: trunk/Source/WebKit/ChangeLog (225772 => 225773)


--- trunk/Source/WebKit/ChangeLog	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/ChangeLog	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,3 +1,19 @@
+2017-12-11  Zan Dobersek  <[email protected]>
+
+        [CoordGraphics] Move UpdateAtlas, AreaAllocator into the platform layer
+        https://bugs.webkit.org/show_bug.cgi?id=180641
+
+        Reviewed by Michael Catanzaro.
+
+        Move the UpdateAtlas and AreaAllocator classes into the platform layer,
+        moving over build targets and adjust UpdateAtlas class references in
+        CompositingCoordinator.
+
+        * PlatformGTK.cmake:
+        * PlatformWPE.cmake:
+        * PlatformWin.cmake:
+        * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
+
 2017-12-11  Alex Christensen  <[email protected]>
 
         Add a WKPageGroupRef setter in WKWebViewConfiguration

Modified: trunk/Source/WebKit/PlatformGTK.cmake (225772 => 225773)


--- trunk/Source/WebKit/PlatformGTK.cmake	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/PlatformGTK.cmake	2017-12-12 07:04:44 UTC (rev 225773)
@@ -386,11 +386,9 @@
     WebProcess/WebPage/AcceleratedDrawingArea.cpp
     WebProcess/WebPage/AcceleratedSurface.cpp
 
-    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
     WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
-    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
 
     WebProcess/WebPage/DrawingAreaImpl.cpp
 

Modified: trunk/Source/WebKit/PlatformWPE.cmake (225772 => 225773)


--- trunk/Source/WebKit/PlatformWPE.cmake	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/PlatformWPE.cmake	2017-12-12 07:04:44 UTC (rev 225773)
@@ -260,11 +260,9 @@
     WebProcess/WebPage/AcceleratedDrawingArea.cpp
     WebProcess/WebPage/AcceleratedSurface.cpp
 
-    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
     WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
-    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
 
     WebProcess/WebPage/gstreamer/WebPageGStreamer.cpp
 

Modified: trunk/Source/WebKit/PlatformWin.cmake (225772 => 225773)


--- trunk/Source/WebKit/PlatformWin.cmake	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/PlatformWin.cmake	2017-12-12 07:04:44 UTC (rev 225773)
@@ -46,11 +46,9 @@
     WebProcess/WebPage/AcceleratedSurface.cpp
     WebProcess/WebPage/DrawingAreaImpl.cpp
 
-    WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
     WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
     WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
-    WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
 
     WebProcess/WebPage/win/WebInspectorUIWin.cpp
     WebProcess/WebPage/win/WebPageWin.cpp

Deleted: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp (225772 => 225773)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,328 +0,0 @@
-/*
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#include "config.h"
-#include "AreaAllocator.h"
-
-#if USE(COORDINATED_GRAPHICS)
-
-using namespace WebCore;
-
-namespace WebKit {
-
-AreaAllocator::AreaAllocator(const IntSize& size)
-    : m_size(size)
-    , m_minAlloc(1, 1)
-    , m_margin(0, 0)
-{
-}
-
-AreaAllocator::~AreaAllocator()
-{
-}
-
-void AreaAllocator::expand(const IntSize& size)
-{
-    m_size = m_size.expandedTo(size);
-}
-
-void AreaAllocator::expandBy(const IntSize& size)
-{
-    m_size += size;
-}
-
-void AreaAllocator::release(const IntRect&)
-{
-}
-
-int AreaAllocator::overhead() const
-{
-    return 0;
-}
-
-IntSize AreaAllocator::roundAllocation(const IntSize& size) const
-{
-    int width = size.width() + m_margin.width();
-    int height = size.height() + m_margin.height();
-    int extra = width % m_minAlloc.width();
-    if (extra)
-        width += m_minAlloc.width() - extra;
-    extra = height % m_minAlloc.height();
-    if (extra)
-        height += m_minAlloc.height() - extra;
-
-    return IntSize(width, height);
-}
-
-GeneralAreaAllocator::GeneralAreaAllocator(const IntSize& size)
-    : AreaAllocator(nextPowerOfTwo(size))
-{
-    m_root = new Node();
-    m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
-    m_root->largestFree = m_size;
-    m_nodeCount = 1;
-    setMinimumAllocation(IntSize(8, 8));
-}
-
-GeneralAreaAllocator::~GeneralAreaAllocator()
-{
-    freeNode(m_root);
-}
-
-void GeneralAreaAllocator::freeNode(Node* node)
-{
-    if (node) {
-        freeNode(node->left);
-        freeNode(node->right);
-    }
-    delete node;
-}
-
-void GeneralAreaAllocator::expand(const IntSize& size)
-{
-    AreaAllocator::expand(nextPowerOfTwo(size));
-
-    if (m_root->rect.size() == m_size)
-        return; // No change.
-
-    if (!m_root->left && m_root->largestFree.width() > 0) {
-        // No allocations have occurred, so just adjust the root size.
-        m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
-        m_root->largestFree = m_size;
-        return;
-    }
-
-    // Add extra nodes above the current root to expand the tree.
-    Node* oldRoot = m_root;
-    Split split;
-    if (m_size.width() >= m_size.height())
-        split = SplitOnX;
-    else
-        split = SplitOnY;
-
-    while (m_root->rect.size() != m_size) {
-        if (m_root->rect.width() == m_size.width())
-            split = SplitOnY;
-        else if (m_root->rect.height() == m_size.height())
-            split = SplitOnX;
-        Node* parent = new Node();
-        Node* right = new Node();
-        m_nodeCount += 2;
-        m_root->parent = parent;
-        parent->parent = nullptr;
-        parent->left = m_root;
-        parent->right = right;
-        parent->largestFree = m_root->rect.size();
-        right->parent = parent;
-        right->left = nullptr;
-        right->right = nullptr;
-        right->largestFree = m_root->rect.size();
-        if (split == SplitOnX) {
-            parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
-                m_root->rect.width() * 2, m_root->rect.height());
-            right->rect = IntRect(m_root->rect.x() + m_root->rect.width(), m_root->rect.y(),
-                m_root->rect.width(), m_root->rect.height());
-        } else {
-            parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
-                m_root->rect.width(), m_root->rect.height() * 2);
-            right->rect = IntRect(m_root->rect.x(), m_root->rect.y() + m_root->rect.width(),
-                m_root->rect.width(), m_root->rect.height());
-        }
-        split = (split == SplitOnX ? SplitOnY : SplitOnX);
-        m_root = parent;
-    }
-    updateLargestFree(oldRoot);
-}
-
-static inline bool fitsWithin(const IntSize& size1, const IntSize& size2)
-{
-    return size1.width() <= size2.width() && size1.height() <= size2.height();
-}
-
-IntRect GeneralAreaAllocator::allocate(const IntSize& size)
-{
-    IntSize rounded = roundAllocation(size);
-    rounded = nextPowerOfTwo(rounded);
-    if (rounded.width() <= 0 || rounded.width() > m_size.width()
-        || rounded.height() <= 0 || rounded.height() > m_size.height())
-        return IntRect();
-
-    IntPoint point = allocateFromNode(rounded, m_root);
-    if (point.x() >= 0)
-        return IntRect(point, size);
-    return IntRect();
-}
-
-IntPoint GeneralAreaAllocator::allocateFromNode(const IntSize& size, Node* node)
-{
-    // Find the best node to insert into, which should be
-    // a node with the least amount of unused space that is
-    // big enough to contain the requested size.
-    while (node) {
-        // Go down a level and determine if the left or right
-        // sub-tree contains the best chance of allocation.
-        Node* left = node->left;
-        Node* right = node->right;
-        if (left && fitsWithin(size, left->largestFree)) {
-            if (right && fitsWithin(size, right->largestFree)) {
-                if (left->largestFree.width() < right->largestFree.width()
-                    || left->largestFree.height() < right->largestFree.height()) {
-                    // The largestFree values may be a little oversized,
-                    // so try the left sub-tree and then the right sub-tree.
-                    IntPoint point = allocateFromNode(size, left);
-                    if (point.x() >= 0)
-                        return point;
-                    return allocateFromNode(size, right);
-                }
-                node = right;
-            } else
-                node = left;
-        } else if (right && fitsWithin(size, right->largestFree))
-            node = right;
-        else if (left || right) {
-            // Neither sub-node has enough space to allocate from.
-            return IntPoint(-1, -1);
-        } else if (fitsWithin(size, node->largestFree)) {
-            // Do we need to split this node into smaller pieces?
-            Split split;
-            if (fitsWithin(IntSize(size.width() * 2, size.height() * 2), node->largestFree)) {
-                // Split in either direction: choose the inverse of
-                // the parent node's split direction to try to balance
-                // out the wasted space as further subdivisions happen.
-                if (node->parent
-                    && node->parent->left->rect.x() == node->parent->right->rect.x())
-                    split = SplitOnX;
-                else if (node->parent)
-                    split = SplitOnY;
-                else if (node->rect.width() >= node->rect.height())
-                    split = SplitOnX;
-                else
-                    split = SplitOnY;
-            } else if (fitsWithin(IntSize(size.width() * 2, size.height()), node->largestFree)) {
-                // Split along the X direction.
-                split = SplitOnX;
-            } else if (fitsWithin(IntSize(size.width(), size.height() * 2), node->largestFree)) {
-                // Split along the Y direction.
-                split = SplitOnY;
-            } else {
-                // Cannot split further - allocate this node.
-                node->largestFree = IntSize(0, 0);
-                updateLargestFree(node);
-                return node->rect.location();
-            }
-
-            // Split the node, then go around again using the left sub-tree.
-            node = splitNode(node, split);
-        } else {
-            // Cannot possibly fit into this node.
-            break;
-        }
-    }
-    return IntPoint(-1, -1);
-}
-
-GeneralAreaAllocator::Node* GeneralAreaAllocator::splitNode(Node* node, Split split)
-{
-    Node* left = new Node();
-    left->parent = node;
-    Node* right = new Node();
-    right->parent = node;
-    node->left = left;
-    node->right = right;
-    m_nodeCount += 2;
-
-    if (split == SplitOnX) {
-        left->rect = IntRect(node->rect.x(), node->rect.y(),
-            node->rect.width() / 2, node->rect.height());
-        right->rect = IntRect(left->rect.maxX(), node->rect.y(),
-            node->rect.width() / 2, node->rect.height());
-    } else {
-        left->rect = IntRect(node->rect.x(), node->rect.y(),
-            node->rect.width(), node->rect.height() / 2);
-        right->rect = IntRect(node->rect.x(), left->rect.maxY(),
-            node->rect.width(), node->rect.height() / 2);
-    }
-
-    left->largestFree = left->rect.size();
-    right->largestFree = right->rect.size();
-    node->largestFree = right->largestFree;
-    return left;
-}
-
-void GeneralAreaAllocator::updateLargestFree(Node* node)
-{
-    while ((node = node->parent)) {
-        node->largestFree = IntSize(
-            std::max(node->left->largestFree.width(), node->right->largestFree.width()),
-            std::max(node->left->largestFree.height(), node->right->largestFree.height())
-            );
-    }
-}
-
-void GeneralAreaAllocator::release(const IntRect& rect)
-{
-    // Locate the node that contains the allocated region.
-    Node* node = m_root;
-    IntPoint point = rect.location();
-    while (node) {
-        if (node->left && node->left->rect.contains(point))
-            node = node->left;
-        else if (node->right && node->right->rect.contains(point))
-            node = node->right;
-        else if (node->rect.contains(point))
-            break;
-        else
-            return; // Point is completely outside the tree.
-    }
-    if (!node)
-        return;
-
-    // Mark the node as free and then work upwards through the tree
-    // recombining and deleting nodes until we reach a sibling
-    // that is still allocated.
-    node->largestFree = node->rect.size();
-    while (node->parent) {
-        if (node->parent->left == node) {
-            if (node->parent->right->largestFree != node->parent->right->rect.size())
-                break;
-        } else {
-            if (node->parent->left->largestFree != node->parent->left->rect.size())
-                break;
-        }
-        node = node->parent;
-        freeNode(node->left);
-        freeNode(node->right);
-        m_nodeCount -= 2;
-        node->left = nullptr;
-        node->right = nullptr;
-        node->largestFree = node->rect.size();
-    }
-
-    // Make the rest of our ancestors have the correct "largest free size".
-    updateLargestFree(node);
-}
-
-int GeneralAreaAllocator::overhead() const
-{
-    return m_nodeCount * sizeof(Node);
-}
-
-} // namespace WebKit
-
-#endif // USE(COORDINATED_GRAPHICS)

Deleted: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h (225772 => 225773)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifndef AreaAllocator_h
-#define AreaAllocator_h
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include <WebCore/IntPoint.h>
-#include <WebCore/IntRect.h>
-#include <WebCore/IntSize.h>
-
-namespace WebKit {
-
-inline int nextPowerOfTwo(int number)
-{
-    // This is a fast trick to get nextPowerOfTwo for an integer.
-    --number;
-    number |= number >> 1;
-    number |= number >> 2;
-    number |= number >> 4;
-    number |= number >> 8;
-    number |= number >> 16;
-    number++;
-    return number;
-}
-
-inline WebCore::IntSize nextPowerOfTwo(const WebCore::IntSize& size)
-{
-    return WebCore::IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));
-}
-
-class AreaAllocator {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    explicit AreaAllocator(const WebCore::IntSize&);
-    virtual ~AreaAllocator();
-
-    WebCore::IntSize size() const { return m_size; }
-
-    WebCore::IntSize minimumAllocation() const { return m_minAlloc; }
-    void setMinimumAllocation(const WebCore::IntSize& size) { m_minAlloc = size; }
-
-    WebCore::IntSize margin() const { return m_margin; }
-    void setMargin(const WebCore::IntSize &margin) { m_margin = margin; }
-
-    virtual void expand(const WebCore::IntSize&);
-    void expandBy(const WebCore::IntSize&);
-
-    virtual WebCore::IntRect allocate(const WebCore::IntSize&) = 0;
-    virtual void release(const WebCore::IntRect&);
-
-    virtual int overhead() const;
-
-protected:
-    WebCore::IntSize m_size;
-    WebCore::IntSize m_minAlloc;
-    WebCore::IntSize m_margin;
-
-    WebCore::IntSize roundAllocation(const WebCore::IntSize&) const;
-};
-
-class GeneralAreaAllocator final : public AreaAllocator {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    explicit GeneralAreaAllocator(const WebCore::IntSize&);
-    virtual ~GeneralAreaAllocator();
-
-    void expand(const WebCore::IntSize&) override;
-    WebCore::IntRect allocate(const WebCore::IntSize&) override;
-    void release(const WebCore::IntRect&) override;
-    int overhead() const override;
-
-private:
-    enum Split { SplitOnX, SplitOnY };
-
-    struct Node {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        WebCore::IntRect rect;
-        WebCore::IntSize largestFree;
-        Node* parent { nullptr };
-        Node* left { nullptr };
-        Node* right { nullptr };
-    };
-
-    Node* m_root;
-    int m_nodeCount;
-
-    static void freeNode(Node*);
-    WebCore::IntPoint allocateFromNode(const WebCore::IntSize&, Node*);
-    Node* splitNode(Node*, Split);
-    static void updateLargestFree(Node*);
-};
-
-} // namespace WebKit
-
-#endif // USE(COORDINATED_GRAPHICS)
-#endif // AreaAllocator_h

Modified: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h (225772 => 225773)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h	2017-12-12 07:04:44 UTC (rev 225773)
@@ -29,7 +29,6 @@
 
 #if USE(COORDINATED_GRAPHICS)
 
-#include "UpdateAtlas.h"
 #include <WebCore/CoordinatedGraphicsLayer.h>
 #include <WebCore/CoordinatedGraphicsState.h>
 #include <WebCore/CoordinatedImageBacking.h>
@@ -38,6 +37,7 @@
 #include <WebCore/GraphicsLayerFactory.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/NicosiaBuffer.h>
+#include <WebCore/UpdateAtlas.h>
 
 namespace Nicosia {
 class PaintingEngine;
@@ -54,7 +54,7 @@
 class CompositingCoordinator final : public WebCore::GraphicsLayerClient
     , public WebCore::CoordinatedGraphicsLayerClient
     , public WebCore::CoordinatedImageBacking::Client
-    , public UpdateAtlas::Client
+    , public WebCore::UpdateAtlas::Client
     , public WebCore::GraphicsLayerFactory {
     WTF_MAKE_NONCOPYABLE(CompositingCoordinator);
 public:
@@ -122,8 +122,8 @@
     void syncLayerState(WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayerState&) override;
 
     // UpdateAtlas::Client
-    void createUpdateAtlas(UpdateAtlas::ID, Ref<Nicosia::Buffer>&&) override;
-    void removeUpdateAtlas(UpdateAtlas::ID) override;
+    void createUpdateAtlas(WebCore::UpdateAtlas::ID, Ref<Nicosia::Buffer>&&) override;
+    void removeUpdateAtlas(WebCore::UpdateAtlas::ID) override;
 
     // GraphicsLayerFactory
     std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
@@ -153,7 +153,7 @@
     HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking>> m_imageBackings;
 
     std::unique_ptr<Nicosia::PaintingEngine> m_paintingEngine;
-    Vector<std::unique_ptr<UpdateAtlas>> m_updateAtlases;
+    Vector<std::unique_ptr<WebCore::UpdateAtlas>> m_updateAtlases;
     Vector<uint32_t> m_atlasesToRemove;
 
     // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.

Deleted: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp (225772 => 225773)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,77 +0,0 @@
-/*
- Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- Copyright (C) 2012 Company 100, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB.  If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "UpdateAtlas.h"
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include <WebCore/CoordinatedGraphicsState.h>
-#include <WebCore/GraphicsContext.h>
-#include <WebCore/IntRect.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-UpdateAtlas::UpdateAtlas(Client& client, const IntSize& size, Nicosia::Buffer::Flags flags)
-    : m_client(client)
-    , m_buffer(Nicosia::Buffer::create(size, flags))
-{
-    static ID s_nextID { 0 };
-    m_id = ++s_nextID;
-
-    m_client.createUpdateAtlas(m_id, m_buffer.copyRef());
-}
-
-UpdateAtlas::~UpdateAtlas()
-{
-    m_client.removeUpdateAtlas(m_id);
-}
-
-void UpdateAtlas::buildLayoutIfNeeded()
-{
-    if (m_areaAllocator)
-        return;
-    m_areaAllocator = std::make_unique<GeneralAreaAllocator>(size());
-    m_areaAllocator->setMinimumAllocation(IntSize(32, 32));
-}
-
-void UpdateAtlas::didSwapBuffers()
-{
-    m_areaAllocator = nullptr;
-}
-
-RefPtr<Nicosia::Buffer> UpdateAtlas::getCoordinatedBuffer(const IntSize& size, uint32_t& atlasID, IntRect& allocatedRect)
-{
-    m_inactivityInSeconds = 0;
-    buildLayoutIfNeeded();
-    allocatedRect = m_areaAllocator->allocate(size);
-
-    if (allocatedRect.isEmpty())
-        return nullptr;
-
-    atlasID = m_id;
-    return m_buffer.copyRef();
-}
-
-} // namespace WebKit
-
-#endif // USE(COORDINATED_GRAPHICS)

Deleted: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h (225772 => 225773)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h	2017-12-12 06:30:34 UTC (rev 225772)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h	2017-12-12 07:04:44 UTC (rev 225773)
@@ -1,81 +0,0 @@
-/*
- Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- Copyright (C) 2012 Company 100, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB.  If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-#include "AreaAllocator.h"
-#include <WebCore/NicosiaBuffer.h>
-#include <wtf/RefPtr.h>
-
-#if USE(COORDINATED_GRAPHICS)
-
-namespace WebCore {
-class IntRect;
-class IntSize;
-}
-
-namespace WebKit {
-
-class UpdateAtlas {
-    WTF_MAKE_FAST_ALLOCATED;
-    WTF_MAKE_NONCOPYABLE(UpdateAtlas);
-public:
-    using ID = uint32_t;
-
-    class Client {
-    public:
-        virtual void createUpdateAtlas(ID, Ref<Nicosia::Buffer>&&) = 0;
-        virtual void removeUpdateAtlas(ID) = 0;
-    };
-
-    UpdateAtlas(Client&, const WebCore::IntSize&, Nicosia::Buffer::Flags);
-    ~UpdateAtlas();
-
-    const WebCore::IntSize& size() const { return m_buffer->size(); }
-
-    RefPtr<Nicosia::Buffer> getCoordinatedBuffer(const WebCore::IntSize&, uint32_t&, WebCore::IntRect&);
-    void didSwapBuffers();
-    bool supportsAlpha() const { return m_buffer->supportsAlpha(); }
-
-    void addTimeInactive(double seconds)
-    {
-        ASSERT(!isInUse());
-        m_inactivityInSeconds += seconds;
-    }
-    bool isInactive() const
-    {
-        const double inactiveSecondsTolerance = 3;
-        return m_inactivityInSeconds > inactiveSecondsTolerance;
-    }
-    bool isInUse() const { return !!m_areaAllocator; }
-
-private:
-    void buildLayoutIfNeeded();
-
-    ID m_id { 0 };
-    Client& m_client;
-    std::unique_ptr<GeneralAreaAllocator> m_areaAllocator;
-    Ref<Nicosia::Buffer> m_buffer;
-    double m_inactivityInSeconds { 0 };
-};
-
-} // namespace WebKit
-
-#endif // USE(COORDINATED_GRAPHICS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to