Skip to content

Commit

Permalink
Video layer use device composition
Browse files Browse the repository at this point in the history
Due to video layer update frequently, we need
force video layer to use plane for composition even
we don't set prop 'vendor.hwcomposer.planes.enabling'

Tracked-On: OAM-108575
Signed-off-by: Li, HaihongX <haihongx.li@intel.com>
  • Loading branch information
HaihongxLi committed Mar 29, 2023
1 parent 50b21ad commit 4ea7e11
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ cc_defaults {
"libutils",
],

include_dirs: ["vendor/intel/external/drm-hwcomposer"],
include_dirs: [
"vendor/intel/external/drm-hwcomposer",
"hardware/intel/external/minigbm-intel/cros_gralloc",
],

static_libs: ["libdrmhwc_utils"],

Expand Down
14 changes: 9 additions & 5 deletions backend/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ HWC2::Error Backend::ValidateDisplay(HwcDisplay *display, uint32_t *num_types,
MarkValidated(layers, client_start, client_size);
} else {
std::tie(client_start, client_size) = GetClientLayers(display, layers);

MarkValidated(layers, client_start, client_size);

bool testing_needed = !(client_start == 0 && client_size == layers.size());
Expand Down Expand Up @@ -86,7 +85,8 @@ bool Backend::IsClientLayer(HwcDisplay *display, HwcLayer *layer) {
!layer->IsLayerUsableAsDevice() ||
display->color_transform_hint() != HAL_COLOR_TRANSFORM_IDENTITY ||
(layer->GetLayerData().pi.RequireScalingOrPhasing() &&
display->GetHwc2()->GetResMan().ForcedScalingWithGpu());
display->GetHwc2()->GetResMan().ForcedScalingWithGpu()) ||
(!layer->IsVideoLayer() && !display->GetPipe().device->planes_enabling_);
}

