diff options
author | Paulo Zanoni <paulo.r.zanoni@intel.com> | 2012-03-20 11:53:21 -0300 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2012-03-26 14:12:56 +0100 |
commit | 89091dd8a3fba6520a651e3e135c87546b81df9b (patch) | |
tree | b0923d759927df0a1992a352269e33ce12896340 /src/sna/sna_display.c | |
parent | 62f9833298ea936eaefe973eca04b1dde858fbd8 (diff) |
Avoid duplicated code with intel_output_create_ranged_atom
Same change for intel_display.c and sna_display.c.
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/sna/sna_display.c')
-rw-r--r-- | src/sna/sna_display.c | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index 9401ca45..a5d69dd5 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -1205,6 +1205,33 @@ sna_property_ignore(drmModePropertyPtr prop) return FALSE; } +static void +sna_output_create_ranged_atom(xf86OutputPtr output, Atom *atom, + const char *name, INT32 min, INT32 max, + uint64_t value, Bool immutable) +{ + int err; + INT32 atom_range[2]; + + atom_range[0] = min; + atom_range[1] = max; + + *atom = MakeAtom(name, strlen(name), TRUE); + + err = RRConfigureOutputProperty(output->randr_output, *atom, FALSE, + TRUE, immutable, 2, atom_range); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRConfigureOutputProperty error, %d\n", err); + + err = RRChangeOutputProperty(output->randr_output, *atom, XA_INTEGER, + 32, PropModeReplace, 1, &value, FALSE, + TRUE); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); +} + #define BACKLIGHT_NAME "Backlight" #define BACKLIGHT_DEPRECATED_NAME "BACKLIGHT" static Atom backlight_atom, backlight_deprecated_atom; @@ -1244,30 +1271,18 @@ sna_output_create_resources(xf86OutputPtr output) drmModePropertyPtr drmmode_prop = p->mode_prop; if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 range[2]; - p->num_atoms = 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); if (!p->atoms) continue; - p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - range[0] = drmmode_prop->values[0]; - range[1] = drmmode_prop->values[1]; - err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], - FALSE, TRUE, - drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, - 2, range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_INTEGER, 32, PropModeReplace, 1, &p->value, FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + sna_output_create_ranged_atom(output, &p->atoms[0], + drmmode_prop->name, + drmmode_prop->values[0], + drmmode_prop->values[1], + p->value, + drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE); + } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { p->num_atoms = drmmode_prop->count_enums + 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); @@ -1303,50 +1318,21 @@ sna_output_create_resources(xf86OutputPtr output) } if (sna_output->backlight_iface) { - INT32 data, backlight_range[2]; - /* Set up the backlight property, which takes effect * immediately and accepts values only within the * backlight_range. */ - backlight_atom = MakeAtom(BACKLIGHT_NAME, sizeof(BACKLIGHT_NAME) - 1, TRUE); - backlight_deprecated_atom = MakeAtom(BACKLIGHT_DEPRECATED_NAME, - sizeof(BACKLIGHT_DEPRECATED_NAME) - 1, TRUE); - - backlight_range[0] = 0; - backlight_range[1] = sna_output->backlight_max; - err = RRConfigureOutputProperty(output->randr_output, - backlight_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRConfigureOutputProperty(output->randr_output, - backlight_deprecated_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - /* Set the current value of the backlight property */ - data = sna_output->backlight_active_level; - err = RRChangeOutputProperty(output->randr_output, backlight_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, backlight_deprecated_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + sna_output_create_ranged_atom(output, &backlight_atom, + BACKLIGHT_NAME, 0, + sna_output->backlight_max, + sna_output->backlight_active_level, + FALSE); + sna_output_create_ranged_atom(output, + &backlight_deprecated_atom, + BACKLIGHT_DEPRECATED_NAME, 0, + sna_output->backlight_max, + sna_output->backlight_active_level, + FALSE); } } |