Skip to content

Commit c754621

Browse files
committed
adds a basic dirty region
1 parent 22eabd0 commit c754621

File tree

4 files changed

+125
-22
lines changed

4 files changed

+125
-22
lines changed

ARM.Arm-2D.pdsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@
531531
</Pre_Include_Global_h>
532532
</component>
533533

534-
<component Cclass="Acceleration" Cgroup="Arm-2D Extras" Csub="Controls" Cversion="2.14.0" condition="Arm-2D-Controls">
534+
<component Cclass="Acceleration" Cgroup="Arm-2D Extras" Csub="Controls" Cversion="2.14.1" condition="Arm-2D-Controls">
535535
<description>A set of example controls, e.g. round-corner-box, spinning-wheels etc</description>
536536
<files>
537537
<!-- example control source files -->
@@ -1003,11 +1003,11 @@
10031003
</RTE_Components_h>
10041004
</component>
10051005

1006-
<component Cclass="Acceleration" Cgroup="Arm-2D Demos" Csub="Waveform" Cversion="1.3.0" condition="Arm-2D-Demos">
1006+
<component Cclass="Acceleration" Cgroup="Arm-2D Demos" Csub="Waveform" Cversion="1.3.1" condition="Arm-2D-Demos">
10071007
<description>A demo of showing a waveform diagram.</description>
10081008
<files>
1009-
<file category="sourceC" name="examples/demos/arm_2d_scene_waveform.c" attr="config" version="1.3.0" />
1010-
<file category="header" name="examples/demos/arm_2d_scene_waveform.h" attr="config" version="1.3.0" />
1009+
<file category="sourceC" name="examples/demos/arm_2d_scene_waveform.c" attr="config" version="1.3.1" />
1010+
<file category="header" name="examples/demos/arm_2d_scene_waveform.h" attr="config" version="1.3.1" />
10111011
</files>
10121012
<RTE_Components_h>
10131013
#define RTE_Acceleration_Arm_2D_Demos_Waveform

examples/common/controls/waveform_view.c

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070

7171
/*============================ MACROFIED FUNCTIONS ===========================*/
7272
/*============================ TYPES =========================================*/
73+
enum {
74+
WAVEFORM_START,
75+
WAVEFORM_UPDATE_BINS,
76+
WAVEFORM_DONE,
77+
};
78+
7379
/*============================ GLOBAL VARIABLES ==============================*/
7480
/*============================ PROTOTYPES ====================================*/
7581
ARM_NONNULL(1)
@@ -164,6 +170,32 @@ arm_2d_err_t waveform_view_init(waveform_view_t *ptThis,
164170

165171
} while(0);
166172

173+
if (NULL == this.tCFG.ptScene) {
174+
this.tCFG.bUseDirtyRegion = false;
175+
} else if (this.tCFG.bUseDirtyRegion) {
176+
arm_2d_scene_player_dynamic_dirty_region_init(
177+
&this.DirtyRegion.tDirtyRegionItem,
178+
this.tCFG.ptScene);
179+
180+
if (this.tCFG.chDirtyRegionItemCount > 0 && NULL != this.tCFG.ptWaveformDirtyRegionItems) {
181+
182+
/* update bin width */
183+
this.DirtyRegion.q16BinWidth
184+
= reinterpret_q16_f32( (float)this.tCFG.tSize.iWidth
185+
/ (float)this.tCFG.chDirtyRegionItemCount);
186+
187+
/* reset bins */
188+
memset( this.tCFG.ptWaveformDirtyRegionItems,
189+
0,
190+
( sizeof(waveform_dirty_region_item_t)
191+
* this.tCFG.chDirtyRegionItemCount));
192+
193+
} else {
194+
this.tCFG.chDirtyRegionItemCount = 0;
195+
}
196+
}
197+
198+
167199
return tResult;
168200

