5#include "roo_backport.h"
6#include "roo_backport/byte.h"
13template <
typename Target>
29 buffer_dev_(target_.width(), target_.height(), buffer_.get(),
31 buffer_raster_(buffer_dev_.raster()),
36 void init()
override { target_.init(); }
38 void begin()
override { target_.begin(); }
49 rect_cache_.setWindow(x0, y0, x1, y1);
67 target_.flushRect(buffer_raster_, *x0++, *y0++, *x1++, *y1++);
76 target_.flushRect(buffer_raster_, *x0++, *y0++, *x1++, *y1++);
102 buffer_dev_.
setAddress(x, y, x + count - 1, y, mode);
103 buffer_dev_.
write(colors + offset, count);
104 target_.flushRect(buffer_raster_, x, y, x + count - 1, y);
108 buffer_dev_.
setAddress(x, y, x, y + count - 1, mode);
109 buffer_dev_.
write(colors + offset, count);
110 target_.flushRect(buffer_raster_, x, y, x, y + count - 1);
114 buffer_dev_.
setAddress(x - count + 1, y, x, y, mode);
115 std::reverse(colors + offset, colors + offset + count);
116 buffer_dev_.
write(colors + offset, count);
117 target_.flushRect(buffer_raster_, x - count + 1, y, x, y);
121 buffer_dev_.
setAddress(x, y - count + 1, x, y, mode);
122 std::reverse(colors + offset, colors + offset + count);
123 buffer_dev_.
write(colors + offset, count);
124 target_.flushRect(buffer_raster_, x, y - count + 1, x, y);
141 target_.flushRect(buffer_raster_, x, y, x + count - 1, y);
146 target_.flushRect(buffer_raster_, x, y, x, y + count - 1);
151 target_.flushRect(buffer_raster_, x - count + 1, y, x, y);
156 target_.flushRect(buffer_raster_, x, y - count + 1, x, y);
172 typename Target::ColorMode mode;
173 return mode.fromArgbColor(
color);
181 window_ =
Box(x0, y0, x1, y1);
185 void pixelsWritten(uint16_t count) { end_ += count; }
187 bool isDirty()
const {
return begin_ != end_; }
189 uint32_t dirtyPixelCount()
const {
190 return static_cast<uint32_t
>(end_ - begin_);
198 if (!isDirty())
return Box(0, 0, -1, -1);
202 uint32_t remaining =
static_cast<uint32_t
>(window_.width()) - begin_;
203 bool unfinished_line = dirtyPixelCount() < remaining;
204 if (unfinished_line) {
207 Box result(window_.xMin() + begin_, window_.yMin(),
208 window_.xMin() + end_ - 1, window_.yMin());
213 Box result(window_.xMin() + begin_, window_.yMin(), window_.xMax(),
215 window_ = Box(window_.xMin(), window_.yMin() + 1, window_.xMax(),
218 end_ -= window_.width();
222 int16_t full_lines = dirtyPixelCount() / window_.width();
223 if (full_lines > 0) {
224 Box result(window_.xMin(), window_.yMin(), window_.xMax(),
225 window_.yMin() + full_lines - 1);
227 window_ = Box(window_.xMin(), window_.yMin() + full_lines - 1,
228 window_.xMax(), window_.yMax());
229 end_ -= full_lines * window_.width();
234 Box result(window_.xMin(), window_.yMin(), window_.xMin() + end_ - 1,
236 window_ = Box(window_.xMin(), window_.yMin() + full_lines,
237 window_.xMax(), window_.yMax());
250 void flushRectCache() {
252 Box box = rect_cache_.consume();
253 if (box.empty())
return;
254 target_.flushRect(buffer_raster_, box.xMin(), box.yMin(), box.xMax(),
260 std::unique_ptr<roo::byte[]> buffer_;
261 OffscreenDevice<typename Target::ColorMode> buffer_dev_;
262 ConstDramRaster<typename Target::ColorMode> buffer_raster_;
263 RectCache rect_cache_;
264 Compactor compactor_;
Axis-aligned integer rectangle.
static constexpr ByteOrder byte_order
void fill(Color color, uint32_t pixel_count) override
Write pixel_count copies of the same color into the current address window.
void writePixels(BlendingMode mode, Color *colors, int16_t *xs, int16_t *ys, uint16_t pixel_count) override
Draw the specified pixels (per-pixel colors). Invalidates the address window.
static raw_color_type to_raw_color(Color color)
void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, BlendingMode mode) override
Set a rectangular window filled by subsequent calls to write().
void write(Color *color, uint32_t pixel_count) override
Write pixels into the current address window.
void begin() override
Enter a write transaction.
void init() override
Initialize the display driver.
const ColorFormat & getColorFormat() const override
Return the native color format used by this device for direct drawing.
void drawDirectRect(const roo::byte *data, size_t row_width_bytes, int16_t src_x0, int16_t src_y0, int16_t src_x1, int16_t src_y1, int16_t dst_x0, int16_t dst_y0) override
Draw a rectangle represented in the device's native color format.
const ColorMode & color_mode() const
void writeRects(BlendingMode mode, Color *color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles (per-rectangle colors). Invalidates the address window.
void fillRects(BlendingMode mode, Color color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles using the same color. Invalidates the address window.
static constexpr ColorPixelOrder pixel_order
void end() override
Finalize the previously entered write transaction, flushing any pending writes.
void orientationUpdated() override
Invoked when orientation() is updated.
BufferedAddrWindowDevice(Orientation orientation=Orientation::Default(), Target target=Target())
ColorStorageType< typename Target::ColorMode > raw_color_type
~BufferedAddrWindowDevice() override
void fillPixels(BlendingMode mode, Color color, int16_t *xs, int16_t *ys, uint16_t pixel_count) override
Draw the specified pixels using the same color. Invalidates the address window.
typename Target::ColorMode ColorMode
ARGB8888 color stored as a 32-bit unsigned integer.
void drawPixels(int16_t *xs, int16_t *ys, uint16_t pixel_count, Writer write=Writer())
Base class for display device drivers.
Orientation orientation() const
Return the current orientation of the display.
void fillRect(BlendingMode blending_mode, const Box &rect, Color color)
Fill a single rectangle. Invalidates the address window.
virtual void fill(Color color, uint32_t pixel_count)
Write pixel_count copies of the same color into the current address window.
ColorMode & color_mode()
Access color mode.
void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, BlendingMode mode) override
Set a rectangular window filled by subsequent calls to write().
void writeRects(BlendingMode mode, Color *color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles (per-rectangle colors). Invalidates the address window.
const ColorFormat & getColorFormat() const override
Return the native color format used by this device for direct drawing.
void drawDirectRect(const roo::byte *data, size_t row_width_bytes, int16_t src_x0, int16_t src_y0, int16_t src_x1, int16_t src_y1, int16_t dst_x0, int16_t dst_y0) override
Draw a rectangle represented in the device's native color format.
void fillRects(BlendingMode mode, Color color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles using the same color. Invalidates the address window.
void write(Color *color, uint32_t pixel_count) override
Write pixels into the current address window.
Represents the orientation of a display device.
static constexpr Orientation Default()
Return the default orientation (RightDown).
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
roo_io::ByteOrder ByteOrder