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> |
| 21 | #include <hardware/gralloc.h> |
| 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: |
| 34 | virtual ~BufferInfoGetter() { |
| 35 | } |
| 36 | |
| 37 | virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0; |
| 38 | |
| 39 | bool IsHandleUsable(buffer_handle_t handle); |
| 40 | |
| 41 | static BufferInfoGetter *GetInstance(); |
| 42 | |
| 43 | static uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format); |
| 44 | static bool IsDrmFormatRgb(uint32_t drm_format); |
| 45 | }; |
| 46 | |
| 47 | class LegacyBufferInfoGetter : public BufferInfoGetter { |
| 48 | public: |
| 49 | using BufferInfoGetter::BufferInfoGetter; |
| 50 | |
| 51 | int Init(); |
| 52 | |
| 53 | int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0; |
| 54 | |
| 55 | static LegacyBufferInfoGetter *CreateInstance(); |
| 56 | |
| 57 | static uint32_t ConvertHalFormatToDrm(uint32_t hal_format); |
| 58 | const gralloc_module_t *gralloc_; |
| 59 | }; |
| 60 | |
| 61 | #define LEGACY_BUFFER_INFO_GETTER(getter_) \ |
| 62 | LegacyBufferInfoGetter *LegacyBufferInfoGetter::CreateInstance() { \ |
| 63 | auto *instance = new getter_(); \ |
| 64 | if (!instance) \ |
| 65 | return NULL; \ |
| 66 | \ |
| 67 | int ret = instance->Init(); \ |
| 68 | if (ret) { \ |
| 69 | ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \ |
| 70 | delete instance; \ |
| 71 | return NULL; \ |
| 72 | } \ |
| 73 | return instance; \ |
| 74 | } |
| 75 | |
| 76 | } // namespace android |
| 77 | #endif |