diff options
author | Nicolas Roard <nicolasroard@google.com> | 2012-07-16 13:07:31 -0700 |
---|---|---|
committer | Nicolas Roard <nicolasroard@google.com> | 2012-07-16 14:24:02 -0700 |
commit | f87a68b1847dffdc65542deaed6d924878c99db4 (patch) | |
tree | eb06aac3563ffcb731d3c12f4e3f079db86fd345 /Source/WebCore/platform/graphics/android/context | |
parent | 9f3301215ab53611b995a2303e2b0de2d52a464d (diff) | |
download | external_webkit-f87a68b1847dffdc65542deaed6d924878c99db4.zip external_webkit-f87a68b1847dffdc65542deaed6d924878c99db4.tar.gz external_webkit-f87a68b1847dffdc65542deaed6d924878c99db4.tar.bz2 |
Add remove function
Change-Id: I1d9c361cff6d8b5ff5f1cd198ca97740fdcc2954
Diffstat (limited to 'Source/WebCore/platform/graphics/android/context')
-rw-r--r-- | Source/WebCore/platform/graphics/android/context/RTree.cpp | 42 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/context/RTree.h | 6 |
2 files changed, 43 insertions, 5 deletions
diff --git a/Source/WebCore/platform/graphics/android/context/RTree.cpp b/Source/WebCore/platform/graphics/android/context/RTree.cpp index caa2fb4..5ba4622 100644 --- a/Source/WebCore/platform/graphics/android/context/RTree.cpp +++ b/Source/WebCore/platform/graphics/android/context/RTree.cpp @@ -146,6 +146,11 @@ void RTree::search(WebCore::IntRect& clip, Vector<WebCore::RecordingData*>&list) m_root->search(clip.x(), clip.y(), clip.maxX(), clip.maxY(), list); } +void RTree::remove(WebCore::IntRect& clip) +{ + m_root->remove(clip.x(), clip.y(), clip.maxX(), clip.maxY()); +} + void RTree::display() { m_root->drawTree(); @@ -304,6 +309,15 @@ void Node::remove(Node* node) m_nbChildren--; } +void Node::destroy(int index) +{ + delete m_children[index]; + // compact + for (unsigned int i = index; i < m_nbChildren - 1; i++) + m_children[i] = m_children[i + 1]; + m_nbChildren--; +} + void Node::removeAll() { m_nbChildren = 0; @@ -465,12 +479,12 @@ void Node::display(int level) 2*level, "", m_tid, m_minX, m_minY, m_maxX, m_maxY, m_maxX - m_minX, m_maxY - m_minY); } -bool Node::overlap(int pminx, int pminy, int pmaxx, int pmaxy) +bool Node::overlap(int minx, int miny, int maxx, int maxy) { - return ! (pminx > m_maxX - || pmaxx < m_minX - || pmaxy < m_minY - || pminy > m_maxY); + return ! (minx > m_maxX + || maxx < m_minX + || maxy < m_minY + || miny > m_maxY); } void Node::search(int minx, int miny, int maxx, int maxy, Vector<WebCore::RecordingData*>& list) @@ -484,6 +498,24 @@ void Node::search(int minx, int miny, int maxx, int maxy, Vector<WebCore::Record } } +bool Node::inside(int minx, int miny, int maxx, int maxy) +{ + return (minx <= m_minX + && maxx >= m_maxX + && miny <= m_minY + && maxy >= m_maxY); +} + +void Node::remove(int minx, int miny, int maxx, int maxy) +{ + for (unsigned int i = 0; i < m_nbChildren; i++) { + if (m_children[i]->inside(minx, miny, maxx, maxy)) + destroy(i); + else if (m_children[i]->overlap(minx, miny, maxx, maxy)) + m_children[i]->remove(minx, miny, maxx, maxy); + } +} + ////////////////////////////////////////////////////////////////////// // Element diff --git a/Source/WebCore/platform/graphics/android/context/RTree.h b/Source/WebCore/platform/graphics/android/context/RTree.h index 5c2f021..d7df750 100644 --- a/Source/WebCore/platform/graphics/android/context/RTree.h +++ b/Source/WebCore/platform/graphics/android/context/RTree.h @@ -62,6 +62,9 @@ public: void insert(WebCore::IntRect& bounds, WebCore::RecordingData* payload); // Does an overlap search void search(WebCore::IntRect& clip, Vector<WebCore::RecordingData*>& list); + // Does an inclusive remove -- all elements fully inside the clip will + // be removed from the tree + void remove(WebCore::IntRect& clip); void display(); private: @@ -106,6 +109,7 @@ public: void insert(Node* n); void search(int minx, int miny, int maxx, int maxy, Vector<WebCore::RecordingData*>& list); + void remove(int minx, int miny, int maxx, int maxy); void drawTree(int level = 0); virtual void display(int level = 0); @@ -115,6 +119,7 @@ private: Node* findNode(Node* n); void add(Node* n); void remove(Node* n); + void destroy(int index); void removeAll(); Node* split(); void adjustTree(Node* N, Node* NN); @@ -122,6 +127,7 @@ private: int delta(Node* n); bool overlap(int minx, int miny, int maxx, int maxy); + bool inside(int minx, int miny, int maxx, int maxy); virtual bool isElement() { return false; } bool isRoot(); |