-
Notifications
You must be signed in to change notification settings - Fork 3
/
lv_gpu_arm2d.c
1326 lines (1187 loc) · 61.8 KB
/
lv_gpu_arm2d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file lv_gpu_arm2d.c
*
*/
/*
* Copyright (C) 2010-2023 Arm Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*********************
* INCLUDES
*********************/
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wreserved-identifier"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-align"
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wfloat-conversion"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wdeclaration-after-statement"
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#pragma clang diagnostic ignored "-Wint-conversion"
#endif
#include "lv_gpu_arm2d.h"
//#include "../../core/lv_refr.h"
#include "lvgl.h"
#if LV_USE_GPU_ARM2D
#define __ARM_2D_IMPL__
#include "arm_2d.h"
#include "__arm_2d_impl.h"
#if defined(__IS_COMPILER_ARM_COMPILER_5__)
#pragma diag_suppress 174,177,188,68,513,144,1296
#elif defined(__IS_COMPILER_IAR__)
#pragma diag_suppress=Pa093
#elif defined(__IS_COMPILER_GCC__)
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
#endif
/*********************
* DEFINES
*********************/
#if ( !defined(__ARM_2D_CFG_SUPPORT_COLOUR_CHANNEL_ACCESS__) \
|| !__ARM_2D_CFG_SUPPORT_COLOUR_CHANNEL_ACCESS__) \
&& LV_COLOR_DEPTH == 32 \
&& !defined(__ARM_2D_LVGL_CFG_NO_WARNING__)
#warning Please set macro __ARM_2D_CFG_SUPPORT_COLOUR_CHANNEL_ACCESS__ to 1 to get more acceleration opportunities. Or you can define macro __ARM_2D_LVGL_CFG_NO_WARNING__ to suppress this warning.
#endif
#define MAX_BUF_SIZE (uint32_t) lv_disp_get_hor_res(_lv_refr_get_disp_refreshing())
#if LV_COLOR_DEPTH == 16
#define arm_2d_fill_colour arm_2d_rgb16_fill_colour
#define arm_2d_fill_colour_with_alpha arm_2d_rgb565_fill_colour_with_alpha
#define arm_2d_fill_colour_with_mask arm_2d_rgb565_fill_colour_with_mask
#define arm_2d_fill_colour_with_mask_and_opacity \
arm_2d_rgb565_fill_colour_with_mask_and_opacity
#define arm_2d_tile_copy arm_2d_rgb16_tile_copy
#define arm_2d_alpha_blending arm_2d_rgb565_alpha_blending
#define arm_2d_tile_copy_with_src_mask arm_2d_rgb565_tile_copy_with_src_mask
#define __arm_2d_impl_tile_copy_with_src_mask_and_opacity \
__arm_2d_impl_rgb565_tile_copy_with_src_mask_and_opacity
#define arm_2d_color_t arm_2d_color_rgb565_t
/* arm-2d direct mode apis */
#define __arm_2d_impl_colour_filling __arm_2d_impl_rgb16_colour_filling
#define __arm_2d_impl_colour_filling_with_opacity \
__arm_2d_impl_rgb565_colour_filling_with_opacity
#define __arm_2d_impl_colour_filling_mask \
__arm_2d_impl_rgb565_colour_filling_mask
#define __arm_2d_impl_colour_filling_mask_opacity \
__arm_2d_impl_rgb565_colour_filling_mask_opacity
#define __arm_2d_impl_copy __arm_2d_impl_rgb16_copy
#define __arm_2d_impl_alpha_blending __arm_2d_impl_rgb565_alpha_blending
#define __arm_2d_impl_src_msk_copy __arm_2d_impl_rgb565_src_msk_copy
#define __arm_2d_impl_src_chn_msk_copy __arm_2d_impl_rgb565_src_chn_msk_copy
#define __arm_2d_impl_cl_key_copy __arm_2d_impl_rgb16_cl_key_copy
#define __arm_2d_impl_alpha_blending_colour_keying \
__arm_2d_impl_rgb565_alpha_blending_colour_keying
#define arm_2d_tile_transform_with_src_mask_and_opacity_prepare \
arm_2dp_rgb565_tile_transform_with_src_mask_and_opacity_prepare
#define arm_2d_tile_transform_with_opacity_prepare \
arm_2dp_rgb565_tile_transform_with_opacity_prepare
#define arm_2d_tile_transform_only_with_opacity_prepare \
arm_2dp_rgb565_tile_transform_only_with_opacity_prepare
#define arm_2d_tile_transform_prepare \
arm_2dp_rgb565_tile_transform_prepare
#define __ARM_2D_PIXEL_BLENDING_OPA __ARM_2D_PIXEL_BLENDING_OPA_RGB565
#define color_int uint16_t
#elif LV_COLOR_DEPTH == 32
#define arm_2d_fill_colour arm_2d_rgb32_fill_colour
#define arm_2d_fill_colour_with_alpha arm_2d_cccn888_fill_colour_with_alpha
#define arm_2d_fill_colour_with_mask arm_2d_cccn888_fill_colour_with_mask
#define arm_2d_fill_colour_with_mask_and_opacity \
arm_2d_cccn888_fill_colour_with_mask_and_opacity
#define arm_2d_tile_copy arm_2d_rgb32_tile_copy
#define arm_2d_alpha_blending arm_2d_cccn888_alpha_blending
#define arm_2d_tile_copy_with_src_mask arm_2d_cccn888_tile_copy_with_src_mask
#define __arm_2d_impl_tile_copy_with_src_mask_and_opacity \
__arm_2d_impl_cccn888_tile_copy_with_src_mask_and_opacity
#define arm_2d_color_t arm_2d_color_cccn888_t
/* arm-2d direct mode apis */
#define __arm_2d_impl_colour_filling __arm_2d_impl_rgb32_colour_filling
#define __arm_2d_impl_colour_filling_with_opacity \
__arm_2d_impl_cccn888_colour_filling_with_opacity
#define __arm_2d_impl_colour_filling_mask \
__arm_2d_impl_cccn888_colour_filling_mask
#define __arm_2d_impl_colour_filling_mask_opacity \
__arm_2d_impl_cccn888_colour_filling_mask_opacity
#define __arm_2d_impl_copy __arm_2d_impl_rgb32_copy
#define __arm_2d_impl_alpha_blending __arm_2d_impl_cccn888_alpha_blending
#define __arm_2d_impl_src_msk_copy __arm_2d_impl_cccn888_src_msk_copy
#define __arm_2d_impl_src_chn_msk_copy __arm_2d_impl_cccn888_src_chn_msk_copy
#define __arm_2d_impl_cl_key_copy __arm_2d_impl_rgb32_cl_key_copy
#define __arm_2d_impl_alpha_blending_colour_keying \
__arm_2d_impl_cccn888_alpha_blending_colour_keying
#define arm_2d_tile_transform_with_src_mask_and_opacity_prepare \
arm_2dp_cccn888_tile_transform_with_src_mask_and_opacity_prepare
#define arm_2d_tile_transform_with_opacity_prepare \
arm_2dp_cccn888_tile_transform_with_opacity_prepare
#define arm_2d_tile_transform_only_with_opacity_prepare \
arm_2dp_cccn888_tile_transform_only_with_opacity_prepare
#define arm_2d_tile_transform_prepare \
arm_2dp_cccn888_tile_transform_prepare
#define __ARM_2D_PIXEL_BLENDING_OPA __ARM_2D_PIXEL_BLENDING_OPA_CCCN888
#define color_int uint32_t
#else
#error The specified LV_COLOR_DEPTH is not supported by this version of lv_gpu_arm2d.c.
#endif
/* *INDENT-OFF* */
#define __PREPARE_LL_ACCELERATION__() \
int32_t src_stride = lv_area_get_width(coords); \
\
uint8_t px_size_byte = cf == LV_IMG_CF_TRUE_COLOR_ALPHA \
? LV_IMG_PX_SIZE_ALPHA_BYTE \
: sizeof(lv_color_t); \
\
const uint8_t * src_buf_tmp = src_buf; \
src_buf_tmp += src_stride \
* (draw_area.y1 - coords->y1) \
* px_size_byte; \
src_buf_tmp += (draw_area.x1 - coords->x1) * px_size_byte; \
\
lv_area_t blend_area2; \
if(!_lv_area_intersect(&blend_area2, \
&draw_area, \
draw_ctx->clip_area)) return; \
\
int32_t w = lv_area_get_width(&blend_area2); \
int32_t h = lv_area_get_height(&blend_area2); \
\
lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area); \
\
lv_color_t * dest_buf = draw_ctx->buf; \
dest_buf += dest_stride * (blend_area2.y1 - draw_ctx->buf_area->y1) \
+ (blend_area2.x1 - draw_ctx->buf_area->x1); \
\
arm_2d_size_t copy_size = { \
.iWidth = lv_area_get_width(&blend_area2), \
.iHeight = lv_area_get_height(&blend_area2), \
}
#define __PREPARE_TARGET_TILE__(__blend_area) \
static arm_2d_tile_t target_tile; \
static arm_2d_region_t target_region; \
\
lv_color_t * dest_buf = draw_ctx->buf; \
\
target_tile = (arm_2d_tile_t) { \
.tRegion = { \
.tSize = { \
.iWidth = lv_area_get_width(draw_ctx->buf_area), \
.iHeight = lv_area_get_height(draw_ctx->buf_area), \
}, \
}, \
.tInfo.bIsRoot = true, \
.phwBuffer = (uint16_t *)draw_ctx->buf, \
}; \
\
target_region = (arm_2d_region_t) { \
.tLocation = { \
.iX = (__blend_area).x1 - draw_ctx->buf_area->x1, \
.iY = (__blend_area).y1 - draw_ctx->buf_area->y1, \
}, \
.tSize = { \
.iWidth = lv_area_get_width(&(__blend_area)), \
.iHeight = lv_area_get_height(&(__blend_area)), \
}, \
}
#define __PREPARE_SOURCE_TILE__(__dsc, __blend_area) \
static arm_2d_tile_t source_tile_orig; \
static arm_2d_tile_t source_tile; \
const lv_color_t * src_buf = (__dsc)->src_buf; \
if (src_buf) { \
source_tile_orig = (arm_2d_tile_t) { \
.tRegion = { \
.tSize = { \
.iWidth = lv_area_get_width((__dsc)->blend_area), \
.iHeight = lv_area_get_height((__dsc)->blend_area), \
}, \
}, \
.tInfo.bIsRoot = true, \
.phwBuffer = (uint16_t *)src_buf, \
}; \
\
arm_2d_tile_generate_child( \
&source_tile_orig, \
(arm_2d_region_t []) { \
{ \
.tLocation = { \
.iX = (__blend_area).x1 - (__dsc)->blend_area->x1, \
.iY = (__blend_area).y1 - (__dsc)->blend_area->y1, \
}, \
.tSize = source_tile_orig.tRegion.tSize, \
} \
}, \
&source_tile, \
false); \
source_tile.tInfo.bDerivedResource = true; \
}
#define __PREPARE_MASK_TILE__(__dsc, __blend_area, __mask, __is_chn) \
static arm_2d_tile_t mask_tile_orig; \
static arm_2d_tile_t mask_tile; \
if(NULL != (__mask)) { \
mask_tile_orig = (arm_2d_tile_t) { \
.tRegion = { \
.tSize = { \
.iWidth = lv_area_get_width((__dsc)->mask_area), \
.iHeight = lv_area_get_height((__dsc)->mask_area), \
}, \
}, \
.tInfo = { \
.bIsRoot = true, \
.bHasEnforcedColour = true, \
.tColourInfo = { \
.chScheme = (__is_chn) ? ARM_2D_CHANNEL_8in32 \
: ARM_2D_COLOUR_8BIT, \
}, \
}, \
.pchBuffer = ((uint8_t *)(__mask)) + (__is_chn) ? 3 : 0, \
}; \
\
arm_2d_tile_generate_child( \
&mask_tile_orig, \
(arm_2d_region_t []) { \
{ \
.tLocation = { \
.iX = (__dsc)->mask_area->x1 - (__blend_area).x1, \
.iY = (__dsc)->mask_area->y1 - (__blend_area).y1, \
}, \
.tSize = mask_tile_orig.tRegion.tSize, \
} \
}, \
&mask_tile, \
false); \
mask_tile.tInfo.bDerivedResource = true; \
}
/* *INDENT-ON* */
/* *INDENT-OFF* */
#define __RECOLOUR_WRAPPER(...) \
do { \
lv_color_t *rgb_tmp_buf = NULL; \
if(draw_dsc->recolor_opa > LV_OPA_MIN) { \
rgb_tmp_buf \
= lv_mem_buf_get(src_w * src_h * sizeof(lv_color_t)); \
if (NULL == rgb_tmp_buf) { \
LV_LOG_WARN( \
"Failed to allocate memory for accelerating recolour, " \
"use normal route instead."); \
break; \
} \
lv_memcpy(rgb_tmp_buf, src_buf, src_w * src_h * sizeof(lv_color_t));\
arm_2d_size_t copy_size = { \
.iWidth = src_w, \
.iHeight = src_h, \
}; \
/* apply re-colour */ \
__arm_2d_impl_colour_filling_with_opacity( \
(color_int *)rgb_tmp_buf, \
src_w, \
©_size, \
(color_int)draw_dsc->recolor.full, \
draw_dsc->recolor_opa); \
\
/* replace src_buf for the following operation */ \
src_buf = (const uint8_t *)rgb_tmp_buf; \
} \
do { \
__VA_ARGS__ \
} while(0); \
if (NULL != rgb_tmp_buf) { \
lv_mem_buf_release(rgb_tmp_buf); \
} \
} while(0); \
src_buf = src_buf_org;
#define __RECOLOUR_BEGIN() \
do { \
lv_color_t *rgb_tmp_buf = NULL; \
if(draw_dsc->recolor_opa > LV_OPA_MIN) { \
rgb_tmp_buf \
= lv_mem_buf_get(src_w * src_h * sizeof(lv_color_t)); \
if (NULL == rgb_tmp_buf) { \
LV_LOG_WARN( \
"Failed to allocate memory for accelerating recolour, " \
"use normal route instead."); \
break; \
} \
lv_memcpy(rgb_tmp_buf, src_buf, src_w * src_h * sizeof(lv_color_t));\
arm_2d_size_t copy_size = { \
.iWidth = src_w, \
.iHeight = src_h, \
}; \
/* apply re-colour */ \
__arm_2d_impl_colour_filling_with_opacity( \
(color_int *)rgb_tmp_buf, \
src_w, \
©_size, \
(color_int)draw_dsc->recolor.full, \
draw_dsc->recolor_opa); \
\
/* replace src_buf for the following operation */ \
src_buf = (const uint8_t *)rgb_tmp_buf; \
} \
do {
#define __RECOLOUR_END() \
} while(0); \
if (NULL != rgb_tmp_buf) { \
lv_mem_buf_release(rgb_tmp_buf); \
} \
} while(0); \
src_buf = src_buf_org;
#define __ARM_2D_PREPARE_TRANS_AND_TARGET_REGION(__TRANS_PREPARE, ...) \
do { \
__TRANS_PREPARE( \
NULL, \
__VA_ARGS__); \
\
target_region = (arm_2d_region_t) { \
.tLocation = { \
.iX = coords->x1 - draw_ctx->clip_area->x1, \
.iY = coords->y1 - draw_ctx->clip_area->y1, \
}, \
.tSize = { \
.iWidth = lv_area_get_width(coords), \
.iHeight = lv_area_get_height(coords), \
}, \
}; \
\
arm_2d_size_t tTransSize \
= ARM_2D_CTRL.DefaultOP \
.tTransform.Source.ptTile->tRegion.tSize; \
\
if (target_region.tSize.iWidth < tTransSize.iWidth) { \
int16_t iDelta = tTransSize.iWidth - target_region.tSize.iWidth;\
target_region.tLocation.iX -= iDelta / 2; \
target_region.tSize.iWidth = tTransSize.iWidth; \
} \
\
if (target_region.tSize.iHeight < tTransSize.iHeight) { \
int16_t iDelta \
= tTransSize.iHeight - target_region.tSize.iHeight; \
target_region.tLocation.iY -= iDelta / 2; \
target_region.tSize.iHeight = tTransSize.iHeight; \
} \
} while(0)
/* *INDENT-ON* */
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void convert_cb(const lv_area_t * dest_area,
const void * src_buf,
lv_coord_t src_w,
lv_coord_t src_h,
lv_coord_t src_stride,
const lv_draw_img_dsc_t * draw_dsc,
lv_img_cf_t cf,
lv_color_t * cbuf,
lv_opa_t * abuf);
static bool /* LV_ATTRIBUTE_FAST_MEM */ arm_2d_fill_normal(lv_color_t * dest_buf,
const lv_area_t * dest_area,
lv_coord_t dest_stride,
lv_color_t color,
lv_opa_t opa,
const lv_opa_t * mask,
lv_coord_t mask_stride);
static bool /* LV_ATTRIBUTE_FAST_MEM */ arm_2d_copy_normal(lv_color_t * dest_buf,
const lv_area_t * dest_area,
lv_coord_t dest_stride,
const lv_color_t * src_buf,
lv_coord_t src_stride,
lv_opa_t opa,
const lv_opa_t * mask,
lv_coord_t mask_stride);
static void /* LV_ATTRIBUTE_FAST_MEM */ lv_draw_arm2d_blend(lv_draw_ctx_t * draw_ctx,
const lv_draw_sw_blend_dsc_t * dsc);
static void /* LV_ATTRIBUTE_FAST_MEM */ lv_gpu_arm2d_wait_cb(lv_draw_ctx_t * draw_ctx);
static void /* LV_ATTRIBUTE_FAST_MEM */ lv_draw_arm2d_img_decoded(struct _lv_draw_ctx_t * draw_ctx,
const lv_draw_img_dsc_t * draw_dsc,
const lv_area_t * coords,
const uint8_t * src_buf,
lv_img_cf_t cf);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_arm2d_ctx_init(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
{
arm_2d_init();
lv_draw_sw_init_ctx(drv, draw_ctx);
lv_draw_arm2d_ctx_t * arm2d_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
arm2d_draw_ctx->blend = lv_draw_arm2d_blend;
arm2d_draw_ctx->base_draw.wait_for_finish = lv_gpu_arm2d_wait_cb;
arm2d_draw_ctx->base_draw.draw_img_decoded = lv_draw_arm2d_img_decoded;
}
void lv_draw_arm2d_ctx_deinit(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
{
LV_UNUSED(drv);
LV_UNUSED(draw_ctx);
}
extern void test_flush(lv_color_t * color_p);
static void LV_ATTRIBUTE_FAST_MEM lv_draw_arm2d_blend(lv_draw_ctx_t * draw_ctx,
const lv_draw_sw_blend_dsc_t * dsc)
{
const lv_opa_t * mask;
if(dsc->mask_buf == NULL) mask = NULL;
if(dsc->mask_buf && dsc->mask_res == LV_DRAW_MASK_RES_TRANSP) return;
else if(dsc->mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask = NULL;
else mask = dsc->mask_buf;
lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
lv_area_t blend_area;
if(!_lv_area_intersect(&blend_area, dsc->blend_area, draw_ctx->clip_area)) return;
//lv_disp_t * disp = _lv_refr_get_disp_refreshing();
bool is_accelerated = false;
do {
/* target buffer */
lv_color_t * dest_buf = draw_ctx->buf;
lv_disp_t * disp = _lv_refr_get_disp_refreshing();
if(disp->driver->screen_transp == 0) {
dest_buf += dest_stride * (blend_area.y1 - draw_ctx->buf_area->y1) + (blend_area.x1 - draw_ctx->buf_area->x1);
}
else {
/*With LV_COLOR_DEPTH 16 it means ARGB8565 (3 bytes format)*/
uint8_t * dest_buf8 = (uint8_t *) dest_buf;
dest_buf8 += dest_stride * (blend_area.y1 - draw_ctx->buf_area->y1) * LV_IMG_PX_SIZE_ALPHA_BYTE;
dest_buf8 += (blend_area.x1 - draw_ctx->buf_area->x1) * LV_IMG_PX_SIZE_ALPHA_BYTE;
dest_buf = (lv_color_t *)dest_buf8;
}
/* source buffer */
const lv_color_t * src_buf = dsc->src_buf;
lv_coord_t src_stride;
if(src_buf) {
src_stride = lv_area_get_width(dsc->blend_area);
src_buf += src_stride * (blend_area.y1 - dsc->blend_area->y1) + (blend_area.x1 - dsc->blend_area->x1);
}
else {
src_stride = 0;
}
lv_coord_t mask_stride;
if(mask) {
mask_stride = lv_area_get_width(dsc->mask_area);
mask += mask_stride * (blend_area.y1 - dsc->mask_area->y1) + (blend_area.x1 - dsc->mask_area->x1);
}
else {
mask_stride = 0;
}
lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
if(disp->driver->screen_transp) {
break;
}
if(dsc->src_buf == NULL) {
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
is_accelerated = arm_2d_fill_normal(dest_buf,
&blend_area,
dest_stride,
dsc->color,
dsc->opa,
mask,
mask_stride);
}
}
else {
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
is_accelerated = arm_2d_copy_normal(dest_buf,
&blend_area,
dest_stride,
src_buf,
src_stride,
dsc->opa,
mask,
mask_stride);
}
}
} while(0);
if(!is_accelerated) lv_draw_sw_blend_basic(draw_ctx, dsc);
}
static bool LV_ATTRIBUTE_FAST_MEM arm_2d_fill_normal(lv_color_t * dest_buf,
const lv_area_t * dest_area,
lv_coord_t dest_stride,
lv_color_t color,
lv_opa_t opa,
const lv_opa_t * mask,
lv_coord_t mask_stride)
{
arm_2d_size_t target_size = {
.iWidth = lv_area_get_width(dest_area),
.iHeight = lv_area_get_height(dest_area),
};
/*No mask*/
if(mask == NULL) {
if(opa >= LV_OPA_MAX) {
__arm_2d_impl_colour_filling((color_int *)dest_buf,
dest_stride,
&target_size,
color.full);
}
/*Has opacity*/
else {
__arm_2d_impl_colour_filling_with_opacity((color_int *)dest_buf,
dest_stride,
&target_size,
color.full,
opa);
}
}
/*Masked*/
else {
/*Only the mask matters*/
if(opa >= LV_OPA_MAX) {
__arm_2d_impl_colour_filling_mask((color_int *)dest_buf,
dest_stride,
(uint8_t *)mask,
mask_stride,
&target_size,
color.full);
}
/*With opacity*/
else {
__arm_2d_impl_colour_filling_mask_opacity((color_int *)dest_buf,
dest_stride,
(uint8_t *)mask,
mask_stride,
&target_size,
color.full,
opa);
}
}
return true;
}
static bool LV_ATTRIBUTE_FAST_MEM arm_2d_copy_normal(lv_color_t * dest_buf,
const lv_area_t * dest_area,
lv_coord_t dest_stride,
const lv_color_t * src_buf,
lv_coord_t src_stride,
lv_opa_t opa,
const lv_opa_t * mask,
lv_coord_t mask_stride)
{
int32_t w = lv_area_get_width(dest_area);
int32_t h = lv_area_get_height(dest_area);
arm_2d_size_t copy_size = {
.iWidth = lv_area_get_width(dest_area),
.iHeight = lv_area_get_height(dest_area),
};
/*Simple fill (maybe with opacity), no masking*/
if(mask == NULL) {
if(opa >= LV_OPA_MAX) {
__arm_2d_impl_copy((color_int *)src_buf,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size);
}
else {
__arm_2d_impl_alpha_blending((color_int *)src_buf,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size,
opa);
}
}
/*Masked*/
else {
/*Only the mask matters*/
if(opa > LV_OPA_MAX) {
__arm_2d_impl_src_msk_copy((color_int *)src_buf,
src_stride,
(uint8_t *)mask,
mask_stride,
©_size,
(color_int *)dest_buf,
dest_stride,
©_size);
}
/*Handle opa and mask values too*/
else {
__arm_2d_impl_tile_copy_with_src_mask_and_opacity((color_int *)src_buf,
src_stride,
(uint8_t *)mask,
mask_stride,
©_size,
(color_int *)dest_buf,
dest_stride,
©_size,
opa);
}
}
return true;
}
static void LV_ATTRIBUTE_FAST_MEM lv_draw_arm2d_img_decoded(struct _lv_draw_ctx_t * draw_ctx,
const lv_draw_img_dsc_t * draw_dsc,
const lv_area_t * coords,
const uint8_t * src_buf,
lv_img_cf_t cf)
{
/*Use the clip area as draw area*/
lv_area_t draw_area;
lv_area_copy(&draw_area, draw_ctx->clip_area);
const uint8_t * src_buf_org = src_buf;
bool mask_any = lv_draw_mask_is_any(&draw_area);
bool transform = draw_dsc->angle != 0 || draw_dsc->zoom != LV_IMG_ZOOM_NONE ? true : false;
lv_area_t blend_area;
lv_draw_sw_blend_dsc_t blend_dsc;
lv_memset_00(&blend_dsc, sizeof(lv_draw_sw_blend_dsc_t));
blend_dsc.opa = draw_dsc->opa;
blend_dsc.blend_mode = draw_dsc->blend_mode;
blend_dsc.blend_area = &blend_area;
if(lv_img_cf_is_chroma_keyed(cf)) cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
else if(cf == LV_IMG_CF_ALPHA_8BIT) {}
else if(cf == LV_IMG_CF_RGB565A8) {}
else if(lv_img_cf_has_alpha(cf)) cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
else cf = LV_IMG_CF_TRUE_COLOR;
/*The simplest case just copy the pixels into the draw_buf*/
if(!mask_any && !transform && cf == LV_IMG_CF_TRUE_COLOR && draw_dsc->recolor_opa == LV_OPA_TRANSP) {
blend_dsc.src_buf = (const lv_color_t *)src_buf;
blend_dsc.blend_area = coords;
lv_draw_sw_blend(draw_ctx, &blend_dsc);
}
else if(!mask_any && !transform && cf == LV_IMG_CF_ALPHA_8BIT) {
lv_area_t clipped_coords;
if(!_lv_area_intersect(&clipped_coords, coords, draw_ctx->clip_area)) return;
blend_dsc.mask_buf = (lv_opa_t *)src_buf;
blend_dsc.mask_area = coords;
blend_dsc.src_buf = NULL;
blend_dsc.color = draw_dsc->recolor;
blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
blend_dsc.blend_area = coords;
lv_draw_sw_blend(draw_ctx, &blend_dsc);
}
#if LV_COLOR_DEPTH == 16
else if(!mask_any && !transform && cf == LV_IMG_CF_RGB565A8 && draw_dsc->recolor_opa == LV_OPA_TRANSP &&
blend_dsc.opa >= LV_OPA_MAX) {
lv_coord_t src_w = lv_area_get_width(coords);
lv_coord_t src_h = lv_area_get_height(coords);
blend_dsc.src_buf = (const lv_color_t *)src_buf;
blend_dsc.mask_buf = (lv_opa_t *)src_buf;
blend_dsc.mask_buf += sizeof(lv_color_t) * src_w * src_h;
blend_dsc.blend_area = coords;
blend_dsc.mask_area = coords;
blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
lv_draw_sw_blend(draw_ctx, &blend_dsc);
}
#endif
/*In the other cases every pixel need to be checked one-by-one*/
else {
blend_area.x1 = draw_ctx->clip_area->x1;
blend_area.x2 = draw_ctx->clip_area->x2;
blend_area.y1 = draw_ctx->clip_area->y1;
blend_area.y2 = draw_ctx->clip_area->y2;
lv_coord_t src_w = lv_area_get_width(coords);
lv_coord_t src_h = lv_area_get_height(coords);
lv_coord_t blend_h = lv_area_get_height(&blend_area);
lv_coord_t blend_w = lv_area_get_width(&blend_area);
uint32_t max_buf_size = MAX_BUF_SIZE;
uint32_t blend_size = lv_area_get_size(&blend_area);
uint32_t buf_h;
uint32_t buf_w = blend_w;
if(blend_size <= max_buf_size) {
buf_h = blend_h;
}
else {
/*Round to full lines*/
buf_h = max_buf_size / blend_w;
}
/*Create buffers and masks*/
uint32_t buf_size = buf_w * buf_h;
lv_color_t * rgb_buf = lv_mem_buf_get(buf_size * sizeof(lv_color_t));
lv_opa_t * mask_buf = lv_mem_buf_get(buf_size);
blend_dsc.mask_buf = mask_buf;
blend_dsc.mask_area = &blend_area;
blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
blend_dsc.src_buf = rgb_buf;
lv_coord_t y_last = blend_area.y2;
blend_area.y2 = blend_area.y1 + buf_h - 1;
lv_draw_mask_res_t mask_res_def = (cf != LV_IMG_CF_TRUE_COLOR || draw_dsc->angle ||
draw_dsc->zoom != LV_IMG_ZOOM_NONE) ?
LV_DRAW_MASK_RES_CHANGED : LV_DRAW_MASK_RES_FULL_COVER;
blend_dsc.mask_res = mask_res_def;
if(cf == LV_IMG_CF_ALPHA_8BIT) {
/* original code:
lv_color_fill(rgb_buf, draw_dsc->recolor, buf_size);
*/
arm_2d_size_t copy_size = {
.iWidth = buf_w,
.iHeight = buf_h,
};
/* apply re-colour */
__arm_2d_impl_colour_filling(
(color_int *)rgb_buf,
buf_w,
©_size,
(color_int)draw_dsc->recolor.full);
}
bool is_accelerated = false;
if(!transform) {
if(LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED == cf) {
/* copy with colour keying */
/* *INDENT-OFF* */
__RECOLOUR_WRAPPER(
lv_color_t chrome_key = LV_COLOR_CHROMA_KEY;
/* calculate new chrome-key colour */
if(draw_dsc->recolor_opa > LV_OPA_MIN) {
__ARM_2D_PIXEL_BLENDING_OPA(
(color_int *) & (draw_dsc->recolor.full),
(color_int *) & (chrome_key.full),
draw_dsc->recolor_opa
);
}
__PREPARE_LL_ACCELERATION__();
if(blend_dsc.opa >= LV_OPA_MAX) {
__arm_2d_impl_cl_key_copy(
(color_int *)src_buf_tmp,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size,
(color_int)chrome_key.full);
}
else {
__arm_2d_impl_alpha_blending_colour_keying(
(color_int *)src_buf_tmp,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size,
blend_dsc.opa,
(color_int)chrome_key.full);
}
is_accelerated = true;
)
/* *INDENT-ON* */
}
else if((LV_COLOR_DEPTH == 32)
&& !mask_any
&& (LV_IMG_CF_TRUE_COLOR_ALPHA == cf)) {
/* accelerate copy-with-source-masks-and-opacity */
/* *INDENT-OFF* */
__RECOLOUR_WRAPPER(
__PREPARE_LL_ACCELERATION__();
uint8_t * mask_temp_buf = NULL;
if(blend_dsc.opa < LV_OPA_MAX) {
__arm_2d_impl_ccca8888_tile_copy_to_cccn888_with_opacity(
(uint32_t *)src_buf_tmp,
src_stride,
(uint32_t *)dest_buf,
dest_stride,
©_size,
blend_dsc.opa);
}
else {
__arm_2d_impl_ccca8888_to_cccn888(
(uint32_t *)src_buf_tmp,
src_stride,
(uint32_t *)dest_buf,
dest_stride,
©_size);
}
is_accelerated = true;
)
/* *INDENT-ON* */
}
else if(!mask_any
&& (LV_IMG_CF_RGB565A8 == cf)) {
/* accelerate copy-with-source-masks-and-opacity */
uint8_t * mask_after_rgb = src_buf + sizeof(lv_color_t) * src_w * src_h;
/* *INDENT-OFF* */
__RECOLOUR_WRAPPER(
__PREPARE_LL_ACCELERATION__();
uint8_t * mask_temp_buf = NULL;
if(blend_dsc.opa < LV_OPA_MAX) {
__arm_2d_impl_rgb565_tile_copy_with_src_mask_and_opacity(
(uint16_t *)src_buf_tmp,
src_stride,
(uint8_t *)mask_after_rgb,
src_stride,
©_size,
(uint16_t *)dest_buf,
dest_stride,
©_size,
blend_dsc.opa);
}
else {
__arm_2d_impl_src_msk_copy(
(color_int *)src_buf_tmp,
src_stride,
mask_after_rgb,
src_stride,
©_size,
(color_int *)dest_buf,
dest_stride,
©_size);
}
is_accelerated = true;
)
/* *INDENT-ON* */
}
else if(!mask_any && (cf == LV_IMG_CF_TRUE_COLOR)) {
/* accelerate copy-with-source-masks-and-opacity */
/* *INDENT-OFF* */
__RECOLOUR_WRAPPER(
__PREPARE_LL_ACCELERATION__();
if(blend_dsc.opa >= LV_OPA_MAX) {
__arm_2d_impl_copy(
(color_int *)src_buf_tmp,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size);
}
else {
__arm_2d_impl_alpha_blending(
(color_int *)src_buf_tmp,
src_stride,
(color_int *)dest_buf,
dest_stride,
©_size,
blend_dsc.opa);
}
is_accelerated = true;
)
/* *INDENT-ON* */
}
}
else if(!mask_any
#if defined(__ARM_2D_HAS_ANTI_ALIAS_TRANSFORM__) && __ARM_2D_HAS_ANTI_ALIAS_TRANSFORM__
&& (draw_dsc->antialias == 1)
#else
&& (draw_dsc->antialias == 0)
#endif
&& (draw_dsc->recolor_opa == LV_OPA_TRANSP)
&& (((LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED == cf)
|| (LV_IMG_CF_TRUE_COLOR == cf))
|| (LV_IMG_CF_RGB565A8 == cf)
#if defined(__ARM_2D_CFG_SUPPORT_COLOUR_CHANNEL_ACCESS__) && __ARM_2D_CFG_SUPPORT_COLOUR_CHANNEL_ACCESS__
|| ((LV_IMG_CF_TRUE_COLOR_ALPHA == cf)
&& (LV_COLOR_DEPTH == 32))
#endif
)
) {
uint8_t * mask_after_rgb = src_buf + sizeof(lv_color_t) * src_w * src_h;
/* *INDENT-OFF* */
__RECOLOUR_WRAPPER(
/* accelerate transform without re-color */
static arm_2d_tile_t target_tile_origin;
static arm_2d_tile_t target_tile;
arm_2d_region_t clip_region;
static arm_2d_region_t target_region;
lv_color_t * dest_buf = draw_ctx->buf;
target_tile_origin = (arm_2d_tile_t) {
.tRegion = {
.tSize = {
.iWidth = lv_area_get_width(draw_ctx->buf_area),