ddcProperty.c revision 35c4bbdf
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 <X11/Xatom.h> 31#include "property.h" 32#include "propertyst.h" 33#include <string.h> 34 35#define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA" 36 37static void 38edidMakeAtom(int i, const char *name, CARD8 *data, int size) 39{ 40 Atom atom; 41 unsigned char *atom_data; 42 43 if (!(atom_data = malloc(size * sizeof(CARD8)))) 44 return; 45 46 atom = MakeAtom(name, strlen(name), TRUE); 47 memcpy(atom_data, data, size); 48 xf86RegisterRootWindowProperty(i, atom, XA_INTEGER, 8, size, atom_data); 49} 50 51static void 52addRootWindowProperties(ScrnInfoPtr pScrn, xf86MonPtr DDC) 53{ 54 int scrnIndex = pScrn->scrnIndex; 55 56 if (DDC->flags & MONITOR_DISPLAYID) { 57 /* Don't bother, use RANDR already */ 58 return; 59 } 60 else if (DDC->ver.version == 1) { 61 int size = 128 + 62 (DDC->flags & EDID_COMPLETE_RAWDATA ? DDC->no_sections * 128 : 0); 63 64 edidMakeAtom(scrnIndex, EDID1_ATOM_NAME, DDC->rawData, size); 65 } 66 else { 67 xf86DrvMsg(scrnIndex, X_PROBED, "unexpected EDID version %d.%d\n", 68 DDC->ver.version, DDC->ver.revision); 69 return; 70 } 71} 72 73Bool 74xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC) 75{ 76 if (!pScrn || !pScrn->monitor || !DDC) 77 return FALSE; 78 79 if (DDC->flags & MONITOR_DISPLAYID); 80 else 81 xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC); 82 83 addRootWindowProperties(pScrn, DDC); 84 85 return TRUE; 86} 87