Flutter Engine
The Flutter Engine
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
5#include "flutter/shell/platform/fuchsia/flutter/rtree.h"
6
7#include <list>
8
9#include "flutter/display_list/geometry/dl_region.h"
10#include "flutter/fml/logging.h"
13
14namespace flutter {
15
16RTree::RTree() : bbh_{SkRTreeFactory{}()}, all_ops_count_(0) {}
17
18void RTree::insert(const SkRect boundsArray[],
19 const SkBBoxHierarchy::Metadata metadata[],
20 int N) {
21 FML_DCHECK(0 == all_ops_count_);
22 bbh_->insert(boundsArray, metadata, N);
23 for (int i = 0; i < N; i++) {
24 if (metadata != nullptr && metadata[i].isDraw) {
25 draw_op_[i] = boundsArray[i];
26 }
27 }
28 all_ops_count_ = N;
29}
30
31void RTree::insert(const SkRect boundsArray[], int N) {
32 insert(boundsArray, nullptr, N);
33}
34
35void RTree::search(const SkRect& query, std::vector<int>* results) const {
36 bbh_->search(query, results);
37}
38
40 const SkRect& query) const {
41 // Get the indexes for the operations that intersect with the query rect.
42 std::vector<int> intermediary_results;
43 search(query, &intermediary_results);
44
45 std::vector<SkIRect> rects;
46 for (int index : intermediary_results) {
47 auto draw_op = draw_op_.find(index);
48 // Ignore records that don't draw anything.
49 if (draw_op == draw_op_.end()) {
50 continue;
51 }
52 SkIRect current_record_rect;
53 draw_op->second.roundOut(&current_record_rect);
54 rects.push_back(current_record_rect);
55 }
56
57 DlRegion region(rects);
58 auto non_overlapping_rects = region.getRects(true);
59 std::list<SkRect> final_results;
60 for (const auto& rect : non_overlapping_rects) {
61 final_results.push_back(SkRect::Make(rect));
62 }
63 return final_results;
64}
65
66size_t RTree::bytesUsed() const {
67 return bbh_->bytesUsed();
68}
69
71 r_tree_ = sk_make_sp<RTree>();
72}
73
75 return r_tree_;
76}
77
79 return r_tree_;
80}
81
82} // namespace flutter
#define N
Definition: beziers.cpp:19
virtual size_t bytesUsed() const =0
virtual void search(const SkRect &query, std::vector< int > *results) const =0
virtual void insert(const SkRect[], int N)=0
sk_sp< RTree > getInstance()
Definition: rtree.cc:74
sk_sp< SkBBoxHierarchy > operator()() const override
Definition: rtree.cc:78
std::list< SkRect > searchNonOverlappingDrawnRects(const SkRect &query) const
Definition: rtree.cc:39
size_t bytesUsed() const override
Definition: rtree.cc:66
void insert(const SkRect[], const SkBBoxHierarchy::Metadata[], int N) override
Definition: rtree.cc:18
void search(const SkRect &query, std::vector< int > *results) const override
Definition: rtree.cc:35
#define FML_DCHECK(condition)
Definition: logging.h:103
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkRect.h:32
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669