Skip to content

Commit a3237b7

Browse files
committed
Support underlay planes by turning off unused active planes
1 parent 377409f commit a3237b7

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

app/streaming/video/ffmpeg-renderers/drm.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ DrmRenderer::~DrmRenderer()
191191
m_PropSetter.set(*zpos, zpos->initialValue());
192192
}
193193
}
194+
for (auto &plane : m_UnusedActivePlanes) {
195+
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
196+
"Restoring previously active plane: %u",
197+
plane.second.objectId());
198+
m_PropSetter.restoreToInitial(plane.second);
199+
}
194200

195201
m_PropSetter.apply();
196202
}
@@ -392,6 +398,14 @@ void DrmRenderer::prepareToRender()
392398
}
393399
}
394400

401+
// Disable all other active planes in atomic mode
402+
for (auto &plane : m_UnusedActivePlanes) {
403+
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
404+
"Disabling unused plane: %u",
405+
plane.second.objectId());
406+
m_PropSetter.disablePlane(plane.second);
407+
}
408+
395409
m_PropSetter.apply();
396410

397411
// We've now changed state that must be restored
@@ -598,22 +612,28 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
598612
}
599613

600614
// Find the active plane (if any) on this CRTC with the highest zpos.
601-
// We'll need to use a plane with a equal or greater zpos to be visible.
615+
// We'll need to use a plane with a equal or greater zpos to be visible,
616+
// or we'll disable the active planes if we're in atomic mode.
602617
std::set<uint64_t> activePlanesZpos;
603618
for (uint32_t i = 0; i < planeRes->count_planes; i++) {
604619
drmModePlane* plane = drmModeGetPlane(m_DrmFd, planeRes->planes[i]);
605620
if (plane != nullptr) {
621+
DrmPropertyMap props { m_DrmFd, planeRes->planes[i], DRM_MODE_OBJECT_PLANE };
622+
606623
if (plane->crtc_id == m_Crtc.objectId()) {
607624
// Don't consider cursor planes when searching for the highest active zpos
608-
DrmPropertyMap props { m_DrmFd, planeRes->planes[i], DRM_MODE_OBJECT_PLANE };
609-
if (props.property("type")->initialValue() == DRM_PLANE_TYPE_PRIMARY ||
610-
props.property("type")->initialValue() == DRM_PLANE_TYPE_OVERLAY) {
625+
uint64_t type = props.property("type")->initialValue();
626+
if (type == DRM_PLANE_TYPE_PRIMARY || type == DRM_PLANE_TYPE_OVERLAY) {
611627
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
612628
"Plane %u is active on CRTC %u",
613629
plane->plane_id,
614630
plane->crtc_id);
615631

616-
if (auto zpos = props.property("zpos")) {
632+
// We can only restore state of planes on atomic
633+
if (m_PropSetter.isAtomic()) {
634+
m_UnusedActivePlanes.try_emplace(planeRes->planes[i], m_DrmFd, planeRes->planes[i], DRM_MODE_OBJECT_PLANE);
635+
}
636+
else if (auto zpos = props.property("zpos")) {
617637
activePlanesZpos.emplace(zpos->initialValue());
618638
}
619639
}
@@ -752,6 +772,7 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
752772
SDL_assert(!m_VideoPlane.isValid());
753773
m_VideoPlane.load(m_DrmFd, plane->plane_id, DRM_MODE_OBJECT_PLANE);
754774
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Selected plane %u for video", plane->plane_id);
775+
m_UnusedActivePlanes.erase(plane->plane_id);
755776
drmModeFreePlane(plane);
756777
}
757778
}
@@ -831,6 +852,7 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
831852
m_OverlayPlanes[overlayIndex++].load(m_DrmFd, plane->plane_id, DRM_MODE_OBJECT_PLANE);
832853
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Selected plane %u for overlay %d",
833854
plane->plane_id, overlayIndex);
855+
m_UnusedActivePlanes.erase(plane->plane_id);
834856
drmModeFreePlane(plane);
835857
}
836858
}

app/streaming/video/ffmpeg-renderers/drm.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ class DrmRenderer : public IFFmpegRenderer {
189189
return m_ObjectType;
190190
}
191191

192+
const std::unordered_map<std::string, DrmProperty>& properties() const {
193+
return m_Props;
194+
}
195+
192196
private:
193197
uint32_t m_ObjectId = 0;
194198
uint32_t m_ObjectType = 0;
@@ -605,6 +609,17 @@ class DrmRenderer : public IFFmpegRenderer {
605609
return m_Atomic;
606610
}
607611

612+
void restoreToInitial(const DrmPropertyMap& object) {
613+
SDL_assert(m_Atomic);
614+
615+
// Set all mutable properties back to their initial values
616+
for (auto& prop : object.properties()) {
617+
if (!prop.second.isImmutable()) {
618+
set(prop.second, prop.second.initialValue());
619+
}
620+
}
621+
}
622+
608623
private:
609624
int m_Fd = -1;
610625
bool m_Atomic = false;
@@ -668,6 +683,7 @@ class DrmRenderer : public IFFmpegRenderer {
668683
DrmPropertyMap m_Encoder;
669684
DrmPropertyMap m_Connector;
670685
DrmPropertyMap m_Crtc;
686+
std::unordered_map<uint32_t, DrmPropertyMap> m_UnusedActivePlanes;
671687
DrmPropertyMap m_VideoPlane;
672688
uint64_t m_VideoPlaneZpos;
673689
DrmPropertyMap m_OverlayPlanes[Overlay::OverlayMax];

0 commit comments

Comments
 (0)