From: Christopher N. Hesse Date: Sat, 26 Nov 2016 18:23:50 +0000 (+0100) Subject: gralloc: Move rgb/yuv format handling to header X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e011d719a06ddf930cf6ff6238f2c54ae51a937c;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung_slsi_exynos5.git gralloc: Move rgb/yuv format handling to header Change-Id: Id9537c49555db7921663ee52fccc10b319ec6a17 --- diff --git a/gralloc/gralloc.cpp b/gralloc/gralloc.cpp index d48acab..a373fba 100644 --- a/gralloc/gralloc.cpp +++ b/gralloc/gralloc.cpp @@ -37,6 +37,7 @@ #include "gralloc_priv.h" #include "exynos_format.h" +#include "exynos_gralloc.h" #define ION_HEAP_EXYNOS_CONTIG_MASK (1 << 4) #define ION_EXYNOS_FIMD_VIDEO_MASK (1 << 28) @@ -159,40 +160,9 @@ static int gralloc_alloc_rgb(int ionfd, int w, int h, int format, int usage, } } - switch (format) { - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_sRGB_A_8888: - case HAL_PIXEL_FORMAT_sRGB_X_8888: - bpp = 4; - break; - case HAL_PIXEL_FORMAT_RGB_888: - bpp = 3; - break; - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_RAW16: - bpp = 2; - break; - case HAL_PIXEL_FORMAT_BLOB: - *stride = w; - vstride = h; - size = w * h; - break; - default: - return -EINVAL; - } - - if (format != HAL_PIXEL_FORMAT_BLOB) { - bpr = ALIGN(w*bpp, 64); - vstride = ALIGN(h, 16); - if (vstride < h + 2) - size = bpr * (h + 2); - else - size = bpr * vstride; - *stride = bpr / bpp; - size = ALIGN(size, PAGE_SIZE); - } + err = handle_rgb_format(w, h, format, usage, stride, &size, &bpr, &bpp, &vstride); + if (err) + return err; if (usage & GRALLOC_USAGE_PROTECTED) { alignment = MB_1; @@ -215,19 +185,9 @@ static int gralloc_alloc_framework_yuv(int ionfd, int w, int h, int format, int err, fd; unsigned int heap_mask = _select_heap(usage); - switch (format) { - case HAL_PIXEL_FORMAT_YV12: - *stride = ALIGN(w, 16); - size = (*stride * h) + (ALIGN(*stride / 2, 16) * h); - break; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - *stride = w; - size = *stride * h * 3 / 2; - break; - default: - ALOGE("invalid yuv format %d\n", format); - return -EINVAL; - } + err = handle_framework_yuv_format(w, h, format, stride, &size); + if (err) + return err; err = ion_alloc_fd(ionfd, size, 0, heap_mask, ion_flags, &fd); if (err) @@ -258,43 +218,11 @@ static int gralloc_alloc_yuv(int ionfd, int w, int h, int format, format = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M } } - switch (format) { - case HAL_PIXEL_FORMAT_EXYNOS_YV12: - { - *stride = ALIGN(w, 32); - luma_vstride = ALIGN(h, 16); - luma_size = luma_vstride * *stride; - chroma_size = (luma_vstride / 2) * ALIGN(*stride / 2, 16); - planes = 3; - break; - } - case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: - { - size_t chroma_vstride = ALIGN(h / 2, 32); - luma_vstride = ALIGN(h, 32); - luma_size = luma_vstride * *stride; - chroma_size = chroma_vstride * *stride; - planes = 2; - break; - } - case HAL_PIXEL_FORMAT_YV12: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - return gralloc_alloc_framework_yuv(ionfd, w, h, format, usage, - ion_flags, hnd, stride); - case HAL_PIXEL_FORMAT_YCbCr_422_I: - { - luma_vstride = h; - luma_size = luma_vstride * *stride * 2; - chroma_size = 0; - planes = 1; - break; - } - default: - ALOGE("invalid yuv format %d\n", format); - return -EINVAL; - } + + err = handle_yuv_format(ionfd, w, h, format, usage, ion_flags, hnd, stride, &luma_vstride, + &luma_size, &chroma_size, &planes); + if (err) + return err; if (usage & GRALLOC_USAGE_PROTECTED) ion_flags |= ION_EXYNOS_MFC_OUTPUT_MASK; diff --git a/include/exynos_gralloc.h b/include/exynos_gralloc.h new file mode 100644 index 0000000..ed3428f --- /dev/null +++ b/include/exynos_gralloc.h @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EXYNOS_GRALLOC_H_ +#define EXYNOS_GRALLOC_H_ + +/* + * Static data + */ +static const int HAL_PIXEL_FORMAT_sRGB_A_8888 = 12; +static const int HAL_PIXEL_FORMAT_sRGB_X_8888 = 13; + +/* + * Prototypes + */ +static int gralloc_alloc_framework_yuv(int ionfd, int w, int h, int format, + int usage, unsigned int ion_flags, + private_handle_t **hnd, int *stride); + +/* + * Board specific implementations + */ +static int handle_rgb_format(const int &w, const int &h, const int &format, const int &usage, + int *stride, size_t *size, size_t *bpr, int *bpp, int *vstride) +{ + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_sRGB_A_8888: + case HAL_PIXEL_FORMAT_sRGB_X_8888: + *bpp = 4; + break; + case HAL_PIXEL_FORMAT_RGB_888: + *bpp = 3; + break; + case HAL_PIXEL_FORMAT_RGB_565: + case HAL_PIXEL_FORMAT_RAW16: + *bpp = 2; + break; + case HAL_PIXEL_FORMAT_BLOB: + *stride = w; + *vstride = h; + *size = w * h; + break; + default: + return -EINVAL; + } + + if (format != HAL_PIXEL_FORMAT_BLOB) { + *bpr = ALIGN(w* *bpp, 64); + *vstride = ALIGN(h, 16); + if (*vstride < h + 2) + *size = *bpr * (h + 2); + else + *size = *bpr * *vstride; + *stride = *bpr / *bpp; + *size = ALIGN(*size, PAGE_SIZE); + } + + return 0; +} + +static int handle_yuv_format(const int &ionfd, const int &w, const int &h, const int &format, + const int &usage, unsigned int &ion_flags, private_handle_t **hnd, + int *stride, size_t *luma_vstride, size_t *luma_size, + size_t *chroma_size, int *planes) +{ + switch (format) { + case HAL_PIXEL_FORMAT_EXYNOS_YV12: + { + *stride = ALIGN(w, 32); + *luma_vstride = ALIGN(h, 16); + *luma_size = *luma_vstride * *stride; + *chroma_size = (*luma_vstride / 2) * ALIGN(*stride / 2, 16); + *planes = 3; + break; + } + case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP: + case HAL_PIXEL_FORMAT_YCbCr_420_SP: + case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: + { + size_t chroma_vstride = ALIGN(h / 2, 32); + *luma_vstride = ALIGN(h, 32); + *luma_size = *luma_vstride * *stride; + *chroma_size = chroma_vstride * *stride; + *planes = 2; + break; + } + case HAL_PIXEL_FORMAT_YV12: + case HAL_PIXEL_FORMAT_YCrCb_420_SP: + return gralloc_alloc_framework_yuv(ionfd, w, h, format, usage, + ion_flags, hnd, stride); + case HAL_PIXEL_FORMAT_YCbCr_422_I: + { + *luma_vstride = h; + *luma_size = *luma_vstride * *stride * 2; + *chroma_size = 0; + *planes = 1; + break; + } + default: + ALOGE("invalid yuv format %d\n", format); + return -EINVAL; + } + + return 0; +} + +static int handle_framework_yuv_format(const int &w, const int &h, const int &format, int *stride, + size_t *size) +{ + switch (format) { + case HAL_PIXEL_FORMAT_YV12: + *stride = ALIGN(w, 16); + *size = (*stride * h) + (ALIGN(*stride / 2, 16) * h); + break; + case HAL_PIXEL_FORMAT_YCrCb_420_SP: + *stride = w; + *size = *stride * 3 / 2; + break; + default: + ALOGE("invalid yuv format %d\n", format); + return -EINVAL; + } + + return 0; +} + +#endif /* EXYNOS_GRALLOC_H_ */