2 * Copyright (C) 2014 ARM Limited. All rights reserved.
4 * Copyright (C) 2008 The Android Open Source Project
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
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)
28 /* It's for compression check format, width, usage*/
29 int check_for_compression(int w
, int h
, int format
, int usage
)
34 property_get("ddk.set.afbc", value
, "0");
35 afbc_prop
= atoi(value
);
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
:
48 if (w
% 16 != 0) /* width isn't 16 pixel alignment */
50 if ((w
<= 144) || (h
<= 144)) /* min restriction for performance */
52 if ((usage
& GRALLOC_USAGE_SW_READ_MASK
) == GRALLOC_USAGE_SW_READ_OFTEN
)
54 if ((usage
& FBT
) || (usage
& GENERAL_UI
)) /*only support FBT and General UI */
67 uint64_t gralloc_select_format(int req_format
, int usage
, int is_compressible
)
69 uint64_t new_format
= req_format
;
76 if( (usage
& (GRALLOC_USAGE_SW_READ_MASK
| GRALLOC_USAGE_SW_WRITE_MASK
)) != 0 ||
82 if( is_compressible
== 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
)
94 new_format
|= GRALLOC_ARM_INTFMT_AFBC
;
96 ALOGD("Returned iterated format: 0x%llX", new_format
);