Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ba0ed87

Browse files
author
Emmanuel Garcia
committed
Address Chinmay comments
1 parent 4440e96 commit ba0ed87

File tree

7 files changed

+161
-85
lines changed

7 files changed

+161
-85
lines changed

BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ group("flutter") {
7979
"//flutter/shell/platform/embedder:embedder_unittests",
8080
"//flutter/shell/platform/glfw/client_wrapper:client_wrapper_glfw_unittests",
8181
"//flutter/testing:testing_unittests",
82+
"//flutter/third_party/skia:skia_unittests",
8283
"//flutter/third_party/txt:txt_unittests",
8384
]
8485

testing/run_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def RunCCTests(build_dir, filter):
147147
if IsLinux():
148148
RunEngineExecutable(build_dir, 'txt_unittests', filter, shuffle_flags)
149149

150+
RunEngineExecutable(build_dir, 'skia_unittests', filter, shuffle_flags)
151+
150152

151153
def RunEngineBenchmarks(build_dir, filter):
152154
print("Running Engine Benchmarks.")

third_party/skia/BUILD.gn

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

6+
import("//flutter/testing/testing.gni")
7+
68
source_set("skia") {
79
sources = [
810
"platform_view_rtree.cc",
@@ -13,3 +15,22 @@ source_set("skia") {
1315
"//third_party/skia",
1416
]
1517
}
18+
19+
test_fixtures("skia_fixtures") {
20+
fixtures = []
21+
}
22+
23+
executable("skia_unittests") {
24+
testonly = true
25+
sources = [
26+
"platform_view_rtree_unittests.cc",
27+
"main_unittests.cc",
28+
]
29+
deps = [
30+
":skia",
31+
":skia_fixtures",
32+
"//flutter/testing:testing_lib",
33+
"//third_party/dart/runtime:libdart_jit", # For logging.
34+
"//third_party/skia",
35+
]
36+
}

third_party/skia/main_unittests.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright 2012 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "flutter/testing/testing.h"
9+
10+
#include <cassert>
11+
12+
int main(int argc, char** argv) {
13+
testing::InitGoogleTest(&argc, argv);
14+
return RUN_ALL_TESTS();
15+
}

third_party/skia/platform_view_rtree.cc

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* found in the LICENSE file.
66
*/
77

8-
#include "skia/platform_view_rtree.h"
8+
#include "platform_view_rtree.h"
99

1010
PlatformViewRTree::PlatformViewRTree() : fCount(0) {}
1111

@@ -25,27 +25,23 @@ void PlatformViewRTree::insert(const SkRect boundsArray[],
2525
Branch b;
2626
b.fBounds = bounds;
2727
b.fOpIndex = i;
28+
b.isDraw = (metadata == nullptr) ? false : metadata[i].isDraw;
2829
branches.push_back(b);
2930
}
30-
Branch b;
31-
b.fBounds = bounds;
32-
b.fOpIndex = i;
33-
b.isDraw = (metadata == nullptr) ? false : metadata[i].isDraw;
34-
branches.push_back(b);
35-
}
3631

37-
fCount = (int)branches.size();
38-
if (fCount) {
39-
if (1 == fCount) {
40-
fNodes.reserve(1);
41-
Node* n = this->allocateNodeAtLevel(0);
42-
n->fNumChildren = 1;
43-
n->fChildren[0] = branches[0];
44-
fRoot.fSubtree = n;
45-
fRoot.fBounds = branches[0].fBounds;
46-
} else {
47-
fNodes.reserve(CountNodes(fCount));
48-
fRoot = this->bulkLoad(&branches);
32+
fCount = (int)branches.size();
33+
if (fCount) {
34+
if (1 == fCount) {
35+
fNodes.reserve(1);
36+
Node* n = this->allocateNodeAtLevel(0);
37+
n->fNumChildren = 1;
38+
n->fChildren[0] = branches[0];
39+
fRoot.fSubtree = n;
40+
fRoot.fBounds = branches[0].fBounds;
41+
} else {
42+
fNodes.reserve(CountNodes(fCount));
43+
fRoot = this->bulkLoad(&branches);
44+
}
4945
}
5046
}
5147

@@ -176,15 +172,17 @@ void PlatformViewRTree::search(Node* node, const SkRect& query, std::vector<int>
176172
}
177173
}
178174

