Merge branch 'gallium-polygon-stipple'
[mesa.git] / src / gallium / state_trackers / xorg / xvmc / attributes.c
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <assert.h>
29 #include <stdlib.h>
30
31 #include <X11/Xlib.h>
32 #include <X11/extensions/Xvlib.h>
33 #include <X11/extensions/XvMClib.h>
34
35 #include <vl/vl_compositor.h>
36
37 #include "xvmc_private.h"
38
39 #define XV_BRIGHTNESS "XV_BRIGHTNESS"
40 #define XV_CONTRAST "XV_CONTRAST"
41 #define XV_SATURATION "XV_SATURATION"
42 #define XV_HUE "XV_HUE"
43 #define XV_COLORSPACE "XV_COLORSPACE"
44
45 static const XvAttribute attributes[] = {
46 { XvGettable | XvSettable, -1000, 1000, XV_BRIGHTNESS },
47 { XvGettable | XvSettable, -1000, 1000, XV_CONTRAST },
48 { XvGettable | XvSettable, -1000, 1000, XV_SATURATION },
49 { XvGettable | XvSettable, -1000, 1000, XV_HUE },
50 { XvGettable | XvSettable, 0, 1, XV_COLORSPACE }
51 };
52
53 PUBLIC
54 XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number)
55 {
56 XvMCContextPrivate *context_priv;
57 XvAttribute *result;
58
59 assert(dpy && number);
60
61 if (!context || !context->privData)
62 return NULL;
63
64 context_priv = context->privData;
65
66 result = malloc(sizeof(attributes));
67 if (!result)
68 return NULL;
69
70 memcpy(result, attributes, sizeof(attributes));
71 *number = sizeof(attributes) / sizeof(XvAttribute);
72
73 XVMC_MSG(XVMC_TRACE, "[XvMC] Returning %d attributes for context %p.\n", *number, context);
74
75 return result;
76 }
77
78 PUBLIC
79 Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value)
80 {
81 XvMCContextPrivate *context_priv;
82 const char *attr;
83 float csc[16];
84
85 assert(dpy);
86
87 if (!context || !context->privData)
88 return XvMCBadContext;
89
90 context_priv = context->privData;
91
92 attr = XGetAtomName(dpy, attribute);
93 if (!attr)
94 return XvMCBadContext;
95
96 if (strcmp(attr, XV_BRIGHTNESS))
97 context_priv->procamp.brightness = value / 1000.0f;
98 else if (strcmp(attr, XV_CONTRAST))
99 context_priv->procamp.contrast = value / 1000.0f + 1.0f;
100 else if (strcmp(attr, XV_SATURATION))
101 context_priv->procamp.saturation = value / 1000.0f + 1.0f;
102 else if (strcmp(attr, XV_HUE))
103 context_priv->procamp.hue = value / 1000.0f;
104 else if (strcmp(attr, XV_COLORSPACE))
105 context_priv->color_standard = value ?
106 VL_CSC_COLOR_STANDARD_BT_601 :
107 VL_CSC_COLOR_STANDARD_BT_709;
108 else
109 return BadName;
110
111 vl_csc_get_matrix
112 (
113 context_priv->color_standard,
114 &context_priv->procamp, true, csc
115 );
116 vl_compositor_set_csc_matrix(&context_priv->compositor, csc);
117
118 XVMC_MSG(XVMC_TRACE, "[XvMC] Set attribute %s to value %d.\n", attr, value);
119
120 return Success;
121 }
122
123 PUBLIC
124 Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value)
125 {
126 XvMCContextPrivate *context_priv;
127 const char *attr;
128
129 assert(dpy);
130
131 if (!context || !context->privData)
132 return XvMCBadContext;
133
134 context_priv = context->privData;
135
136 attr = XGetAtomName(dpy, attribute);
137 if (!attr)
138 return XvMCBadContext;
139
140 if (strcmp(attr, XV_BRIGHTNESS))
141 *value = context_priv->procamp.brightness * 1000;
142 else if (strcmp(attr, XV_CONTRAST))
143 *value = context_priv->procamp.contrast * 1000 - 1000;
144 else if (strcmp(attr, XV_SATURATION))
145 *value = context_priv->procamp.saturation * 1000 + 1000;
146 else if (strcmp(attr, XV_HUE))
147 *value = context_priv->procamp.hue * 1000;
148 else if (strcmp(attr, XV_COLORSPACE))
149 *value = context_priv->color_standard == VL_CSC_COLOR_STANDARD_BT_709;
150 else
151 return BadName;
152
153 XVMC_MSG(XVMC_TRACE, "[XvMC] Got value %d for attribute %s.\n", *value, attr);
154
155 return Success;
156 }