1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2009 Younes Manton.
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#ifndef xvmc_private_h
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define xvmc_private_h
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <X11/Xlib.h>
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <X11/extensions/XvMClib.h>
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_video_state.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_debug.h"
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_math.h"
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "vl/vl_csc.h"
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "vl/vl_compositor.h"
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define BLOCK_SIZE_SAMPLES 64
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define BLOCK_SIZE_BYTES (BLOCK_SIZE_SAMPLES * 2)
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct pipe_video_decoder;
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct pipe_video_buffer;
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct pipe_sampler_view;
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct pipe_fence_handle;
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef struct
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct vl_screen *vscreen;
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_context *pipe;
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_video_decoder *decoder;
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   enum VL_CSC_COLOR_STANDARD color_standard;
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct vl_procamp procamp;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct vl_compositor compositor;
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct vl_compositor_state cstate;
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned short subpicture_max_width;
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned short subpicture_max_height;
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} XvMCContextPrivate;
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef struct
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_video_buffer *video_buffer;
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* nonzero if this picture is already being decoded */
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   int picture_structure;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   XvMCSurface *ref[2];
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_fence_handle *fence;
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* The subpicture associated with this surface, if any. */
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   XvMCSubpicture *subpicture;
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Some XvMC functions take a surface but not a context,
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      so we keep track of which context each surface belongs to. */
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   XvMCContext *context;
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} XvMCSurfacePrivate;
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef struct
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_sampler_view *sampler;
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* optional palette for this subpicture */
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct pipe_sampler_view *palette;
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct u_rect src_rect;
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct u_rect dst_rect;
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* The surface this subpicture is currently associated with, if any. */
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   XvMCSurface *surface;
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Some XvMC functions take a subpicture but not a context,
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      so we keep track of which context each subpicture belongs to. */
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   XvMCContext *context;
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} XvMCSubpicturePrivate;
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define XVMC_OUT   0
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define XVMC_ERR   1
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define XVMC_WARN  2
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define XVMC_TRACE 3
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void XVMC_MSG(unsigned int level, const char *fmt, ...)
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   static int debug_level = -1;
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (debug_level == -1) {
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      debug_level = MAX2(debug_get_num_option("XVMC_DEBUG", 0), 0);
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (level <= debug_level) {
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      va_list ap;
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      va_start(ap, fmt);
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _debug_vprintf(fmt, ap);
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      va_end(ap);
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* xvmc_private_h */
126