[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

kbr at google.com kbr at google.com
Wed Dec 22 13:00:29 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ff07a0dfbcbca603d53233b2a3605b8cc182a5e7
Author: kbr at google.com <kbr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Sep 4 00:24:58 2010 +0000

    2010-09-03  Kenneth Russell  <kbr at google.com>
    
            Reviewed by Darin Fisher.
    
            Add interval tree capable of holding plain old data (POD)
            https://bugs.webkit.org/show_bug.cgi?id=45160
    
            Adding an interval tree currently capable of holding types which
            do not require their destructors to be called. POD is a slight
            misnomer which will be corrected soon, hopefully by removing this
            restriction.
    
            This class is based on the augmentable property of the red/black
            tree integrated under bug 45059.
    
            Unit tests for the PODIntervalTree will be integrated separately
            under bug 45161.
    
            * WebCore.gypi:
            * platform/graphics/gpu/PODInterval.h: Added.
            (WebCore::PODInterval::PODInterval):
            (WebCore::PODInterval::low):
            (WebCore::PODInterval::high):
            (WebCore::PODInterval::data):
            (WebCore::PODInterval::overlaps):
            (WebCore::PODInterval::operator<):
            (WebCore::PODInterval::operator==):
            (WebCore::PODInterval::maxHigh):
            (WebCore::PODInterval::setMaxHigh):
            (WebCore::PODInterval::toString):
            * platform/graphics/gpu/PODIntervalTree.h: Added.
            (WebCore::PODIntervalTree::PODIntervalTree):
            (WebCore::PODIntervalTree::allOverlaps):
            (WebCore::PODIntervalTree::createInterval):
            (WebCore::PODIntervalTree::checkInvariants):
            (WebCore::PODIntervalTree::init):
            (WebCore::PODIntervalTree::searchForOverlapsFrom):
            (WebCore::PODIntervalTree::updateNode):
            (WebCore::PODIntervalTree::checkInvariantsFromNode):
            (WebCore::valueToString):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66779 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index d7c0f09..709650e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,44 @@
+2010-09-03  Kenneth Russell  <kbr at google.com>
+
+        Reviewed by Darin Fisher.
+
+        Add interval tree capable of holding plain old data (POD)
+        https://bugs.webkit.org/show_bug.cgi?id=45160
+
+        Adding an interval tree currently capable of holding types which
+        do not require their destructors to be called. POD is a slight
+        misnomer which will be corrected soon, hopefully by removing this
+        restriction.
+
+        This class is based on the augmentable property of the red/black
+        tree integrated under bug 45059.
+
+        Unit tests for the PODIntervalTree will be integrated separately
+        under bug 45161.
+
+        * WebCore.gypi:
+        * platform/graphics/gpu/PODInterval.h: Added.
+        (WebCore::PODInterval::PODInterval):
+        (WebCore::PODInterval::low):
+        (WebCore::PODInterval::high):
+        (WebCore::PODInterval::data):
+        (WebCore::PODInterval::overlaps):
+        (WebCore::PODInterval::operator<):
+        (WebCore::PODInterval::operator==):
+        (WebCore::PODInterval::maxHigh):
+        (WebCore::PODInterval::setMaxHigh):
+        (WebCore::PODInterval::toString):
+        * platform/graphics/gpu/PODIntervalTree.h: Added.
+        (WebCore::PODIntervalTree::PODIntervalTree):
+        (WebCore::PODIntervalTree::allOverlaps):
+        (WebCore::PODIntervalTree::createInterval):
+        (WebCore::PODIntervalTree::checkInvariants):
+        (WebCore::PODIntervalTree::init):
+        (WebCore::PODIntervalTree::searchForOverlapsFrom):
+        (WebCore::PODIntervalTree::updateNode):
+        (WebCore::PODIntervalTree::checkInvariantsFromNode):
+        (WebCore::valueToString):
+
 2010-09-02  Vangelis Kokkevis  <vangelis at chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 99e891d..3321cbb 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2349,6 +2349,8 @@
             'platform/graphics/gpu/DrawingBuffer.cpp',
             'platform/graphics/gpu/DrawingBuffer.h',
             'platform/graphics/gpu/PODArena.h',
+            'platform/graphics/gpu/PODInterval.h',
+            'platform/graphics/gpu/PODIntervalTree.h',
             'platform/graphics/gpu/PODRedBlackTree.h',
             'platform/graphics/gpu/SharedGraphicsContext3D.cpp',
             'platform/graphics/gpu/SharedGraphicsContext3D.h',
diff --git a/WebCore/platform/graphics/gpu/PODInterval.h b/WebCore/platform/graphics/gpu/PODInterval.h
new file mode 100644
index 0000000..baf711d
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/PODInterval.h
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2010, Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+
+#ifndef PODInterval_h
+#define PODInterval_h
+
+#ifndef NDEBUG
+#include "StringBuilder.h"
+#endif
+
+namespace WebCore {
+
+// Class representing a closed interval which can hold an arbitrary
+// Plain Old Datatype (POD) as its endpoints and a piece of user
+// data. An important characteristic for the algorithms we use is that
+// if two intervals have identical endpoints but different user data,
+// they are not considered to be equal. This situation can arise when
+// representing the vertical extents of bounding boxes of overlapping
+// triangles, where the pointer to the triangle is the user data of
+// the interval.
+//
+// *Note* that the destructors of type T and UserData will *not* be
+// called by this class. They must not allocate any memory that is
+// required to be cleaned up in their destructors.
+//
+// The following constructors and operators must be implemented on
+// type T:
+//
+//   - Copy constructor (if user data is desired)
+//   - operator<
+//   - operator==
+//   - operator=
+//
+// If the UserData type is specified, it must support a copy
+// constructor and assignment operator.
+//
+// In debug mode, printing of intervals and the data they contain is
+// enabled. This requires the following functions to be available:
+//
+//   String valueToString(const T&);
+//   String valueToString(const UserData&);
+//
+// Note that this class requires a copy constructor and assignment
+// operator in order to be stored in the red-black tree.
+
+template<class T, class UserData = void*>
+class PODInterval {
+public:
+    // Constructor from endpoints. This constructor only works when the
+    // UserData type is a pointer or other type which can be initialized
+    // with 0.
+    PODInterval(const T& low, const T& high)
+        : m_low(low)
+        , m_high(high)
+        , m_data(0)
+        , m_maxHigh(high)
+    {
+    }
+
+    // Constructor from two endpoints plus explicit user data.
+    PODInterval(const T& low, const T& high, const UserData data)
+        : m_low(low)
+        , m_high(high)
+        , m_data(data)
+        , m_maxHigh(high)
+    {
+    }
+
+    const T& low() const { return m_low; }
+    const T& high() const { return m_high; }
+    const UserData& data() const { return m_data; }
+
+    bool overlaps(const T& low, const T& high) const
+    {
+        if (this->high() < low)
+            return false;
+        if (high < this->low())
+            return false;
+        return true;
+    }
+
+    bool overlaps(const PODInterval& other) const
+    {
+        return overlaps(other.low(), other.high());
+    }
+
+    // Returns true if this interval is "less" than the other. The
+    // comparison is performed on the low endpoints of the intervals.
+    bool operator<(const PODInterval& other) const
+    {
+        return low() < other.low();
+    }
+
+    // Returns true if this interval is strictly equal to the other,
+    // including comparison of the user data.
+    bool operator==(const PODInterval& other) const
+    {
+        return (low() == other.low()
+                && high() == other.high()
+                && data() == other.data());
+    }
+
+    const T& maxHigh() const { return m_maxHigh; }
+    void setMaxHigh(const T& maxHigh) { m_maxHigh = maxHigh; }
+
+#ifndef NDEBUG
+    // Support for printing PODIntervals.
+    String toString() const
+    {
+        StringBuilder builder;
+        builder.append("[PODInterval (");
+        builder.append(valueToString(low()));
+        builder.append(", ");
+        builder.append(valueToString(high()));
+        builder.append("), data=");
+        builder.append(valueToString(data()));
+        builder.append(", maxHigh=");
+        builder.append(valueToString(maxHigh()));
+        builder.append("]");
+        return builder.toString();
+    }
+#endif
+
+private:
+    T m_low;
+    T m_high;
+    UserData m_data;
+    T m_maxHigh;
+};
+
+} // namespace WebCore
+
+#endif // PODInterval_h
diff --git a/WebCore/platform/graphics/gpu/PODIntervalTree.h b/WebCore/platform/graphics/gpu/PODIntervalTree.h
new file mode 100644
index 0000000..eb9212f
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/PODIntervalTree.h
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2010, Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+
+#ifndef PODIntervalTree_h
+#define PODIntervalTree_h
+
+#include "PODArena.h"
+#include "PODInterval.h"
+#include "PODRedBlackTree.h"
+#include <wtf/Assertions.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+// An interval tree, which is a form of augmented red-black tree. It
+// supports efficient (O(lg n)) insertion, removal and querying of
+// intervals in the tree.
+template<class T, class UserData = void*>
+class PODIntervalTree : public Noncopyable,
+                        public PODRedBlackTree<PODInterval<T, UserData> > {
+public:
+    // Typedef to reduce typing when declaring intervals to be stored in
+    // this tree.
+    typedef PODInterval<T, UserData> IntervalType;
+
+    PODIntervalTree()
+        : PODRedBlackTree<IntervalType>()
+    {
+        init();
+    }
+
+    explicit PODIntervalTree(PODArena* arena)
+        : PODRedBlackTree<IntervalType>(arena)
+    {
+        init();
+    }
+
+    // Returns all intervals in the tree which overlap the given query
+    // interval. The returned intervals are sorted by increasing low
+    // endpoint.
+    Vector<IntervalType> allOverlaps(const IntervalType& interval) const
+    {
+        Vector<IntervalType> result;
+        allOverlaps(interval, result);
+        return result;
+    }
+
+    // Returns all intervals in the tree which overlap the given query
+    // interval. The returned intervals are sorted by increasing low
+    // endpoint.
+    void allOverlaps(const IntervalType& interval, Vector<IntervalType>& result) const
+    {
+        // Explicit dereference of "this" required because of
+        // inheritance rules in template classes.
+        searchForOverlapsFrom(this->root(), interval, result);
+    }
+
+    // Helper to create interval objects.
+    static IntervalType createInterval(const T& low, const T& high, const UserData data = 0)
+    {
+        return IntervalType(low, high, data);
+    }
+
+    virtual bool checkInvariants() const
+    {
+        if (!PODRedBlackTree<IntervalType>::checkInvariants())
+            return false;
+        if (!this->root())
+            return true;
+        return checkInvariantsFromNode(this->root(), 0);
+    }
+
+private:
+    typedef typename PODRedBlackTree<IntervalType>::Node IntervalNode;
+
+    // Initializes the tree.
+    void init()
+    {
+        // Explicit dereference of "this" required because of
+        // inheritance rules in template classes.
+        this->setNeedsFullOrderingComparisons(true);
+    }
+
+    // Starting from the given node, adds all overlaps with the given
+    // interval to the result vector. The intervals are sorted by
+    // increasing low endpoint.
+    void searchForOverlapsFrom(IntervalNode* node, const IntervalType& interval, Vector<IntervalType>& res) const
+    {
+        if (!node)
+            return;
+
+        // Because the intervals are sorted by left endpoint, inorder
+        // traversal produces results sorted as desired.
+
+        // See whether we need to traverse the left subtree.
+        IntervalNode* left = node->left();
+        if (left
+            // This is phrased this way to avoid the need for operator
+            // <= on type T.
+            && !(left->data().maxHigh() < interval.low()))
+            searchForOverlapsFrom(left, interval, res);
+
+        // Check for overlap with current node.
+        if (node->data().overlaps(interval))
+            res.append(node->data());
+
+        // See whether we need to traverse the right subtree.
+        // This is phrased this way to avoid the need for operator <=
+        // on type T.
+        if (!(interval.high() < node->data().low()))
+            searchForOverlapsFrom(node->right(), interval, res);
+    }
+
+    virtual bool updateNode(IntervalNode* node)
+    {
+        // Would use const T&, but need to reassign this reference in this
+        // function.
+        const T* curMax = &node->data().high();
+        IntervalNode* left = node->left();
+        if (left) {
+            if (*curMax < left->data().maxHigh())
+                curMax = &left->data().maxHigh();
+        }
+        IntervalNode* right = node->right();
+        if (right) {
+            if (*curMax < right->data().maxHigh())
+                curMax = &right->data().maxHigh();
+        }
+        // This is phrased like this to avoid needing operator!= on type T.
+        if (!(*curMax == node->data().maxHigh())) {
+            node->data().setMaxHigh(*curMax);
+            return true;
+        }
+        return false;
+    }
+
+    bool checkInvariantsFromNode(IntervalNode* node, T* currentMaxValue) const
+    {
+        // These assignments are only done in order to avoid requiring
+        // a default constructor on type T.
+        T leftMaxValue(node->data().maxHigh());
+        T rightMaxValue(node->data().maxHigh());
+        IntervalNode* left = node->left();
+        IntervalNode* right = node->right();
+        if (left) {
+            if (!checkInvariantsFromNode(left, &leftMaxValue))
+                return false;
+        }
+        if (right) {
+            if (!checkInvariantsFromNode(right, &rightMaxValue))
+                return false;
+        }
+        if (!left && !right) {
+            // Base case.
+            if (currentMaxValue)
+                *currentMaxValue = node->data().high();
+            return (node->data().high() == node->data().maxHigh());
+        }
+        T localMaxValue(node->data().maxHigh());
+        if (!left || !right) {
+            if (left)
+                localMaxValue = leftMaxValue;
+            else
+                localMaxValue = rightMaxValue;
+        } else
+            localMaxValue = (leftMaxValue < rightMaxValue) ? rightMaxValue : leftMaxValue;
+        if (localMaxValue < node->data().high())
+            localMaxValue = node->data().high();
+        if (!(localMaxValue == node->data().maxHigh())) {
+#ifndef NDEBUG
+            String localMaxValueString = valueToString(localMaxValue);
+            LOG_ERROR("PODIntervalTree verification failed at node 0x%p: localMaxValue=%s and data=%s",
+                      node, localMaxValueString.utf8().data(), node->data().toString().utf8().data());
+#endif
+            return false;
+        }
+        if (currentMaxValue)
+            *currentMaxValue = localMaxValue;
+        return true;
+    }
+};
+
+#ifndef NDEBUG
+// Support for printing PODIntervals at the PODRedBlackTree level.
+template<class T, class UserData>
+String valueToString(const PODInterval<T, UserData>& interval)
+{
+    return interval.toString();
+}
+#endif
+
+} // namespace WebCore
+
+#endif // PODIntervalTree_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list