libhwjpeg: resolve compilation errors
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos.git] / gralloc / format_chooser.cpp
1 /*
2 * Copyright (C) 2014 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 #include <stdlib.h>
19 #include <hardware/hardware.h>
20 #include <cutils/log.h>
21 #include <cutils/properties.h>
22 #include <hardware/gralloc.h>
23 #include "format_chooser.h"
24
25 #define FBT (GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER)
26 #define GENERAL_UI (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER)
27
28 /* It's for compression check format, width, usage*/
29 int check_for_compression(int w, int h, int format, int usage)
30 {
31 char value[256];
32 int afbc_prop;
33
34 property_get("ddk.set.afbc", value, "0");
35 afbc_prop = atoi(value);
36
37 switch(format)
38 {
39 case HAL_PIXEL_FORMAT_RGBA_8888:
40 case HAL_PIXEL_FORMAT_BGRA_8888:
41 case HAL_PIXEL_FORMAT_RGB_888:
42 case HAL_PIXEL_FORMAT_RGBX_8888:
43 case HAL_PIXEL_FORMAT_RGB_565:
44 case HAL_PIXEL_FORMAT_YV12:
45 {
46 if(afbc_prop == 0)
47 return 0;
48 if (w % 16 != 0) /* width isn't 16 pixel alignment */
49 return 0;
50 if ((w <= 144) || (h <= 144)) /* min restriction for performance */
51 return 0;
52 if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN)
53 return 0;
54 if ((usage & FBT) || (usage & GENERAL_UI)) /*only support FBT and General UI */
55 return 1;
56 else
57 return 0;
58
59 break;
60 }
61 default:
62 return 0;
63 }
64
65 }
66
67 uint64_t gralloc_select_format(int req_format, int usage, int is_compressible)
68 {
69 uint64_t new_format = req_format;
70
71 if( req_format == 0 )
72 {
73 return 0;
74 }
75
76 if( (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) != 0 ||
77 usage == 0 )
78 {
79 return new_format;
80 }
81
82 if( is_compressible == 0)
83 {
84 return new_format;
85 }
86 #if 0
87 /* This is currently a limitation with the display and will be removed eventually
88 * We can't allocate fbdev framebuffer buffers in AFBC format */
89 if( usage & GRALLOC_USAGE_HW_FB )
90 {
91 return new_format;
92 }
93 #endif
94 new_format |= GRALLOC_ARM_INTFMT_AFBC;
95
96 ALOGD("Returned iterated format: 0x%llX", new_format);
97
98 return new_format;
99 }