Path: blob/21.2-virgl/src/gallium/frontends/xvmc/attributes.c
4566 views
/**************************************************************************1*2* Copyright 2009 Younes Manton.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include <assert.h>28#include <stdlib.h>2930#include <X11/Xlib.h>31#include <X11/extensions/Xvlib.h>32#include <X11/extensions/XvMClib.h>3334#include "vl/vl_compositor.h"3536#include "xvmc_private.h"3738#define XV_BRIGHTNESS "XV_BRIGHTNESS"39#define XV_CONTRAST "XV_CONTRAST"40#define XV_SATURATION "XV_SATURATION"41#define XV_HUE "XV_HUE"42#define XV_COLORSPACE "XV_COLORSPACE"4344static const XvAttribute attributes[] = {45{ XvGettable | XvSettable, -1000, 1000, XV_BRIGHTNESS },46{ XvGettable | XvSettable, -1000, 1000, XV_CONTRAST },47{ XvGettable | XvSettable, -1000, 1000, XV_SATURATION },48{ XvGettable | XvSettable, -1000, 1000, XV_HUE },49{ XvGettable | XvSettable, 0, 1, XV_COLORSPACE }50};5152PUBLIC53XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number)54{55XvAttribute *result;5657assert(dpy && number);5859if (!context || !context->privData)60return NULL;6162result = malloc(sizeof(attributes));63if (!result)64return NULL;6566memcpy(result, attributes, sizeof(attributes));67*number = sizeof(attributes) / sizeof(XvAttribute);6869XVMC_MSG(XVMC_TRACE, "[XvMC] Returning %d attributes for context %p.\n", *number, context);7071return result;72}7374PUBLIC75Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value)76{77XvMCContextPrivate *context_priv;78const char *attr;79vl_csc_matrix csc;8081assert(dpy);8283if (!context || !context->privData)84return XvMCBadContext;8586context_priv = context->privData;8788attr = XGetAtomName(dpy, attribute);89if (!attr)90return XvMCBadContext;9192if (strcmp(attr, XV_BRIGHTNESS) == 0)93context_priv->procamp.brightness = value / 1000.0f;94else if (strcmp(attr, XV_CONTRAST) == 0)95context_priv->procamp.contrast = value / 1000.0f + 1.0f;96else if (strcmp(attr, XV_SATURATION) == 0)97context_priv->procamp.saturation = value / 1000.0f + 1.0f;98else if (strcmp(attr, XV_HUE) == 0)99context_priv->procamp.hue = value / 1000.0f;100else if (strcmp(attr, XV_COLORSPACE) == 0)101context_priv->color_standard = value ?102VL_CSC_COLOR_STANDARD_BT_601 :103VL_CSC_COLOR_STANDARD_BT_709;104else105return BadName;106107vl_csc_get_matrix108(109context_priv->color_standard,110&context_priv->procamp, true, &csc111);112vl_compositor_set_csc_matrix(&context_priv->cstate, (const vl_csc_matrix *)&csc, 1.0f, 0.0f);113114XVMC_MSG(XVMC_TRACE, "[XvMC] Set attribute %s to value %d.\n", attr, value);115116return Success;117}118119PUBLIC120Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value)121{122XvMCContextPrivate *context_priv;123const char *attr;124125assert(dpy);126127if (!context || !context->privData)128return XvMCBadContext;129130context_priv = context->privData;131132attr = XGetAtomName(dpy, attribute);133if (!attr)134return XvMCBadContext;135136if (strcmp(attr, XV_BRIGHTNESS) == 0)137*value = context_priv->procamp.brightness * 1000;138else if (strcmp(attr, XV_CONTRAST) == 0)139*value = context_priv->procamp.contrast * 1000 - 1000;140else if (strcmp(attr, XV_SATURATION) == 0)141*value = context_priv->procamp.saturation * 1000 + 1000;142else if (strcmp(attr, XV_HUE) == 0)143*value = context_priv->procamp.hue * 1000;144else if (strcmp(attr, XV_COLORSPACE) == 0)145*value = context_priv->color_standard == VL_CSC_COLOR_STANDARD_BT_709;146else147return BadName;148149XVMC_MSG(XVMC_TRACE, "[XvMC] Got value %d for attribute %s.\n", *value, attr);150151return Success;152}153154155