Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
ds_screen.h
1/* Copyright (C) 2017 - 2024, Thornwave Labs Inc - All Rights Reserved.
2 * Unauthorized copying of this file, via any medium is strictly prohibited.
3 * Proprietary and confidential.
4 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
5*/
6
7#ifndef _DS_SCREEN_H
8#define _DS_SCREEN_H
9
10
11#include <ds_event.h>
12#include <ds_view.h>
13
14
15class DsKeyboard;
16
17
28class DsScreen: public DsView
29{
30public:
43 DsScreen(int32_t phys_width, int32_t phys_height, DsRotation rotation, DsColorMode cmode, uint8_t* linebuffer, uint8_t* aa_linebuffer, uint32_t framebuffer_alignment, bool triple_buffered);
44 ~DsScreen();
45
51
61 DsSurface* allocSurface(int32_t width, int32_t height, DsColorMode cmode, size_t palette_size = 0, bool palette_has_alpha = false);
62
63
70
71
77 DsView* getFocusedView(void) const;
78
79
85 void registerView(DsView* view, const char* id);
86
92 DsView* getView(const char* id);
93
104 bool pushView(const char* id, bool on_top = false);
105
106
113 bool popView(void);
114
115
125 bool popView(const char* id);
126
127
134 bool topViewIs(const char* id);
135
136
143 bool unrollViewStack(const char* id);
144
145
152 bool unrollViewStack(size_t level);
153
154
159 size_t getViewStackSize(void) const;
160
161
167
175
176
182 void run(void);
183
184
192
193
198 bool isUiThread(void) const;
199
200
205 bool isTouchTimeoutExpired(void) const;
206
207
213 void kickTouchTimeout(uint32_t timeout_ms);
214
215
220
221
225 void queueVSyncEvent(void);
226
227
232 void queueVSyncEventFromISR(int32_t* woken);
233
234
242 void queueTouchEvent(const DsTouchEvent::Mode &mode, const DsPoint &pos, uint32_t timestamp);
243
244
253 void queueTouchEventFromISR(const DsTouchEvent::Mode &mode, const DsPoint &pos, uint32_t timestamp, int32_t* woken);
254
255
261 void queueKeyboardEvent(int32_t key);
262
263
269 void queueLambda(const lambda<void(void), 64> &lambda);
270
271
278 void queueLambdaFromISR(const lambda<void(void), 64> &lambda, int32_t* woken);
279
280
285 void lcdSurfaceUpdateFinishedFromISR(int32_t* woken);
286
287
288
289protected:
290 volatile bool mDirty;
291 volatile bool mLocked;
292 bool mCoalescePaintEvents;
293 uint8_t mCoalescePaintEventsCounter;
294
295 const uint32_t mFrameBufferAlignment;
296
297 DsSurface* mFrontSurface;
298 DsSurface* mBackSurfaceActive;
299 DsSurface* mBackSurfacePending;
300
301 DsRect mSurfaceUserRect[3];
302
303 DsRenderer mRenderer;
304 DsRotation mScreenRotation;
305
306
311 virtual void lcdSurfaceUpdate(DsSurface* surface) = 0;
312
313
319 virtual void onStart(void);
320
321
327 virtual void onFinish(void);
328
329
338 virtual void onTouchTimeout(bool expired);
339
340
344 virtual void onEventProcessStart(void);
345
346
350 virtual void onEventProcessFinish(void);
351
360 void enableCoalescePaintEvents(bool enabled);
361
362
363private:
364 friend class DsView;
365
366 struct ViewEntry
367 {
368 const char* id;
369 DsView* view;
370
371 bool operator==(const ViewEntry &rhs) const
372 {
373 return strcmp(id, rhs.id) == 0;
374 }
375 };
376
377 ds_thread_t mUiThreadHandler;
378
379 void* mContext;
380 DsView* mFocusedView;
381 DsKeyboard* mKeyboard;
382 DsRect mInvalidRegion;
383
384 DsTimer mUpdateTimer;
385 DsBinarySemaphore mSyncSemaphore;
386
387 queue<512, DsEvent> mEventQueue;
388
389 //touch timeout
390 bool mIsTouchTimeoutExpired;
391 DsTimer mTouchTimeoutTimer;
392
395
396 void touchRotate(int32_t &x, int32_t &y);
397 bool processEvent(const DsEvent &event);
398
399 void onPaint(DsRenderer &renderer) override final;
400 bool onTouch(const DsTouchEvent &event) override final;
401
402 void invalidateRegion(DsRect region) override final;
403
404 void update(DsRect dirty_region);
405};
406
407
408#endif
DsSemaphore is a class that implements a binary semaphore.
Definition ds_os.h:22
Definition ds_keyboard.h:21
DsPoint is a class that represents the X and Y 2D coordinates of a point as integer numbers.
Definition ds_geometry.h:24
DsRect is a class that represents a 2D rectangle (X, Y, W, H)
Definition ds_geometry.h:1507
DsRenderer is a class that implements all the drawing operations.
Definition ds_renderer.h:42
DsScreen is class of type DsView (inherits from DsView) that implements a physical screen.
Definition ds_screen.h:29
size_t getViewStackSize(void) const
Returns the number of views in the view stack.
DsView * getFocusedView(void) const
Returns the focused view.
void kickTouchTimeout(uint32_t timeout_ms)
Kick the touch timeout while setting a new timeout value.
void registerView(DsView *view, const char *id)
Registers a view with the view stack manager.
bool isUiThread(void) const
Returns true if the caller is running in the UI thread.
void queueTouchEventFromISR(const DsTouchEvent::Mode &mode, const DsPoint &pos, uint32_t timestamp, int32_t *woken)
Queues a touch event into the event loop. It can be used from an interrupt handler.
virtual void onEventProcessFinish(void)
Called by the UI thread after processing an event. Can be implemented in a derived class.
bool isTouchTimeoutExpired(void) const
Is the touch timer expired?
bool popView(const char *id)
Pops the top named view from the stack.
void enableCoalescePaintEvents(bool enabled)
Enables or disables the coalescing of the paint events.
void createKeyboard(const ds_bitmap_font_t *font)
Creates the on screen keyboard object.
DsRenderer createRenderer(DsSurface &surface)
Creates a temporary DsRendered using the specified surface.
void lcdSurfaceUpdateFinished(void)
Called from the LCD driver when the surface update is finished.
void queueVSyncEvent(void)
Queues an VSYNC event into the event loop.
bool unrollViewStack(const char *id)
Unrolls the view stack to a specific view ID.
virtual void onFinish(void)
Called by the UI thread after the main event loop exits. Can be implemented in a derived class.
DsKeyboard & getKeyboard(void)
Returns a reference to the on screen keyboard.
DsRotation getRotation(void) const
Returns the logical rotation of the screen.
virtual void lcdSurfaceUpdate(DsSurface *surface)=0
Updates the front framebuffer of the screen. Must be implemented in a derived class.
void queueLambdaFromISR(const lambda< void(void), 64 > &lambda, int32_t *woken)
Queues a lambda to get executed in the UI thread event loop. It can be used from an interrupt handler...
virtual void onEventProcessStart(void)
Called by the UI thread before processing an event. Can be implemented in a derived class.
virtual void onTouchTimeout(bool expired)
Called whenever the touch timeout expiration flag changes. Can be implemented in a derived class.
bool pushView(const char *id, bool on_top=false)
Pushes a new view to the stack.
void queueTouchEvent(const DsTouchEvent::Mode &mode, const DsPoint &pos, uint32_t timestamp)
Queues a touch event into the event loop.
void queueKeyboardEvent(int32_t key)
Queues a keyboard event into the event loop.
virtual void onStart(void)
Called by the UI thread before the main event loop is entered. Can be implemented in a derived class.
void run(void)
Executes the event loop.
void queueLambda(const lambda< void(void), 64 > &lambda)
Queues a lambda to get executed in the UI thread event loop.
void queueExitLoopEvent(void)
Queues an screen vertical sync event into the event loop.
bool popView(void)
Pops the top view from the stack.
DsScreen(int32_t phys_width, int32_t phys_height, DsRotation rotation, DsColorMode cmode, uint8_t *linebuffer, uint8_t *aa_linebuffer, uint32_t framebuffer_alignment, bool triple_buffered)
Creates a DsScreen object.
void setFocusedView(DsView *view)
Sets the focused view.
bool unrollViewStack(size_t level)
Unrolls the view stack to a specific level.
DsSurface * allocSurface(int32_t width, int32_t height, DsColorMode cmode, size_t palette_size=0, bool palette_has_alpha=false)
Allocates a DsSurface object using the screen's allocator and rotation.
DsView * getView(const char *id)
Returns the view based on its identifier.
void queueVSyncEventFromISR(int32_t *woken)
Queues an screen vertical sync event into the event loop. It can be used from an interrupt handler.
bool topViewIs(const char *id)
Returns true if the view on the top of the stack has the specified id.
DsSurface is a class that represents a drawing surface.
Definition ds_surface.h:30
Definition ds_os.h:67
DsView is a base class that represents any view on the screen.
Definition ds_view.h:40
Definition ds_types_lambda.h:24
Definition ds_types_queue.h:19
static_stack implements a stack with statically allocated storage space
Definition ds_types_stack.h:187
static_vector implements a vector with statically allocated storage space
Definition ds_types_vector.h:329
DsColorMode
DsColorMode is an enumeration of all possible color modes. These modes determine the color format use...
Definition ds_color.h:25
DsRotation
DsRotation is an enumeration of all possible values of the rotation used in drawing operations.
Definition ds_types.h:34
Definition ds_event.h:45
This structure implements a touch event.
Definition ds_event.h:25
Mode
Enumeration defining all touch modes.
Definition ds_event.h:30
Definition ds_font.h:45