9 #define LOC QString("DisplayX11: ")
18 static bool s_checked =
false;
19 static bool s_available =
false;
24 s_available = display.
Open();
52 auto * res = XRRGetScreenResourcesCurrent(display->GetDisplay(), display->GetRoot());
57 static_cast<int>(
output->mm_height));
65 auto * currentcrtc = XRRGetCrtcInfo(display->GetDisplay(), res,
m_crtc);
68 for (
int i = 0; i < res->nmode; ++i)
70 if (res->modes[i].id != currentcrtc->mode)
72 auto mode = res->modes[i];
74 static_cast<int>(mode.height));
75 if (mode.dotClock > 1 && mode.vTotal > 1 && mode.hTotal > 1)
77 m_refreshRate =
static_cast<double>(mode.dotClock) / (mode.vTotal * mode.hTotal);
78 if (mode.modeFlags & RR_Interlace)
82 XRRFreeCrtcInfo(currentcrtc);
85 XRRFreeScreenResources(res);
112 auto * res = XRRGetScreenResourcesCurrent(display->GetDisplay(), display->GetRoot());
117 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Failed to find an output that matches '%1'")
119 XRRFreeScreenResources(res);
124 auto mmwidth =
static_cast<int>(
output->mm_width);
125 auto mmheight =
static_cast<int>(
output->mm_height);
129 for (
int i = 0; i <
output->nmode; ++i)
131 RRMode rrmode =
output->modes[i];
132 for (
int j = 0; j < res->nmode; ++j)
134 if (res->modes[j].id != rrmode)
137 auto mode = res->modes[j];
138 if (mode.id != rrmode)
140 if (mode.dotClock <= 1 || mode.vTotal <= 1 || mode.hTotal <= 1)
142 auto width =
static_cast<int>(mode.width);
143 auto height =
static_cast<int>(mode.height);
144 auto rate =
static_cast<double>(mode.dotClock) / (mode.vTotal * mode.hTotal);
149 if ((mode.modeFlags & RR_Interlace) != 0U)
151 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Ignoring interlaced mode %1x%2 %3i")
152 .arg(width).arg(height).arg(rate * 2.0, 2,
'f', 2,
'0'));
156 QSize resolution(width, height);
157 QSize physical(mmwidth, mmheight);
159 if (screenmap.find(key) == screenmap.end())
162 screenmap[key].AddRefreshRate(rate);
167 for (
auto & it : screenmap)
171 XRRFreeOutputInfo(
output);
172 XRRFreeScreenResources(res);
186 auto rate =
static_cast<double>(NAN);
193 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Desired resolution and frame rate not found.");
200 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to find mode");
208 Status status = RRSetConfigFailed;
209 auto * res = XRRGetScreenResourcesCurrent(display->GetDisplay(), display->GetRoot());
212 auto * currentcrtc = XRRGetCrtcInfo(display->GetDisplay(), res,
m_crtc);
215 status = XRRSetCrtcConfig(display->GetDisplay(), res,
m_crtc, CurrentTime,
216 currentcrtc->x, currentcrtc->y,
m_modeMap.value(mode),
217 currentcrtc->rotation, currentcrtc->outputs,
218 currentcrtc->noutput);
219 XRRFreeCrtcInfo(currentcrtc);
220 auto * config = XRRGetScreenInfo(display->GetDisplay(), display->GetRoot());
222 XRRFreeScreenConfigInfo(config);
224 XRRFreeScreenResources(res);
228 if (RRSetConfigSuccess != status)
229 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to set video mode");
230 return RRSetConfigSuccess == status;
235 QScreen* qScreen, RROutput* Output)
240 XRROutputInfo* result =
nullptr;
241 for (
int i = 0; i <
Resources->noutput; ++i)
245 XRRFreeOutputInfo(result);
250 if (!result || result->nameLen < 1)
252 if (result->connection != RR_Connected)
254 LOG(VB_GENERAL, LOG_DEBUG,
LOC + QString(
"Output '%1' is disconnected")
259 QString name(result->name);
260 if (name == qScreen->name())
262 LOG(VB_GENERAL, LOG_DEBUG,
LOC + QString(
"Matched '%1' to output %2")
263 .arg(qScreen->name()).arg(
Resources->outputs[i]));
269 XRRFreeOutputInfo(result);
281 auto * res = XRRGetScreenResourcesCurrent(mDisplay->
GetDisplay(), mDisplay->
GetRoot());
282 RROutput rroutput = 0;
287 auto edidproperty = XInternAtom(mDisplay->
GetDisplay(), RR_PROPERTY_RANDR_EDID,
288 static_cast<Bool
>(
false));
292 int propertycount = 0;
293 auto * properties = XRRListOutputProperties(mDisplay->
GetDisplay(), rroutput, &propertycount);
298 for (
int i = 0; i < propertycount; ++i)
300 if (properties[i] == edidproperty)
311 int actualformat = 0;
312 unsigned long bytesafter = 0;
313 unsigned long nitems = 0;
314 unsigned char* data =
nullptr;
315 if (XRRGetOutputProperty(mDisplay->
GetDisplay(), rroutput, edidproperty,
316 0, 128,
static_cast<Bool
>(
false),
static_cast<Bool
>(
false),
317 AnyPropertyType, &actualtype,
318 &actualformat, &nitems, &bytesafter, &data) == Success)
320 if (actualtype == XA_INTEGER && actualformat == 8)
321 m_edid =
MythEDID(
reinterpret_cast<const char*
>(data),
static_cast<int>(nitems));
325 XRRFreeOutputInfo(
output);
326 XRRFreeScreenResources(res);