• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Samsung Electronics Co.,LTD.  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __HARDWARE_EXYNOS_ACRYLIC_H__
18 #define __HARDWARE_EXYNOS_ACRYLIC_H__
19 
20 #include <vector>
21 #include <cstdint>
22 #include <unistd.h>
23 #include <system/graphics.h>
24 #include <hardware/hwcomposer.h>
25 
26 /* basic primitives */
27 
28 #define MAX_HW2D_PLANES 4
29 
30 /*
31  * Structure to express 2-dimensional coordinates.
32  * Invented to pass or to return two values in a single word
33  */
34 typedef struct hw2d_coord {
35     int16_t hori;
36     int16_t vert;
swaphw2d_coord37     void swap()
38     {
39         int16_t tmp = hori;
40         hori = vert;
41         vert = tmp;
42     }
43 } hw2d_coord_t;
44 
45 /*
46  * Structure to express a rectangle in a 2-dimensional grid.
47  * Invented to pass or to return four values in a single 64-bit word
48  */
49 typedef struct hw2d_rect {
50     hw2d_coord_t pos;
51     hw2d_coord_t size;
52 } hw2d_rect_t;
53 
54 /*
55  * Structure to express the capability of HW 2D Accelerators
56  */
57 struct stHW2DCapability {
58     /* maximum magnification with filter applied */
59     hw2d_coord_t max_upsampling_num;
60     /* maximum minification factor with filter applied */
61     hw2d_coord_t max_downsampling_factor;
62     /* maximum maginifcation without filter applied */
63     hw2d_coord_t max_upsizing_num;
64     /* maximum minification factor without filter applied */
65     hw2d_coord_t max_downsizing_factor;
66     /* the smallest source image size the HW can process */
67     hw2d_coord_t min_src_dimension;
68     /* the largest source image size the HW can process */
69     hw2d_coord_t max_src_dimension;
70     /* the smallest output image size the HW can process */
71     hw2d_coord_t min_dst_dimension;
72     /* the largest output image size the HW can process */
73     hw2d_coord_t max_dst_dimension;
74     /*
75      * the restriction of the alignments of the numbers of pixels
76      * in both of horizontal and vertical direction
77      */
78     hw2d_coord_t min_pix_align;
79     /*
80      * The number of repeats of rescaling that the compositor supports. Note
81      * that this is not the capability of the driver and H/W but the capability.
82      * of the compositor(Acrylic).
83      * If the driver and H/W supports rescaling, it is 0. If the compositor is
84      * capable of running the H/W twice to overcome the minification restriction,
85      * it is then 1.
86      */
87     int16_t rescaling_count;
88     /*
89      * the compositing mode that the HW 2D supports.
90      * should be combination of the values of HW2DCapability::blend_ops_t.
91      */
92     uint32_t compositing_mode;
93     /*
94      * the geometric transformation in the 2-dimensional coordinate.
95      * should be combination of the values of HW2DCapability::transform_t.
96      */
97     uint32_t transform_type;
98     /*
99      * the capabilities of HW. The value is the combination of the values of
100      * HW2DCapability::feature_t.
101      */
102     uint32_t auxiliary_feature;
103     /*
104      * the number of color formats supported by HW 2D.
105      * it is also the number of elements in pixformats array.
106      */
107     unsigned int num_formats;
108     /*
109      * the number of color spaces supported by HW 2D.
110      * it is also the number of elements in dataspaces array.
111      */
112     unsigned int num_dataspaces;
113     /*
114      * the number of source images that HW 2D can process.
115      */
116     unsigned int max_layers;
117     /*
118      * the array of color formats that are supported by HW 2D. the values should
119      * be selected from the definitions in <system/graphics.h> and exynos_formats.h.
120      */
121     uint32_t *pixformats;
122     /*
123      * the array of color spaces that are supported by HW 2D. the values should
124      * be selected from the definitions in <system/graphics.h>.
125      */
126     int *dataspaces;
127     /*
128      * the restriction of the alignments of the base addresses of buffers of images.
129      */
130     size_t base_align;
131 };
132 
133 /*
134  * HW2DCapability - Description of the capability of HW 2D.
135  */
136 class HW2DCapability {
137 public:
138     /*
139      * the values to indicate the capabilities of geometric transformations
140      * supported by HW 2D accelerators.
141      */
142     enum transform_t {
143         TRANSFORM_FLIP_H = 1,   /* horizontal flip: (symmetrical displacement by x = -x, y = y) */
144         TRANSFORM_FLIP_V = 2,   /* vertical flip: (symmetrical displacement by x = x, y = -y) */
145         TRANSFORM_FLIP_HV = 3,  /* horizontal flip then vertical flip */
146         TRANSFORM_ROT_90 = 4,   /* clockwise rotation by 90 degree */
147         TRANSFORM_ROT_180 = 8,  /* clockwise rotation by 180 degree */
148         TRANSFORM_ROT_270 = 16, /* clockwise rotation by 270 degree */
149         TRANSFORM_ROT_ALL = 28, /* bitmask to select rotation degrees */
150         TRANSFORM_ALL = 31      /* bitmask to select the correct bits */
151     };
152     /*
153      * the values to indicate the capabilities of layer compositing
154      * supported by HW 2D accelerators.
155      * Sc: Source color, Dc: Destination(background) color,
156      * Sa: Source alpha, Pa: Plane alpha
157      */
158     enum blend_ops_t {
159         BLEND_NONE = 1,     /* Sc * 1 + Dc * 0 */
160         BLEND_SRC_COPY = 2, /* Sc * 1 * Pa + Dc * (1 - Sa) */
161         BLEND_SRC_OVER = 4, /* Sc * Sa * Pa + Dc * (1 - Sa) */
162     };
163 
164     /*
165      * The values to indicate the capabilities of 2D H/W. The capabilities
166      * listed here shows if a function is supported or not.
167      */
168     enum feature_t {
169         FEATURE_PLANE_ALPHA  = 1 << 0,
170         FEATURE_AFBC_ENCODE  = 1 << 4,
171         FEATURE_AFBC_DECODE  = 1 << 5,
172         FEATURE_UORDER_READ  = 1 << 6,
173         FEATURE_UORDER_WRITE = 1 << 7,
174         FEATURE_OTF_READ     = 1 << 8,
175         FEATURE_OTF_WRITE    = 1 << 9,
176         FEATURE_SOLIDCOLOR  = 1 << 10,
177     };
178 
179     enum { RESAMPLING_FRACTION_BITS = 20 };
180 
HW2DCapability(const stHW2DCapability & cap)181     HW2DCapability(const stHW2DCapability &cap): mCap(cap) { }
182 
183     /*
184      * returns the bitmask of supporting flip directions
185      * the returned value is the combination of the values of transform_t.
186      */
supportedFlip()187     transform_t supportedFlip() const { return static_cast<transform_t>(mCap.transform_type & TRANSFORM_FLIP_HV); }
188     /*
189      * returns the bitmask of supporting rotation degrees
190      * the returned value is the combination of the values of transform_t.
191      */
supportedRotation()192     transform_t supportedRotation() const { return static_cast<transform_t>(mCap.transform_type & TRANSFORM_ROT_ALL); }
193     /*
194      * returns the pair of the maximum maginifcation
195      * in the horizontal and vertical direction with filter applied
196      */
supportedMaxMagnification()197     hw2d_coord_t supportedMaxMagnification() const { return mCap.max_upsampling_num;}
198     /*
199      * returns the pair of the maximum minifcation factor
200      * in the horizontal and vertical direction with filter applied
201      */
supportedMinMinification()202     hw2d_coord_t supportedMinMinification() const { return mCap.max_downsampling_factor;}
203     /*
204      * returns the pair of the maximum maginifcation
205      * in the horizontal and vertical direction without filter applied
206      */
supportedMaxEnlarging()207     hw2d_coord_t supportedMaxEnlarging() const { return mCap.max_upsizing_num;}
208     /*
209      * returns the pair of the maximum minifcation factor
210      * in the horizontal and vertical direction without filter applied
211      */
supportedMinDecimation()212     hw2d_coord_t supportedMinDecimation() const { return mCap.max_downsizing_factor;}
213     /*
214      * returns the bitmask of supporting compositing modes
215      * The returned value is the combination of the value sof blend_ops_t.
216      */
supportedCompositingMode()217     uint32_t supportedCompositingMode() const { return mCap.compositing_mode; }
218     /*
219      * returns the alignment restriction of HW 2D in the base memory address.
220      */
supportedBaseAlign()221     size_t supportedBaseAlign() const { return mCap.base_align; }
222     /*
223      * returns the maximum number of horizontal and vertical pixels
224      * of the source images that HW 2D can process
225      */
supportedMaxSrcDimension()226     hw2d_coord_t supportedMaxSrcDimension() const { return mCap.max_src_dimension; }
227     /*
228      * returns the minimum number of horizontal and vertical pixels
229      * of the source images that HW 2D can process
230      */
supportedMinSrcDimension()231     hw2d_coord_t supportedMinSrcDimension() const { return mCap.min_src_dimension; }
232     /*
233      * returns the maximum number of horizontal and vertical pixels
234      * of the output image that HW 2D can process
235      */
supportedMaxDstDimension()236     hw2d_coord_t supportedMaxDstDimension() const { return mCap.max_dst_dimension; }
237     /*
238      * returns the minimum number of horizontal and vertical pixels
239      * of the output image that HW 2D can process
240      */
supportedMinDstDimension()241     hw2d_coord_t supportedMinDstDimension() const { return mCap.min_dst_dimension; }
242     /*
243      * returns the alignment restriction of the number of horizontal
244      * and vertical pixels that HW 2D can process
245      */
supportedDimensionAlign()246     hw2d_coord_t supportedDimensionAlign() const { return mCap.min_pix_align; }
247     /*
248      * returns the number of source images that HW 2D can composit
249      */
maxLayerCount()250     unsigned int maxLayerCount() const { return mCap.max_layers; }
251     /*
252      * study if the given format is supported by the HW 2D
253      */
isFormatSupported(uint32_t fmt)254     bool isFormatSupported(uint32_t fmt) const {
255         for (unsigned int i = 0; i < mCap.num_formats; i++)
256             if (mCap.pixformats[i] == fmt)
257                 return true;
258         return false;
259     }
260     /*
261      * study if the given colorspace is supported by HW 2D
262      */
isDataspaceSupported(int dataspace)263     bool isDataspaceSupported(int dataspace) const {
264         // discard transfer function information because it is required during display
265         dataspace &= ~HAL_DATASPACE_TRANSFER_MASK;
266 
267         for (unsigned int i = 0; i < mCap.num_dataspaces; i++)
268             if (mCap.dataspaces[i] == dataspace)
269                 return true;
270         return false;
271     }
272     /*
273      * convert the transformation mask in transform_type into the values
274      * that Android Graphics HAL understands.
275      */
getHWCTransformMask()276     uint32_t getHWCTransformMask() const {
277         uint32_t mask = 0;
278         if (mCap.transform_type & TRANSFORM_FLIP_H)
279             mask |= HAL_TRANSFORM_FLIP_H;
280         if (mCap.transform_type & TRANSFORM_FLIP_V)
281             mask |= HAL_TRANSFORM_FLIP_V;
282         if (mCap.transform_type & TRANSFORM_ROT_90)
283             mask |= HAL_TRANSFORM_ROT_90;
284         if (mCap.transform_type & TRANSFORM_ROT_180)
285             mask |= HAL_TRANSFORM_ROT_180;
286         if (mCap.transform_type & TRANSFORM_ROT_270)
287             mask |= HAL_TRANSFORM_ROT_270;
288         return mask;
289     }
290     /*
291      * discover if the given feature that is defined in feature_t is supported.
292      */
isFeatureSupported(uint32_t feature)293     bool isFeatureSupported(uint32_t feature) const { return !!(mCap.auxiliary_feature & feature); }
294     /*
295      * study if the given horizontal resolution change from @from into @to is
296      * supported by HW 2D
297      */
298     bool supportedHResampling(int16_t from, int16_t to, int16_t resamping_count = 1) const
299     {
300         return supportedResampling(from, to,
301                                    mCap.max_upsampling_num.hori * resamping_count,
302                                    mCap.max_downsampling_factor.hori * resamping_count);
303     }
304     /*
305      * study if the given vertical resolution change from @from into @to is
306      * supported by HW 2D
307      */
308     bool supportedVResampling(int16_t from, int16_t to, int16_t resamping_count = 1) const
309     {
310         return supportedResampling(from, to,
311                                    mCap.max_upsampling_num.vert * resamping_count,
312                                    mCap.max_downsampling_factor.vert * resamping_count);
313     }
314     /*
315      * study if the given resampling from @from to @to is supported by HW 2D compositor
316      * implementation.
317      */
supportedResampling(hw2d_coord_t from,hw2d_coord_t to,uint32_t transform)318     bool supportedResampling(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
319     {
320         int count = supportedRescalingCount();
321 
322         if (!!(transform & HAL_TRANSFORM_ROT_90))
323             to.swap();
324 
325         return supportedHResampling(from.hori, to.hori, count) &&
326                supportedVResampling(from.vert, to.vert, count);
327     }
328     /*
329      * study if the given resampling from @from to @to is supported by HW 2D
330      */
supportedHWResampling(hw2d_coord_t from,hw2d_coord_t to,uint32_t transform)331     bool supportedHWResampling(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
332     {
333         if (!!(transform & HAL_TRANSFORM_ROT_90))
334             to.swap();
335 
336         return supportedHResampling(from.hori, to.hori, 1) &&
337                supportedVResampling(from.vert, to.vert, 1);
338     }
339     /*
340      * study if the given number of horizontal pixels (@from) can be changed
341      * to @to by HW 2D
342      */
supportedHResizing(int16_t from,int16_t to)343     bool supportedHResizing(int16_t from, int16_t to) const
344     {
345         return supportedResizing(from, to,
346                 mCap.max_upsizing_num.hori, mCap.max_downsizing_factor.hori);
347     }
348     /*
349      * study if the given number of vertical pixels (@from) can be changed
350      * to @to by HW 2D
351      */
supportedVResizing(int16_t from,int16_t to)352     bool supportedVResizing(int16_t from, int16_t to) const
353     {
354         return supportedResizing(from, to,
355                 mCap.max_upsizing_num.vert, mCap.max_downsizing_factor.vert);
356     }
357     /*
358      * study if the given resizing from @from to @to is supported by HW 2D compositor
359      * implementation.
360      */
supportedResizing(hw2d_coord_t from,hw2d_coord_t to,uint32_t transform)361     bool supportedResizing(hw2d_coord_t from, hw2d_coord_t to, uint32_t transform) const
362     {
363         if (!!(transform & HAL_TRANSFORM_ROT_90))
364             to.swap();
365 
366         return supportedHResizing(from.hori, to.hori) && supportedVResizing(from.vert, to.vert);
367     }
368     /*
369      * study the number rescaling by the compositor for a layer
370      * 1 if the compositor does not repeat the scaling. 2 if the compositor
371      * repeat the scaling once.
372      * Note that the return value of supportedRescalingCount() is the one
373      * incremented from the struct stHW2DCapability.rescaling_count.
374      */
supportedRescalingCount()375     int supportedRescalingCount() const
376     {
377         return mCap.rescaling_count + 1;
378     }
379 private:
supportedResampling(int16_t from,int16_t to,int16_t upfactor,int16_t downfactor)380     bool supportedResampling(int16_t from, int16_t to, int16_t upfactor, int16_t downfactor) const
381     {
382         int64_t factor = static_cast<int64_t>(from);
383 
384         factor <<= RESAMPLING_FRACTION_BITS;
385         factor /= to;
386 
387         if (factor > (static_cast<int64_t>(downfactor) << RESAMPLING_FRACTION_BITS))
388             return false;
389 
390         // @upfactor is a reciprocal number of an upsampling factor
391         if (factor < ((1 << RESAMPLING_FRACTION_BITS) / static_cast<int64_t>(upfactor)))
392             return false;
393 
394         return true;
395     }
396 
supportedResizing(int16_t from,int16_t to,int16_t upfactor,int16_t downfactor)397     bool supportedResizing(int16_t from, int16_t to, int16_t upfactor, int16_t downfactor) const
398     {
399         if ((from < to) && (upfactor == 0))
400             return true;
401 
402         if ((from > to) && (downfactor == 0))
403             return true;
404 
405         return supportedResampling(from, to, upfactor, downfactor);
406     }
407     const stHW2DCapability &mCap;
408 };
409 
410 class Acrylic;
411 
412 /*
413  * AcrylicCanvas - Description of an image and its buffers
414  *
415  * It includes the entire image area and how the image is stored in the memory,
416  * where it is stored and the buffer synchronization objects called Fence.
417  * AcrylicCanvas contains the following attributes:
418  * - image dimension: number of horizontal and vertical pixels
419  * - color format of the image
420  * - colorspace of the image
421  * - the identifiers of the image buffers (userptr or dmabuf)
422  *
423  * Creation of AcrylicCanvas by new operator is prohibited. The only way to
424  * create an instance of AcrylicCavans is to call Acrylic::createLayer().
425  */
426 class AcrylicCanvas {
427     friend class Acrylic;
428 public:
429     /*
430      * The attributes of the image described by AcrylicCanvas:
431      * The attributes are bit masks and therefore combination of them may be
432      * also required.
433      * - ATTR_NONE: indicates no special attributes are specified
434      * - ATTR_PROTECTED: the buffer of the image is protected.  Reading or
435      *                   writing to the buffer of the image is prohibited.
436      * - ATTR_COMPRESSED: the image is or is to be stored in a compressed form.
437      *                    e.g. AFBC
438      * - ATTR_UORDER: the image data is written in U-order instead of raster-scan order.
439      *                U-order memory access by GPU helps the BUS efficiency.
440      * - ATTR_OTF: The image buffer is hard-wired. If this attribute is given, libacryl
441      *             ignores the buffer configuration to the canvas.
442      * - ATTR_SOLIDCOLOR : The image buffer is empty and should be filled with one RGBA value by H/W.
443      */
444     enum layer_attr_t {
445         ATTR_NONE = 0,
446         ATTR_PROTECTED = 1,
447         ATTR_COMPRESSED = 2,
448         ATTR_UORDER = 4,
449         ATTR_OTF = 8,
450         ATTR_SOLIDCOLOR = 16,
451         ATTR_COMPRESSED_WIDEBLK = 32,
452         ATTR_ALL_MASK = 0x3F
453     };
454     /*
455      * Describes how the buffer of the image is identified.
456      * - MT_DMABUF: the buffer is identified by an open file descriptor that is
457      *              exported by dmabuf.
458      * - MT_USERPTR: the buffer is identified by a memory address that is valid
459      *               in the current process. Usally it is a bug if mAttributes
460      *               has ATTR_PROTECTED whlie mMemoryType is MT_USERPTR.
461      * - MT_EMTPY : the buffer is empty such as hare-wired buffer or colorfill layer.
462      */
463     enum memory_type { MT_DMABUF = 1, MT_USERPTR = 2, MT_EMPTY = 3 };
464     /*
465      * Indicates the configured or modified settings
466      * - SETTING_TYPE: Image format and color space information is configured by users.
467      * - SETTING_BUFFER: Image buffer information is configured by users.
468      * - SETTING_DIMENSION: Image dimension information is configured by users.
469      * - SETTING_TYPE_MODIFIED: Image format and color space information is configured
470      *                          by users and it is not applied to HW yet.
471      * - SETTING_BUFFER_MODIFIED: Image buffer information is configured by users and
472      *                            it is not applied to HW yet.
473      * - SETTING_DIMENSION_MODIFIED: Image dimension information is configured by users
474      *                               and it is not applied to HW yet.
475      */
476     enum setting_check_t {
477         SETTING_TYPE = 1,
478         SETTING_BUFFER = 2,
479         SETTING_DIMENSION = 4,
480         SETTING_MASK = SETTING_TYPE | SETTING_BUFFER | SETTING_DIMENSION,
481         SETTING_TYPE_MODIFIED = 16,
482         SETTING_BUFFER_MODIFIED = 32,
483         SETTING_DIMENSION_MODIFIED = 64,
484         SETTIMG_MODIFIED_MASK = SETTING_TYPE_MODIFIED | SETTING_BUFFER_MODIFIED | SETTING_DIMENSION_MODIFIED,
485     };
486 
487     /*
488      * MEMBER FUNCTIONS FOR THE USERS
489      */
490 
491     /*
492      * Configure the dimension of the image
493      */
494     virtual bool setImageDimension(int32_t width, int32_t height);
495     /*
496      * Find the dimension of the image configured to AcyrilicCanvas
497      */
getImageDimension()498     hw2d_coord_t getImageDimension() { return mImageDimension; }
499     /*
500      * Configure the image color format and color space
501      * You should configure the correct colorspace if you want to change the
502      * the image is YCbCr and the target image is RGB because the brightness
503      * of the pixel data encoded in YCbCr is generated from various colorspaces
504      * including BT.601, BT.709(sRGB) and BT.2020. If the YCbCr image is a frame
505      * of a moving picture, we should likely consider the 1/16 headroom and
506      * footroom. Generally BT.601, BT.709 and BT.2020 have footroom and headroom
507      * while JFIF(JPEG, SRGB) does not have.
508      */
509     bool setImageType(uint32_t fmt, int dataspace);
510     /*
511      * Configure color fill layer that fill only one RGBA color without actual buffer.
512      * Note that this successes if the compositor supports FEATURE_SOLIDCOLOR.
513      */
514     bool setImageBuffer(int a, int r, int g, int b, uint32_t attr = ATTR_NONE);
515     /*
516      * Configure the image buffer of dmabuf type.
517      */
518     bool setImageBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], off_t offset[MAX_HW2D_PLANES],
519                         int num_buffers, int fence = -1, uint32_t attr = ATTR_NONE);
520     /*
521      * Configure the image buffer of dmabuf type.
522      * This does not receives a parameter 'offset' compared to the above
523      * setImageBuffer(). The latter type of setImageBuffer() is provided to
524      * provide convenience to the users because offsets are mostly zero.
525      */
526     bool setImageBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], int num_buffers,
527                         int fence = -1, uint32_t attr = ATTR_NONE)
528     {
529         off_t offset[MAX_HW2D_PLANES] = {0, 0, 0};
530         return setImageBuffer(fd, len, offset, num_buffers, fence, attr);
531     }
532     /*
533      * Configure the image buffer of userptr type.
534      * Note that you cannot pass a fence if the buffer type is userptr because
535      * userptr buffer is not shareable between processes and devices.
536      */
537     bool setImageBuffer(void *addr[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES],
538                         int num_buffers, uint32_t attr = ATTR_NONE);
539     /*
540      * Configure the image buffer is hard-wired which means that the buffer is always
541      * prepared in the compositor H/W.
542      * Note that this successes if the compositor supports FEATURE_OTF_READ or FEATURE_OTF_WRITE.
543      */
544     bool setImageOTFBuffer(uint32_t attr = AcrylicCanvas::ATTR_NONE);
545     /*
546      * Configure the fence. setFence() overwrites the fence specified by
547      * setImageBuffer().
548      */
549     void setFence(int fence);
550     /*
551      * Called by the implementations of Acyrlic to determine if all required
552      * configurations are completed.
553      */
isSettingOkay()554     bool isSettingOkay()
555     {
556         return (mSettingFlags & SETTING_MASK) == (SETTING_TYPE | SETTING_BUFFER | SETTING_DIMENSION);
557     }
558 
559     /*
560      * MEMBER FUNCTIONS FOR THE IMPLEMENTATIONS of Acrylic
561      */
562 
563     /*
564      * Determine if the buffer is protected. If the buffer or the image is
565      * protected, the driver of HW 2D should specially care the buffer and the
566      * processing involving the buffer.
567      */
isProtected()568     bool isProtected() { return !!(mAttributes & ATTR_PROTECTED); }
569     /*
570      * Determine if the image in the buffer is or should be in a compressed form.
571      */
isCompressed()572     bool isCompressed() { return !!(mAttributes & ATTR_COMPRESSED); }
573 
574     /*Check if the AFBC 32x8 format size is being used*/
isCompressedWideblk()575     bool isCompressedWideblk() { return !!(mAttributes & ATTR_COMPRESSED_WIDEBLK); }
576 
577     /*
578      * Study if the image is or should be written in U-Order for accelerated
579      * graphic processing instead of raster-scan order.
580      */
isUOrder()581     bool isUOrder() { return !!(mAttributes & ATTR_UORDER); }
582     /*
583      * Study if the canvas buffer is hard-wired.
584      */
isOTF()585     bool isOTF() { return !!(mAttributes & ATTR_OTF); }
586     /*
587      * Study if the image is filled with solid color.
588      */
isSolidColor()589     bool isSolidColor() { return !!(mAttributes & ATTR_SOLIDCOLOR); }
590     /*
591      * Obtain the acquire fence of the buffer.
592      */
getFence()593     int getFence() const { return mFence; }
594     /*
595      * Invalidate the confgured acquire fence without destryoing(close()) it
596      */
clearFence()597     void clearFence() { mFence = -1; }
598     /*
599      * Obtain the image color format
600      */
getFormat()601     uint32_t getFormat() { return mPixFormat; }
602     /*
603      * Obtain the color space information
604      */
getDataspace()605     int getDataspace() { return mDataSpace; }
606     /*
607      * Obtain the buffer type whether the buffer is MT_USERPTR or MT_DMABUF
608      */
getBufferType()609     memory_type getBufferType() { return mMemoryType; }
610     /*
611      * Obtain the number of buffers.
612      * The parameter 'index' of the following member functions including
613      * getDmabuf(), getUserptr(), getOffset(), getBufferLength() should be
614      * smaller than the return value of getBufferCount(). Otherwise, you will
615      * get invalid memory area referenced.
616      */
getBufferCount()617     unsigned int getBufferCount() { return mNumBuffers; }
618     /*
619      * Obtain the open file descriptor exported by dmabuf if the buffer type is
620      * MT_DMABUF
621      */
getDmabuf(unsigned int index)622     int getDmabuf(unsigned int index)
623     {
624         return (mMemoryType == MT_DMABUF) ? m.mBufferFd[index] : -1;
625     }
626     /*
627      * Obtain the buffer address if the buffer type is MT_USERPTR
628      */
getUserptr(unsigned int index)629     void *getUserptr(unsigned int index)
630     {
631         return (mMemoryType == MT_USERPTR) ? m.mBufferAddr[index] : NULL;
632     }
633     /*
634      * Obtain the offset where the image is stored in the buffer if the buffer
635      * type is MT_DMABUF
636      */
getOffset(unsigned int index)637     uint32_t getOffset(unsigned int index)
638     {
639         return (mMemoryType == MT_DMABUF) ? mBufferOffset[index] : 0;
640     }
641     /*
642      * Obtain the length of the buffer
643      */
getBufferLength(unsigned int index)644     uint32_t getBufferLength(unsigned int index)
645     {
646         return mBufferLength[index];
647     }
648     /*
649      * Clear all modified states. It is called by the Acrylic implementations after
650      * they executes their HWs
651      */
clearSettingModified()652     void clearSettingModified()
653     {
654         unset(SETTING_TYPE_MODIFIED |
655               SETTING_BUFFER_MODIFIED |
656               SETTING_DIMENSION_MODIFIED);
657     }
658     /*
659      * Obtain the flags that indicates the configuration status
660      */
getSettingFlags()661     uint32_t getSettingFlags() { return mSettingFlags; }
662     /*
663      * Obtain the solid color combined by 8bit of A, R, G, B
664      */
getSolidColor()665     uint32_t getSolidColor() { return mSolidColor; }
666 protected:
667     enum canvas_type_t {
668         CANVAS_SOURCE,
669         CANVAS_TARGET,
670     };
671 
672     Acrylic *mCompositor;
673 
674     AcrylicCanvas(Acrylic *compositor, canvas_type_t type = CANVAS_SOURCE);
675     virtual ~AcrylicCanvas();
676 
getCompositor()677     Acrylic *getCompositor() { return mCompositor; }
678 
unset(uint32_t flag)679     void unset(uint32_t flag) { mSettingFlags &= ~flag; }
set(uint32_t flag)680     void set(uint32_t flag) { mSettingFlags |= flag; }
681 private:
682     /*
683      * called when Acrylic is being destroyed to inform AcrylicCanvas
684      * that no Acrylic has a reference to it.
685      */
disconnectLayer()686     void disconnectLayer() { mCompositor = NULL; }
687 
688     hw2d_coord_t mImageDimension;
689     uint32_t mPixFormat;
690     int mDataSpace;
691     memory_type mMemoryType;
692     union {
693         void *mBufferAddr[MAX_HW2D_PLANES];
694         int mBufferFd[MAX_HW2D_PLANES];
695     } m;
696     size_t mBufferLength[MAX_HW2D_PLANES];
697     uint32_t mBufferOffset[MAX_HW2D_PLANES];
698     int mNumBuffers;
699     int mFence; // NOTE: this should be reset to -1 after Acrylic::execute()
700     uint32_t mAttributes;
701     uint32_t mSettingFlags;
702     uint32_t mSolidColor; // [32:0] ARGB order.
703     canvas_type_t mCanvasType;
704 };
705 
706 /*
707  * AcrylicLayer - Description of compositing properties
708  *                as well as an image and its buffers
709  *
710  * AcrylicLayer extends the properties of AcrylicCanvas for compositing purpose.
711  * It adds the following propertes to AcrylicCanvas:
712  * - The rectangle region of interest in the image. It is usually called 'crop'
713  * - The rectangle region to map the crop area in the target dimension. It is
714  *   usually called 'window'. If the width or the height of the window is
715  *   different from crop, resampling or resizing is invloved.
716  * - How the input images are composited. Currently Acrylic supports only the
717  *   following opertions:
718  *   .HWC_BLENDING_NONE:    The alpha channel in the image should be ignored
719  *   .HWC_BLENDING_PREMULT: The color brightness values are regardted as they
720  *                          are multiplied with its alpha channel value
721  *   .HWC_BLENDING_COVERAGE: The alpha value of each pixel is multiplied with
722  *                           the brighness of each pixel during compositing.
723  * - How to transfrom the image into window: flip, rotation
724  * - The order of input images to be stacked on the background
725  * - The transparent level of the image. It is multiplied to every pixel
726  *   brightness values when compositing. The transparent level of the entire
727  *   image is also called 'plane alpha' or 'global alpha'.
728  *
729  * The default properties are:
730  * - mImageRect: the entire image dimension.
731  * - mTargetRect: the entire target dimension
732  * - mBlendingMode: HWC_BLENDING_NONE
733  * - mTransform: 0 (no flip, no rotation)
734  * - mZOrder: 0
735  * - mPlaneAlpha: 1.0(255)
736  *
737  * Creation of AcrylicLayer by new operator is prohibited. The only way to
738  * create an instance of AcrylicLayer is to call Acrylic::createLayer().
739  */
740 class AcrylicLayer: public AcrylicCanvas {
741     friend class Acrylic;
742 public:
743     /*
744      * The various/special attributes to the source images
745      * - ATTR_NORESAMPLING: Force resize the image speicifed to the layer even
746      *                      though the target image size is too small to apply
747      *                      the interpolation filter correctly.
748      */
749     enum composit_attr_t { ATTR_NORESAMPLING = 1, ATTR_ALL_MASK = 1};
750 
751     virtual ~AcrylicLayer();
752 
753     /*
754      * MEMBER FUNCTIONS FOR THE USERS
755      */
756 
757     /*
758      * Configure the compositing mode including the compositing operations,
759      * plane alpha and z-order
760      */
761     bool setCompositMode(uint32_t mode, uint8_t alpha = 0xFF, int z_order = 0);
762     /*
763      * Configure the crop, window, transformation and special compositing attributes.
764      */
765     bool setCompositArea(hwc_rect_t &src_area, hwc_rect_t &out_area, uint32_t transform = 0, uint32_t attr = 0);
766     /*
767      * Configure the crop and transformation information. The window rect is
768      * is regarded as the entire target dimension.
769      */
770     bool setCompositArea(hwc_rect_t &src_area, uint32_t transform = 0, uint32_t attr = 0)
771     {
772         hwc_rect_t out_area = {0, 0, 0, 0};
773         return setCompositArea(src_area, out_area, transform, attr);
774     }
775     /*
776      * Configure the dimension of the image. This function overrides
777      * AcrylicCanvas::setImageDimension(). Once this function is called, the
778      * crop rect, mImageRect reset to the entire image dimension configured
779      * by this function. Note that the window, mTargetRect is not reset because
780      * it is not dependent upon the image dimension.
781      */
782     virtual bool setImageDimension(int32_t width, int32_t height);
783     /*
784      * Configure the source image area(crop) with the target rect and transform
785      * untouched while setCompositArea() modifies source rect, target rect and
786      * transform with the given arguments.
787      */
setImageRect(hwc_rect_t & src_area)788     bool setImageRect(hwc_rect_t &src_area)
789     {
790         hwc_rect_t out_area = {
791             mTargetRect.pos.hori,
792             mTargetRect.pos.vert,
793             mTargetRect.pos.hori + mTargetRect.size.hori,
794             mTargetRect.pos.vert + mTargetRect.size.vert
795         };
796         return setCompositArea(src_area, out_area, mTransform);
797     }
798     /*
799      * Configure the minimum liminance and the maximum luminance of the display
800      * used in the HDR video mastering environment. It is spepcified in the
801      * metatata of the HDR video contents.
802      * @min: minimum luminance in 0.0001 cd/m^2 unit
803      * @max: maximum luminance in 1 cd/m^2 unit
804      *
805      * The followings are the default values:
806      * @min: 0
807      * @max: 100 (SDR)
808      *
809      * NOTE:
810      * The configured video is treated as SDR until setMasterDisplayLuminance()
811      * is called. It means that the target image is to be SDR.
812      */
813     void setMasterDisplayLuminance(uint16_t min, uint16_t max);
814 
815     /*
816      * Configure an opaque data associated to a layer
817      * @data: pointer to data associated to this layer
818      * @data_len: number of effective bytes pointed by @data
819      *
820      * The configured data is opaque to libacryl. It should be handled by the
821      * implementations. How to specify and how to understand the data is just
822      * contract between the user of a specific implementation and the implemtation.
823      * The configured data is effective until the data is cleared by invoking
824      * clearLayerData().
825      * The second argument @data_lan can be used for checking the contract. The
826      * implementation and the users should decide the data structure delivered by
827      * setLayerData(). If the data structure has fixed length, the implementation
828      * can determine if the delivered data is correctly configured with comparing
829      * @data_len and the expected size.
830      */
setLayerData(void * data,size_t data_len)831     void setLayerData(void *data, size_t data_len) {
832         mLayerData = data;
833         mLayerDataLen = data_len;
834     }
835 
setLayerHDR(bool hdr_en)836     void setLayerHDR(bool hdr_en) { mLayerHDR = hdr_en; }
837 
838     /*
839      * Clears the configured layer data.
840      */
clearLayerData()841     void clearLayerData() {
842         mLayerData = nullptr;
843         mLayerDataLen = 0;
844     }
845 
846     /*
847      * MEMBER FUNCTIONS FOR THE IMPLEMENTATIONS of Acrylic
848      */
849     /*
850      * Optain the configured compositing mode
851      */
getCompositingMode()852     uint32_t getCompositingMode() { return mBlendingMode; }
853     /*
854      * Obtain the z-order of the layer
855      */
getZOrder()856     int32_t getZOrder() { return mZOrder; }
857     /*
858      * Obtain the plane alpha value of the layer
859      */
getPlaneAlpha()860     uint8_t getPlaneAlpha() { return mPlaneAlpha; }
861     /*
862      * Obtain the crop region of the layer
863      */
getImageRect()864     hw2d_rect_t getImageRect() { return mImageRect; }
865     /*
866      * Obtain the window region onto the background. If all four values are
867      * zero, the window region should be regarded as the entire background
868      * dimension.
869      */
getTargetRect()870     hw2d_rect_t getTargetRect() { return mTargetRect; }
871     /*
872      * Obtain the transform property of the layer
873      */
getTransform()874     uint32_t getTransform() { return mTransform; }
875     /*
876      * Obtain the special compositing attribute flags
877      */
getCompositAttr()878     uint32_t getCompositAttr() { return mCompositAttr; }
879     /*
880      * Obtain the minimum luminance of the display of the mastering environment
881      * of the video layer in the unit of 0.0001 cd/m^2.
882      */
getMinMasteringLuminance()883     uint16_t getMinMasteringLuminance() { return mMinLuminance; }
884     /*
885      * Obtain the maximum luminance of the display of the mastering environment
886      * of the video layer in the unit of 1 cd/m^2.
887      */
getMaxMasteringLuminance()888     uint16_t getMaxMasteringLuminance() { return mMaxLuminance; }
889     /*
890      * Copy the contents of @layer into the callee instance.
891      * Note that the file descriptors of @layer are not duplicated. The caller
892      * should care about that. Note also that importLayer() invalidates the
893      * acquire fence of @layer because it is transferred to the callee.
894      */
895     void importLayer(AcrylicLayer &layer, bool inherit_transform);
896     /*
897      * Store the given transit data to the instance. It is generated by the
898      * implementations of Acrylic class.
899      */
storeTransit(void * transitData)900     void storeTransit(void *transitData) { mTransitData = transitData; }
901     /*
902      * Retrieve the transit data from the instance.
903      */
getTransit()904     void *getTransit() { return mTransitData; }
905     /*
906      * Retrieve the layer opaque data.
907      */
getLayerData()908     void *getLayerData() { return mLayerData; }
getLayerDataLength()909     size_t getLayerDataLength() { return mLayerDataLen; }
910 
getLayerHDR()911     bool getLayerHDR() { return mLayerHDR; }
912 
913 private:
914     AcrylicLayer(Acrylic *compositor);
915 
916     void *mTransitData;
917     void *mLayerData;
918     size_t mLayerDataLen;
919     hw2d_rect_t mImageRect;
920     hw2d_rect_t mTargetRect;
921     uint32_t mBlendingMode;
922     uint32_t mTransform;
923     int32_t mZOrder;
924     uint32_t mCompositAttr;
925     uint16_t mMaxLuminance; // in nit
926     uint16_t mMinLuminance; // in 0.0001 nit
927     uint8_t mPlaneAlpha;
928     bool mLayerHDR;
929 };
930 
931 class AcrylicPerformanceRequest;
932 
933 /*
934  * DEPRECATED:
935  * AcrylicFactory works as it did for now but it will be removed in the future
936  * because new factory methods to create an instance of Acrylic is introduced:
937  * use the followings instead of AcrylicFactory:
938  * - Acrylic::createInstance() for a specific Acrylic backend
939  * - Acrylic::createCompositor() to create the "default_compositor"
940  * - Acrylic::createScaler() to create the "default_scaler"
941  *
942  * AcrylicFactory - The creator of Acrylic
943  *
944  * Users are prohibited to create an instance of Acrylic because the does not
945  * have enough knowledge how to create. Instead, users should ask the factory
946  * to create an instance of Acrylic with a special 'name'(spec) to identify a
947  * specific HW 2D.
948  */
949 class AcrylicFactory {
950 public:
AcrylicFactory()951     AcrylicFactory() { };
~AcrylicFactory()952     ~AcrylicFactory() { };
953     /*
954      * Creator of Acrylic instance
955      */
956     static Acrylic *createAcrylic(const char *spec);
957 };
958 
959 /*
960  * Acrylic - The type of the object for 2D compositing with HW 2D
961  *
962  * Acrylic executes HW 2D with the image information specified on AcrylicLayers
963  * and AcrylicCanvas that are created by Acrylic.
964  * To create an instance of Acrylic, you should use AcrylicFactory.
965  */
966 class Acrylic {
967 public:
968     /*
969      * Factory methods of an instance of Acrylic subclasses
970      * createInstance() - create the instance exactly specified by @spec
971      * createCompositor() - create an instance of HW 2D compositor defined in board definition
972      * createScaler() - create an instance of image post processor defined in board definition
973      * createBlter() - create an instance of H/W accelerator of bit block transfer defined in board definition
974      */
975     static Acrylic *createInstance(const char *spec);
976     static Acrylic *createCompositor();
977     static Acrylic *createScaler();
978     static Acrylic *createBlter();
979 
980     Acrylic(const HW2DCapability &capability);
981     virtual ~Acrylic();
982     /*
983      * Create a new instance of AcrylicLayer. If the number of created
984      * AcrylicLayer is already mCapability.maxLayerCount(), createLayer()
985      * fails.
986      * The caller of createLayer() should destroy the instance of AcrylicLayer
987      * by itself. The instance of AcrylicLayer is only available while the
988      * Acrylic that created it lives. If the Acrylic that created AcrylicLayer
989      * has been destroyed, all configuration to AcrylicLayer have no effect.
990      */
991     AcrylicLayer *createLayer();
992     /*
993      * Obtain HW2DCapability object to study the capability fo HW 2D that the
994      * Acrylic handles.
995      */
getCapabilities()996     const HW2DCapability &getCapabilities() { return mCapability; }
997     /*
998      * Configure the image dimension of the background. The background image
999      * is not the input image with the lowest z-order but the target image in
1000      * this context.
1001      */
setCanvasDimension(int32_t width,int32_t height)1002     bool setCanvasDimension(int32_t width, int32_t height)
1003     {
1004         return mCanvas.setImageDimension(width, height);
1005     }
1006     /*
1007      * Configure the image color format and the address space of the target image
1008      */
setCanvasImageType(uint32_t fmt,int dataspace)1009     bool setCanvasImageType(uint32_t fmt, int dataspace)
1010     {
1011         return mCanvas.setImageType(fmt, dataspace);
1012     }
1013     /*
1014      * Configure the buffers where to write the result (target) image. The
1015      * identifier of the buffer is a open file descriptor exported by dmabuf.
1016      * Users can also configure if the result image is in the compressed form
1017      * or to be protected from access by non-previliged users.
1018      */
1019     bool setCanvasBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], off_t offset[MAX_HW2D_PLANES],
1020                          int num_buffers, int fence = -1, uint32_t attr = AcrylicCanvas::ATTR_NONE)
1021     {
1022         return mCanvas.setImageBuffer(fd, len, offset, num_buffers, fence, attr);
1023     }
1024     /*
1025      * Configure the buffers where to write the result (target) image.
1026      * This version ov setCanvasBuffer() is the same as the above version except
1027      * that this version does not require @offset as its argument.
1028      */
1029     bool setCanvasBuffer(int fd[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES], int num_buffers,
1030                          int fence = -1, uint32_t attr = AcrylicCanvas::ATTR_NONE)
1031     {
1032         return mCanvas.setImageBuffer(fd, len, num_buffers, fence, attr);
1033     }
1034     /*
1035      * Configure the buffers where to write the result (target) image. The
1036      * identifier of the buffer is a valid memory address in the address space
1037      * of the caller. AcrylicCanvas::ATTR_PROTECTED to @attr is not allowed
1038      * because userptr buffer should not be protected.
1039      */
1040     bool setCanvasBuffer(void *addr[MAX_HW2D_PLANES], size_t len[MAX_HW2D_PLANES],
1041                          int num_buffers, uint32_t attr = AcrylicCanvas::ATTR_NONE)
1042     {
1043         return mCanvas.setImageBuffer(addr, len, num_buffers, attr);
1044     }
1045     /*
1046      * Configure the target buffers as hard-wired.
1047      */
1048     bool setCanvasOTF(uint32_t attr = AcrylicCanvas::ATTR_NONE)
1049     {
1050         return mCanvas.setImageOTFBuffer(attr);
1051     }
1052     /*
1053      * Configure the default background color and the opacity. It is effecitve
1054      * when the source images are not opaque or the source images does not fill
1055      * the entire target image buffer.
1056      * Configuring the default color makes the result image more deterministic.
1057      * NOTE that the value(brightness) of each color components and the opacity
1058      * are 16-bit wide. If your system supports 8-bit brightness, you should
1059      * shift the brightness value to the left in the amount of 8 bits. Again,
1060      * you should multiply the value of each color components and the opacity
1061      * with 256 (2^8) if your color system supports 8-bit brightness levels.
1062      */
setDefaultColor(uint16_t red,uint16_t green,uint16_t blue,uint16_t alpha)1063     void setDefaultColor(uint16_t red, uint16_t green, uint16_t blue, uint16_t alpha)
1064     {
1065         mBackgroundColor.R = red;
1066         mBackgroundColor.G = green;
1067         mBackgroundColor.B = blue;
1068         mBackgroundColor.A = alpha;
1069         mHasBackgroundColor = true;
1070     }
1071     /*
1072      * Cancel the configured default color values.
1073      */
clearDefaultColor()1074     void clearDefaultColor()
1075     {
1076         mHasBackgroundColor = false;
1077     }
1078     /*
1079      * Configures cofficients the tone mapper if the user of Acrylic wants to
1080      * overrides the default coefficients of the tone mapper for HDR display.
1081      * The coefficients are a two dimensional array of coefficients of x-axis
1082      * and y-axis. If no coefficient is configured, the default function of the
1083      * implemntation of Acrylic is used. It may be ether of gamma 2.2 for SDR,
1084      * gamma 2.6 for HDR.
1085      * The configured coefficients are not enabled if no layer has HDR video
1086      * because HDR processing is not enabled.
1087      */
1088     virtual bool setHDRToneMapCoefficients(uint32_t *matrix[2], int num_elements);
1089     /*
1090      * Configure the minimum luminance and the maximum luminance of the target
1091      * display.
1092      * @min: minimum luminance in 0.0001 cd/m^2 unit
1093      * @max: maximum luminance in 1 cd/m^2 unit
1094      *
1095      * The following sare the default values:
1096      * @min: 0
1097      * @max 100 (SDR)
1098      *
1099      * NOTE:
1100      * How to handle the target display luminance depends on the implementation
1101      * of Acrylic. An implementation does not refer to the configured target
1102      * display luminance while another implementation may us the taret display
1103      * luminance to choose its HDR conversion logic.
1104      */
setTargetDisplayLuminance(uint16_t min,uint16_t max)1105     inline void setTargetDisplayLuminance(uint16_t min, uint16_t max)
1106     {
1107         mMaxTargetLuminance = max;
1108         mMinTargetLuminance = min;
1109     }
1110     /*
1111      * Configure information of target display device.
1112      */
setTargetDisplayInfo(void * data)1113     inline void setTargetDisplayInfo(void *data)
1114     {
1115         mTargetDisplayInfo = data;
1116     }
1117     /*
1118      * Run HW 2D. If @fence is not NULL and num_fences is not zero, execute()
1119      * fills the release fences to the array of @fence. The number of fences
1120      * filled by execute() is min(num_fences, mLayers.size()). If num_fences is
1121      * larger than mLayers.size(), execute() fills -1 to the rest of the elements
1122      * of @fence.
1123      * execute() returns before HW 2D completes the processing, of course.
1124      */
1125     virtual bool execute(int fence[], unsigned int num_fences) = 0;
1126     /*
1127      * Run HW 2D. This version of execute() does not provides release fences.
1128      * If @handle is NULL, execute() does not return until HW 2D completes
1129      * the processng. If @handle is not NULL, execute() returns before HW 2D
1130      * completes and stores a value(handle) to @handle. Users can wait for HW 2D
1131      * to be finished with that handle. Users does not need to wait HW 2D. Then,
1132      * they sshould release the handle with releaseHandle().
1133      */
1134     virtual bool execute(int *handle = NULL) = 0;
1135     /*
1136      * Release @handle informed by execute()
1137      */
releaseHandle(int handle)1138     virtual void releaseHandle(int __attribute__((__unused__)) handle) { }
1139     /*
1140      * Wait HW 2D to finish the processing associated with @handle. The handle
1141      * is released after the wait completes.
1142      */
1143     virtual bool waitExecution(int handle) = 0;
1144     /*
1145      * Return the last execution time of the H/W in micro seconds.
1146      * It is only vaild when the last call to execute() succeeded.
1147      */
getLaptimeUSec()1148     virtual unsigned int getLaptimeUSec() { return 0; }
1149     /*
1150      * Configure the priority of the image processing tasks requested
1151      * to this compositor object. The default priority is -1 and the
1152      * highest priority is 15. If a user configure a priority outside
1153      * of the range between -1 and 15, the user will get failure.
1154      * How the priority to be applied is the implmentation specific.
1155      * prioritize() returns a negative value (-1) on failure. On successful,
1156      * prioritize() returns zero or a positive value. An implementation may
1157      * return a positive value to inform additional information.
1158      */
1159     virtual int prioritize(int priority = -1);
1160     /*
1161      * Configure a value for guaranteeing quality of service in terms
1162      * of image processing performance. The types and ranges of the
1163      * value is not defined by libacryl but the end users including
1164      * HWC and the driver. libacryl just deliver the value to the
1165      * driver that the implementation of Acrylic is talking with.
1166      * If the implementation does not implement requestPerformanceQoS(),
1167      * calling requestPerformanceQoS() effects nothing.
1168      * The types, the size and the number of the parameters are defined
1169      * as required. They should be defined in acrylic_soc.h.
1170      */
1171     virtual bool requestPerformanceQoS(AcrylicPerformanceRequest *request);
1172     /*
1173      * Called when an AcrylicLayer is being destroyed
1174      */
1175     void removeLayer(AcrylicLayer *layer);
1176     /*
1177      * Obtains the instance AcrylicCanvas of the taret image. It is called by
1178      * the implementations of Acrylic and the test modules of Acrylic. The other
1179      * users of Acrylic do not need to call getCanvas(). Instead, consider
1180      * setCanvasDimension(), setCanvasImageType() and setCanvasBuffer().
1181      */
getCanvas()1182     AcrylicCanvas &getCanvas() { return mCanvas; }
layerCount()1183     unsigned int layerCount() { return static_cast<unsigned int>(mLayers.size()); }
1184 protected:
1185     /*
1186      * Called when an AcrylicLayer is destroyed. Unlike removeLayer(),
1187      * removeTransitData() is called whenever an AcrylicLayer which is still
1188      * associated with an instance of Acrylic is destroyed. It means that
1189      * removeTransitData() is called even when an instance of Acrylic is
1190      * destroyed to remove all transit data installed in an AcrylicLayer instance.
1191      * If an implmentation of Acrylic may install a transit data to an instance of
1192      * AcrylicLayer, it should implement removeTransitData().
1193      */
removeTransitData(AcrylicLayer * layer)1194     virtual void removeTransitData(AcrylicLayer __attribute__((__unused__)) *layer) { }
1195     bool validateAllLayers();
1196     void sortLayers();
getLayer(unsigned int index)1197     AcrylicLayer *getLayer(unsigned int index)
1198     {
1199         return (index < mLayers.size()) ? mLayers[index] : nullptr;
1200     }
getBackgroundColor(uint16_t * red,uint16_t * green,uint16_t * blue,uint16_t * alpha)1201     void getBackgroundColor(uint16_t *red, uint16_t *green, uint16_t *blue,
1202                          uint16_t *alpha)
1203     {
1204         *red   = mBackgroundColor.R;
1205         *green = mBackgroundColor.G;
1206         *blue  = mBackgroundColor.B;
1207         *alpha = mBackgroundColor.A;
1208     }
hasBackgroundColor()1209     bool hasBackgroundColor() { return mHasBackgroundColor; }
getMaxTargetDisplayLuminance()1210     uint16_t getMaxTargetDisplayLuminance() { return mMaxTargetLuminance; }
getMinTargetDisplayLuminance()1211     uint16_t getMinTargetDisplayLuminance() { return mMinTargetLuminance; }
getTargetDisplayInfo()1212     void *getTargetDisplayInfo() { return mTargetDisplayInfo; }
1213 private:
1214     std::vector<AcrylicLayer *> mLayers;
1215     const HW2DCapability &mCapability;
1216     struct {
1217         uint16_t R;
1218         uint16_t G;
1219         uint16_t B;
1220         uint16_t A;
1221     } mBackgroundColor;
1222     bool mHasBackgroundColor;
1223     uint16_t mMaxTargetLuminance;
1224     uint16_t mMinTargetLuminance;
1225     void *mTargetDisplayInfo;
1226     AcrylicCanvas mCanvas;
1227 };
1228 
1229 struct AcrylicPerformanceRequestLayer {
1230     hw2d_coord_t    mSourceDimension;
1231     uint32_t        mPixFormat;
1232     hw2d_rect_t     mSourceRect;
1233     hw2d_rect_t     mTargetRect;
1234     uint32_t        mTransform;
1235     uint32_t        mAttribute;
1236 };
1237 
1238 struct AcrylicPerformanceRequestFrame {
1239     int             mNumLayers;
1240     int             mNumAllocLayers;
1241     int             mFrameRate;
1242     uint32_t        mTargetPixFormat;
1243     hw2d_coord_t    mTargetDimension;
1244     bool            mHasBackgroundLayer;
1245     struct AcrylicPerformanceRequestLayer *mLayers;
1246 
1247     AcrylicPerformanceRequestFrame();
1248     ~AcrylicPerformanceRequestFrame();
1249 
1250     bool reset(int num_layers = 0);
1251 
setSourceDimensionAcrylicPerformanceRequestFrame1252     void setSourceDimension(int layer, int width, int height, uint32_t fmt) {
1253         if (layer < mNumLayers) {
1254             mLayers[layer].mSourceDimension.hori = width;
1255             mLayers[layer].mSourceDimension.vert = height;
1256             mLayers[layer].mPixFormat = fmt;
1257         }
1258     }
1259 
setAttributeAcrylicPerformanceRequestFrame1260     void setAttribute(int layer, uint32_t attribute) {
1261         if (layer < mNumLayers)
1262             mLayers[layer].mAttribute = attribute;
1263     }
1264 
setTransferAcrylicPerformanceRequestFrame1265     void setTransfer(int layer, hwc_rect_t &src_area, hwc_rect_t &out_area, uint32_t transform) {
1266         if (layer < mNumLayers) {
1267             mLayers[layer].mSourceRect.pos.hori = src_area.left;
1268             mLayers[layer].mSourceRect.pos.vert = src_area.top;
1269             mLayers[layer].mSourceRect.size.hori = src_area.right - src_area.left;
1270             mLayers[layer].mSourceRect.size.vert = src_area.bottom - src_area.top;
1271             mLayers[layer].mTargetRect.pos.hori = out_area.left;
1272             mLayers[layer].mTargetRect.pos.vert = out_area.top;
1273             mLayers[layer].mTargetRect.size.hori = out_area.right - out_area.left;
1274             mLayers[layer].mTargetRect.size.vert = out_area.bottom - out_area.top;
1275             mLayers[layer].mTransform = transform;
1276         }
1277     }
1278 
setTargetDimensionAcrylicPerformanceRequestFrame1279     void setTargetDimension(int width, int height, uint32_t fmt, bool bBackground) {
1280         mTargetDimension.hori = width;
1281         mTargetDimension.vert = height;
1282         mTargetPixFormat = fmt;
1283         mHasBackgroundLayer = bBackground;
1284     }
1285 
setFrameRateAcrylicPerformanceRequestFrame1286     void setFrameRate(int rate) { mFrameRate = rate; }
1287 
getLayerCountAcrylicPerformanceRequestFrame1288     int getLayerCount() { return mNumLayers; }
1289 };
1290 
1291 class AcrylicPerformanceRequest {
1292 public:
1293     AcrylicPerformanceRequest();
1294     ~AcrylicPerformanceRequest();
1295 
1296     bool reset(int num_frames = 0);
1297 
getFrameCount()1298     int getFrameCount() { return mNumFrames; }
getFrame(int idx)1299     AcrylicPerformanceRequestFrame *getFrame(int idx) { return (idx < mNumFrames) ? &mFrames[idx] : NULL; }
1300 
1301 private:
1302     int mNumFrames;
1303     int mNumAllocFrames;
1304     AcrylicPerformanceRequestFrame *mFrames;
1305 };
1306 
1307 #endif /*__HARDWARE_EXYNOS_ACRYLIC_H__*/
1308