13 for (
int i = 0; i < result.
touch_points && i < max_points; ++i) {
26 std::swap(p.
vx, p.
vy);
61 : display_device_(display_device),
62 output_(&display_device_),
63 touch_(display_device,
64 touch_device == nullptr ?
dummy_touch : *touch_device,
67 orientation_(display_device.orientation()),
68 extents_(
Box::MaximumBox()),
70 background_(nullptr) {
75 if (orientation_ == orientation)
return;
76 orientation_ = orientation;
78 display_device_.setOrientation(orientation);
90void Display::clear() {
98 setBlendingMode(BlendingMode::kSource);
99 setFillMode(FillMode::kExtents);
105void DrawingContext::clear() {
108 setBlendingMode(BlendingMode::kSource);
109 setFillMode(FillMode::kExtents);
115void Display::enableTurbo() {
116 if (turbo_ !=
nullptr)
return;
117 turbo_frame_buffer_ =
118 std::make_unique<BackgroundFillOptimizer::FrameBuffer>(width(), height());
119 turbo_ = std::make_unique<BackgroundFillOptimizer>(display_device_,
120 *turbo_frame_buffer_);
121 output_ = turbo_.get();
124void Display::disableTurbo() {
125 output_ = &display_device_;
127 turbo_frame_buffer_.reset();
136 : fn_(fn), extents_(extents), blending_mode_(
blending_mode) {}
138 Box
extents()
const override {
return extents_; }
141 void drawTo(
const Surface& s)
const override {
142 if (s.dx() == 0 && s.dy() == 0) {
143 ClippingBufferedPixelWriter
writer(s.out(), extents_, blending_mode_);
146 TransformedDisplayOutput
out(s.out(),
147 Transformation().translate(s.dx(), s.dy()));
148 ClippingBufferedPixelWriter
writer(
out, extents_, blending_mode_);
153 const std::function<void(ClippingBufferedPixelWriter&)>& fn_;
160DrawingContext::~DrawingContext() { unnest_(); }
162void DrawingContext::setWriteOnce() {
163 if (write_once_)
return;
165 front_to_back_writer_.reset(
169void DrawingContext::drawPixels(
172 draw(Pixels(fn, transformation_.smallestEnclosingRect(clip_box_),
176void DrawingContext::drawInternal(
const Drawable&
object, int16_t dx,
179 ? *front_to_back_writer_
181 Surface s(
out, dx + dx_, dy + dy_, clip_box_.translate(dx_, dy_), write_once_,
182 bgcolor, fill_mode_, blending_mode_);
183 if (clip_mask_ ==
nullptr) {
184 drawInternalWithBackground(s,
object);
186 ClipMaskFilter filter(
out, clip_mask_, dx_, dy_);
188 drawInternalWithBackground(s,
object);
192void DrawingContext::drawInternalWithBackground(Surface& s,
193 const Drawable&
object) {
194 if (background_ ==
nullptr) {
195 drawInternalTransformed(s,
object);
199 s.set_bgcolor(color::Transparent);
200 drawInternalTransformed(s,
object);
204void DrawingContext::drawInternalTransformed(Surface& s,
205 const Drawable&
object) {
207 if (s.clipToExtents(
object.extents()) == Box::ClipResult::kEmpty)
return;
208 s.drawObject(
object);
209 }
else if (!transformation_.is_rescaled() && !transformation_.xy_swap()) {
211 s.set_dx(s.dx() + transformation_.x_offset());
212 s.set_dy(s.dy() + transformation_.y_offset());
213 if (s.clipToExtents(
object.extents()) == Box::ClipResult::kEmpty)
return;
214 s.drawObject(
object);
216 auto transformed = TransformedDrawable(transformation_, &
object);
217 if (s.clipToExtents(transformed.extents()) == Box::ClipResult::kEmpty) {
220 s.drawObject(transformed);
226class ErasedDrawable :
public Drawable {
228 ErasedDrawable(
const Drawable* delegate) : delegate_(delegate) {}
230 Box extents()
const override {
return delegate_->extents(); }
231 Box anchorExtents()
const override {
return delegate_->anchorExtents(); }
234 void drawTo(
const Surface& s)
const override {
236 ColorFilter<Erasure> filter(s.out(), s.bgcolor());
237 news.set_out(&filter);
238 news.set_blending_mode(BlendingMode::kSource);
239 news.drawObject(*delegate_);
242 const Drawable* delegate_;
247void DrawingContext::erase(
const Drawable&
object) {
248 draw(ErasedDrawable(&
object));
251void DrawingContext::erase(
const Drawable&
object, int16_t dx, int16_t dy) {
252 draw(ErasedDrawable(&
object), dx, dy);
256 draw(ErasedDrawable(&
object), alignment);
259void Fill::readColors(
const int16_t* x,
const int16_t* y, uint32_t count,
260 Color* result)
const {
264bool Fill::readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax,
265 Color* result)
const {
270void Fill::drawTo(
const Surface& s)
const {
272 if (
color == color::Transparent && s.
fill_mode() == FillMode::kVisible) {
278void Clear::readColors(
const int16_t* x,
const int16_t* y, uint32_t count,
279 Color* result)
const {
280 FillColor(result, count, color::Transparent);
283bool Clear::readColorRect(int16_t xMin, int16_t yMin, int16_t xMax,
284 int16_t yMax,
Color* result)
const {
285 *result = color::Transparent;
289void Clear::drawTo(
const Surface& s)
const {
290 if (s.
fill_mode() == FillMode::kVisible &&
291 s.
bgcolor() == color::Transparent) {
BufferedRectWriter & writer
Combines horizontal and vertical alignment.
Axis-aligned integer rectangle.
Infinite transparent area.
Buffered pixel writer with a clipping box.
ARGB8888 color stored as a 32-bit unsigned integer.
Base class for display device drivers.
int16_t effective_height() const
Return the display height in the current orientation.
Orientation orientation() const
Return the current orientation of the display.
int16_t effective_width() const
Return the display width in the current orientation.
The abstraction for drawing to a display.
void fillRect(BlendingMode blending_mode, const Box &rect, Color color)
Fill a single rectangle. Invalidates the address window.
Display(DisplayDevice &display_device)
Constructs a display without touch support.
TouchResult getTouch(TouchPoint *points, int max_points)
Returns calibrated touch points in display coordinates.
Interface for objects that can be drawn to an output device.
virtual Box extents() const =0
Return the bounding box encompassing all pixels that need to be drawn.
Primary top-level interface for drawing to screens, off-screen buffers, or other devices.
void clear()
Clears the display, respecting the clip box, and background settings.
void initTouch() override
Initialize the touch controller.
TouchResult getTouch(TouchPoint *points, int max_points) override
Read the current touch state.
Infinite single-color area.
Writer that ensures front-most pixels are written first.
Represents the orientation of a display device.
bool isRightToLeft() const
Return whether horizontal direction is right-to-left.
bool isBottomToTop() const
Return whether vertical direction is bottom-to-top.
bool isXYswapped() const
Return whether x maps to the vertical direction.
Low-level handle used to draw to an underlying device.
Color bgcolor() const
Return the background color used for blending.
const Box & clip_box() const
Return the clip box in device coordinates (independent of offsets).
BlendingMode blending_mode() const
Return the default blending mode for drawing.
FillMode fill_mode() const
Return the fill mode the drawable should observe. FillMode::kVisible If FillMode::kExtents,...
DisplayOutput & out() const
Return the device output.
Touch calibration parameters (bounds + orientation).
void Calibrate(TouchPoint &point)
Apply calibration and orientation to the given touch point.
Touch controller interface.
TouchResult getTouch(TouchPoint *points, int max_points)
Returns calibrated touch points in display coordinates.
TouchResult getRawTouch(TouchPoint *points, int max_points)
Returns raw touch points in absolute 0-4095 coordinates.
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
static DummyTouch dummy_touch
Color AlphaBlend(Color bgc, Color fgc)
BlendingFilter< BlendOp< BlendingMode::kSourceOver > > BackgroundFilter
Filtering device that blends with a rasterizable background.
void FillColor(Color *buf, uint32_t count, Color color)
Fill an array with a single color.
FillMode
Specifies whether a Drawable should fill its entire extents box, including fully transparent pixels.
Public API surface for roo_display display, touch, and drawing utilities.
BlendingMode blending_mode
A single touch point returned by a touch controller.
int16_t x
X-coordinate of the touch.
int16_t y
Y-coordinate of the touch.
int32_t vy
Y-axis velocity at the touch point, in pixels/sec.
int32_t vx
X-axis velocity at the touch point, in pixels/sec.
Metadata for a touch sampling result.