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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
|
/*
* Copyright Samsung Electronics Co.,LTD. * Copyright (C) 2016 The Android Open Source Project
*
* 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
*
* http://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.
*/
#ifndef __HARDWARE_EXYNOS_ACRYLIC_H__
#define __HARDWARE_EXYNOS_ACRYLIC_H__
#include <vector>
#include <cstdint>
#include <unistd.h>
#include <system/graphics.h>
#include <hardware/hwcomposer.h>
/* basic primitives */
#define MAX_HW2D_PLANES 4
/*
* Structure to express 2-dimensional coordinates.
* Invented to pass or to return two values in a single word
*/
typedef struct hw2d_coord {
int16_t hori;
int16_t vert;
void swap()
{
int16_t tmp = hori;
hori = vert;
vert = tmp;
}
} hw2d_coord_t;
/*
* Structure to express a rectangle in a 2-dimensional grid.
* Invented to pass or to return four values in a single 64-bit word
*/
typedef struct hw2d_rect {
hw2d_coord_t pos;
hw2d_coord_t size;
} hw2d_rect_t;
/*
* Structure to express the capability of HW 2D Accelerators
*/
struct stHW2DCapability {
/* maximum magnification with filter applied */
hw2d_coord_t max_upsampling_num;
/* maximum minification factor with filter applied */
hw2d_coord_t max_downsampling_factor;
/* maximum maginifcation without filter applied */
hw2d_coord_t max_upsizing_num;
/* maximum minification factor without filter applied */
hw2d_coord_t max_downsizing_factor;
/* the smallest source image size the HW can process */
hw2d_coord_t min_src_dimension;
/* the largest source image size the HW can process */
hw2d_coord_t max_src_dimension;
/* the smallest output image size the HW can process */
hw2d_coord_t min_dst_dimension;
/* the largest output image size the HW can process */
hw2d_coord_t max_dst_dimension;
/*
* the restriction of the alignments of the numbers of pixels
* in both of horizontal and vertical direction
*/
hw2d_coord_t min_pix_align;
/*
* The number of repeats of rescaling that the compositor supports. Note
* that this is not the capability of the driver and H/W but the capability.
* of the compositor(Acrylic).
* If the driver and H/W supports rescaling, it is 0. If the compositor is
* capable of running the H/W twice to overcome the minification restriction,
* it is then 1.
*/
int16_t rescaling_count;
/*
* the compositing mode that the HW 2D supports.
* should be combination of the values of HW2DCapability::blend_ops_t.
*/
uint32_t compositing_mode;
/*
* the geometric transformation in the 2-dimensional coordinate.
* should be combination of the values of HW2DCapability::transform_t.
*/
uint32_t transform_type;
/*
* the capabilities of HW. The value is the combination of the values of
* HW2DCapability::feature_t.
*/
uint32_t auxiliary_feature;
/*
* the number of color formats supported by HW 2D.
* it is also the number of elements in pixformats array.
*/
unsigned int num_formats;
/*
* the number of color spaces supported by HW 2D.
* it is also the number of elements in dataspaces array.
*/
unsigned int num_dataspaces;
/*
* the number of source images that HW 2D can process.
*/
unsigned int max_layers;
/*
* the array of color formats that are supported by HW 2D. the values should
* be selected from the definitions in <system/graphics.h> and exynos_formats.h.
*/
uint32_t *pixformats;
/*
* the array of color spaces that are supported by HW 2D. the values should
* be selected from the definitions in <system/graphics.h>.
*/
int *dataspaces;
/*
* the restriction of the alignments of the base addresses of buffers of images.
*/
size_t base_align;
};
/*
* HW2DCapability - Description of the capability of HW 2D.
*/
class HW2DCapability {
public:
/*
* the values to indicate the capabilities of geometric transformations
* supported by HW 2D accelerators.
*/
enum transform_t {
TRANSFORM_FLIP_H = 1, /* horizontal flip: (symmetrical displacement by x = -x, y = y) */
TRANSFORM_FLIP_V = 2, /* vertical flip: (symmetrical displacement by x = x, y = -y) */
TRANSFORM_FLIP_HV = 3, /* horizontal flip then vertical flip */
TRANSFORM_ROT_90 = 4, /* clockwise rotation by 90 degree */
TRANSFORM_ROT_180 = 8, /* clockwise rotation by 180 degree */
TRANSFORM_ROT_270 = 16, /* clockwise rotation by 270 degree */
TRANSFORM_ROT_ALL = 28, /* bitmask to select rotation degrees */
TRANSFORM_ALL = 31 /* bitmask to select the correct bits */
};
/*
* the values to indicate the capabilities of layer compositing
* supported by HW 2D accelerators.
* Sc: Source color, Dc: Destination(background) color,
* Sa: Source alpha, Pa: Plane alpha
*/
enum blend_ops_t {
BLEND_NONE = 1, /* Sc * 1 + Dc * 0 */
BLEND_SRC_COPY = 2, /* Sc * 1 * Pa + Dc * (1 - Sa) */
BLEND_SRC_OVER = 4, /* Sc * Sa * Pa + Dc * (1 - Sa) */
};
/*
* The values to indicate the capabilities of 2D H/W. The capabilities
* listed here shows if a function is supported or not.
*/
enum feature_t {
FEATURE_PLANE_ALPHA = 1 << 0,
FEATURE_AFBC_ENCODE = 1 << 4,
FEATURE_AFBC_DECODE = 1 << 5,
FEATURE_UORDER_READ = 1 << 6,
FEATURE_UORDER_WRITE = 1 << 7,
FEATURE_OTF_READ = 1 << 8,
FEATURE_OTF_WRITE = 1 << 9,
FEATURE_SOLIDCOLOR = 1 << 10,
};
enum { RESAMPLING_FRACTION_BITS = 20 };
HW2DCapability(const stHW2DCapability &cap): mCap(cap) { }
/*
* returns the bitmask of supporting flip directions
* the returned value is the combination of the values of transform_t.
*/
transform_t supportedFlip() const { return static_cast<transform_t>(mCap.transform_type & TRANSFORM_FLIP_HV); }
/*
* returns the bitmask of supporting rotation degrees
* the returned value is the combination of the values of transform_t.
*/
transform_t supportedRotation() const { return static_cast<transform_t>(mCap.transform_type & TRANSFORM_ROT_ALL); }
/*
* returns the pair of the maximum maginifcation
* in the horizontal and vertical direction with filter applied
*/
hw2d_coord_t supportedMaxMagnification() const { return mCap.max_upsampling_num;}
/*
* returns the pair of the maximum minifcation factor
* in the horizontal and vertical direction with filter applied
*/
hw2d_coord_t supportedMinMinification() const { return mCap.max_downsampling_factor;}
/*
* returns the pair of the maximum maginifcation
* in the horizontal and vertical direction without filter applied
*/
hw2d_coord_t supportedMaxEnlarging() const { return mCap.max_upsizing_num;}
/*
* returns the pair of the maximum minifcation factor
* in the horizontal and vertical direction without filter applied
*/
hw2d_coord_t supportedMinDecimation() const { return mCap.max_downsizing_factor;}
/*
* returns the bitmask of supporting compositing modes
* The returned value is the combination of the value sof blend_ops_t.
*/
uint32_t supportedCompositingMode() const { return mCap.compositing_mode; }
/*
* returns the alignment restriction of HW 2D in the base memory address.
*/
size_t supportedBaseAlign() const { return mCap.base_align; }
/*
* returns the maximum number of horizontal and vertical pixels
* of the source images that HW 2D can process
*/
hw2d_coord_t supportedMaxSrcDimension() const { return mCap.max_src_dimension; }
/*
* returns the minimum number of horizontal and vertical pixels
* of the source images that HW 2D can process
*/
hw2d_coord_t supportedMinSrcDimension() const { return mCap.min_src_dimension; }
/*
* returns the maximum number of horizontal and vertical pixels
* of the output image that HW 2D can process
*/
hw2d_coord_t supportedMaxDstDimension() const { return mCap.max_dst_dimension; }
/*
* returns the minimum number of horizontal and vertical pixels
* of the output image that HW 2D can process
*/
hw2d_coord_t supportedMinDstDimension() const { return mCap.min_dst_dimension; }
/*
* returns the alignment restriction of the number of horizontal
* and vertical pixels that HW 2D can process
*/
hw2d_coord_t supportedDimensionAlign() const { return mCap.min_pix_align; }
/*
* returns the number of source images that HW 2D can composit
*/
unsigned int maxLayerCount() const { return mCap.max_layers; }
/*
* study if the given format is supported by the HW 2D
*/
bool isFormatSupported(uint32_t fmt) const {
for (unsigned int i = 0; i < mCap.num_formats; i++)
if (mCap.pixformats[i] == fmt)
return true;
return false;
}
/*
* study if the given colorspace is supported by HW 2D
*/
bool isDataspaceSupported(int dataspace) const {
// discard transfer function information because it is required during display
dataspace &= ~HAL_DATASPACE_TRANSFER_MASK;
for (unsigned int i = 0; i < mCap.num_dataspaces; i++)
if (mCap.dataspaces[i] == dataspace)
return true;
return false;
}
/*
* convert the transformation mask in transform_type into the values
* that Android Graphics HAL understands.
*/
uint32_t getHWCTransformMask() const {
uint32_t mask = 0;
if (mCap.transform_type & TRANSFORM_FLIP_H)
mask |= HAL_TRANSFORM_FLIP_H;
if (mCap.transform_type & TRANSFORM_FLIP_V)
mask |= HAL_TRANSFORM_FLIP_V;
if (mCap.transform_type & TRANSFORM_ROT_90)
mask |= HAL_TRANSFORM_ROT_90;
if (mCap.transform_type & TRANSFORM_ROT_180)
mask |= HAL_TRANSFORM_ROT_180;
if (mCap.transform_type & TRANSFORM_ROT_270)
mask |= HAL_TRANSFORM_ROT_270;
return mask;
}
/*
* discover if the given feature that is defined in feature_t is supported.
*/
bool isFeatureSupported(uint32_t feature) const { return !!(mCap.auxiliary_feature & feature); }
/*
* study if the given horizontal resolution change from @from into @to is
* supported by HW 2D
*/
bool supportedHResampling(int16_t from, int16_t to, int16_t resamping_count = 1) const
{
return supportedResampling(from, to,
mCap.max_upsampling_num.hori * resamping_count,
mCap.max_downsampling_factor.hori * resamping_count);
}
/*
* study if the given vertical resolution change from @from into @to is
* supported by HW 2D
*/
bool supportedVResampling(int16_t from, int16_t to, int16_t resamping_count = 1) const
{
return supportedResampling(from, to,
mCap.max_upsampling_num.vert * resamping_count,
mCap.max_downsampling_factor.vert * resamping_count);
}
/*
* study if the given resampling from @from to @to is supported by HW 2D compositor
* implementation.
*/
bool supportedResampling(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
{
int count = supportedRescalingCount();
if (!!(transform & HAL_TRANSFORM_ROT_90))
to.swap();
return supportedHResampling(from.hori, to.hori, count) &&
supportedVResampling(from.vert, to.vert, count);
}
/*
* study if the given resampling from @from to @to is supported by HW 2D
*/
bool supportedHWResampling(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
{
if (!!(transform & HAL_TRANSFORM_ROT_90))
to.swap();
return supportedHResampling(from.hori, to.hori, 1) &&
supportedVResampling(from.vert, to.vert, 1);
}
/*
* study if the given number of horizontal pixels (@from) can be changed
* to @to by HW 2D
*/
bool supportedHResizing(int16_t from, int16_t to) const
{
return supportedResizing(from, to,
mCap.max_upsizing_num.hori, mCap.max_downsizing_factor.hori);
}
/*
* study if the given number of vertical pixels (@from) can be changed
* to @to by HW 2D
*/
bool supportedVResizing(int16_t from, int16_t to) const
{
return supportedResizing(from, to,
mCap.max_upsizing_num.vert, mCap.max_downsizing_factor.vert);
}
/*
* study if the given resizing from @from to @to is supported by HW 2D compositor
* implementation.
*/
bool supportedResizing(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
{
if (!!(transform & HAL_TRANSFORM_ROT_90))
to.swap();
return supportedHResizing(from.hori, to.hori) && supportedVResizing(from.vert, to.vert);
}
/*
* study the number rescaling by the compositor for a layer
* 1 if the compositor does not repeat the scaling. 2 if the compositor
* repeat the scaling once.
* Note that the return value of supportedRescalingCount() is the one
* incremented from the struct stHW2DCapability.rescaling_count.
*/
int supportedRescalingCount() const
{
return mCap.rescaling_count + 1;
}
private:
bool supportedResampling(int16_t from, int16_t to, int16_t upfactor, int16_t downfactor) const
{
int64_t factor = static_cast<int64_t>(from);
factor <<= RESAMPLING_FRACTION_BITS;
factor /= to;
if (factor > (static_cast<int64_t>(downfactor) << RESAMPLING_FRACTION_BITS))
return false;
// @upfactor is a reciprocal number of an upsampling factor
if (factor < ((1 << RESAMPLING_FRACTION_BITS) / static_cast<int64_t>(upfactor)))
return false;
return true;
}
bool supportedResizing(int16_t from, int16_t to, int16_t upfactor, int16_t downfactor) const
{
if ((from < to) && (upfactor == 0))
return true;
if ((from > to) && (downfactor == 0))
return true;
return supportedResampling(from, to, upfactor, downfactor);
}
const stHW2DCapability &mCap;
};
class Acrylic;
/*
* AcrylicCanvas - Description of an image and its buffers
*
* It includes the entire image area and how the image is stored in the memory,
* where it is stored and the buffer synchronization objects called Fence.
* AcrylicCanvas contains the following attributes:
* - image dimension: number of horizontal and vertical pixels
* - color format of the image
* - colorspace of the image
* - the identifiers of the image buffers (userptr or dmabuf)
*
* Creation of AcrylicCanvas by new operator is prohibited. The only way to
* create an instance of AcrylicCavans is to call Acrylic::createLayer().
*/
class AcrylicCanvas {
friend class Acrylic;
public:
/*
* The attributes of the image described by AcrylicCanvas:
* The attributes are bit masks and therefore combination of them may be
* also required.
* - ATTR_NONE: indicates no special attributes are specified
* - ATTR_PROTECTED: the buffer of the image is protected. Reading or
* writing to the buffer of the image is prohibited.
* - ATTR_COMPRESSED: the image is or is to be stored in a compressed form.
* e.g. AFBC
* - ATTR_UORDER: the image data is written in U-order instead of raster-scan order.
* U-order memory access by GPU helps the BUS efficiency.
* - ATTR_OTF: The image buffer is hard-wired. If this attribute is given, libacryl
* ignores the buffer configuration to the canvas.
* - ATTR_SOLIDCOLOR : The image buffer is empty and should be filled with one RGBA value by H/W.
*/
enum layer_attr_t {
ATTR_NONE = 0,
ATTR_PROTECTED = 1,
ATTR_COMPRESSED = 2,
ATTR_UORDER = 4,
ATTR_OTF = 8,
ATTR_SOLIDCOLOR = 16,
ATTR_ALL_MASK = 0x1F
};
/*
* Describes how the buffer of the image is identified.
* - MT_DMABUF: the buffer is identified by an open file descriptor that is
* exported by dmabuf.
* - MT_USERPTR: the buffer is identified by a memory address that is valid
* in the current process. Usally it is a bug if mAttributes
* has ATTR_PROTECTED whlie mMemoryType is MT_USERPTR.
* - MT_EMTPY : the buffer is empty such as hare-wired buffer or colorfill layer.
*/
enum memory_type { MT_DMABUF = 1, MT_USERPTR = 2, MT_EMPTY = 3 };
/*
* Indicates the configured or modified settings
* - SETTING_TYPE: Image format and color space information is configured by users.
* - SETTING_BUFFER: Image buffer information is configured by users.
* - SETTING_DIMENSION: Image dimension information is configured by users.
* - SETTING_TYPE_MODIFIED: Image format and color space information is configured
* by users and it is not applied to HW yet.
* - SETTING_BUFFER_MODIFIED: Image buffer information is configured by users and
* it is not applied to HW yet.
* - SETTING_DIMENSION_MODIFIED: Image dimension information is configured by users
* and it is not applied to HW yet.
*/
enum setting_check_t {
SETTING_TYPE = 1,
SETTING_BUFFER = 2,
SETTING_DIMENSION = 4,
SETTING_MASK = SETTING_TYPE | SETTING_BUFFER | SETTING_DIMENSION,
SETTING_TYPE_MODIFIED = 16,
SETTING_BUFFER_MODIFIED = 32,
SETTING_DIMENSION_MODIFIED = 64,
SETTIMG_MODIFIED_MASK = SETTING_TYPE_MODIFIED | SETTING_BUFFER_MODIFIED | SETTING_DIMENSION_MODIFIED,
};
/*
* MEMBER FUNCTIONS FOR THE USERS
*/
/*
* Configure the dimension of the image
*/
virtual bool setImageDimension(int32_t width, int32_t height);
/*
* Find the dimension of the image configured to AcyrilicCanvas
*/
hw2d_coord_t getImageDimension() { return mImageDimension; }
/*
* Configure the image color format and color space
* You should configure the correct colorspace if you want to change the
* the image is YCbCr and the target image is RGB because the brightness
* of the pixel data encoded in YCbCr is generated from various colorspaces
* including BT.601, BT.709(sRGB) and BT.2020. If the YCbCr image is a frame
* of a moving picture, we should likely consider the 1/16 headroom and
* footroom. Generally BT.601, BT.709 and BT.2020 have footroom and headroom
* while JFIF(JPEG, SRGB) does not have.
*/
bool setImageType(uint32_t fmt, int dataspace);
/*
* Configure color fill layer that fill only one RGBA color without actual buffer.
* Note that this successes if the compositor supports FEATURE_SOLIDCOLOR.
*/
bool setImageBuffer(int a, int r, int g, int b, uint32_t attr = ATTR_NONE);
/*
* Configure the image buffer of dmabuf type.
*/
bool setImageBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], off_t offset[MAX_HW2D_PLANES],
int num_buffers, int fence = -1, uint32_t attr = ATTR_NONE);
/*
* Configure the image buffer of dmabuf type.
* This does not receives a parameter 'offset' compared to the above
* setImageBuffer(). The latter type of setImageBuffer() is provided to
* provide convenience to the users because offsets are mostly zero.
*/
bool setImageBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], int num_buffers,
int fence = -1, uint32_t attr = ATTR_NONE)
{
off_t offset[MAX_HW2D_PLANES] = {0, 0, 0};
return setImageBuffer(fd, len, offset, num_buffers, fence, attr);
}
/*
* Configure the image buffer of userptr type.
* Note that you cannot pass a fence if the buffer type is userptr because
* userptr buffer is not shareable between processes and devices.
*/
bool setImageBuffer(void *addr[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES],
int num_buffers, uint32_t attr = ATTR_NONE);
/*
* Configure the image buffer is hard-wired which means that the buffer is always
* prepared in the compositor H/W.
* Note that this successes if the compositor supports FEATURE_OTF_READ or FEATURE_OTF_WRITE.
*/
bool setImageOTFBuffer(uint32_t attr = AcrylicCanvas::ATTR_NONE);
/*
* Configure the fence. setFence() overwrites the fence specified by
* setImageBuffer().
*/
void setFence(int fence);
/*
* Called by the implementations of Acyrlic to determine if all required
* configurations are completed.
*/
bool isSettingOkay()
{
return (mSettingFlags & SETTING_MASK) == (SETTING_TYPE | SETTING_BUFFER | SETTING_DIMENSION);
}
/*
* MEMBER FUNCTIONS FOR THE IMPLEMENTATIONS of Acrylic
*/
/*
* Determine if the buffer is protected. If the buffer or the image is
* protected, the driver of HW 2D should specially care the buffer and the
* processing involving the buffer.
*/
bool isProtected() { return !!(mAttributes & ATTR_PROTECTED); }
/*
* Determine if the image in the buffer is or should be in a compressed form.
*/
bool isCompressed() { return !!(mAttributes & ATTR_COMPRESSED); }
/*
* Study if the image is or should be written in U-Order for accelerated
* graphic processing instead of raster-scan order.
*/
bool isUOrder() { return !!(mAttributes & ATTR_UORDER); }
/*
* Study if the canvas buffer is hard-wired.
*/
bool isOTF() { return !!(mAttributes & ATTR_OTF); }
/*
* Study if the image is filled with solid color.
*/
bool isSolidColor() { return !!(mAttributes & ATTR_SOLIDCOLOR); }
/*
* Obtain the acquire fence of the buffer.
*/
int getFence() const { return mFence; }
/*
* Invalidate the confgured acquire fence without destryoing(close()) it
*/
void clearFence() { mFence = -1; }
/*
* Obtain the image color format
*/
uint32_t getFormat() { return mPixFormat; }
/*
* Obtain the color space information
*/
int getDataspace() { return mDataSpace; }
/*
* Obtain the buffer type whether the buffer is MT_USERPTR or MT_DMABUF
*/
memory_type getBufferType() { return mMemoryType; }
/*
* Obtain the number of buffers.
* The parameter 'index' of the following member functions including
* getDmabuf(), getUserptr(), getOffset(), getBufferLength() should be
* smaller than the return value of getBufferCount(). Otherwise, you will
* get invalid memory area referenced.
*/
unsigned int getBufferCount() { return mNumBuffers; }
/*
* Obtain the open file descriptor exported by dmabuf if the buffer type is
* MT_DMABUF
*/
int getDmabuf(unsigned int index)
{
return (mMemoryType == MT_DMABUF) ? m.mBufferFd[index] : -1;
}
/*
* Obtain the buffer address if the buffer type is MT_USERPTR
*/
void *getUserptr(unsigned int index)
{
return (mMemoryType == MT_USERPTR) ? m.mBufferAddr[index] : NULL;
}
/*
* Obtain the offset where the image is stored in the buffer if the buffer
* type is MT_DMABUF
*/
uint32_t getOffset(unsigned int index)
{
return (mMemoryType == MT_DMABUF) ? mBufferOffset[index] : 0;
}
/*
* Obtain the length of the buffer
*/
uint32_t getBufferLength(unsigned int index)
{
return mBufferLength[index];
}
/*
* Clear all modified states. It is called by the Acrylic implementations after
* they executes their HWs
*/
void clearSettingModified()
{
unset(SETTING_TYPE_MODIFIED |
SETTING_BUFFER_MODIFIED |
SETTING_DIMENSION_MODIFIED);
}
/*
* Obtain the flags that indicates the configuration status
*/
uint32_t getSettingFlags() { return mSettingFlags; }
/*
* Obtain the solid color combined by 8bit of A, R, G, B
*/
uint32_t getSolidColor() { return mSolidColor; }
protected:
enum canvas_type_t {
CANVAS_SOURCE,
CANVAS_TARGET,
};
Acrylic *mCompositor;
AcrylicCanvas(Acrylic *compositor, canvas_type_t type = CANVAS_SOURCE);
virtual ~AcrylicCanvas();
Acrylic *getCompositor() { return mCompositor; }
void unset(uint32_t flag) { mSettingFlags &= ~flag; }
void set(uint32_t flag) { mSettingFlags |= flag; }
private:
/*
* called when Acrylic is being destroyed to inform AcrylicCanvas
* that no Acrylic has a reference to it.
*/
void disconnectLayer() { mCompositor = NULL; }
hw2d_coord_t mImageDimension;
uint32_t mPixFormat;
int mDataSpace;
memory_type mMemoryType;
union {
void *mBufferAddr[MAX_HW2D_PLANES];
int mBufferFd[MAX_HW2D_PLANES];
} m;
size_t mBufferLength[MAX_HW2D_PLANES];
uint32_t mBufferOffset[MAX_HW2D_PLANES];
int mNumBuffers;
int mFence; // NOTE: this should be reset to -1 after Acrylic::execute()
uint32_t mAttributes;
uint32_t mSettingFlags;
uint32_t mSolidColor; // [32:0] ARGB order.
canvas_type_t mCanvasType;
};
/*
* AcrylicLayer - Description of compositing properties
* as well as an image and its buffers
*
* AcrylicLayer extends the properties of AcrylicCanvas for compositing purpose.
* It adds the following propertes to AcrylicCanvas:
* - The rectangle region of interest in the image. It is usually called 'crop'
* - The rectangle region to map the crop area in the target dimension. It is
* usually called 'window'. If the width or the height of the window is
* different from crop, resampling or resizing is invloved.
* - How the input images are composited. Currently Acrylic supports only the
* following opertions:
* .HWC_BLENDING_NONE: The alpha channel in the image should be ignored
* .HWC_BLENDING_PREMULT: The color brightness values are regardted as they
* are multiplied with its alpha channel value
* .HWC_BLENDING_COVERAGE: The alpha value of each pixel is multiplied with
* the brighness of each pixel during compositing.
* - How to transfrom the image into window: flip, rotation
* - The order of input images to be stacked on the background
* - The transparent level of the image. It is multiplied to every pixel
* brightness values when compositing. The transparent level of the entire
* image is also called 'plane alpha' or 'global alpha'.
*
* The default properties are:
* - mImageRect: the entire image dimension.
* - mTargetRect: the entire target dimension
* - mBlendingMode: HWC_BLENDING_NONE
* - mTransform: 0 (no flip, no rotation)
* - mZOrder: 0
* - mPlaneAlpha: 1.0(255)
*
* Creation of AcrylicLayer by new operator is prohibited. The only way to
* create an instance of AcrylicLayer is to call Acrylic::createLayer().
*/
class AcrylicLayer: public AcrylicCanvas {
friend class Acrylic;
public:
/*
* The various/special attributes to the source images
* - ATTR_NORESAMPLING: Force resize the image speicifed to the layer even
* though the target image size is too small to apply
* the interpolation filter correctly.
*/
enum composit_attr_t { ATTR_NORESAMPLING = 1, ATTR_ALL_MASK = 1};
virtual ~AcrylicLayer();
/*
* MEMBER FUNCTIONS FOR THE USERS
*/
/*
* Configure the compositing mode including the compositing operations,
* plane alpha and z-order
*/
bool setCompositMode(uint32_t mode, uint8_t alpha = 0xFF, int z_order = 0);
/*
* Configure the crop, window, transformation and special compositing attributes.
*/
bool setCompositArea(hwc_rect_t &src_area, hwc_rect_t &out_area, uint32_t transform = 0, uint32_t attr = 0);
/*
* Configure the crop and transformation information. The window rect is
* is regarded as the entire target dimension.
*/
bool setCompositArea(hwc_rect_t &src_area, uint32_t transform = 0, uint32_t attr = 0)
{
hwc_rect_t out_area = {0, 0, 0, 0};
return setCompositArea(src_area, out_area, transform, attr);
}
/*
* Configure the dimension of the image. This function overrides
* AcrylicCanvas::setImageDimension(). Once this function is called, the
* crop rect, mImageRect reset to the entire image dimension configured
* by this function. Note that the window, mTargetRect is not reset because
* it is not dependent upon the image dimension.
*/
virtual bool setImageDimension(int32_t width, int32_t height);
/*
* Configure the source image area(crop) with the target rect and transform
* untouched while setCompositArea() modifies source rect, target rect and
* transform with the given arguments.
*/
bool setImageRect(hwc_rect_t &src_area)
{
hwc_rect_t out_area = {
mTargetRect.pos.hori,
mTargetRect.pos.vert,
mTargetRect.pos.hori + mTargetRect.size.hori,
mTargetRect.pos.vert + mTargetRect.size.vert
};
return setCompositArea(src_area, out_area, mTransform);
}
/*
* Configure the minimum liminance and the maximum luminance of the display
* used in the HDR video mastering environment. It is spepcified in the
* metatata of the HDR video contents.
* @min: minimum luminance in 0.0001 cd/m^2 unit
* @max: maximum luminance in 1 cd/m^2 unit
*
* The followings are the default values:
* @min: 0
* @max: 100 (SDR)
*
* NOTE:
* The configured video is treated as SDR until setMasterDisplayLuminance()
* is called. It means that the target image is to be SDR.
*/
void setMasterDisplayLuminance(uint16_t min, uint16_t max);
/*
* Configure an opaque data associated to a layer
* @data: pointer to data associated to this layer
* @data_len: number of effective bytes pointed by @data
*
* The configured data is opaque to libacryl. It should be handled by the
* implementations. How to specify and how to understand the data is just
* contract between the user of a specific implementation and the implemtation.
* The configured data is effective until the data is cleared by invoking
* clearLayerData().
* The second argument @data_lan can be used for checking the contract. The
* implementation and the users should decide the data structure delivered by
* setLayerData(). If the data structure has fixed length, the implementation
* can determine if the delivered data is correctly configured with comparing
* @data_len and the expected size.
*/
void setLayerData(void *data, size_t data_len) {
mLayerData = data;
mLayerDataLen = data_len;
}
/*
* Clears the configured layer data.
*/
void clearLayerData() {
mLayerData = nullptr;
mLayerDataLen = 0;
}
/*
* MEMBER FUNCTIONS FOR THE IMPLEMENTATIONS of Acrylic
*/
/*
* Optain the configured compositing mode
*/
uint32_t getCompositingMode() { return mBlendingMode; }
/*
* Obtain the z-order of the layer
*/
int32_t getZOrder() { return mZOrder; }
/*
* Obtain the plane alpha value of the layer
*/
uint8_t getPlaneAlpha() { return mPlaneAlpha; }
/*
* Obtain the crop region of the layer
*/
hw2d_rect_t getImageRect() { return mImageRect; }
/*
* Obtain the window region onto the background. If all four values are
* zero, the window region should be regarded as the entire background
* dimension.
*/
hw2d_rect_t getTargetRect() { return mTargetRect; }
/*
* Obtain the transform property of the layer
*/
uint32_t getTransform() { return mTransform; }
/*
* Obtain the special compositing attribute flags
*/
uint32_t getCompositAttr() { return mCompositAttr; }
/*
* Obtain the minimum luminance of the display of the mastering environment
* of the video layer in the unit of 0.0001 cd/m^2.
*/
uint16_t getMinMasteringLuminance() { return mMinLuminance; }
/*
* Obtain the maximum luminance of the display of the mastering environment
* of the video layer in the unit of 1 cd/m^2.
*/
uint16_t getMaxMasteringLuminance() { return mMaxLuminance; }
/*
* Copy the contents of @layer into the callee instance.
* Note that the file descriptors of @layer are not duplicated. The caller
* should care about that. Note also that importLayer() invalidates the
* acquire fence of @layer because it is transferred to the callee.
*/
void importLayer(AcrylicLayer &layer, bool inherit_transform);
/*
* Store the given transit data to the instance. It is generated by the
* implementations of Acrylic class.
*/
void storeTransit(void *transitData) { mTransitData = transitData; }
/*
* Retrieve the transit data from the instance.
*/
void *getTransit() { return mTransitData; }
/*
* Retrieve the layer opaque data.
*/
void *getLayerData() { return mLayerData; }
size_t getLayerDataLength() { return mLayerDataLen; }
private:
AcrylicLayer(Acrylic *compositor);
void *mTransitData;
void *mLayerData;
size_t mLayerDataLen;
hw2d_rect_t mImageRect;
hw2d_rect_t mTargetRect;
uint32_t mBlendingMode;
uint32_t mTransform;
int32_t mZOrder;
uint32_t mCompositAttr;
uint16_t mMaxLuminance; // in nit
uint16_t mMinLuminance; // in 0.0001 nit
uint8_t mPlaneAlpha;
};
class AcrylicPerformanceRequest;
/*
* DEPRECATED:
* AcrylicFactory works as it did for now but it will be removed in the future
* because new factory methods to create an instance of Acrylic is introduced:
* use the followings instead of AcrylicFactory:
* - Acrylic::createInstance() for a specific Acrylic backend
* - Acrylic::createCompositor() to create the "default_compositor"
* - Acrylic::createScaler() to create the "default_scaler"
*
* AcrylicFactory - The creator of Acrylic
*
* Users are prohibited to create an instance of Acrylic because the does not
* have enough knowledge how to create. Instead, users should ask the factory
* to create an instance of Acrylic with a special 'name'(spec) to identify a
* specific HW 2D.
*/
class AcrylicFactory {
public:
AcrylicFactory() { };
~AcrylicFactory() { };
/*
* Creator of Acrylic instance
*/
static Acrylic *createAcrylic(const char *spec);
};
/*
* Acrylic - The type of the object for 2D compositing with HW 2D
*
* Acrylic executes HW 2D with the image information specified on AcrylicLayers
* and AcrylicCanvas that are created by Acrylic.
* To create an instance of Acrylic, you should use AcrylicFactory.
*/
class Acrylic {
public:
/*
* Factory methods of an instance of Acrylic subclasses
* createInstance() - create the instance exactly specified by @spec
* createCompositor() - create an instance of HW 2D compositor defined in board definition
* createScaler() - create an instance of image post processor defined in board definition
* createBlter() - create an instance of H/W accelerator of bit block transfer defined in board definition
*/
static Acrylic *createInstance(const char *spec);
static Acrylic *createCompositor();
static Acrylic *createScaler();
static Acrylic *createBlter();
Acrylic(const HW2DCapability &capability);
virtual ~Acrylic();
/*
* Create a new instance of AcrylicLayer. If the number of created
* AcrylicLayer is already mCapability.maxLayerCount(), createLayer()
* fails.
* The caller of createLayer() should destroy the instance of AcrylicLayer
* by itself. The instance of AcrylicLayer is only available while the
* Acrylic that created it lives. If the Acrylic that created AcrylicLayer
* has been destroyed, all configuration to AcrylicLayer have no effect.
*/
AcrylicLayer *createLayer();
/*
* Obtain HW2DCapability object to study the capability fo HW 2D that the
* Acrylic handles.
*/
const HW2DCapability &getCapabilities() { return mCapability; }
/*
* Configure the image dimension of the background. The background image
* is not the input image with the lowest z-order but the target image in
* this context.
*/
bool setCanvasDimension(int32_t width, int32_t height)
{
return mCanvas.setImageDimension(width, height);
}
/*
* Configure the image color format and the address space of the target image
*/
bool setCanvasImageType(uint32_t fmt, int dataspace)
{
return mCanvas.setImageType(fmt, dataspace);
}
/*
* Configure the buffers where to write the result (target) image. The
* identifier of the buffer is a open file descriptor exported by dmabuf.
* Users can also configure if the result image is in the compressed form
* or to be protected from access by non-previliged users.
*/
bool setCanvasBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], off_t offset[MAX_HW2D_PLANES],
int num_buffers, int fence = -1, uint32_t attr = AcrylicCanvas::ATTR_NONE)
{
return mCanvas.setImageBuffer(fd, len, offset, num_buffers, fence, attr);
}
/*
* Configure the buffers where to write the result (target) image.
* This version ov setCanvasBuffer() is the same as the above version except
* that this version does not require @offset as its argument.
*/
bool setCanvasBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], int num_buffers,
int fence = -1, uint32_t attr = AcrylicCanvas::ATTR_NONE)
{
return mCanvas.setImageBuffer(fd, len, num_buffers, fence, attr);
}
/*
* Configure the buffers where to write the result (target) image. The
* identifier of the buffer is a valid memory address in the address space
* of the caller. AcrylicCanvas::ATTR_PROTECTED to @attr is not allowed
* because userptr buffer should not be protected.
*/
bool setCanvasBuffer(void *addr[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES],
int num_buffers, uint32_t attr = AcrylicCanvas::ATTR_NONE)
{
return mCanvas.setImageBuffer(addr, len, num_buffers, attr);
}
/*
* Configure the target buffers as hard-wired.
*/
bool setCanvasOTF(uint32_t attr = AcrylicCanvas::ATTR_NONE)
{
return mCanvas.setImageOTFBuffer(attr);
}
/*
* Configure the default background color and the opacity. It is effecitve
* when the source images are not opaque or the source images does not fill
* the entire target image buffer.
* Configuring the default color makes the result image more deterministic.
* NOTE that the value(brightness) of each color components and the opacity
* are 16-bit wide. If your system supports 8-bit brightness, you should
* shift the brightness value to the left in the amount of 8 bits. Again,
* you should multiply the value of each color components and the opacity
* with 256 (2^8) if your color system supports 8-bit brightness levels.
*/
void setDefaultColor(uint16_t red, uint16_t green, uint16_t blue, uint16_t alpha)
{
mBackgroundColor.R = red;
mBackgroundColor.G = green;
mBackgroundColor.B = blue;
mBackgroundColor.A = alpha;
mHasBackgroundColor = true;
}
/*
* Cancel the configured default color values.
*/
void clearDefaultColor()
{
mHasBackgroundColor = false;
}
/*
* Configures cofficients the tone mapper if the user of Acrylic wants to
* overrides the default coefficients of the tone mapper for HDR display.
* The coefficients are a two dimensional array of coefficients of x-axis
* and y-axis. If no coefficient is configured, the default function of the
* implemntation of Acrylic is used. It may be ether of gamma 2.2 for SDR,
* gamma 2.6 for HDR.
* The configured coefficients are not enabled if no layer has HDR video
* because HDR processing is not enabled.
*/
virtual bool setHDRToneMapCoefficients(uint32_t *matrix[2], int num_elements);
/*
* Configure the minimum luminance and the maximum luminance of the target
* display.
* @min: minimum luminance in 0.0001 cd/m^2 unit
* @max: maximum luminance in 1 cd/m^2 unit
*
* The following sare the default values:
* @min: 0
* @max 100 (SDR)
*
* NOTE:
* How to handle the target display luminance depends on the implementation
* of Acrylic. An implementation does not refer to the configured target
* display luminance while another implementation may us the taret display
* luminance to choose its HDR conversion logic.
*/
inline void setTargetDisplayLuminance(uint16_t min, uint16_t max)
{
mMaxTargetLuminance = max;
mMinTargetLuminance = min;
}
/*
* Configure information of target display device.
*/
inline void setTargetDisplayInfo(void *data)
{
mTargetDisplayInfo = data;
}
/*
* Run HW 2D. If @fence is not NULL and num_fences is not zero, execute()
* fills the release fences to the array of @fence. The number of fences
* filled by execute() is min(num_fences, mLayers.size()). If num_fences is
* larger than mLayers.size(), execute() fills -1 to the rest of the elements
* of @fence.
* execute() returns before HW 2D completes the processing, of course.
*/
virtual bool execute(int fence[], unsigned int num_fences) = 0;
/*
* Run HW 2D. This version of execute() does not provides release fences.
* If @handle is NULL, execute() does not return until HW 2D completes
* the processng. If @handle is not NULL, execute() returns before HW 2D
* completes and stores a value(handle) to @handle. Users can wait for HW 2D
* to be finished with that handle. Users does not need to wait HW 2D. Then,
* they sshould release the handle with releaseHandle().
*/
virtual bool execute(int *handle = NULL) = 0;
/*
* Release @handle informed by execute()
*/
virtual void releaseHandle(int __attribute__((__unused__)) handle) { }
/*
* Wait HW 2D to finish the processing associated with @handle. The handle
* is released after the wait completes.
*/
virtual bool waitExecution(int handle) = 0;
/*
* Return the last execution time of the H/W in micro seconds.
* It is only vaild when the last call to execute() succeeded.
*/
virtual unsigned int getLaptimeUSec() { return 0; }
/*
* Configure the priority of the image processing tasks requested
* to this compositor object. The default priority is -1 and the
* highest priority is 15. If a user configure a priority outside
* of the range between -1 and 15, the user will get failure.
* How the priority to be applied is the implmentation specific.
* prioritize() returns a negative value (-1) on failure. On successful,
* prioritize() returns zero or a positive value. An implementation may
* return a positive value to inform additional information.
*/
virtual int prioritize(int priority = -1);
/*
* Configure a value for guaranteeing quality of service in terms
* of image processing performance. The types and ranges of the
* value is not defined by libacryl but the end users including
* HWC and the driver. libacryl just deliver the value to the
* driver that the implementation of Acrylic is talking with.
* If the implementation does not implement requestPerformanceQoS(),
* calling requestPerformanceQoS() effects nothing.
* The types, the size and the number of the parameters are defined
* as required. They should be defined in acrylic_soc.h.
*/
virtual bool requestPerformanceQoS(AcrylicPerformanceRequest *request);
/*
* Called when an AcrylicLayer is being destroyed
*/
void removeLayer(AcrylicLayer *layer);
/*
* Obtains the instance AcrylicCanvas of the taret image. It is called by
* the implementations of Acrylic and the test modules of Acrylic. The other
* users of Acrylic do not need to call getCanvas(). Instead, consider
* setCanvasDimension(), setCanvasImageType() and setCanvasBuffer().
*/
AcrylicCanvas &getCanvas() { return mCanvas; }
unsigned int layerCount() { return static_cast<unsigned int>(mLayers.size()); }
protected:
/*
* Called when an AcrylicLayer is destroyed. Unlike removeLayer(),
* removeTransitData() is called whenever an AcrylicLayer which is still
* associated with an instance of Acrylic is destroyed. It means that
* removeTransitData() is called even when an instance of Acrylic is
* destroyed to remove all transit data installed in an AcrylicLayer instance.
* If an implmentation of Acrylic may install a transit data to an instance of
* AcrylicLayer, it should implement removeTransitData().
*/
virtual void removeTransitData(AcrylicLayer __attribute__((__unused__)) *layer) { }
bool validateAllLayers();
void sortLayers();
AcrylicLayer *getLayer(unsigned int index)
{
return (index < mLayers.size()) ? mLayers[index] : nullptr;
}
void getBackgroundColor(uint16_t *red, uint16_t *green, uint16_t *blue,
uint16_t *alpha)
{
*red = mBackgroundColor.R;
*green = mBackgroundColor.G;
*blue = mBackgroundColor.B;
*alpha = mBackgroundColor.A;
}
bool hasBackgroundColor() { return mHasBackgroundColor; }
uint16_t getMaxTargetDisplayLuminance() { return mMaxTargetLuminance; }
uint16_t getMinTargetDisplayLuminance() { return mMinTargetLuminance; }
void *getTargetDisplayInfo() { return mTargetDisplayInfo; }
private:
std::vector<AcrylicLayer *> mLayers;
const HW2DCapability &mCapability;
struct {
uint16_t R;
uint16_t G;
uint16_t B;
uint16_t A;
} mBackgroundColor;
bool mHasBackgroundColor;
uint16_t mMaxTargetLuminance;
uint16_t mMinTargetLuminance;
void *mTargetDisplayInfo;
AcrylicCanvas mCanvas;
};
struct AcrylicPerformanceRequestLayer {
hw2d_coord_t mSourceDimension;
uint32_t mPixFormat;
hw2d_rect_t mSourceRect;
hw2d_rect_t mTargetRect;
uint32_t mTransform;
uint32_t mAttribute;
};
struct AcrylicPerformanceRequestFrame {
int mNumLayers;
int mNumAllocLayers;
int mFrameRate;
uint32_t mTargetPixFormat;
hw2d_coord_t mTargetDimension;
bool mHasBackgroundLayer;
struct AcrylicPerformanceRequestLayer *mLayers;
AcrylicPerformanceRequestFrame();
~AcrylicPerformanceRequestFrame();
bool reset(int num_layers = 0);
void setSourceDimension(int layer, int width, int height, uint32_t fmt) {
if (layer < mNumLayers) {
mLayers[layer].mSourceDimension.hori = width;
mLayers[layer].mSourceDimension.vert = height;
mLayers[layer].mPixFormat = fmt;
}
}
void setAttribute(int layer, uint32_t attribute) {
if (layer < mNumLayers)
mLayers[layer].mAttribute = attribute;
}
void setTransfer(int layer, hwc_rect_t &src_area, hwc_rect_t &out_area, uint32_t transform) {
if (layer < mNumLayers) {
mLayers[layer].mSourceRect.pos.hori = src_area.left;
mLayers[layer].mSourceRect.pos.vert = src_area.top;
mLayers[layer].mSourceRect.size.hori = src_area.right - src_area.left;
mLayers[layer].mSourceRect.size.vert = src_area.bottom - src_area.top;
mLayers[layer].mTargetRect.pos.hori = out_area.left;
mLayers[layer].mTargetRect.pos.vert = out_area.top;
mLayers[layer].mTargetRect.size.hori = out_area.right - out_area.left;
mLayers[layer].mTargetRect.size.vert = out_area.bottom - out_area.top;
mLayers[layer].mTransform = transform;
}
}
void setTargetDimension(int width, int height, uint32_t fmt, bool bBackground) {
mTargetDimension.hori = width;
mTargetDimension.vert = height;
mTargetPixFormat = fmt;
mHasBackgroundLayer = bBackground;
}
void setFrameRate(int rate) { mFrameRate = rate; }
int getLayerCount() { return mNumLayers; }
};
class AcrylicPerformanceRequest {
public:
AcrylicPerformanceRequest();
~AcrylicPerformanceRequest();
bool reset(int num_frames = 0);
int getFrameCount() { return mNumFrames; }
AcrylicPerformanceRequestFrame *getFrame(int idx) { return (idx < mNumFrames) ? &mFrames[idx] : NULL; }
private:
int mNumFrames;
int mNumAllocFrames;
AcrylicPerformanceRequestFrame *mFrames;
};
#endif /*__HARDWARE_EXYNOS_ACRYLIC_H__*/
|