drm_hwcomposer: Add type to DrmCompositionPlane
Instead of encoding the plane/composition type in source_layer,
move it to its own explicit type. This will allow us to expand
source_layer to include more than one layer.
BUG=b/28117135
TEST=compiles and runs on smaug
Change-Id: I19b1ed8e395347bbefb0fb6a0ab02d6ac0e5c1c1
Signed-off-by: Sean Paul <seanpaul@chromium.org>
diff --git a/drmdisplaycomposition.cpp b/drmdisplaycomposition.cpp
index 2c5ef09..2089157 100644
--- a/drmdisplaycomposition.cpp
+++ b/drmdisplaycomposition.cpp
@@ -33,11 +33,6 @@
namespace android {
-const size_t DrmCompositionPlane::kSourceNone;
-const size_t DrmCompositionPlane::kSourcePreComp;
-const size_t DrmCompositionPlane::kSourceSquash;
-const size_t DrmCompositionPlane::kSourceLayerMax;
-
DrmDisplayComposition::~DrmDisplayComposition() {
if (timeline_fd_ >= 0) {
SignalCompositionDone();
@@ -119,7 +114,10 @@
int DrmDisplayComposition::AddPlaneDisable(DrmPlane *plane) {
composition_planes_.emplace_back(
- DrmCompositionPlane{plane, crtc_, DrmCompositionPlane::kSourceNone});
+ DrmCompositionPlane{.plane = plane,
+ .crtc = crtc_,
+ .type = DrmCompositionPlaneType::kDisable,
+ .source_layer = -1});
return 0;
}
@@ -155,7 +153,8 @@
}
void DrmDisplayComposition::EmplaceCompositionPlane(
- size_t source_layer, std::vector<DrmPlane *> *primary_planes,
+ DrmCompositionPlaneType type, int source_layer,
+ std::vector<DrmPlane *> *primary_planes,
std::vector<DrmPlane *> *overlay_planes) {
DrmPlane *plane = TakePlane(crtc_, primary_planes, overlay_planes);
if (plane == NULL) {
@@ -165,7 +164,10 @@
return;
}
composition_planes_.emplace_back(
- DrmCompositionPlane{plane, crtc_, source_layer});
+ DrmCompositionPlane{.plane = plane,
+ .crtc = crtc_,
+ .type = type,
+ .source_layer = source_layer});
}
static std::vector<size_t> SetBitsToVector(uint64_t in, size_t *index_map) {
@@ -273,7 +275,7 @@
}
for (const DrmCompositionPlane &plane : composition_planes_) {
- if (plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
+ if (plane.type == DrmCompositionPlaneType::kLayer) {
DrmHwcLayer *source_layer = &layers_[plane.source_layer];
comp_layers.emplace(source_layer);
pre_comp_layers.erase(source_layer);
@@ -390,8 +392,9 @@
}
if (planes_can_use == 0 && layers_remaining.size() > 0) {
- for(auto i : protected_layers)
- EmplaceCompositionPlane(i, primary_planes, overlay_planes);
+ for (auto i : protected_layers)
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kLayer, i,
+ primary_planes, overlay_planes);
ALOGE("Protected layers consumed all hardware planes");
return CreateAndAssignReleaseFences();
@@ -427,13 +430,15 @@
// that again.
if (protected_idx < protected_layers.size() &&
idx > protected_layers[protected_idx]) {
- EmplaceCompositionPlane(protected_layers[protected_idx], primary_planes,
- overlay_planes);
- protected_idx++;
- continue;
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kLayer,
+ protected_layers[protected_idx], primary_planes,
+ overlay_planes);
+ protected_idx++;
+ continue;
}
- EmplaceCompositionPlane(layers_remaining[last_hw_comp_layer],
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kLayer,
+ layers_remaining[last_hw_comp_layer],
primary_planes, overlay_planes);
last_hw_comp_layer++;
planes_can_use--;
@@ -444,13 +449,14 @@
// Enqueue the rest of the protected layers (if any) between the hw composited
// overlay layers and the squash/precomp layers.
- for(int i = protected_idx; i < protected_layers.size(); ++i)
- EmplaceCompositionPlane(protected_layers[i], primary_planes,
+ for (int i = protected_idx; i < protected_layers.size(); ++i)
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kLayer,
+ protected_layers[i], primary_planes,
overlay_planes);
if (layers_remaining.size() > 0) {
- EmplaceCompositionPlane(DrmCompositionPlane::kSourcePreComp, primary_planes,
- overlay_planes);
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kPrecomp, -1,
+ primary_planes, overlay_planes);
SeparateLayers(layers_.data(), layers_remaining.data(),
layers_remaining.size(), protected_layers.data(),
protected_layers.size(), exclude_rects.data(),
@@ -458,8 +464,8 @@
}
if (use_squash_framebuffer) {
- EmplaceCompositionPlane(DrmCompositionPlane::kSourceSquash, primary_planes,
- overlay_planes);
+ EmplaceCompositionPlane(DrmCompositionPlaneType::kSquash, -1,
+ primary_planes, overlay_planes);
}
return CreateAndAssignReleaseFences();
@@ -626,27 +632,26 @@
const DrmCompositionPlane &comp_plane = composition_planes_[i];
*out << " [" << i << "]"
<< " plane=" << (comp_plane.plane ? comp_plane.plane->id() : -1)
- << " source_layer=";
- if (comp_plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
- *out << comp_plane.source_layer;
- } else {
- switch (comp_plane.source_layer) {
- case DrmCompositionPlane::kSourceNone:
- *out << "NONE";
- break;
- case DrmCompositionPlane::kSourcePreComp:
- *out << "PRECOMP";
- break;
- case DrmCompositionPlane::kSourceSquash:
- *out << "SQUASH";
- break;
- default:
- *out << "<invalid>";
- break;
- }
+ << " type=";
+ switch (comp_plane.type) {
+ case DrmCompositionPlaneType::kDisable:
+ *out << "DISABLE";
+ break;
+ case DrmCompositionPlaneType::kLayer:
+ *out << "LAYER";
+ break;
+ case DrmCompositionPlaneType::kPrecomp:
+ *out << "PRECOMP";
+ break;
+ case DrmCompositionPlaneType::kSquash:
+ *out << "SQUASH";
+ break;
+ default:
+ *out << "<invalid>";
+ break;
}
- *out << "\n";
+ *out << " source_layer=" << comp_plane.source_layer << "\n";
}
*out << " Squash Regions: count=" << squash_regions_.size() << "\n";
diff --git a/drmdisplaycomposition.h b/drmdisplaycomposition.h
index 264963c..0362404 100644
--- a/drmdisplaycomposition.h
+++ b/drmdisplaycomposition.h
@@ -46,14 +46,18 @@
std::vector<size_t> source_layers;
};
+enum class DrmCompositionPlaneType : int32_t {
+ kDisable,
+ kLayer,
+ kPrecomp,
+ kSquash,
+};
+
struct DrmCompositionPlane {
- const static size_t kSourceNone = SIZE_MAX;
- const static size_t kSourcePreComp = kSourceNone - 1;
- const static size_t kSourceSquash = kSourcePreComp - 1;
- const static size_t kSourceLayerMax = kSourceSquash - 1;
+ DrmCompositionPlaneType type;
DrmPlane *plane;
DrmCrtc *crtc;
- size_t source_layer;
+ int source_layer;
};
class DrmDisplayComposition {
@@ -135,7 +139,7 @@
int IncreaseTimelineToPoint(int point);
- void EmplaceCompositionPlane(size_t source_layer,
+ void EmplaceCompositionPlane(DrmCompositionPlaneType type, int source_layer,
std::vector<DrmPlane *> *primary_planes,
std::vector<DrmPlane *> *overlay_planes);
int CreateAndAssignReleaseFences();
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index df8e331..c9cf40c 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -172,9 +172,8 @@
static bool UsesSquash(const std::vector<DrmCompositionPlane> &comp_planes) {
return std::any_of(comp_planes.begin(), comp_planes.end(),
[](const DrmCompositionPlane &plane) {
- return plane.source_layer ==
- DrmCompositionPlane::kSourceSquash;
- });
+ return plane.type == DrmCompositionPlaneType::kSquash;
+ });
}
DrmDisplayCompositor::FrameWorker::FrameWorker(DrmDisplayCompositor *compositor)
@@ -573,11 +572,11 @@
}
for (DrmCompositionPlane &comp_plane : comp_planes) {
- switch (comp_plane.source_layer) {
- case DrmCompositionPlane::kSourceSquash:
+ switch (comp_plane.type) {
+ case DrmCompositionPlaneType::kSquash:
comp_plane.source_layer = squash_layer_index;
break;
- case DrmCompositionPlane::kSourcePreComp:
+ case DrmCompositionPlaneType::kPrecomp:
if (!do_pre_comp) {
ALOGE(
"Can not use pre composite framebuffer with no pre composite "
@@ -645,63 +644,54 @@
DrmHwcRect<float> source_crop;
uint64_t rotation = 0;
uint64_t alpha = 0xFF;
- switch (comp_plane.source_layer) {
- case DrmCompositionPlane::kSourceNone:
- break;
- case DrmCompositionPlane::kSourceSquash:
- ALOGE("Actual source layer index expected for squash layer");
- break;
- case DrmCompositionPlane::kSourcePreComp:
- ALOGE("Actual source layer index expected for pre-comp layer");
- break;
- default: {
- if (comp_plane.source_layer >= layers.size()) {
- ALOGE("Source layer index %zu out of bounds %zu",
- comp_plane.source_layer, layers.size());
- break;
- }
- DrmHwcLayer &layer = layers[comp_plane.source_layer];
- if (!test_only && layer.acquire_fence.get() >= 0) {
- int acquire_fence = layer.acquire_fence.get();
- int total_fence_timeout = 0;
- for (int i = 0; i < kAcquireWaitTries; ++i) {
- int fence_timeout = kAcquireWaitTimeoutMs * (1 << i);
- total_fence_timeout += fence_timeout;
- ret = sync_wait(acquire_fence, fence_timeout);
- if (ret)
- ALOGW("Acquire fence %d wait %d failed (%d). Total time %d",
- acquire_fence, i, ret, total_fence_timeout);
- }
- if (ret) {
- ALOGE("Failed to wait for acquire %d/%d", acquire_fence, ret);
- break;
- }
- layer.acquire_fence.Close();
- }
- if (!layer.buffer) {
- ALOGE("Expected a valid framebuffer for pset");
- break;
- }
- fb_id = layer.buffer->fb_id;
- display_frame = layer.display_frame;
- source_crop = layer.source_crop;
- if (layer.blending == DrmHwcBlending::kPreMult)
- alpha = layer.alpha;
- rotation = 0;
- if (layer.transform & DrmHwcTransform::kFlipH)
- rotation |= 1 << DRM_REFLECT_X;
- if (layer.transform & DrmHwcTransform::kFlipV)
- rotation |= 1 << DRM_REFLECT_Y;
- if (layer.transform & DrmHwcTransform::kRotate90)
- rotation |= 1 << DRM_ROTATE_90;
- else if (layer.transform & DrmHwcTransform::kRotate180)
- rotation |= 1 << DRM_ROTATE_180;
- else if (layer.transform & DrmHwcTransform::kRotate270)
- rotation |= 1 << DRM_ROTATE_270;
+ if (comp_plane.type != DrmCompositionPlaneType::kDisable) {
+ if (comp_plane.source_layer < 0 ||
+ static_cast<size_t>(comp_plane.source_layer) >= layers.size()) {
+ ALOGE("Source layer index %d out of bounds %zu type=%d",
+ comp_plane.source_layer, layers.size(), comp_plane.type);
+ break;
}
- }
+ DrmHwcLayer &layer = layers[comp_plane.source_layer];
+ if (!test_only && layer.acquire_fence.get() >= 0) {
+ int acquire_fence = layer.acquire_fence.get();
+ int total_fence_timeout = 0;
+ for (int i = 0; i < kAcquireWaitTries; ++i) {
+ int fence_timeout = kAcquireWaitTimeoutMs * (1 << i);
+ total_fence_timeout += fence_timeout;
+ ret = sync_wait(acquire_fence, fence_timeout);
+ if (ret)
+ ALOGW("Acquire fence %d wait %d failed (%d). Total time %d",
+ acquire_fence, i, ret, total_fence_timeout);
+ }
+ if (ret) {
+ ALOGE("Failed to wait for acquire %d/%d", acquire_fence, ret);
+ break;
+ }
+ layer.acquire_fence.Close();
+ }
+ if (!layer.buffer) {
+ ALOGE("Expected a valid framebuffer for pset");
+ break;
+ }
+ fb_id = layer.buffer->fb_id;
+ display_frame = layer.display_frame;
+ source_crop = layer.source_crop;
+ if (layer.blending == DrmHwcBlending::kPreMult)
+ alpha = layer.alpha;
+ rotation = 0;
+ if (layer.transform & DrmHwcTransform::kFlipH)
+ rotation |= 1 << DRM_REFLECT_X;
+ if (layer.transform & DrmHwcTransform::kFlipV)
+ rotation |= 1 << DRM_REFLECT_Y;
+ if (layer.transform & DrmHwcTransform::kRotate90)
+ rotation |= 1 << DRM_ROTATE_90;
+ else if (layer.transform & DrmHwcTransform::kRotate180)
+ rotation |= 1 << DRM_ROTATE_180;
+ else if (layer.transform & DrmHwcTransform::kRotate270)
+ rotation |= 1 << DRM_ROTATE_270;
+ }
// Disable the plane if there's no framebuffer
if (fb_id < 0) {
ret = drmModeAtomicAddProperty(pset, plane->id(),
@@ -1039,7 +1029,7 @@
// Make sure there is more than one layer to squash.
size_t src_planes_with_layer = std::count_if(
src_planes.begin(), src_planes.end(), [](DrmCompositionPlane &p) {
- return p.source_layer <= DrmCompositionPlane::kSourceLayerMax;
+ return p.type == DrmCompositionPlaneType::kLayer;
});
if (src_planes_with_layer <= 1)
return -EALREADY;
@@ -1063,19 +1053,10 @@
goto move_layers_back;
}
- if (comp_plane.source_layer == DrmCompositionPlane::kSourceNone)
+ if (comp_plane.type == DrmCompositionPlaneType::kDisable ||
+ comp_plane.source_layer < 0)
continue;
- // Out of range layers should never happen. If they do, somebody probably
- // forgot to replace the symbolic names (kSourceSquash, kSourcePreComp) with
- // real ones.
- if (comp_plane.source_layer >= src_layers.size()) {
- ALOGE("Skipping squash all because of out of range source layer %zu",
- comp_plane.source_layer);
- ret = -EINVAL;
- goto move_layers_back;
- }
-
DrmHwcLayer &layer = src_layers[comp_plane.source_layer];
// Squashing protected layers is impossible.
@@ -1120,7 +1101,7 @@
framebuffer_index_ = (framebuffer_index_ + 1) % DRM_DISPLAY_BUFFERS;
for (DrmCompositionPlane &plane : dst->composition_planes())
- if (plane.source_layer == DrmCompositionPlane::kSourcePreComp)
+ if (plane.type == DrmCompositionPlaneType::kPrecomp)
plane.source_layer = pre_comp_layer_index;
return 0;