blob: 7b088df708b125aa36e5cdbebfee718f64e2ae1b [file] [log] [blame]
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +03001/*
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 Stratiienkod21071f2021-03-09 21:56:50 +020021#include <hardware/gralloc.h>
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030022
23#include "drm/DrmDevice.h"
24#include "drmhwcgralloc.h"
25
26#ifndef DRM_FORMAT_INVALID
27#define DRM_FORMAT_INVALID 0
28#endif
29
30namespace android {
31
32class 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
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030043 static bool IsDrmFormatRgb(uint32_t drm_format);
44};
45
46class LegacyBufferInfoGetter : public BufferInfoGetter {
47 public:
48 using BufferInfoGetter::BufferInfoGetter;
49
50 int Init();
51
Roman Stratiienko39d8f7e2021-11-30 17:06:44 +020052 virtual int ValidateGralloc() {
53 return 0;
54 }
55
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030056 int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0;
57
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020058 static std::unique_ptr<LegacyBufferInfoGetter> CreateInstance();
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030059
60 static uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
61 const gralloc_module_t *gralloc_;
62};
63
Roman Stratiienkoe3983342021-02-15 15:41:53 +020064#ifdef DISABLE_LEGACY_GETTERS
65#define LEGACY_BUFFER_INFO_GETTER(getter_)
66#else
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020067#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 Stratiienko39d8f7e2021-11-30 17:06:44 +020072 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 Stratiienkoe2f2c922021-02-13 10:57:47 +020079 instance.reset(); \
80 } \
81 } \
82 return std::move(instance); \
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030083 }
Roman Stratiienkoe3983342021-02-15 15:41:53 +020084#endif
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030085
86} // namespace android
87#endif