22class FrontToBackWriter;
30 : display_device_(display_device),
31 touch_device_(touch_device),
32 touch_calibration_(touch_calibration) {}
42 return touch_device_.
getTouch(points, max_points);
47 touch_calibration_ = touch_calibration;
73 :
Display(display_device, &touch_device, touch_calibration) {}
77 :
Display(device.display(), device.touch(), device.touch_calibration()) {}
94 display_device_.
init();
125 return touch_.
getTouch(points, max_points);
134 bool getTouch(int16_t& x, int16_t& y);
151 bgcolor_ = color::Transparent;
188 if (nest_level_++ == 0) {
189 display_device_.
begin();
194 if (--nest_level_ == 0) {
195 display_device_.
end();
199 int16_t dx()
const {
return 0; }
200 int16_t dy()
const {
return 0; }
201 bool is_write_once()
const {
return false; }
205 DisplayDevice& display_device_;
206 std::unique_ptr<BackgroundFillOptimizer::FrameBuffer> turbo_frame_buffer_;
207 std::unique_ptr<BackgroundFillOptimizer> turbo_;
209 DisplayOutput* output_;
212 Orientation orientation_;
216 const Rasterizable* background_;
228 template <
typename Display>
237 template <
typename Display>
243 template <
typename Display>
246 display.extents().translate(-x_offset, -y_offset)) {}
256 template <
typename Display>
259 : output_(display.output()),
260 dx_(display.dx() + x_offset),
261 dy_(display.dy() + y_offset),
263 max_clip_box_(
Box::Intersect(
264 bounds, display.extents().translate(-x_offset, -y_offset))),
265 clip_box_(max_clip_box_),
266 unnest_([&display]() { display.unnest(); }),
267 write_once_(display.is_write_once()),
268 fill_mode_(display.fill_mode()),
269 blending_mode_(display.blending_mode()),
271 background_(display.getRasterizableBackground()),
272 bgcolor_(display.getBackgroundColor()),
318 void setClipBox(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
358 drawInternal(
object, 0, 0, bgcolor_);
365 drawInternal(
object, dx, dy, bgcolor_);
372 Box anchorExtents =
object.anchorExtents();
374 anchorExtents = transformation_.
transformBox(anchorExtents);
377 drawInternal(
object, offset.
dx, offset.
dy, bgcolor_);
394 const DisplayOutput& output()
const {
return output_; }
396 void drawInternal(
const Drawable&
object, int16_t dx, int16_t dy,
399 void drawInternalWithBackground(Surface& s,
const Drawable&
object);
401 void drawInternalTransformed(Surface& s,
const Drawable&
object);
403 DisplayOutput& output_;
417 const Box max_clip_box_;
422 std::function<void()> unnest_;
425 std::unique_ptr<FrontToBackWriter> front_to_back_writer_;
430 const ClipMask* clip_mask_;
431 const Rasterizable* background_;
434 Transformation transformation_;
449 void readColors(
const int16_t* x,
const int16_t* y, uint32_t count,
450 Color* result)
const override;
452 bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax,
453 Color* result)
const override;
456 void drawTo(
const Surface& s)
const override;
474 void readColors(
const int16_t* x,
const int16_t* y, uint32_t count,
475 Color* result)
const override;
477 bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax,
478 Color* result)
const override;
481 void drawTo(
const Surface& s)
const override;
Combines horizontal and vertical alignment.
Offset resolveOffset(const Box &outer, const Box &inner) const
Axis-aligned integer rectangle.
int16_t width() const
Width in pixels (inclusive coordinates).
static Box MaximumBox()
Return a large sentinel box used for unbounded extents.
int16_t height() const
Height in pixels (inclusive coordinates).
static Box Intersect(const Box &a, const Box &b)
Return the intersection of two boxes (may be empty).
Infinite transparent area.
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.
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
Clear()
Constructs a clear fill.
Binary clip mask using a packed bit buffer.
Buffered pixel writer with a clipping box.
ARGB8888 color stored as a 32-bit unsigned integer.
Base class for displays with integrated, pre-calibrated touch.
Base class for display device drivers.
int16_t raw_width() const
Return the width of the display in its native orientation.
int16_t raw_height() const
Return the height of the display in its native orientation.
int16_t effective_height() const
Return the display height in the current orientation.
virtual void init()
Initialize the display driver.
int16_t effective_width() const
Return the display width in the current orientation.
virtual void setBgColorHint(Color bgcolor)
Provide a background color hint for source-over blending.
The abstraction for drawing to a display.
virtual void end()
Finalize the previously entered write transaction, flushing any pending writes.
virtual void begin()
Enter a write transaction.
Display facade that owns a display device and optional touch input.
TouchResult getRawTouch(TouchPoint *points, int max_points)
Returns raw touch points in absolute coordinates (0-4095).
const Rasterizable * getRasterizableBackground() const
Returns the rasterizable background for derived contexts.
const DisplayOutput & output() const
Returns const access to the display output.
Display(DisplayDevice &display_device)
Constructs a display without touch support.
int16_t height() const
Returns the height in pixels of the current extents.
void setOrientation(Orientation orientation)
Sets the display orientation. Resets the clip box to the max display area.
TouchResult getTouch(TouchPoint *points, int max_points)
Returns calibrated touch points in display coordinates.
int16_t width() const
Returns the width in pixels of the current extents.
void setBackground(const Rasterizable *bg)
Sets a rasterizable background for all derived contexts.
void resetExtents()
Resets the clip box to the maximum device-allowed values.
Color getBackgroundColor() const
Returns the background color for derived contexts.
void setTouchCalibration(TouchCalibration touch_calibration)
Sets the touch calibration mapping.
int32_t area() const
Returns the total pixel area of the raw device.
Display(ComboDevice &device)
Constructs a display from a combo device.
Display(DisplayDevice &display_device, TouchDevice &touch_device, TouchCalibration touch_calibration=TouchCalibration())
Constructs a display with touch support and optional calibration.
Orientation orientation() const
Returns the current orientation.
void init()
Initializes the display and touch devices.
const Box & extents() const
Returns the current extents used by this display.
bool isTurboEnabled() const
void setBackgroundColor(Color bgcolor)
Sets a background color used by all derived contexts. Initially set to color::Transparent.
void setExtents(const Box &extents)
Sets a default clip box, inherited by derived contexts.
DisplayOutput & output()
Returns mutable access to the display output.
const TouchCalibration & touchCalibration() const
Returns the touch calibration for the display.
void clear()
Clears the display, respecting the clip box and background settings.
Interface for objects that can be drawn to an output device.
Primary top-level interface for drawing to screens, off-screen buffers, or other devices.
DrawingContext(Display &display, int16_t x_offset, int16_t y_offset)
Constructs a drawing context covering the entire display, with device coordinates offset by the speci...
const Transformation & transformation() const
Returns the current transformation. (The identity transformation by default).
DrawingContext(Display &display)
Constructs a drawing context covering the entire display.
void setBackground(const Rasterizable *bg)
void fill(Color color)
Fills the display with the specified color, respecting the clip box.
void setFillMode(FillMode fill_mode)
const Rasterizable * getBackground() const
const uint16_t width() const
Returns the width of the drawing context. Equivalent to bounds().width().
void setClipBox(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.
void setTransformation(Transformation t)
Sets a transformation to be applied to all drawn objects when converting the drawing coordinates to d...
void setBackgroundColor(Color bgcolor)
void erase(const Drawable &object)
Analogous to draw(object), but instead of drawing, replaces all the output pixels with the background...
void setClipBox(const Box &clip_box)
Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.
void draw(const Drawable &object, int16_t dx, int16_t dy)
Draws the object using the specified absolute offset. The point (0, 0) in the object's coordinates ma...
BlendingMode blendingMode() const
Color getBackgroundColor() const
DrawingContext(Display &display, Box bounds)
Constructs a drawing context covering the specified bounds, relative to the display's extents....
void drawPixels(const std::function< void(ClippingBufferedPixelWriter &)> &fn, BlendingMode blending_mode=BlendingMode::kSourceOver)
Allows to efficiently draw pixels to the context, using a buffered pixel writer (avoiding virtual cal...
const Box & getClipBox() const
Returns the current clip box, in device coordinates.
const uint16_t height() const
Returns the height of the drawing context. Equivalent to bounds().height().
const Box & bounds() const
Returns the bounds used for alignment.
void setBlendingMode(BlendingMode blending_mode)
void setClipMask(const ClipMask *clip_mask)
void draw(const Drawable &object, Alignment alignment)
Draws the object applying the specified alignment, relative to the bounds(). For example,...
void draw(const Drawable &object)
Draws the object using its inherent coordinates. The point (0, 0) in the object's coordinates maps to...
FillMode fillMode() const
DrawingContext(Display &display, int16_t x_offset, int16_t y_offset, Box bounds)
Constructs a drawing context covering the specified bounds, with device coordinates offset by the spe...
void clear()
Clears the display, respecting the clip box, and background settings.
Infinite single-color area.
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const override
Read colors for a rectangle.
Fill(Color color)
Constructs a fill with a constant color.
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
Represents the orientation of a display device.
Temporarily pauses the output transport while a DrawingContext is active.
PauseOutput(DisplayOutput &out)
Ends the output transaction on construction.
~PauseOutput()
Restarts the output transaction on destruction.
Drawable that can provide a color for any point within its extents.
Resumes a paused output transaction.
~ResumeOutput()
Ends the output transaction on destruction.
ResumeOutput(DisplayOutput &out)
Begins the output transaction on construction.
Low-level handle used to draw to an underlying device.
Touch calibration parameters (bounds + orientation).
Touch controller interface.
virtual void initTouch()
Initialize the touch controller.
virtual TouchResult getTouch(TouchPoint *points, int max_points)=0
Read the current touch state.
Wrapper providing calibrated touch input for a display device.
TouchDisplay(DisplayDevice &display_device, TouchDevice &touch_device, TouchCalibration touch_calibration=TouchCalibration())
Constructs a touch display wrapper.
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.
void setCalibration(TouchCalibration touch_calibration)
Sets the touch calibration mapping.
const TouchCalibration & calibration() const
Returns the current touch calibration.
void init()
Initializes the touch device.
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
@ kSourceOver
Source is placed (alpha-blended) over the destination. This is the default blending mode.
FillMode
Specifies whether a Drawable should fill its entire extents box, including fully transparent pixels.
@ kVisible
Fully transparent pixels do not need to be filled.
BlendingMode blending_mode
A single touch point returned by a touch controller.
Metadata for a touch sampling result.