1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 Younes Manton og Thomas Balling Sørensen.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_compiler.h"
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_memory.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_debug.h"
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_sampler.h"
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "vdpau_private.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Create a VdpDevice object for use with X11.
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC VdpStatus
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          VdpGetProcAddress **get_proc_address)
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_screen *pscreen;
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpDevice *dev = NULL;
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   VdpStatus ret;
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!(display && device && get_proc_address))
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_POINTER;
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!vlCreateHTAB()) {
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_RESOURCES;
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_htab;
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev = CALLOC(1, sizeof(vlVdpDevice));
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev) {
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_RESOURCES;
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_dev;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->vscreen = vl_screen_create(display, screen);
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev->vscreen) {
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_RESOURCES;
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_vscreen;
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pscreen = dev->vscreen->pscreen;
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->context = pscreen->context_create(pscreen, dev->vscreen);
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev->context) {
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_RESOURCES;
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_context;
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   *device = vlAddDataHTAB(dev);
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (*device == 0) {
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_ERROR;
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_handle;
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vl_compositor_init(&dev->compositor, dev->context);
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_mutex_init(dev->mutex);
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   *get_proc_address = &vlVdpGetProcAddress;
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return VDP_STATUS_OK;
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_handle:
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Destroy vscreen */
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_context:
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vl_screen_destroy(dev->vscreen);
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_vscreen:
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(dev);
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_dev:
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlDestroyHTAB();
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_htab:
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return ret;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Create a VdpPresentationQueueTarget for use with X11.
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC VdpStatus
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpPresentationQueueTargetCreateX11(VdpDevice device, Drawable drawable,
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      VdpPresentationQueueTarget *target)
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpPresentationQueueTarget *pqt;
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   VdpStatus ret;
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!drawable)
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_HANDLE;
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpDevice *dev = vlGetDataHTAB(device);
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev)
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_HANDLE;
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pqt = CALLOC(1, sizeof(vlVdpPresentationQueue));
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!pqt)
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_RESOURCES;
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pqt->device = dev;
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pqt->drawable = drawable;
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   *target = vlAddDataHTAB(pqt);
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (*target == 0) {
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ret = VDP_STATUS_ERROR;
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      goto no_handle;
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return VDP_STATUS_OK;
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgno_handle:
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(pqt);
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return ret;
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Destroy a VdpPresentationQueueTarget.
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgVdpStatus
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpPresentationQueueTargetDestroy(VdpPresentationQueueTarget presentation_queue_target)
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpPresentationQueueTarget *pqt;
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pqt = vlGetDataHTAB(presentation_queue_target);
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!pqt)
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_HANDLE;
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlRemoveDataHTAB(presentation_queue_target);
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(pqt);
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return VDP_STATUS_OK;
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Destroy a VdpDevice.
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgVdpStatus
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpDeviceDestroy(VdpDevice device)
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpDevice *dev = vlGetDataHTAB(device);
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev)
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_HANDLE;
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_mutex_destroy(dev->mutex);
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vl_compositor_cleanup(&dev->compositor);
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->context->destroy(dev->context);
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vl_screen_destroy(dev->vscreen);
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(dev);
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlDestroyHTAB();
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return VDP_STATUS_OK;
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Retrieve a VDPAU function pointer.
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgVdpStatus
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer)
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpDevice *dev = vlGetDataHTAB(device);
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dev)
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_HANDLE;
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!function_pointer)
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_POINTER;
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!vlGetFuncFTAB(function_id, function_pointer))
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return VDP_STATUS_INVALID_FUNC_ID;
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Got proc adress %p for id %d\n", *function_pointer, function_id);
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return VDP_STATUS_OK;
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define _ERROR_TYPE(TYPE,STRING) case TYPE: return STRING;
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Retrieve a string describing an error code.
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgchar const *
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpGetErrorString (VdpStatus status)
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (status) {
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_OK,"The operation completed successfully; no error.");
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_NO_IMPLEMENTATION,"No backend implementation could be loaded.");
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_DISPLAY_PREEMPTED,"The display was preempted, or a fatal error occurred. The application must re-initialize VDPAU.");
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_HANDLE,"An invalid handle value was provided. Either the handle does not exist at all, or refers to an object of an incorrect type.");
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_POINTER,"An invalid pointer was provided. Typically, this means that a NULL pointer was provided for an 'output' parameter.");
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_CHROMA_TYPE,"An invalid/unsupported VdpChromaType value was supplied.");
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_Y_CB_CR_FORMAT,"An invalid/unsupported VdpYCbCrFormat value was supplied.");
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_RGBA_FORMAT,"An invalid/unsupported VdpRGBAFormat value was supplied.");
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_INDEXED_FORMAT,"An invalid/unsupported VdpIndexedFormat value was supplied.");
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_STANDARD,"An invalid/unsupported VdpColorStandard value was supplied.");
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_TABLE_FORMAT,"An invalid/unsupported VdpColorTableFormat value was supplied.");
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_FACTOR,"An invalid/unsupported VdpOutputSurfaceRenderBlendFactor value was supplied.");
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_EQUATION,"An invalid/unsupported VdpOutputSurfaceRenderBlendEquation value was supplied.");
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_FLAG,"An invalid/unsupported flag value/combination was supplied.");
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_DECODER_PROFILE,"An invalid/unsupported VdpDecoderProfile value was supplied.");
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE,"An invalid/unsupported VdpVideoMixerFeature value was supplied.");
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER,"An invalid/unsupported VdpVideoMixerParameter value was supplied.");
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE,"An invalid/unsupported VdpVideoMixerAttribute value was supplied.");
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE,"An invalid/unsupported VdpVideoMixerPictureStructure value was supplied.");
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_FUNC_ID,"An invalid/unsupported VdpFuncId value was supplied.");
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_SIZE,"The size of a supplied object does not match the object it is being used with.\
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      For example, a VdpVideoMixer is configured to process VdpVideoSurface objects of a specific size.\
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      If presented with a VdpVideoSurface of a different size, this error will be raised.");
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_VALUE,"An invalid/unsupported value was supplied.\
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      This is a catch-all error code for values of type other than those with a specific error code.");
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_INVALID_STRUCT_VERSION,"An invalid/unsupported structure version was specified in a versioned structure. \
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      This implies that the implementation is older than the header file the application was built against.");
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_RESOURCES,"The system does not have enough resources to complete the requested operation at this time.");
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_HANDLE_DEVICE_MISMATCH,"The set of handles supplied are not all related to the same VdpDevice.When performing operations \
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      that operate on multiple surfaces, such as VdpOutputSurfaceRenderOutputSurface or VdpVideoMixerRender, \
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      all supplied surfaces must have been created within the context of the same VdpDevice object. \
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      This error is raised if they were not.");
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _ERROR_TYPE(VDP_STATUS_ERROR,"A catch-all error, used when no other error code applies.");
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default: return "Unknown Error";
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view *templ, struct pipe_resource *res)
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const struct util_format_description *desc;
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   memset(templ, 0, sizeof(*templ));
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   u_sampler_view_default_template(templ, res, res->format);
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   desc = util_format_description(res->format);
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_0)
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      templ->swizzle_r = PIPE_SWIZZLE_ONE;
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0)
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      templ->swizzle_g = PIPE_SWIZZLE_ONE;
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0)
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      templ->swizzle_b = PIPE_SWIZZLE_ONE;
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_0)
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      templ->swizzle_a = PIPE_SWIZZLE_ONE;
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpResolveDelayedRendering(vlVdpDevice *dev, struct pipe_surface *surface, struct u_rect *dirty_area)
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct vl_compositor_state *cstate;
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpOutputSurface *vlsurface;
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   assert(dev);
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   cstate = dev->delayed_rendering.cstate;
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!cstate)
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlsurface = vlGetDataHTAB(dev->delayed_rendering.surface);
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!vlsurface)
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!surface) {
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      surface = vlsurface->surface;
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      dirty_area = &vlsurface->dirty_area;
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vl_compositor_render(cstate, &dev->compositor, surface, dirty_area);
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->delayed_rendering.surface = VDP_INVALID_HANDLE;
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->delayed_rendering.cstate = NULL;
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* test if we need to create a new sampler for the just filled texture */
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (surface->texture != vlsurface->sampler_view->texture) {
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      struct pipe_resource *res = surface->texture;
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      struct pipe_sampler_view sv_templ;
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      vlVdpDefaultSamplerViewTemplate(&sv_templ, res);
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      vlsurface->sampler_view = dev->context->create_sampler_view(dev->context, res, &sv_templ);
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return;
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvlVdpSave4DelayedRendering(vlVdpDevice *dev, VdpOutputSurface surface, struct vl_compositor_state *cstate)
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   assert(dev);
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   vlVdpResolveDelayedRendering(dev, NULL, NULL);
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->delayed_rendering.surface = surface;
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dev->delayed_rendering.cstate = cstate;
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
310