179-
void PlatformViewRTree::searchRects(const SkRect& query, std::vector<SkRect*>* results) const {
175+
std::vector<SkRect> PlatformViewRTree::searchRects(const SkRect& query) const {
176+
std::vector<SkRect> results;
180177
if (fCount > 0 && SkRect::Intersects(fRoot.fBounds, query)) {
181178
this->searchRects(fRoot.fSubtree, query, results);
182179
}
180+
return results;
183181
}
184182

185183
void PlatformViewRTree::searchRects(Node* node,
186184
const SkRect& query,
187-
std::vector<SkRect*>* results) const {
185+
std::vector<SkRect>& results) const {
188186
if (!SkRect::Intersects(fRoot.fBounds, query)) {
189187
return;
190188
}
@@ -201,38 +199,36 @@ void PlatformViewRTree::searchRects(Node* node,
201199
if (!node->fChildren[i].isDraw) {
202200
continue;
203201
}
204-
SkRect* currentRecordRect = &node->fChildren[i].fBounds;
205-
std::vector<SkRect*> currentResults = *results;
202+
SkRect currentRecordRect = node->fChildren[i].fBounds;
206203
bool replacedExistingRect = false;
207-
// If the current record rect intersects with any of the rects in the
208-
// result vector, then join them, and update the rect in results.
209-
size_t joiningRectIdx = currentResults.size();
204+
// // If the current record rect intersects with any of the rects in the
205+
// // result vector, then join them, and update the rect in results.
206+
size_t joiningRectIdx = results.size();
210207
size_t resultIdx = 0;
211-
while (resultIdx < results->size()) {
212-
if (SkRect::Intersects(*currentResults[resultIdx], *currentRecordRect)) {
208+
while (resultIdx < results.size()) {
209+
if (SkRect::Intersects(results[resultIdx], currentRecordRect)) {
213210
joiningRectIdx = resultIdx;
214211
replacedExistingRect = true;
215-
currentResults[joiningRectIdx]->join(*currentRecordRect);
212+
results[joiningRectIdx].join(currentRecordRect);
216213
break;
217214
}
218215
resultIdx++;
219216
}
220217
resultIdx = joiningRectIdx + 1;
221-
// It's possible that after joining rects will result in duplicated
222-
// rects in the results vector. For example, consider a result vector
223-
// that contains rects A, B. If a new rect C is a superset of A and B,
224-
// then A and B are the same set after the merge. As a result, find such
225-
// cases and remove them from the result vector.
226-
while (replacedExistingRect && resultIdx < results->size()) {
227-
if (SkRect::Intersects(*currentResults[resultIdx], *currentResults[joiningRectIdx])) {
228-
currentResults[joiningRectIdx]->join(*currentResults[resultIdx]);
229-
results->erase(results->begin() + resultIdx);
218+
// It's possible that the result contains duplicated rects at this point.
219+
// For example, consider a result vector that contains rects A, B. If a
220+
// new rect C is a superset of A and B, then A and B are the same set after
221+
// the merge. As a result, find such cases and remove them from the result vector.
222+
while (replacedExistingRect && resultIdx < results.size()) {
223+
if (SkRect::Intersects(results[resultIdx], results[joiningRectIdx])) {
224+
results[joiningRectIdx].join(results[resultIdx]);
225+
results.erase(results.begin() + resultIdx);
230226
} else {
231227
resultIdx++;
232228
}
233229
}
234230
if (!replacedExistingRect) {
235-
results->push_back(currentRecordRect);
231+
results.push_back(currentRecordRect);
236232
}
237233
}
238234
}

third_party/skia/platform_view_rtree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PlatformViewRTree : public SkBBoxHierarchy {
3838
// Finds the rects in the tree that intersect with the query rect. Each of the
3939
// entries in the result vector don't intersect with each other. In other words,
4040
// the entries are mutually exclusive.
41-
void searchRects(const SkRect& query, std::vector<SkRect*>* results) const;
41+
std::vector<SkRect> searchRects(const SkRect& query) const;
4242

4343
size_t bytesUsed() const override;
4444

@@ -72,7 +72,7 @@ class PlatformViewRTree : public SkBBoxHierarchy {
7272
};
7373

7474
void search(Node* root, const SkRect& query, std::vector<int>* results) const;
75-
void searchRects(Node* root, const SkRect& query, std::vector<SkRect*>* results) const;
75+
void searchRects(Node* root, const SkRect& query, std::vector<SkRect>& results) const;
7676

7777
// Consumes the input array.
7878
Branch bulkLoad(std::vector<Branch>* branches, int level = 0);

0 commit comments

Comments
 (0)