diff options
author | Roman Stratiienko <r.stratiienko@gmail.com> | 2020-10-03 10:52:36 +0300 |
---|---|---|
committer | Roman Stratiienko <r.stratiienko@gmail.com> | 2020-10-20 23:19:42 +0300 |
commit | b2e9fe23cdb5ed99186b26be7eed8f1f26f65966 (patch) | |
tree | 6da6e6fb22e4a24e9e4186f6e3562c15a84d8b16 | |
parent | 946126c9b3d7db49413664578ef569e48a85b439 (diff) | |
download | drm_hwcomposer-b2e9fe23cdb5ed99186b26be7eed8f1f26f65966.tar.gz |
drm_hwcomposer: refactor platform directory
Motivation:
Platform term meaning used in drm_hwcomposer does not correspond to the
content of the platform directory. Platform directory consists of:
1. Buffer information getters for different gralloc (currently called platform).
2. Composition planner logic (which has flaws and should be reworked into
layer->plane mapping during validation stage logic).
3. DrmGenericImpoter with reference counting logic.
Android-11 IMapper@4 metadata API offers a generic way to access buffer
information which makes other gralloc buffer information getters obsolete.
Legacy getters should be maintained for some time until all known users
will migrate to Mapper@4 API.
Implementation:
1. Split 'PlatformImporter' logic to 'Importer' only and 'Buffer Getter' logic.
a. Remove buffer_handle_t parameter from ImportBuffer(). Instead user should
get BufferInfo using ConvertBoInfo to struct hwc_drm_bo_t, then use it for
ImportBuffer().
b. Move DrmGenericImporter.{cpp/h} into the drm directory.
2. Isolate planner code in single file and move it to compositor directory as
compositor/Planner.{cpp/h}
3. Rename platform definition
a. Rename platform directory to bufferinfo.
b. Rename/move bufferinfo/platorm*.{cpp,h} getters to
bufferinfo/legacy/BufferInfo*.{cpp,h}. Align class names/includes.
4. Split legacy/metadata getters logic.
a. Apply existing bufferinfogetter base class only for legacy getters.
b. Combine legacy/generic gettera under new base class.
c. Create a placeholder for generic(metadata) getter.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
-rw-r--r-- | Android.bp | 35 | ||||
-rw-r--r-- | DrmHwcTwo.h | 3 | ||||
-rw-r--r-- | backend/Backend.cpp | 3 | ||||
-rw-r--r-- | backend/BackendRCarDu.cpp | 4 | ||||
-rw-r--r-- | bufferinfo/BufferInfoGetter.cpp | 136 | ||||
-rw-r--r-- | bufferinfo/BufferInfoGetter.h | 77 | ||||
-rw-r--r-- | bufferinfo/BufferInfoMapperMetadata.cpp | 49 | ||||
-rw-r--r-- | bufferinfo/BufferInfoMapperMetadata.h | 34 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoImagination.cpp (renamed from platform/platformimagination.cpp) | 38 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoImagination.h | 34 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoLibdrm.cpp (renamed from platform/platformlibdrm.cpp) | 26 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoLibdrm.h (renamed from platform/platformlibdrm.h) | 13 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliHisi.cpp (renamed from platform/platformhisi.cpp) | 56 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliHisi.h (renamed from platform/platformhisi.h) | 19 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliMediatek.cpp (renamed from platform/platformmediatek.cpp) | 22 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliMediatek.h (renamed from platform/platformmediatek.h) | 12 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliMeson.cpp (renamed from platform/platformmeson.cpp) | 31 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMaliMeson.h (renamed from platform/platformmeson.h) | 16 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMinigbm.cpp (renamed from platform/platformminigbm.cpp) | 24 | ||||
-rw-r--r-- | bufferinfo/legacy/BufferInfoMinigbm.h (renamed from platform/platformminigbm.h) | 13 | ||||
-rw-r--r-- | compositor/DrmDisplayComposition.cpp | 2 | ||||
-rw-r--r-- | compositor/DrmDisplayCompositor.h | 1 | ||||
-rw-r--r-- | compositor/Planner.cpp (renamed from platform/platform.cpp) | 8 | ||||
-rw-r--r-- | compositor/Planner.h (renamed from platform/platform.h) | 27 | ||||
-rw-r--r-- | drm/DrmDevice.cpp | 1 | ||||
-rw-r--r-- | drm/DrmDevice.h | 2 | ||||
-rw-r--r-- | drm/DrmGenericImporter.cpp (renamed from platform/platformdrmgeneric.cpp) | 93 | ||||
-rw-r--r-- | drm/DrmGenericImporter.h (renamed from platform/platformdrmgeneric.h) | 35 | ||||
-rw-r--r-- | drm/ResourceManager.cpp | 9 | ||||
-rw-r--r-- | drm/ResourceManager.h | 2 | ||||
-rw-r--r-- | platform/platformimagination.h | 21 | ||||
-rw-r--r-- | utils/hwcutils.cpp | 9 |
32 files changed, 498 insertions, 357 deletions
@@ -82,22 +82,25 @@ cc_library_static { srcs: [ "DrmHwcTwo.cpp", + "bufferinfo/BufferInfoGetter.cpp", + "bufferinfo/BufferInfoMapperMetadata.cpp", + "compositor/DrmDisplayComposition.cpp", "compositor/DrmDisplayCompositor.cpp", + "compositor/Planner.cpp", "drm/DrmConnector.cpp", "drm/DrmCrtc.cpp", "drm/DrmDevice.cpp", "drm/DrmEncoder.cpp", "drm/DrmEventListener.cpp", + "drm/DrmGenericImporter.cpp", "drm/DrmMode.cpp", "drm/DrmPlane.cpp", "drm/DrmProperty.cpp", "drm/ResourceManager.cpp", "drm/VSyncWorker.cpp", - "platform/platform.cpp", - "utils/autolock.cpp", "utils/hwcutils.cpp", @@ -112,53 +115,37 @@ cc_library_shared { name: "hwcomposer.drm", defaults: ["hwcomposer.drm_defaults"], whole_static_libs: ["drm_hwcomposer"], - srcs: ["platform/platformdrmgeneric.cpp", - "platform/platformlibdrm.cpp"], + srcs: ["bufferinfo/legacy/BufferInfoLibdrm.cpp"], } cc_library_shared { name: "hwcomposer.drm_minigbm", defaults: ["hwcomposer.drm_defaults"], whole_static_libs: ["drm_hwcomposer"], - srcs: [ - "platform/platformdrmgeneric.cpp", - "platform/platformminigbm.cpp", - ], + srcs: ["bufferinfo/legacy/BufferInfoMinigbm.cpp"], include_dirs: ["external/minigbm/cros_gralloc"], } // Used by hwcomposer.drm_imagination filegroup { name: "drm_hwcomposer_platformimagination", - srcs: [ - "platform/platformdrmgeneric.cpp", - "platform/platformimagination.cpp", - ], + srcs: ["bufferinfo/legacy/BufferInfoImagination.cpp"], } // Used by hwcomposer.drm_hikey and hwcomposer.drm_hikey960 filegroup { name: "drm_hwcomposer_platformhisi", - srcs: [ - "platform/platformdrmgeneric.cpp", - "platform/platformhisi.cpp", - ], + srcs: ["bufferinfo/legacy/BufferInfoMaliHisi.cpp"], } // Used by hwcomposer.drm_meson filegroup { name: "drm_hwcomposer_platformmeson", - srcs: [ - "platform/platformdrmgeneric.cpp", - "platform/platformmeson.cpp", - ], + srcs: ["bufferinfo/legacy/BufferInfoMaliMeson.cpp"], } // Used by hwcomposer.drm_mediatek filegroup { name: "drm_hwcomposer_platformmediatek", - srcs: [ - "platform/platformdrmgeneric.cpp", - "platform/platformmediatek.cpp", - ], + srcs: ["bufferinfo/legacy/BufferInfoMaliMediatek.cpp"], } diff --git a/DrmHwcTwo.h b/DrmHwcTwo.h index 7c3b856..d489113 100644 --- a/DrmHwcTwo.h +++ b/DrmHwcTwo.h @@ -24,10 +24,11 @@ #include <map> #include "compositor/DrmDisplayCompositor.h" +#include "compositor/Planner.h" +#include "drm/DrmGenericImporter.h" #include "drm/ResourceManager.h" #include "drm/VSyncWorker.h" #include "drmhwcomposer.h" -#include "platform/platform.h" namespace android { diff --git a/backend/Backend.cpp b/backend/Backend.cpp index 50ef900..887eb0e 100644 --- a/backend/Backend.cpp +++ b/backend/Backend.cpp @@ -17,6 +17,7 @@ #include "Backend.h" #include "BackendManager.h" +#include "bufferinfo/BufferInfoGetter.h" namespace android { @@ -125,7 +126,7 @@ std::tuple<int, int> Backend::GetClientLayers( bool Backend::IsClientLayer(DrmHwcTwo::HwcDisplay *display, DrmHwcTwo::HwcLayer *layer) { return !display->HardwareSupportsLayerType(layer->sf_type()) || - !display->importer()->CanImportBuffer(layer->buffer()) || + !BufferInfoGetter::GetInstance()->IsHandleUsable(layer->buffer()) || display->color_transform_hint() != HAL_COLOR_TRANSFORM_IDENTITY || (layer->RequireScalingOrPhasing() && display->resource_manager()->ForcedScalingWithGpu()); diff --git a/backend/BackendRCarDu.cpp b/backend/BackendRCarDu.cpp index d52f0c3..e85fa71 100644 --- a/backend/BackendRCarDu.cpp +++ b/backend/BackendRCarDu.cpp @@ -17,6 +17,7 @@ #include "BackendRCarDu.h" #include "BackendManager.h" +#include "bufferinfo/BufferInfoGetter.h" #include "drm_fourcc.h" namespace android { @@ -25,7 +26,8 @@ bool BackendRCarDu::IsClientLayer(DrmHwcTwo::HwcDisplay *display, DrmHwcTwo::HwcLayer *layer) { hwc_drm_bo_t bo; - int ret = display->importer()->ConvertBoInfo(layer->buffer(), &bo); + int ret = BufferInfoGetter::GetInstance()->ConvertBoInfo(layer->buffer(), + &bo); if (ret) return true; diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp new file mode 100644 index 0000000..8b3f1a4 --- /dev/null +++ b/bufferinfo/BufferInfoGetter.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2020 The Android Open Source 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. + */ + +#define LOG_TAG "hwc-buffer-info-getter" + +#include "BufferInfoGetter.h" + +#if PLATFORM_SDK_VERSION >= 30 +#include "BufferInfoMapperMetadata.h" +#endif + +#include <cutils/properties.h> +#include <gralloc_handle.h> +#include <hardware/gralloc.h> +#include <log/log.h> +#include <xf86drm.h> +#include <xf86drmMode.h> + +namespace android { + +BufferInfoGetter *BufferInfoGetter::GetInstance() { + static std::unique_ptr<BufferInfoGetter> inst; + if (inst == nullptr) { +#if PLATFORM_SDK_VERSION >= 30 + inst.reset(BufferInfoMapperMetadata::CreateInstance()); + if (inst == nullptr) { + ALOGW( + "Generic buffer getter is not available. Falling back to legacy..."); +#endif + inst.reset(LegacyBufferInfoGetter::CreateInstance()); +#if PLATFORM_SDK_VERSION >= 30 + } +#endif + } + + return inst.get(); +} + +bool BufferInfoGetter::IsHandleUsable(buffer_handle_t handle) { + hwc_drm_bo_t bo; + memset(&bo, 0, sizeof(hwc_drm_bo_t)); + + if (ConvertBoInfo(handle, &bo) != 0) + return false; + + if (bo.prime_fds[0] == 0) + return false; + + return true; +} + +int LegacyBufferInfoGetter::Init() { + int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, + (const hw_module_t **)&gralloc_); + if (ret) { + ALOGE("Failed to open gralloc module"); + return ret; + } + + ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name, + gralloc_->common.author); + + return 0; +} + +uint32_t LegacyBufferInfoGetter::ConvertHalFormatToDrm(uint32_t hal_format) { + switch (hal_format) { + case HAL_PIXEL_FORMAT_RGB_888: + return DRM_FORMAT_BGR888; + case HAL_PIXEL_FORMAT_BGRA_8888: + return DRM_FORMAT_ARGB8888; + case HAL_PIXEL_FORMAT_RGBX_8888: + return DRM_FORMAT_XBGR8888; + case HAL_PIXEL_FORMAT_RGBA_8888: + return DRM_FORMAT_ABGR8888; + case HAL_PIXEL_FORMAT_RGB_565: + return DRM_FORMAT_BGR565; + case HAL_PIXEL_FORMAT_YV12: + return DRM_FORMAT_YVU420; + default: + ALOGE("Cannot convert hal format to drm format %u", hal_format); + return DRM_FORMAT_INVALID; + } +} + +uint32_t BufferInfoGetter::DrmFormatToBitsPerPixel(uint32_t drm_format) { + switch (drm_format) { + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + return 32; + case DRM_FORMAT_BGR888: + return 24; + case DRM_FORMAT_BGR565: + return 16; + case DRM_FORMAT_YVU420: + return 12; + default: + ALOGE("Cannot convert hal format %u to bpp (returning 32)", drm_format); + return 32; + } +} + +bool BufferInfoGetter::IsDrmFormatRgb(uint32_t drm_format) { + switch (drm_format) { + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_BGR888: + case DRM_FORMAT_BGR565: + return true; + default: + return false; + } +} + +__attribute__((weak)) LegacyBufferInfoGetter * +LegacyBufferInfoGetter::CreateInstance() { + ALOGE("No legacy buffer info getters available"); + return nullptr; +} + +} // namespace android diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h new file mode 100644 index 0000000..78c29ff --- /dev/null +++ b/bufferinfo/BufferInfoGetter.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2020 The Android Open Source 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 ANDROID_BUFFERINFOGETTER_H_ +#define ANDROID_BUFFERINFOGETTER_H_ + +#include <drm/drm_fourcc.h> +#include <hardware/gralloc.h> + +#include "drm/DrmDevice.h" +#include "drmhwcgralloc.h" + +#ifndef DRM_FORMAT_INVALID +#define DRM_FORMAT_INVALID 0 +#endif + +namespace android { + +class BufferInfoGetter { + public: + virtual ~BufferInfoGetter() { + } + + virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0; + + bool IsHandleUsable(buffer_handle_t handle); + + static BufferInfoGetter *GetInstance(); + + static uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format); + static bool IsDrmFormatRgb(uint32_t drm_format); +}; + +class LegacyBufferInfoGetter : public BufferInfoGetter { + public: + using BufferInfoGetter::BufferInfoGetter; + + int Init(); + + int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0; + + static LegacyBufferInfoGetter *CreateInstance(); + + static uint32_t ConvertHalFormatToDrm(uint32_t hal_format); + const gralloc_module_t *gralloc_; +}; + +#define LEGACY_BUFFER_INFO_GETTER(getter_) \ + LegacyBufferInfoGetter *LegacyBufferInfoGetter::CreateInstance() { \ + auto *instance = new getter_(); \ + if (!instance) \ + return NULL; \ + \ + int ret = instance->Init(); \ + if (ret) { \ + ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \ + delete instance; \ + return NULL; \ + } \ + return instance; \ + } + +} // namespace android +#endif diff --git a/bufferinfo/BufferInfoMapperMetadata.cpp b/bufferinfo/BufferInfoMapperMetadata.cpp new file mode 100644 index 0000000..2725802 --- /dev/null +++ b/bufferinfo/BufferInfoMapperMetadata.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020 The Android Open Source 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. + */ + +#if PLATFORM_SDK_VERSION >= 30 + +#define LOG_TAG "hwc-bufferinfo-mappermetadata" + +#include "BufferInfoMapperMetadata.h" + +#include <drm/drm_fourcc.h> +#include <inttypes.h> +#include <log/log.h> +#include <ui/GraphicBufferMapper.h> +#include <xf86drm.h> +#include <xf86drmMode.h> + +using android::hardware::graphics::common::V1_1::BufferUsage; + +namespace android { + +BufferInfoGetter *BufferInfoMapperMetadata::CreateInstance() { + if (GraphicBufferMapper::getInstance().getMapperVersion() < + GraphicBufferMapper::GRALLOC_4) + return nullptr; + + return new BufferInfoMapperMetadata(); +} + +int BufferInfoMapperMetadata::ConvertBoInfo(buffer_handle_t /*handle*/, + hwc_drm_bo_t * /*bo*/) { + return -EINVAL; +} + +} // namespace android + +#endif diff --git a/bufferinfo/BufferInfoMapperMetadata.h b/bufferinfo/BufferInfoMapperMetadata.h new file mode 100644 index 0000000..49c788a --- /dev/null +++ b/bufferinfo/BufferInfoMapperMetadata.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 The Android Open Source 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 PLATFORMIMAGINATION_H +#define PLATFORMIMAGINATION_H + +#include "bufferinfo/BufferInfoGetter.h" + +namespace android { + +class BufferInfoMapperMetadata : public BufferInfoGetter { + public: + using BufferInfoGetter::BufferInfoGetter; + + int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; + + static BufferInfoGetter *CreateInstance(); +}; +} // namespace android + +#endif // PLATFORMIMAGINATION_H diff --git a/platform/platformimagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp index 7001d64..3d04a4b 100644 --- a/platform/platformimagination.cpp +++ b/bufferinfo/legacy/BufferInfoImagination.cpp @@ -1,6 +1,22 @@ -#define LOG_TAG "hwc-platform-imagination" +/* + * Copyright (C) 2020 The Android Open Source 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. + */ -#include "platformimagination.h" +#define LOG_TAG "hwc-bufferinfo-imagination" + +#include "BufferInfoImagination.h" #include <log/log.h> #include <xf86drm.h> @@ -9,22 +25,10 @@ namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - ImaginationImporter *importer = new ImaginationImporter(drm); - if (!importer) - return NULL; - - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the Imagination importer %d", ret); - delete importer; - return NULL; - } - return importer; -} +LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination); -int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle, - hwc_drm_bo_t *bo) { +int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle, + hwc_drm_bo_t *bo) { IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle; if (!hnd) return -EINVAL; diff --git a/bufferinfo/legacy/BufferInfoImagination.h b/bufferinfo/legacy/BufferInfoImagination.h new file mode 100644 index 0000000..765b279 --- /dev/null +++ b/bufferinfo/legacy/BufferInfoImagination.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 The Android Open Source 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 BUFFERINFOIMAGINATION_H +#define BUFFERINFOIMAGINATION_H + +#include <hardware/gralloc.h> + +#include "bufferinfo/BufferInfoGetter.h" + +namespace android { + +class BufferInfoImagination : public LegacyBufferInfoGetter { + public: + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; + + int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; +}; +} // namespace android + +#endif // PLATFORMIMAGINATION_H diff --git a/platform/platformlibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp index 59f1be9..872ee19 100644 --- a/platform/platformlibdrm.cpp +++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -#define LOG_TAG "hwc-platform-libdrm" +#define LOG_TAG "hwc-bufferinfo-libdrm" -#include "platformlibdrm.h" +#include "BufferInfoLibdrm.h" #include <cutils/properties.h> #include <gralloc_handle.h> @@ -27,19 +27,7 @@ namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - DrmGenericImporter *importer = new LibdrmImporter(drm); - if (!importer) - return NULL; - - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the libdrm importer %d", ret); - delete importer; - return NULL; - } - return importer; -} +LEGACY_BUFFER_INFO_GETTER(BufferInfoLibdrm); enum chroma_order { YCbCr, @@ -94,8 +82,8 @@ static bool is_yuv(int native) { return false; } -bool LibdrmImporter::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, - hwc_drm_bo_t *bo) { +bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, + hwc_drm_bo_t *bo) { struct android_ycbcr ycbcr; enum chroma_order chroma_order; int ret; @@ -165,7 +153,7 @@ bool LibdrmImporter::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, return true; } -int LibdrmImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { +int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { gralloc_handle_t *gr_handle = gralloc_handle(handle); if (!gr_handle) return -EINVAL; diff --git a/platform/platformlibdrm.h b/bufferinfo/legacy/BufferInfoLibdrm.h index abec17c..4d37d00 100644 --- a/platform/platformlibdrm.h +++ b/bufferinfo/legacy/BufferInfoLibdrm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ * limitations under the License. */ -#ifndef ANDROID_PLATFORM_LIBDRM_H_ -#define ANDROID_PLATFORM_LIBDRM_H_ +#ifndef BUFFERINFOLIBDRM_H_ +#define BUFFERINFOLIBDRM_H_ #include <hardware/gralloc.h> -#include "platform.h" -#include "platformdrmgeneric.h" +#include "bufferinfo/BufferInfoGetter.h" namespace android { -class LibdrmImporter : public DrmGenericImporter { +class BufferInfoLibdrm : public LegacyBufferInfoGetter { public: - using DrmGenericImporter::DrmGenericImporter; + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; private: diff --git a/platform/platformhisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp index 67793db..98b2786 100644 --- a/platform/platformhisi.cpp +++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,39 +14,28 @@ * limitations under the License. */ -#define LOG_TAG "hwc-platform-hisi" +#define LOG_TAG "hwc-bufferinfo-mali-hisi" -#include "platformhisi.h" +#include "BufferInfoMaliHisi.h" +#include <log/log.h> #include <xf86drm.h> #include <xf86drmMode.h> + #include <cinttypes> -#include <log/log.h> #include "gralloc_priv.h" #define MALI_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1)) namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - HisiImporter *importer = new HisiImporter(drm); - if (!importer) - return NULL; - - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the hisi importer %d", ret); - delete importer; - return NULL; - } - return importer; -} +LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliHisi); #if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \ defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16) -uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags, - bool is_rgb) { +uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(uint64_t flags, + bool is_rgb) { uint64_t features = 0UL; if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) @@ -71,29 +60,14 @@ uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags, return 0; } #else -uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t /* flags */, - bool /* is_rgb */) { +uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers( + uint64_t /* flags */, bool /* is_rgb */) { return 0; } #endif -bool HisiImporter::IsDrmFormatRgb(uint32_t drm_format) { - switch (drm_format) { - case DRM_FORMAT_ARGB8888: - case DRM_FORMAT_XBGR8888: - case DRM_FORMAT_ABGR8888: - case DRM_FORMAT_BGR888: - case DRM_FORMAT_BGR565: - return true; - case DRM_FORMAT_YVU420: - return false; - default: - ALOGV("Unsupported format %u assuming rgb?", drm_format); - return true; - } -} - -int HisiImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { +int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle, + hwc_drm_bo_t *bo) { bool is_rgb; private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( @@ -108,9 +82,9 @@ int HisiImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { if (fmt == DRM_FORMAT_INVALID) return -EINVAL; - is_rgb = HisiImporter::IsDrmFormatRgb(fmt); - bo->modifiers[0] = HisiImporter:: - ConvertGrallocFormatToDrmModifiers(hnd->internal_format, is_rgb); + is_rgb = IsDrmFormatRgb(fmt); + bo->modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format, + is_rgb); bo->width = hnd->width; bo->height = hnd->height; diff --git a/platform/platformhisi.h b/bufferinfo/legacy/BufferInfoMaliHisi.h index 272e547..698a0d3 100644 --- a/platform/platformhisi.h +++ b/bufferinfo/legacy/BufferInfoMaliHisi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,23 @@ * limitations under the License. */ -#ifndef ANDROID_PLATFORM_HISI_H_ -#define ANDROID_PLATFORM_HISI_H_ - -#include "platform.h" -#include "platformdrmgeneric.h" - -#include <stdatomic.h> +#ifndef BUFFERINFOMALIHISI_H_ +#define BUFFERINFOMALIHISI_H_ #include <hardware/gralloc.h> +#include "bufferinfo/BufferInfoGetter.h" + namespace android { -class HisiImporter : public DrmGenericImporter { +class BufferInfoMaliHisi : public LegacyBufferInfoGetter { public: - using DrmGenericImporter::DrmGenericImporter; + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; private: uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb); - - bool IsDrmFormatRgb(uint32_t drm_format); }; } // namespace android diff --git a/platform/platformmediatek.cpp b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp index bbf76ea..594b582 100644 --- a/platform/platformmediatek.cpp +++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp @@ -14,9 +14,9 @@ * limitations under the License. */ -#define LOG_TAG "hwc-platform-mediatek" +#define LOG_TAG "hwc-bufferinfo-mali-mediatek" -#include "platformmediatek.h" +#include "BufferInfoMaliMediatek.h" #include <hardware/gralloc.h> #include <log/log.h> @@ -27,25 +27,13 @@ #include <cinttypes> #include "gralloc_priv.h" -#include "platform.h" namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - MediatekImporter *importer = new MediatekImporter(drm); - if (!importer) - return NULL; +LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek); - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the mediatek importer %d", ret); - delete importer; - return NULL; - } - return importer; -} - -int MediatekImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { +int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle, + hwc_drm_bo_t *bo) { private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( handle); if (!hnd) diff --git a/platform/platformmediatek.h b/bufferinfo/legacy/BufferInfoMaliMediatek.h index 61fcf47..1204818 100644 --- a/platform/platformmediatek.h +++ b/bufferinfo/legacy/BufferInfoMaliMediatek.h @@ -14,20 +14,18 @@ * limitations under the License. */ -#ifndef ANDROID_PLATFORM_MTK_H_ -#define ANDROID_PLATFORM_MTK_H_ +#ifndef BUFFERINFOMALIMTK_H_ +#define BUFFERINFOMALIMTK_H_ #include <hardware/gralloc.h> -#include <stdatomic.h> -#include "platform.h" -#include "platformdrmgeneric.h" +#include "bufferinfo/BufferInfoGetter.h" namespace android { -class MediatekImporter : public DrmGenericImporter { +class BufferInfoMaliMediatek : public LegacyBufferInfoGetter { public: - using DrmGenericImporter::DrmGenericImporter; + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; }; diff --git a/platform/platformmeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp index 278eac5..2f1ca21 100644 --- a/platform/platformmeson.cpp +++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp @@ -14,36 +14,26 @@ * limitations under the License. */ -#define LOG_TAG "hwc-platform-meson" +#define LOG_TAG "hwc-bufferinfo-mali-meson" -#include "platformmeson.h" +#include "BufferInfoMaliMeson.h" +#include <log/log.h> #include <xf86drm.h> #include <xf86drmMode.h> + #include <cinttypes> -#include <log/log.h> #include "gralloc_priv.h" namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - MesonImporter *importer = new MesonImporter(drm); - if (!importer) - return NULL; - - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the meson importer %d", ret); - delete importer; - return NULL; - } - return importer; -} +LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMeson); #if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \ defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16) -uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags) { +uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers( + uint64_t flags) { uint64_t features = 0UL; if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) { @@ -65,13 +55,14 @@ uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags) { return 0; } #else -uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers( +uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers( uint64_t /* flags */) { return 0; } #endif -int MesonImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { +int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle, + hwc_drm_bo_t *bo) { private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( handle); if (!hnd) @@ -84,7 +75,7 @@ int MesonImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { if (fmt == DRM_FORMAT_INVALID) return -EINVAL; - bo->modifiers[0] = MesonImporter::ConvertGrallocFormatToDrmModifiers( + bo->modifiers[0] = BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers( hnd->internal_format); bo->width = hnd->width; diff --git a/platform/platformmeson.h b/bufferinfo/legacy/BufferInfoMaliMeson.h index 1b428a4..ce5d3f9 100644 --- a/platform/platformmeson.h +++ b/bufferinfo/legacy/BufferInfoMaliMeson.h @@ -14,22 +14,18 @@ * limitations under the License. */ -#ifndef ANDROID_PLATFORM_HISI_H_ -#define ANDROID_PLATFORM_HISI_H_ - -#include "platform.h" -#include "platformdrmgeneric.h" - -#include <stdatomic.h> +#ifndef BUFFERINFOMALIHISI_H_ +#define BUFFERINFOMALIHISI_H_ #include <hardware/gralloc.h> +#include "bufferinfo/BufferInfoGetter.h" + namespace android { -class MesonImporter : public DrmGenericImporter { +class BufferInfoMaliMeson : public LegacyBufferInfoGetter { public: - using DrmGenericImporter::DrmGenericImporter; - + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; private: diff --git a/platform/platformminigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp index 4360b0a..67a85cb 100644 --- a/platform/platformminigbm.cpp +++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp @@ -14,35 +14,21 @@ * limitations under the License. */ -#define LOG_TAG "hwc-platform-drm-minigbm" +#define LOG_TAG "hwc-bufferinfo-minigbm" -#include "platformminigbm.h" +#include "BufferInfoMinigbm.h" +#include <log/log.h> #include <xf86drm.h> #include <xf86drmMode.h> -#include <log/log.h> - #include "cros_gralloc_handle.h" namespace android { -Importer *Importer::CreateInstance(DrmDevice *drm) { - DrmMinigbmImporter *importer = new DrmMinigbmImporter(drm); - if (!importer) - return NULL; - - int ret = importer->Init(); - if (ret) { - ALOGE("Failed to initialize the minigbm importer %d", ret); - delete importer; - return NULL; - } - return importer; -} +LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm); -int DrmMinigbmImporter::ConvertBoInfo(buffer_handle_t handle, - hwc_drm_bo_t *bo) { +int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle; if (!gr_handle) return -EINVAL; diff --git a/platform/platformminigbm.h b/bufferinfo/legacy/BufferInfoMinigbm.h index 1eea6ca..bff9d74 100644 --- a/platform/platformminigbm.h +++ b/bufferinfo/legacy/BufferInfoMinigbm.h @@ -14,19 +14,18 @@ * limitations under the License. */ -#ifndef ANDROID_PLATFORM_DRM_MINIGBM_H_ -#define ANDROID_PLATFORM_DRM_MINIGBM_H_ - -#include "platform.h" -#include "platformdrmgeneric.h" +#ifndef BUFFERINFOMINIGBM_H_ +#define BUFFERINFOMINIGBM_H_ #include <hardware/gralloc.h> +#include "bufferinfo/BufferInfoGetter.h" + namespace android { -class DrmMinigbmImporter : public DrmGenericImporter { +class BufferInfoMinigbm : public LegacyBufferInfoGetter { public: - using DrmGenericImporter::DrmGenericImporter; + using LegacyBufferInfoGetter::LegacyBufferInfoGetter; int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; }; diff --git a/compositor/DrmDisplayComposition.cpp b/compositor/DrmDisplayComposition.cpp index 79dd470..4d2e19a 100644 --- a/compositor/DrmDisplayComposition.cpp +++ b/compositor/DrmDisplayComposition.cpp @@ -27,8 +27,8 @@ #include <unordered_set> #include "DrmDisplayCompositor.h" +#include "Planner.h" #include "drm/DrmDevice.h" -#include "platform/platform.h" namespace android { diff --git a/compositor/DrmDisplayCompositor.h b/compositor/DrmDisplayCompositor.h index 29afc66..ab3f867 100644 --- a/compositor/DrmDisplayCompositor.h +++ b/compositor/DrmDisplayCompositor.h @@ -27,6 +27,7 @@ #include "DrmDisplayComposition.h" #include "DrmFramebuffer.h" +#include "Planner.h" #include "drm/ResourceManager.h" #include "drm/VSyncWorker.h" #include "drmhwcomposer.h" diff --git a/platform/platform.cpp b/compositor/Planner.cpp index a500398..f4b5c51 100644 --- a/platform/platform.cpp +++ b/compositor/Planner.cpp @@ -16,7 +16,7 @@ #define LOG_TAG "hwc-platform" -#include "platform.h" +#include "Planner.h" #include <log/log.h> @@ -24,6 +24,12 @@ namespace android { +std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { + std::unique_ptr<Planner> planner(new Planner); + planner->AddStage<PlanStageGreedy>(); + return planner; +} + std::vector<DrmPlane *> Planner::GetUsablePlanes( DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes, std::vector<DrmPlane *> *overlay_planes) { diff --git a/platform/platform.h b/compositor/Planner.h index 13dc360..09034ff 100644 --- a/platform/platform.h +++ b/compositor/Planner.h @@ -30,33 +30,6 @@ namespace android { class DrmDevice; -class Importer { - public: - virtual ~Importer() { - } - - // Creates a platform-specific importer instance - static Importer *CreateInstance(DrmDevice *drm); - - // Imports the buffer referred to by handle into bo. - // - // Note: This can be called from a different thread than ReleaseBuffer. The - // implementation is responsible for ensuring thread safety. - virtual int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0; - - // Releases the buffer object (ie: does the inverse of ImportBuffer) - // - // Note: This can be called from a different thread than ImportBuffer. The - // implementation is responsible for ensuring thread safety. - virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0; - - // Checks if importer can import the buffer. - virtual bool CanImportBuffer(buffer_handle_t handle) = 0; - - // Convert platform-dependent buffer format to drm_hwc internal format. - virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0; -}; - class Planner { public: class PlanStage { diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp index 28ecfda..bf1a5e2 100644 --- a/drm/DrmDevice.cpp +++ b/drm/DrmDevice.cpp @@ -29,6 +29,7 @@ #include <algorithm> #include <array> #include <cinttypes> +#include <sstream> #include <string> static void trim_left(std::string &str) { diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h index d7ea359..be68aa6 100644 --- a/drm/DrmDevice.h +++ b/drm/DrmDevice.h @@ -19,6 +19,7 @@ #include <stdint.h> +#include <map> #include <tuple> #include "DrmConnector.h" @@ -26,7 +27,6 @@ #include "DrmEncoder.h" #include "DrmEventListener.h" #include "DrmPlane.h" -#include "platform/platform.h" namespace android { diff --git a/platform/platformdrmgeneric.cpp b/drm/DrmGenericImporter.cpp index 8c1adba..b4dc063 100644 --- a/platform/platformdrmgeneric.cpp +++ b/drm/DrmGenericImporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,14 @@ #define LOG_TAG "hwc-platform-drm-generic" -#include "platformdrmgeneric.h" - -#include <xf86drm.h> -#include <xf86drmMode.h> +#include "DrmGenericImporter.h" #include <cutils/properties.h> #include <gralloc_handle.h> #include <hardware/gralloc.h> #include <log/log.h> +#include <xf86drm.h> +#include <xf86drmMode.h> namespace android { @@ -34,66 +33,9 @@ DrmGenericImporter::DrmGenericImporter(DrmDevice *drm) : drm_(drm) { DrmGenericImporter::~DrmGenericImporter() { } -int DrmGenericImporter::Init() { - int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, - (const hw_module_t **)&gralloc_); - if (ret) { - ALOGE("Failed to open gralloc module"); - return ret; - } - - ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name, - gralloc_->common.author); - - return 0; -} - -uint32_t DrmGenericImporter::ConvertHalFormatToDrm(uint32_t hal_format) { - switch (hal_format) { - case HAL_PIXEL_FORMAT_RGB_888: - return DRM_FORMAT_BGR888; - case HAL_PIXEL_FORMAT_BGRA_8888: - return DRM_FORMAT_ARGB8888; - case HAL_PIXEL_FORMAT_RGBX_8888: - return DRM_FORMAT_XBGR8888; - case HAL_PIXEL_FORMAT_RGBA_8888: - return DRM_FORMAT_ABGR8888; - case HAL_PIXEL_FORMAT_RGB_565: - return DRM_FORMAT_BGR565; - case HAL_PIXEL_FORMAT_YV12: - return DRM_FORMAT_YVU420; - default: - ALOGE("Cannot convert hal format to drm format %u", hal_format); - return DRM_FORMAT_INVALID; - } -} - -uint32_t DrmGenericImporter::DrmFormatToBitsPerPixel(uint32_t drm_format) { - switch (drm_format) { - case DRM_FORMAT_ARGB8888: - case DRM_FORMAT_XBGR8888: - case DRM_FORMAT_ABGR8888: - return 32; - case DRM_FORMAT_BGR888: - return 24; - case DRM_FORMAT_BGR565: - return 16; - case DRM_FORMAT_YVU420: - return 12; - default: - ALOGE("Cannot convert hal format %u to bpp (returning 32)", drm_format); - return 32; - } -} - -int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { - memset(bo, 0, sizeof(hwc_drm_bo_t)); - - int ret = ConvertBoInfo(handle, bo); - if (ret) - return ret; - - ret = drmPrimeFDToHandle(drm_->fd(), bo->prime_fds[0], &bo->gem_handles[0]); +int DrmGenericImporter::ImportBuffer(hwc_drm_bo_t *bo) { + int ret = drmPrimeFDToHandle(drm_->fd(), bo->prime_fds[0], + &bo->gem_handles[0]); if (ret) { ALOGE("failed to import prime fd %d ret=%d", bo->prime_fds[0], ret); return ret; @@ -152,25 +94,6 @@ int DrmGenericImporter::ReleaseBuffer(hwc_drm_bo_t *bo) { return 0; } -bool DrmGenericImporter::CanImportBuffer(buffer_handle_t handle) { - hwc_drm_bo_t bo; - - int ret = ConvertBoInfo(handle, &bo); - if (ret) - return false; - - if (bo.prime_fds[0] == 0) - return false; - - return true; -} - -std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { - std::unique_ptr<Planner> planner(new Planner); - planner->AddStage<PlanStageGreedy>(); - return planner; -} - int DrmGenericImporter::ImportHandle(uint32_t gem_handle) { gem_refcount_[gem_handle]++; @@ -198,4 +121,4 @@ int DrmGenericImporter::CloseHandle(uint32_t gem_handle) { return ret; } -} +} // namespace android diff --git a/platform/platformdrmgeneric.h b/drm/DrmGenericImporter.h index 6c15ae6..efda6be 100644 --- a/platform/platformdrmgeneric.h +++ b/drm/DrmGenericImporter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ #include <map> #include "drm/DrmDevice.h" -#include "platform.h" +#include "drmhwcgralloc.h" #ifndef DRM_FORMAT_INVALID #define DRM_FORMAT_INVALID 0 @@ -31,33 +31,42 @@ namespace android { +class Importer { + public: + virtual ~Importer() { + } + + // Imports the buffer referred to by handle into bo. + // + // Note: This can be called from a different thread than ReleaseBuffer. The + // implementation is responsible for ensuring thread safety. + virtual int ImportBuffer(hwc_drm_bo_t *bo) = 0; + + // Releases the buffer object (ie: does the inverse of ImportBuffer) + // + // Note: This can be called from a different thread than ImportBuffer. The + // implementation is responsible for ensuring thread safety. + virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0; +}; + class DrmGenericImporter : public Importer { public: DrmGenericImporter(DrmDevice *drm); ~DrmGenericImporter() override; - int Init(); - - int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override; + int ImportBuffer(hwc_drm_bo_t *bo) override; int ReleaseBuffer(hwc_drm_bo_t *bo) override; - bool CanImportBuffer(buffer_handle_t handle) override; int ImportHandle(uint32_t gem_handle); int ReleaseHandle(uint32_t gem_handle); - int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0; - - uint32_t ConvertHalFormatToDrm(uint32_t hal_format); - uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format); - protected: DrmDevice *drm_; - const gralloc_module_t *gralloc_; private: - int CloseHandle(uint32_t gem_handle); std::map<uint32_t, int> gem_refcount_; }; + } // namespace android #endif diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp index 67ef7f8..fc24aea 100644 --- a/drm/ResourceManager.cpp +++ b/drm/ResourceManager.cpp @@ -24,6 +24,8 @@ #include <sstream> +#include "bufferinfo/BufferInfoGetter.h" + namespace android { ResourceManager::ResourceManager() : num_displays_(0), gralloc_(NULL) { @@ -62,6 +64,11 @@ int ResourceManager::Init() { property_get("vendor.hwc.drm.scale_with_gpu", scale_with_gpu, "0"); scale_with_gpu_ = bool(strncmp(scale_with_gpu, "0", 1)); + if (!BufferInfoGetter::GetInstance()) { + ALOGE("Failed to initialize BufferInfoGetter"); + return -EINVAL; + } + return hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&gralloc_); } @@ -73,7 +80,7 @@ int ResourceManager::AddDrmDevice(std::string path) { if (ret) return ret; std::shared_ptr<Importer> importer; - importer.reset(Importer::CreateInstance(drm.get())); + importer.reset(new DrmGenericImporter(drm.get())); if (!importer) { ALOGE("Failed to create importer instance"); return -ENODEV; diff --git a/drm/ResourceManager.h b/drm/ResourceManager.h index 94ba43e..7102cea 100644 --- a/drm/ResourceManager.h +++ b/drm/ResourceManager.h @@ -20,7 +20,7 @@ #include <string.h> #include "DrmDevice.h" -#include "platform/platform.h" +#include "DrmGenericImporter.h" namespace android { diff --git a/platform/platformimagination.h b/platform/platformimagination.h deleted file mode 100644 index 4eec698..0000000 --- a/platform/platformimagination.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef PLATFORMIMAGINATION_H -#define PLATFORMIMAGINATION_H - -#include "platform.h" -#include "platformdrmgeneric.h" - -#include <stdatomic.h> - -#include <hardware/gralloc.h> - -namespace android { - -class ImaginationImporter : public DrmGenericImporter { - public: - using DrmGenericImporter::DrmGenericImporter; - - int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override; -}; -} // namespace android - -#endif // PLATFORMIMAGINATION_H diff --git a/utils/hwcutils.cpp b/utils/hwcutils.cpp index 2dc7e7b..2cd46fa 100644 --- a/utils/hwcutils.cpp +++ b/utils/hwcutils.cpp @@ -20,8 +20,9 @@ #include <log/log.h> #include <ui/GraphicBufferMapper.h> +#include "bufferinfo/BufferInfoGetter.h" +#include "drm/DrmGenericImporter.h" #include "drmhwcomposer.h" -#include "platform/platform.h" #define UNUSED(x) (void)(x) @@ -44,9 +45,11 @@ void DrmHwcBuffer::Clear() { } int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, Importer *importer) { - hwc_drm_bo tmp_bo; + hwc_drm_bo tmp_bo{}; - int ret = importer->ImportBuffer(handle, &tmp_bo); + BufferInfoGetter::GetInstance()->ConvertBoInfo(handle, &tmp_bo); + + int ret = importer->ImportBuffer(&tmp_bo); if (ret) return ret; |