Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 ANDROID_BUFFERINFOGETTER_H_ |
| 18 | #define ANDROID_BUFFERINFOGETTER_H_ |
| 19 | |
| 20 | #include <drm/drm_fourcc.h> |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 21 | #include <hardware/gralloc.h> |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 22 | |
| 23 | #include "drm/DrmDevice.h" |
| 24 | #include "drmhwcgralloc.h" |
| 25 | |
| 26 | #ifndef DRM_FORMAT_INVALID |
| 27 | #define DRM_FORMAT_INVALID 0 |
| 28 | #endif |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class BufferInfoGetter { |
| 33 | public: |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 34 | virtual ~BufferInfoGetter() = default; |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 35 | |
| 36 | virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0; |
| 37 | |
| 38 | bool IsHandleUsable(buffer_handle_t handle); |
| 39 | |
| 40 | static BufferInfoGetter *GetInstance(); |
| 41 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 42 | static bool IsDrmFormatRgb(uint32_t drm_format); |
| 43 | }; |
| 44 | |
| 45 | class LegacyBufferInfoGetter : public BufferInfoGetter { |
| 46 | public: |
| 47 | using BufferInfoGetter::BufferInfoGetter; |
| 48 | |
| 49 | int Init(); |
| 50 | |
Roman Stratiienko | 39d8f7e | 2021-11-30 17:06:44 +0200 | [diff] [blame] | 51 | virtual int ValidateGralloc() { |
| 52 | return 0; |
| 53 | } |
| 54 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 55 | static std::unique_ptr<LegacyBufferInfoGetter> CreateInstance(); |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 56 | |
| 57 | static uint32_t ConvertHalFormatToDrm(uint32_t hal_format); |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 58 | |
| 59 | // NOLINTNEXTLINE:(readability-identifier-naming) |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 60 | const gralloc_module_t *gralloc_; |
| 61 | }; |
| 62 | |
Roman Stratiienko | e398334 | 2021-02-15 15:41:53 +0200 | [diff] [blame] | 63 | #ifdef DISABLE_LEGACY_GETTERS |
| 64 | #define LEGACY_BUFFER_INFO_GETTER(getter_) |
| 65 | #else |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 66 | // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 67 | #define LEGACY_BUFFER_INFO_GETTER(getter_) \ |
| 68 | std::unique_ptr<LegacyBufferInfoGetter> \ |
| 69 | LegacyBufferInfoGetter::CreateInstance() { \ |
| 70 | auto instance = std::make_unique<getter_>(); \ |
| 71 | if (instance) { \ |
Roman Stratiienko | 39d8f7e | 2021-11-30 17:06:44 +0200 | [diff] [blame] | 72 | int err = instance->Init(); \ |
| 73 | if (err) { \ |
| 74 | ALOGE("Failed to initialize the " #getter_ " getter %d", err); \ |
| 75 | instance.reset(); \ |
| 76 | } \ |
| 77 | err = instance->ValidateGralloc(); \ |
| 78 | if (err) { \ |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 79 | instance.reset(); \ |
| 80 | } \ |
| 81 | } \ |
| 82 | return std::move(instance); \ |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 83 | } |
Roman Stratiienko | e398334 | 2021-02-15 15:41:53 +0200 | [diff] [blame] | 84 | #endif |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 85 | |
| 86 | } // namespace android |
| 87 | #endif |