Harish Mahendrakar | f5dec50 | 2022-04-13 15:53:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018, 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 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "Codec2BufferUtils" |
| 19 | #define ATRACE_TAG ATRACE_TAG_VIDEO |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <android/hardware_buffer.h> |
Harish Mahendrakar | dfbaa2e | 2022-05-26 11:17:36 -0700 | [diff] [blame] | 23 | #include <android-base/properties.h> |
Harish Mahendrakar | f5dec50 | 2022-04-13 15:53:55 -0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
| 25 | #include <media/hardware/HardwareAPI.h> |
| 26 | #include <system/graphics.h> |
| 27 | |
| 28 | #include <C2Debug.h> |
| 29 | |
| 30 | #include "Codec2CommonUtils.h" |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | bool isAtLeastT() { |
| 35 | char deviceCodeName[PROP_VALUE_MAX]; |
| 36 | __system_property_get("ro.build.version.codename", deviceCodeName); |
| 37 | return android_get_device_api_level() >= __ANDROID_API_T__ || |
| 38 | !strcmp(deviceCodeName, "Tiramisu"); |
| 39 | } |
| 40 | |
Harish Mahendrakar | c95668e | 2022-10-26 15:06:56 -0700 | [diff] [blame^] | 41 | static bool isP010Allowed() { |
Harish Mahendrakar | dfbaa2e | 2022-05-26 11:17:36 -0700 | [diff] [blame] | 42 | // The first SDK the device shipped with. |
| 43 | static const int32_t kProductFirstApiLevel = |
| 44 | base::GetIntProperty<int32_t>("ro.product.first_api_level", 0); |
| 45 | |
| 46 | // GRF devices (introduced in Android 11) list the first and possibly the current api levels |
| 47 | // to signal which VSR requirements they conform to even if the first device SDK was higher. |
| 48 | static const int32_t kBoardFirstApiLevel = |
| 49 | base::GetIntProperty<int32_t>("ro.board.first_api_level", 0); |
Harish Mahendrakar | c95668e | 2022-10-26 15:06:56 -0700 | [diff] [blame^] | 50 | |
| 51 | // Some devices that launched prior to Android S may not support P010 correctly, even |
| 52 | // though they may advertise it as supported. |
| 53 | if (kProductFirstApiLevel != 0 && kProductFirstApiLevel < __ANDROID_API_S__) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if (kBoardFirstApiLevel != 0 && kBoardFirstApiLevel < __ANDROID_API_S__) { |
| 58 | return false; |
| 59 | } |
| 60 | |
Harish Mahendrakar | dfbaa2e | 2022-05-26 11:17:36 -0700 | [diff] [blame] | 61 | static const int32_t kBoardApiLevel = |
| 62 | base::GetIntProperty<int32_t>("ro.board.api_level", 0); |
| 63 | |
| 64 | // For non-GRF devices, use the first SDK version by the product. |
| 65 | static const int32_t kFirstApiLevel = |
| 66 | kBoardApiLevel != 0 ? kBoardApiLevel : |
| 67 | kBoardFirstApiLevel != 0 ? kBoardFirstApiLevel : |
| 68 | kProductFirstApiLevel; |
| 69 | |
| 70 | return kFirstApiLevel >= __ANDROID_API_T__; |
| 71 | } |
| 72 | |
Harish Mahendrakar | f5dec50 | 2022-04-13 15:53:55 -0700 | [diff] [blame] | 73 | bool isHalPixelFormatSupported(AHardwareBuffer_Format format) { |
Harish Mahendrakar | dfbaa2e | 2022-05-26 11:17:36 -0700 | [diff] [blame] | 74 | // HAL_PIXEL_FORMAT_YCBCR_P010 requirement was added in T VSR, although it could have been |
| 75 | // supported prior to this. |
| 76 | // |
| 77 | // Unfortunately, we cannot detect if P010 is properly supported using AHardwareBuffer |
| 78 | // API alone. For now limit P010 to devices that launched with Android T or known to conform |
| 79 | // to Android T VSR (as opposed to simply limiting to a T vendor image). |
| 80 | if (format == (AHardwareBuffer_Format)HAL_PIXEL_FORMAT_YCBCR_P010 && |
Harish Mahendrakar | c95668e | 2022-10-26 15:06:56 -0700 | [diff] [blame^] | 81 | !isP010Allowed()) { |
Harish Mahendrakar | f5dec50 | 2022-04-13 15:53:55 -0700 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | |
| 85 | const AHardwareBuffer_Desc desc = { |
| 86 | .width = 320, |
| 87 | .height = 240, |
| 88 | .format = format, |
| 89 | .layers = 1, |
Harish Mahendrakar | dfbaa2e | 2022-05-26 11:17:36 -0700 | [diff] [blame] | 90 | .usage = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY | |
| 91 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 92 | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | |
| 93 | AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY, |
Harish Mahendrakar | f5dec50 | 2022-04-13 15:53:55 -0700 | [diff] [blame] | 94 | .stride = 0, |
| 95 | .rfu0 = 0, |
| 96 | .rfu1 = 0, |
| 97 | }; |
| 98 | |
| 99 | return AHardwareBuffer_isSupported(&desc); |
| 100 | } |
| 101 | |
| 102 | } // namespace android |