roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
rasterizable_stack.cpp
Go to the documentation of this file.
2
3namespace roo_display {
4
5namespace {
6static const int kMaxBufSize = 64;
7}
8
10 uint32_t count, Color* result) const {
11 FillColor(result, count, color::Transparent);
16 for (auto r = inputs_.begin(); r != inputs_.end(); r++) {
17 Box bounds = r->extents();
18 uint32_t offset = 0;
19 while (offset < count) {
20 int buf_size = 0;
21 do {
22 if (bounds.contains(x[offset], y[offset])) {
23 newx[buf_size] = x[offset] - r->dx();
24 newy[buf_size] = y[offset] - r->dy();
25 offsets[buf_size] = offset;
26 ++buf_size;
27 }
28 offset++;
29 } while (offset < count && buf_size < kMaxBufSize);
30 r->source()->readColors(newx, newy, buf_size, newresult);
33 }
34 }
35}
36
38 int16_t yMax, Color* result) const {
39 bool is_uniform_color = true;
40 *result = color::Transparent;
41 Box box(xMin, yMin, xMax, yMax);
42 int32_t pixel_count = box.area();
43 Color buffer[pixel_count];
44 for (auto r = inputs_.begin(); r != inputs_.end(); r++) {
45 Box bounds = r->extents();
46 Box clipped = Box::Intersect(bounds, box);
47 if (clipped.empty()) {
48 // This rect does not contribute to the outcome.
49 continue;
50 }
51 if (is_uniform_color && !clipped.contains(box)) {
52 // This rect does not fill the entire box; we can no longer use fast path.
53 is_uniform_color = false;
55 }
56 if (r->source()->readColorRect(
57 clipped.xMin() - r->dx(), clipped.yMin() - r->dy(),
58 clipped.xMax() - r->dx(), clipped.yMax() - r->dy(), buffer)) {
59 if (is_uniform_color) {
60 *result = ApplyBlending(r->blending_mode(), *result, *buffer);
61 } else {
62 for (int16_t y = clipped.yMin(); y <= clipped.yMax(); ++y) {
63 Color* row = &result[(y - yMin) * box.width()];
64 ApplyBlendingSingleSourceInPlace(r->blending_mode(),
65 &row[clipped.xMin() - xMin], *buffer,
66 clipped.width());
67 }
68 }
69 } else {
70 if (is_uniform_color) {
71 is_uniform_color = false;
73 }
74 uint32_t i = 0;
75 for (int16_t y = clipped.yMin(); y <= clipped.yMax(); ++y) {
76 Color* row = &result[(y - yMin) * box.width()];
77 ApplyBlendingInPlace(r->blending_mode(), &row[clipped.xMin() - xMin],
78 &buffer[i], clipped.width());
79 i += clipped.width();
80 }
81 }
82 }
83 if (!is_uniform_color) {
84 // See if maybe it actually is.
85 for (int32_t i = 1; i < pixel_count; ++i) {
86 if (result[i] != result[0]) {
87 // Definitely not uniform.
88 return false;
89 }
90 }
91 }
92 return true;
93}
94
95} // namespace roo_display
Axis-aligned integer rectangle.
Definition box.h:12
int16_t width() const
Width in pixels (inclusive coordinates).
Definition box.h:77
int16_t xMin() const
Minimum x (inclusive).
Definition box.h:65
int16_t xMax() const
Maximum x (inclusive).
Definition box.h:71
bool empty() const
Return whether the box is empty.
Definition box.h:62
bool contains(int16_t x, int16_t y) const
Return whether the point (x, y) lies within the box.
Definition box.h:86
int16_t yMax() const
Maximum y (inclusive).
Definition box.h:74
static Box Intersect(const Box &a, const Box &b)
Return the intersection of two boxes (may be empty).
Definition box.h:25
int16_t yMin() const
Minimum y (inclusive).
Definition box.h:68
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const override
Read colors for a rectangle.
Defines 140 opaque HTML named colors.
void ApplyBlendingInPlace(BlendingMode mode, Color *dst, const Color *src, int16_t count)
Definition blending.h:561
void ApplyBlendingSingleSourceInPlace(BlendingMode mode, Color *dst, Color src, int16_t count)
Definition blending.h:569
void ApplyBlendingInPlaceIndexed(BlendingMode mode, Color *dst, const Color *src, int16_t count, const uint32_t *index)
Definition blending.h:578
Color ApplyBlending(BlendingMode mode, Color dst, Color src)
Definition blending.h:554
void FillColor(Color *buf, uint32_t count, Color color)
Fill an array with a single color.
Definition color.h:109
float r
Definition smooth.cpp:474