bool Backend::HardwareSupportsLayerType(HWC2::Composition comp_type) {
Expand Down Expand Up @@ -119,10 +119,14 @@ void Backend::MarkValidated(std::vector<HwcLayer *> &layers,
std::tuple<int, int> Backend::GetExtraClientRange(
HwcDisplay *display, const std::vector<HwcLayer *> &layers,
int client_start, size_t client_size) {
auto planes = display->GetPipe().GetUsablePlanes();
uint32_t video_layer_number = 0;
for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
if (layers[z_order]->IsVideoLayer())
video_layer_number++;
}
auto planes = display->GetPipe().GetUsablePlanes(video_layer_number);
size_t avail_planes = planes.size();

/*
/*
* If more layers then planes, save one plane
* for client composited layers
*/
Expand Down
5 changes: 3 additions & 2 deletions compositor/DrmKmsPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

namespace android {
auto DrmKmsPlan::CreateDrmKmsPlan(DrmDisplayPipeline &pipe,
std::vector<LayerData> composition)
std::vector<LayerData> composition,
uint32_t video_layer_number)
-> std::unique_ptr<DrmKmsPlan> {
auto plan = std::make_unique<DrmKmsPlan>();

auto avail_planes = pipe.GetUsablePlanes();
auto avail_planes = pipe.GetUsablePlanes(video_layer_number);

int z_pos = 0;
for (auto &dhl : composition) {
Expand Down
3 changes: 2 additions & 1 deletion compositor/DrmKmsPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct DrmKmsPlan {
std::vector<LayerToPlaneJoining> plan;

static auto CreateDrmKmsPlan(DrmDisplayPipeline &pipe,
std::vector<LayerData> composition)
std::vector<LayerData> composition,
uint32_t video_layer_number)
-> std::unique_ptr<DrmKmsPlan>;
};

Expand Down
8 changes: 1 addition & 7 deletions drm/DrmDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,7 @@ auto DrmDevice::Init(const char *path) -> int {
for (uint32_t i = 0; i < plane_res->count_planes; ++i) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
auto plane = DrmPlane::CreateInstance(*this, plane_res->planes[i]);

if (!planes_enabling_) {
if (plane->GetType() == DRM_PLANE_TYPE_PRIMARY)
planes_.emplace_back(std::move(plane));
} else {
planes_.emplace_back(std::move(plane));
}
planes_.emplace_back(std::move(plane));
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions drm/DrmDisplayPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,16 @@ static bool ReadUseOverlayProperty() {
return strtol(use_overlay_planes_prop, nullptr, kStrtolBase) != 0;
}

auto DrmDisplayPipeline::GetUsablePlanes()
auto DrmDisplayPipeline::GetUsablePlanes(uint32_t video_layer_number)
-> std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> {
std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> planes;
planes.emplace_back(primary_plane);

static bool use_overlay_planes = ReadUseOverlayProperty();

if (use_overlay_planes) {
int32_t planes_num = device->planes_num_ - 1;
if (!device->planes_enabling_)
planes_num = video_layer_number;
for (const auto &plane : device->GetPlanes()) {
if (plane->IsCrtcSupported(*crtc->Get())) {
if (plane->GetType() == DRM_PLANE_TYPE_OVERLAY) {
Expand All @@ -190,7 +191,6 @@ auto DrmDisplayPipeline::GetUsablePlanes()
}
}
}

return planes;
}

Expand Down
2 changes: 1 addition & 1 deletion drm/DrmDisplayPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct DrmDisplayPipeline {
static auto CreatePipeline(DrmConnector &connector)
-> std::unique_ptr<DrmDisplayPipeline>;

auto GetUsablePlanes()
auto GetUsablePlanes(uint32_t video_layer_number)
-> std::vector<std::shared_ptr<BindingOwner<DrmPlane>>>;

auto AtomicDisablePipeline() -> int;
Expand Down
6 changes: 5 additions & 1 deletion hwc2_device/HwcDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,10 @@ HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
bool use_client_layer = false;
uint32_t client_z_order = UINT32_MAX;
std::map<uint32_t, HwcLayer *> z_map;
uint32_t video_layer_number = 0;
for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
if (l.second.IsVideoLayer())
video_layer_number++;
switch (l.second.GetValidatedType()) {
case HWC2::Composition::Device:
z_map.emplace(std::make_pair(l.second.GetZOrder(), &l.second));
Expand Down Expand Up @@ -572,7 +575,8 @@ HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
* in between of ValidateDisplay() and PresentDisplay() calls
*/
current_plan_ = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
std::move(composition_layers));
std::move(composition_layers),
video_layer_number);
if (!current_plan_) {
if (!a_args.test_only) {
ALOGE("Failed to create DrmKmsPlan");
Expand Down
35 changes: 34 additions & 1 deletion hwc2_device/HwcLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "HwcDisplay.h"
#include "bufferinfo/BufferInfoGetter.h"
#include "utils/log.h"

#include "cros_gralloc_handle.h"
namespace android {

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
Expand Down Expand Up @@ -60,6 +60,39 @@ HWC2::Error HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
return HWC2::Error::None;
}

bool HwcLayer::IsVideoLayer() {
if (nullptr != buffer_handle_) {
cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)(buffer_handle_);
if ((nullptr != gr_handle) && (IsSupportedMediaFormat(gr_handle->format)))
return true;
}
return false;
}

bool HwcLayer::IsSupportedMediaFormat(uint32_t format) {
switch (format) {
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV16:
case DRM_FORMAT_P010:
case DRM_FORMAT_YVU420:
case DRM_FORMAT_YUV420:
case DRM_FORMAT_YUV422:
case DRM_FORMAT_YUV444:
case DRM_FORMAT_UYVY:
case DRM_FORMAT_YUYV:
case DRM_FORMAT_YVYU:
case DRM_FORMAT_VYUY:
case DRM_FORMAT_AYUV:
case DRM_FORMAT_NV12_Y_TILED_INTEL:
case DRM_FORMAT_NV21:
case DRM_FORMAT_YVU420_ANDROID:
return true;
default:
break;
}
return false;
}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
HWC2::Error HwcLayer::SetLayerColor(hwc_color_t /*color*/) {
// TODO(nobody): Put to client composition here?
Expand Down
7 changes: 5 additions & 2 deletions hwc2_device/HwcLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#include "compositor/LayerData.h"

namespace android {

#define DRM_FORMAT_YVU420_ANDROID fourcc_code('9', '9', '9', '7')
#define DRM_FORMAT_P010 fourcc_code('P', '0', '1', '0')
class HwcDisplay;

class HwcLayer {
Expand Down Expand Up @@ -62,6 +63,8 @@ class HwcLayer {
return layer_data_;
}

bool IsVideoLayer();

// Layer hooks
HWC2::Error SetCursorPosition(int32_t /*x*/, int32_t /*y*/);
HWC2::Error SetLayerBlendMode(int32_t mode);
Expand Down Expand Up @@ -122,7 +125,7 @@ class HwcLayer {
void ImportFb();
bool bi_get_failed_{};
bool fb_import_failed_{};

bool IsSupportedMediaFormat(uint32_t format);
/* SwapChain Cache */
public:
void SwChainClearCache();
Expand Down

0 comments on commit 4ea7e11

Please sign in to comment.