Flutter Engine
The Flutter Engine
dl_region.h
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#ifndef FLUTTER_DISPLAY_LIST_GEOMETRY_DL_REGION_H_
6#define FLUTTER_DISPLAY_LIST_GEOMETRY_DL_REGION_H_
7
9
10#include <memory>
11#include <vector>
12
13namespace flutter {
14
15/// Represents a region as a collection of non-overlapping rectangles.
16/// Implements a subset of SkRegion functionality optimized for quickly
17/// converting set of overlapping rectangles to non-overlapping rectangles.
18class DlRegion {
19 public:
20 /// Creates an empty region.
21 DlRegion() = default;
22
23 /// Creates region by bulk adding the rectangles.
24 /// Matches SkRegion::op(rect, SkRegion::kUnion_Op) behavior.
25 explicit DlRegion(const std::vector<SkIRect>& rects);
26
27 /// Creates region covering area of a rectangle.
28 explicit DlRegion(const SkIRect& rect);
29
30 DlRegion(const DlRegion&) = default;
31 DlRegion(DlRegion&&) = default;
32
33 DlRegion& operator=(const DlRegion&) = default;
35
36 /// Creates union region of region a and b.
37 /// Matches SkRegion a; a.op(b, SkRegion::kUnion_Op) behavior.
38 static DlRegion MakeUnion(const DlRegion& a, const DlRegion& b);
39
40 /// Creates intersection region of region a and b.
41 /// Matches SkRegion a; a.op(b, SkRegion::kIntersect_Op) behavior.
42 static DlRegion MakeIntersection(const DlRegion& a, const DlRegion& b);
43
44 /// Returns list of non-overlapping rectangles that cover current region.
45 /// If |deband| is false, each span line will result in separate rectangles,
46 /// closely matching SkRegion::Iterator behavior.
47 /// If |deband| is true, matching rectangles from adjacent span lines will be
48 /// merged into single rectangle.
49 std::vector<SkIRect> getRects(bool deband = true) const;
50
51 /// Returns maximum and minimum axis values of rectangles in this region.
52 /// If region is empty returns SKIRect::MakeEmpty().
53 const SkIRect& bounds() const { return bounds_; }
54
55 /// Returns whether this region intersects with a rectangle.
56 bool intersects(const SkIRect& rect) const;
57
58 /// Returns whether this region intersects with another region.
59 bool intersects(const DlRegion& region) const;
60
61 /// Returns true if region is empty (contains no rectangles).
62 bool isEmpty() const { return lines_.empty(); }
63
64 /// Returns true if region is not empty and contains more than one rectangle.
65 bool isComplex() const;
66
67 /// Returns true if region can be represented by single rectangle or is
68 /// empty.
69 bool isSimple() const { return !isComplex(); }
70
71 private:
72 typedef std::uint32_t SpanChunkHandle;
73
74 struct Span {
75 int32_t left;
76 int32_t right;
77
78 Span() = default;
79 Span(int32_t left, int32_t right) : left(left), right(right) {}
80 };
81
82 /// Holds spans for the region. Having custom allocated memory that doesn't
83 /// do zero initialization every time the buffer gets resized improves
84 /// performance measurably.
85 class SpanBuffer {
86 public:
87 SpanBuffer() = default;
88 SpanBuffer(const SpanBuffer&);
89 SpanBuffer(SpanBuffer&& m);
90 SpanBuffer& operator=(const SpanBuffer&);
91 SpanBuffer& operator=(SpanBuffer&& m);
92
93 void reserve(size_t capacity);
94 size_t capacity() const { return capacity_; }
95
96 SpanChunkHandle storeChunk(const Span* begin, const Span* end);
97 size_t getChunkSize(SpanChunkHandle handle) const;
98 void getSpans(SpanChunkHandle handle,
99 const DlRegion::Span*& begin,
100 const DlRegion::Span*& end) const;
101
102 ~SpanBuffer();
103
104 private:
105 void setChunkSize(SpanChunkHandle handle, size_t size);
106
107 size_t capacity_ = 0;
108 size_t size_ = 0;
109
110 // Spans for the region chunks. First span in each chunk contains the
111 // chunk size.
112 Span* spans_ = nullptr;
113 };
114
115 struct SpanLine {
116 int32_t top;
117 int32_t bottom;
118 SpanChunkHandle chunk_handle;
119 };
120
121 void setRects(const std::vector<SkIRect>& rects);
122
123 void appendLine(int32_t top,
124 int32_t bottom,
125 const Span* begin,
126 const Span* end);
127 void appendLine(int32_t top,
128 int32_t bottom,
129 const SpanBuffer& buffer,
130 SpanChunkHandle handle) {
131 const Span *begin, *end;
132 buffer.getSpans(handle, begin, end);
133 appendLine(top, bottom, begin, end);
134 }
135
136 typedef std::vector<Span> SpanVec;
137 SpanLine makeLine(int32_t top, int32_t bottom, const SpanVec&);
138 SpanLine makeLine(int32_t top,
139 int32_t bottom,
140 const Span* begin,
141 const Span* end);
142 static size_t unionLineSpans(std::vector<Span>& res,
143 const SpanBuffer& a_buffer,
144 SpanChunkHandle a_handle,
145 const SpanBuffer& b_buffer,
146 SpanChunkHandle b_handle);
147 static size_t intersectLineSpans(std::vector<Span>& res,
148 const SpanBuffer& a_buffer,
149 SpanChunkHandle a_handle,
150 const SpanBuffer& b_buffer,
151 SpanChunkHandle b_handle);
152
153 bool spansEqual(SpanLine& line, const Span* begin, const Span* end) const;
154
155 static bool spansIntersect(const Span* begin1,
156 const Span* end1,
157 const Span* begin2,
158 const Span* end2);
159
160 static void getIntersectionIterators(
161 const std::vector<SpanLine>& a_lines,
162 const std::vector<SpanLine>& b_lines,
163 std::vector<SpanLine>::const_iterator& a_it,
164 std::vector<SpanLine>::const_iterator& b_it);
165
166 std::vector<SpanLine> lines_;
167 SkIRect bounds_ = SkIRect::MakeEmpty();
168 SpanBuffer span_buffer_;
169};
170
171} // namespace flutter
172
173#endif // FLUTTER_DISPLAY_LIST_GEOMETRY_DL_REGION_H_
static DlRegion MakeIntersection(const DlRegion &a, const DlRegion &b)
Definition: dl_region.cc:497
const SkIRect & bounds() const
Definition: dl_region.h:53
std::vector< SkIRect > getRects(bool deband=true) const
Definition: dl_region.cc:563
DlRegion & operator=(const DlRegion &)=default
bool isEmpty() const
Returns true if region is empty (contains no rectangles).
Definition: dl_region.h:62
DlRegion(DlRegion &&)=default
bool isSimple() const
Definition: dl_region.h:69
bool intersects(const SkIRect &rect) const
Returns whether this region intersects with a rectangle.
Definition: dl_region.cc:617
bool isComplex() const
Returns true if region is not empty and contains more than one rectangle.
Definition: dl_region.cc:611
DlRegion & operator=(DlRegion &&)=default
DlRegion(const DlRegion &)=default
static DlRegion MakeUnion(const DlRegion &a, const DlRegion &b)
Definition: dl_region.cc:405
DlRegion()=default
Creates an empty region.
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
static bool b
struct MyStruct a[10]
glong glong end
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkRect.h:32
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45