1 /*
2 * Copyright 2006 Luc Verhaegen.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifdef HAVE_XORG_CONFIG_H
25 #include <xorg-config.h>
26 #endif
27
28 #include "xf86.h"
29 #include "xf86DDC.h"
30 #include "xf86Priv.h"
31 #include <X11/Xatom.h>
32 #include "property.h"
33 #include "propertyst.h"
34 #include <string.h>
35
36 #define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA"
37
38 static int
edidSize(const xf86MonPtr DDC)39 edidSize(const xf86MonPtr DDC)
40 {
41 int ret = 128;
42
43 if (DDC->flags & EDID_COMPLETE_RAWDATA)
44 ret += DDC->no_sections * 128;
45
46 return ret;
47 }
48
49 static void
setRootWindowEDID(ScreenPtr pScreen,xf86MonPtr DDC)50 setRootWindowEDID(ScreenPtr pScreen, xf86MonPtr DDC)
51 {
52 Atom atom = MakeAtom(EDID1_ATOM_NAME, strlen(EDID1_ATOM_NAME), TRUE);
53
54 dixChangeWindowProperty(serverClient, pScreen->root, atom, XA_INTEGER,
55 8, PropModeReplace, edidSize(DDC), DDC->rawData,
56 FALSE);
57 }
58
59 static void
addEDIDProp(CallbackListPtr * pcbl,void * scrn,void * screen)60 addEDIDProp(CallbackListPtr *pcbl, void *scrn, void *screen)
61 {
62 ScreenPtr pScreen = screen;
63 ScrnInfoPtr pScrn = scrn;
64
65 if (xf86ScreenToScrn(pScreen) == pScrn)
66 setRootWindowEDID(pScreen, pScrn->monitor->DDC);
67 }
68
69 Bool
xf86SetDDCproperties(ScrnInfoPtr pScrn,xf86MonPtr DDC)70 xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC)
71 {
72 if (!pScrn || !pScrn->monitor || !DDC)
73 return FALSE;
74
75 xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC);
76
77 if (xf86Initialising)
78 AddCallback(&RootWindowFinalizeCallback, addEDIDProp, pScrn);
79 else
80 setRootWindowEDID(pScrn->pScreen, DDC);
81
82 return TRUE;
83 }
84