169201
}
@@ -173,6 +205,12 @@ void waveform_view_depose( waveform_view_t *ptThis)
173205
{
174206
assert(NULL != ptThis);
175207

208+
if (this.tCFG.bUseDirtyRegion) {
209+
arm_2d_scene_player_dynamic_dirty_region_depose(
210+
&this.DirtyRegion.tDirtyRegionItem,
211+
this.tCFG.ptScene);
212+
}
213+
176214
arm_generic_loader_depose(&this.use_as__arm_generic_loader_t);
177215
}
178216

@@ -188,8 +226,14 @@ ARM_NONNULL(1)
188226
void waveform_view_on_frame_start( waveform_view_t *ptThis)
189227
{
190228
assert(NULL != ptThis);
191-
229+
192230
arm_generic_loader_on_frame_start(&this.use_as__arm_generic_loader_t);
231+
232+
if (this.tCFG.bUseDirtyRegion) {
233+
arm_2d_dynamic_dirty_region_on_frame_start(
234+
&this.DirtyRegion.tDirtyRegionItem,
235+
WAVEFORM_START);
236+
}
193237
}
194238

195239
ARM_NONNULL(1)
@@ -211,15 +255,37 @@ void waveform_view_show(waveform_view_t *ptThis,
211255
ptTile = arm_2d_get_default_frame_buffer();
212256
}
213257

214-
215258
arm_2d_container(ptTile, __waveform_panel, ptRegion) {
216259

217-
arm_2d_tile_copy_only( &this.tTile,
218-
&__waveform_panel,
219-
NULL);
220-
260+
arm_2d_align_centre(__waveform_panel_canvas,
261+
this.tCFG.tSize) {
262+
arm_2d_tile_copy_only( &this.tTile,
263+
&__waveform_panel,
264+
&__centre_region);
265+
266+
if (this.tCFG.bUseDirtyRegion) {
267+
/* update dirty region */
268+
switch (arm_2d_dynamic_dirty_region_wait_next(
269+
&this.DirtyRegion.tDirtyRegionItem)) {
270+
case WAVEFORM_START:
271+
if (0 == this.tCFG.chDirtyRegionItemCount) {
272+
/* The user doesn't provide dirty region bins, let's update the whole diagram instead */
273+
arm_2d_dynamic_dirty_region_update(
274+
&this.DirtyRegion.tDirtyRegionItem,
275+
&__waveform_panel,
276+
&__centre_region,
277+
WAVEFORM_DONE);
278+
}
279+
break;
280+
case WAVEFORM_UPDATE_BINS:
281+
break;
282+
default:
283+
case WAVEFORM_DONE:
284+
break;
285+
}
286+
}
287+
}
221288
}
222-
223289
}
224290

225291
ARM_NONNULL(1)

examples/common/controls/waveform_view.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,29 @@ enum {
6161
WAVEFORM_SAMPLE_SIZE_WORD,
6262
};
6363

64+
typedef struct waveform_dirty_region_item_t {
65+
ARM_PRIVATE(
66+
int16_t iY0;
67+
int16_t iY1;
68+
)
69+
} waveform_dirty_region_item_t;
70+
6471
typedef struct waveform_view_cfg_t {
6572

6673
arm_2d_size_t tSize;
6774

6875
uint16_t bUseHeapForVRES : 1;
6976
uint16_t bShowShadow : 1;
70-
uint16_t : 6;
77+
uint16_t bUseDirtyRegion : 1;
78+
uint16_t : 5;
7179
uint16_t u5DotHeight : 5;
7280
uint16_t u2SampleSize : 2; /* WAVEFORM_SAMPLE_SIZE_xxxx */
7381
uint16_t bUnsigned : 1;
7482

83+
uint8_t : 8;
84+
uint8_t chDirtyRegionItemCount;
85+
waveform_dirty_region_item_t *ptWaveformDirtyRegionItems;
86+
7587
COLOUR_TYPE_T tBrushColour;
7688
COLOUR_TYPE_T tBackgroundColour;
7789
//COLOUR_TYPE_T tShawdowColour;
@@ -106,6 +118,13 @@ ARM_PRIVATE(
106118
q16_t q16Scale;
107119
int16_t iDiagramHeight;
108120
int16_t iStartYOffset;
121+
122+
struct {
123+
arm_2d_region_list_item_t tDirtyRegionItem;
124+
uint8_t chCurrentBin;
125+
q16_t q16BinWidth;
126+
} DirtyRegion;
127+
109128
)
110129
/* place your public member here */
111130

examples/demos/arm_2d_scene_waveform.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,17 @@ void arm_2d_scene_waveform_enqueue( user_scene_waveform_t *ptThis,
194194
hwSampleCount * 2);
195195
}
196196

