drm_hwcomposer: Tracking of the DRM FB objects using RAII
DRM framebuffer objects must be kept registered in DRM/KMS
while used for scanning-out (After atomic commit applied
for processing by display controller and until next atomic
commit is applied for processing).
Existing logic for tracking current state is overcomplicated and
needs to be redesigned. Also further developing of drm_hwc will
require migration to asynchronous atomic commit, so additional
asynchronous FB cleanup logic must be created.
Buffer caching logic will also benefit from this.
With the RAII all further changes will be less painful and more robust.
By this commit I also renamed DrmGenericImporter to DrmFbImporter:
'Fb' word is present in most of existing composers (android and linux)
so it will be easier to compare different implementations.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/utils/hwcutils.cpp b/utils/hwcutils.cpp
index 81097ce..d9b8a87 100644
--- a/utils/hwcutils.cpp
+++ b/utils/hwcutils.cpp
@@ -22,7 +22,7 @@
#include <ui/GraphicBufferMapper.h>
#include "bufferinfo/BufferInfoGetter.h"
-#include "drm/DrmGenericImporter.h"
+#include "drm/DrmFbImporter.h"
#include "drmhwcomposer.h"
#define UNUSED(x) (void)(x)
@@ -30,7 +30,7 @@
namespace android {
const hwc_drm_bo *DrmHwcBuffer::operator->() const {
- if (importer_ == nullptr) {
+ if (mDrmDevice == nullptr) {
ALOGE("Access of non-existent BO");
exit(1);
return nullptr;
@@ -39,13 +39,11 @@
}
void DrmHwcBuffer::Clear() {
- if (importer_ != nullptr) {
- importer_->ReleaseBuffer(&bo_);
- importer_ = nullptr;
- }
+ FbIdHandle.reset();
+ mDrmDevice = nullptr;
}
-int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, Importer *importer) {
+int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, DrmDevice *drmDevice) {
hwc_drm_bo tmp_bo{};
int ret = BufferInfoGetter::GetInstance()->ConvertBoInfo(handle, &tmp_bo);
@@ -54,18 +52,13 @@
return ret;
}
- ret = importer->ImportBuffer(&tmp_bo);
- if (ret) {
- ALOGE("Failed to import buffer %d", ret);
- return ret;
+ FbIdHandle = drmDevice->GetDrmFbImporter().GetOrCreateFbId(&tmp_bo);
+ if (!FbIdHandle) {
+ ALOGE("Failed to import buffer");
+ return -EINVAL;
}
- if (importer_ != nullptr) {
- importer_->ReleaseBuffer(&bo_);
- }
-
- importer_ = importer;
-
+ mDrmDevice = drmDevice;
bo_ = tmp_bo;
return 0;
@@ -106,8 +99,8 @@
}
}
-int DrmHwcLayer::ImportBuffer(Importer *importer) {
- int ret = buffer.ImportBuffer(sf_handle, importer);
+int DrmHwcLayer::ImportBuffer(DrmDevice *drmDevice) {
+ int ret = buffer.ImportBuffer(sf_handle, drmDevice);
if (ret)
return ret;
@@ -123,7 +116,7 @@
}
int DrmHwcLayer::InitFromDrmHwcLayer(DrmHwcLayer *src_layer,
- Importer *importer) {
+ DrmDevice *drmDevice) {
blending = src_layer->blending;
sf_handle = src_layer->sf_handle;
acquire_fence = -1;
@@ -131,7 +124,7 @@
alpha = src_layer->alpha;
source_crop = src_layer->source_crop;
transform = src_layer->transform;
- return ImportBuffer(importer);
+ return ImportBuffer(drmDevice);
}
void DrmHwcLayer::SetTransform(int32_t sf_transform) {