drm_hwcomposer: Set correct source crop for the client layer
Android supports limiting client buffer size using system properties:
"ro.surface_flinger.max_graphics_width"
"ro.surface_flinger.max_graphics_height"
If properties are set, client layer buffer size can no longer be equal to the
display size, which causes composition with CLIENT buffer to fail.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/DrmHwcTwo.cpp b/DrmHwcTwo.cpp
index 5b9b5df..93b6fa7 100644
--- a/DrmHwcTwo.cpp
+++ b/DrmHwcTwo.cpp
@@ -28,6 +28,7 @@
#include <string>
#include "backend/BackendManager.h"
+#include "bufferinfo/BufferInfoGetter.h"
#include "compositor/DrmDisplayComposition.h"
namespace android {
@@ -757,11 +758,6 @@
.right = static_cast<int>(mode->h_display()),
.bottom = static_cast<int>(mode->v_display())};
client_layer_.SetLayerDisplayFrame(display_frame);
- hwc_frect_t source_crop = {.left = 0.0f,
- .top = 0.0f,
- .right = mode->h_display() + 0.0f,
- .bottom = mode->v_display() + 0.0f};
- client_layer_.SetLayerSourceCrop(source_crop);
return HWC2::Error::None;
}
@@ -776,6 +772,18 @@
client_layer_.set_buffer(target);
client_layer_.set_acquire_fence(uf.get());
client_layer_.SetLayerDataspace(dataspace);
+
+ /* TODO: Do not update source_crop every call.
+ * It makes sense to do it once after every hotplug event. */
+ hwc_drm_bo bo{};
+ BufferInfoGetter::GetInstance()->ConvertBoInfo(target, &bo);
+
+ hwc_frect_t source_crop = {.left = 0.0f,
+ .top = 0.0f,
+ .right = bo.width + 0.0f,
+ .bottom = bo.height + 0.0f};
+ client_layer_.SetLayerSourceCrop(source_crop);
+
return HWC2::Error::None;
}