Flutter Engine
 
Loading...
Searching...
No Matches
rtree.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <list>
8
11#include "flutter/fml/logging.h"
12#include "third_party/skia/include/core/SkBBHFactory.h"
13#include "third_party/skia/include/core/SkRect.h"
14
15namespace flutter {
16
17RTree::RTree() : bbh_{SkRTreeFactory{}()}, all_ops_count_(0) {}
18
19void RTree::insert(const SkRect boundsArray[],
20 const SkBBoxHierarchy::Metadata metadata[],
21 int N) {
22 FML_DCHECK(0 == all_ops_count_);
23 bbh_->insert(boundsArray, metadata, N);
24 for (int i = 0; i < N; i++) {
25 if (metadata != nullptr && metadata[i].isDraw) {
26 draw_op_[i] = boundsArray[i];
27 }
28 }
29 all_ops_count_ = N;
30}
31
32void RTree::insert(const SkRect boundsArray[], int N) {
33 insert(boundsArray, nullptr, N);
34}
35
36void RTree::search(const SkRect& query, std::vector<int>* results) const {
37 bbh_->search(query, results);
38}
39
41 const SkRect& query) const {
42 // Get the indexes for the operations that intersect with the query rect.
43 std::vector<int> intermediary_results;
44 search(query, &intermediary_results);
45
46 std::vector<DlIRect> rects;
47 for (int index : intermediary_results) {
48 auto draw_op = draw_op_.find(index);
49 // Ignore records that don't draw anything.
50 if (draw_op == draw_op_.end()) {
51 continue;
52 }
53 SkIRect current_record_rect;
54 draw_op->second.roundOut(&current_record_rect);
55 rects.push_back(ToDlIRect(current_record_rect));
56 }
57
58 DlRegion region(rects);
59 auto non_overlapping_rects = region.getRects(true);
60 std::list<SkRect> final_results;
61 for (const auto& rect : non_overlapping_rects) {
62 final_results.push_back(SkRect::Make(ToSkIRect(rect)));
63 }
64 return final_results;
65}
66
67size_t RTree::bytesUsed() const {
68 return bbh_->bytesUsed();
69}
70
72 r_tree_ = sk_make_sp<RTree>();
73}
74
76 return r_tree_;
77}
78
79sk_sp<SkBBoxHierarchy> RTreeFactory::operator()() const {
80 return r_tree_;
81}
82
83} // namespace flutter
std::vector< DlIRect > getRects(bool deband=true) const
Definition dl_region.cc:560
sk_sp< RTree > getInstance()
Definition rtree.cc:75
sk_sp< SkBBoxHierarchy > operator()() const override
Definition rtree.cc:79
std::list< SkRect > searchNonOverlappingDrawnRects(const SkRect &query) const
Definition rtree.cc:40
size_t bytesUsed() const override
Definition rtree.cc:67
void insert(const SkRect[], const SkBBoxHierarchy::Metadata[], int N) override
Definition rtree.cc:19
void search(const SkRect &query, std::vector< int > *results) const override
Definition rtree.cc:36
#define FML_DCHECK(condition)
Definition logging.h:122
const SkIRect & ToSkIRect(const DlIRect &rect)
const DlIRect & ToDlIRect(const SkIRect &rect)