1fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton/**************************************************************************
2b48676672592271597d07e5ece79cf4d3ffbe04bChristian König *
3fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * Copyright 2009 Younes Manton.
4fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * All Rights Reserved.
5b48676672592271597d07e5ece79cf4d3ffbe04bChristian König *
6fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * Permission is hereby granted, free of charge, to any person obtaining a
7fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * copy of this software and associated documentation files (the
8fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * "Software"), to deal in the Software without restriction, including
9fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * without limitation the rights to use, copy, modify, merge, publish,
10fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * distribute, sub license, and/or sell copies of the Software, and to
11fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * permit persons to whom the Software is furnished to do so, subject to
12fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * the following conditions:
13b48676672592271597d07e5ece79cf4d3ffbe04bChristian König *
14fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * The above copyright notice and this permission notice (including the
15fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * next paragraph) shall be included in all copies or substantial portions
16fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * of the Software.
17b48676672592271597d07e5ece79cf4d3ffbe04bChristian König *
18fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25b48676672592271597d07e5ece79cf4d3ffbe04bChristian König *
26fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton **************************************************************************/
27fcb595c04f9ee275eae49b7bb7c61246671f5ce2Younes Manton
28c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton#include <assert.h>
29b48676672592271597d07e5ece79cf4d3ffbe04bChristian König
30c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton#include <X11/Xlib.h>
31e44c85637a3298918e292e9ddba812856cf92924Younes Manton#include <X11/extensions/XvMClib.h>
32b48676672592271597d07e5ece79cf4d3ffbe04bChristian König
337ea550621e25f9b2f344b2ed60551ceec91b3fcfKai Wasserbäch#include "util/u_memory.h"
34b48676672592271597d07e5ece79cf4d3ffbe04bChristian König
35e44c85637a3298918e292e9ddba812856cf92924Younes Manton#include "xvmc_private.h"
36c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton
373107b54b011c7ceef2b314632bdcf0b87c5e4d36Younes MantonPUBLIC
38e44c85637a3298918e292e9ddba812856cf92924Younes MantonStatus XvMCCreateBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *blocks)
39c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton{
40e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(dpy);
416858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
42e44c85637a3298918e292e9ddba812856cf92924Younes Manton   if (!context)
43e44c85637a3298918e292e9ddba812856cf92924Younes Manton      return XvMCBadContext;
44e44c85637a3298918e292e9ddba812856cf92924Younes Manton   if (num_blocks == 0)
45e44c85637a3298918e292e9ddba812856cf92924Younes Manton      return BadValue;
466858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
47e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(blocks);
48c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton
49e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->context_id = context->context_id;
50e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->num_blocks = num_blocks;
51e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->blocks = MALLOC(BLOCK_SIZE_BYTES * num_blocks);
52e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->privData = NULL;
536858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
54e44c85637a3298918e292e9ddba812856cf92924Younes Manton   return Success;
55c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton}
56c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton
573107b54b011c7ceef2b314632bdcf0b87c5e4d36Younes MantonPUBLIC
58e44c85637a3298918e292e9ddba812856cf92924Younes MantonStatus XvMCDestroyBlocks(Display *dpy, XvMCBlockArray *blocks)
596858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton{
60e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(dpy);
61e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(blocks);
62e44c85637a3298918e292e9ddba812856cf92924Younes Manton   FREE(blocks->blocks);
636858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
64e44c85637a3298918e292e9ddba812856cf92924Younes Manton   return Success;
65c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton}
66c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton
673107b54b011c7ceef2b314632bdcf0b87c5e4d36Younes MantonPUBLIC
68e44c85637a3298918e292e9ddba812856cf92924Younes MantonStatus XvMCCreateMacroBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks)
69c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton{
70e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(dpy);
716858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
72e44c85637a3298918e292e9ddba812856cf92924Younes Manton   if (!context)
73e44c85637a3298918e292e9ddba812856cf92924Younes Manton      return XvMCBadContext;
74e44c85637a3298918e292e9ddba812856cf92924Younes Manton   if (num_blocks == 0)
75e44c85637a3298918e292e9ddba812856cf92924Younes Manton      return BadValue;
766858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
77e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(blocks);
786858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
79e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->context_id = context->context_id;
80e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->num_blocks = num_blocks;
81e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->macro_blocks = MALLOC(sizeof(XvMCMacroBlock) * num_blocks);
82e44c85637a3298918e292e9ddba812856cf92924Younes Manton   blocks->privData = NULL;
836858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
84e44c85637a3298918e292e9ddba812856cf92924Younes Manton   return Success;
85c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton}
86c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton
873107b54b011c7ceef2b314632bdcf0b87c5e4d36Younes MantonPUBLIC
88e44c85637a3298918e292e9ddba812856cf92924Younes MantonStatus XvMCDestroyMacroBlocks(Display *dpy, XvMCMacroBlockArray *blocks)
896858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton{
90e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(dpy);
91e44c85637a3298918e292e9ddba812856cf92924Younes Manton   assert(blocks);
92e44c85637a3298918e292e9ddba812856cf92924Younes Manton   FREE(blocks->macro_blocks);
936858dd50c9b696c1c6044f5a403000f9d20b286bYounes Manton
94e44c85637a3298918e292e9ddba812856cf92924Younes Manton   return Success;
95c11a7ec821d41b91a3825c5abfb4687c98b5bf98Younes Manton}
96