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