197-
static void __on_scene_waveform_frame_start(arm_2d_scene_t *ptScene)
197+
static void __generate_cos_samples( user_scene_waveform_t *ptThis,
198+
size_t tCount,
199+
float fStep)
198200
{
199-
user_scene_waveform_t *ptThis = (user_scene_waveform_t *)ptScene;
200-
ARM_2D_UNUSED(ptThis);
201+
assert(NULL != ptThis);
201202

203+
if (0 == tCount) {
204+
return ;
205+
}
202206
do {
203-
204-
int32_t nResult;
205-
/* simulate a full battery charging/discharge cycle */
206-
arm_2d_helper_time_cos_slider(50, 350, 20000, 0, &nResult, &this.lTimestamp[0]);
207-
208-
this.fDegree += (float)nResult / 100.0f;
207+
this.fDegree += fStep;
209208
int16_t iData = 900 * arm_cos_f32(ARM_2D_ANGLE(this.fDegree));
210209

211210
/* add random noise */
@@ -215,6 +214,24 @@ static void __on_scene_waveform_frame_start(arm_2d_scene_t *ptScene)
215214
arm_2d_scene_waveform_enqueue( ptThis,
216215
&iData,
217216
1);
217+
} while(--tCount);
218+
219+
this.fDegree = ARM_2D_FMODF(this.fDegree, 360.0f);
220+
}
221+
222+
static void __on_scene_waveform_frame_start(arm_2d_scene_t *ptScene)
223+
{
224+
user_scene_waveform_t *ptThis = (user_scene_waveform_t *)ptScene;
225+
ARM_2D_UNUSED(ptThis);
226+
227+
do {
228+
229+
int32_t nResult;
230+
/* simulate a full battery charging/discharge cycle */
231+
arm_2d_helper_time_cos_slider(50, 350, 20000, 0, &nResult, &this.lTimestamp[0]);
232+
233+
__generate_cos_samples(ptThis, 5, (float)nResult / 100.0f);
234+
218235
} while(0);
219236

220237
arm_loader_io_window_on_frame_start(&this.tWindow);
@@ -380,7 +397,7 @@ user_scene_waveform_t *__arm_2d_scene_waveform_init( arm_2d_scene_player_t *pt
380397
.fnOnFrameCPL = &__on_scene_waveform_frame_complete,
381398
.fnDepose = &__on_scene_waveform_depose,
382399

383-
.bUseDirtyRegionHelper = false,
400+
.bUseDirtyRegionHelper = true,
384401
},
385402
.bUserAllocated = bUserAllocated,
386403
};
@@ -431,6 +448,7 @@ user_scene_waveform_t *__arm_2d_scene_waveform_init( arm_2d_scene_player_t *pt
431448
.tBrushColour.tColour = GLCD_COLOR_NIXIE_TUBE,
432449
.tBackgroundColour.tColour = this.use_as__arm_2d_scene_t.tCanvas.wColour,
433450

451+
.bUseDirtyRegion = true,
434452
.ptScene = &this.use_as__arm_2d_scene_t,
435453
};
436454

0 commit comments

Comments
 (0)