summaryrefslogtreecommitdiff
path: root/src/radeon_hwmc.c
blob: 4d6cdb620f312c781e46f12a0d31063377426af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * Copyright 2008 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Author: Cooper Yuan  <cooper.yuan@amd.com>
 *
 */
#include <xf86.h>
#include <xf86xvmc.h>
#include <X11/extensions/Xv.h>
#include <X11/extensions/XvMC.h>
#include "fourcc.h"
#include "radeon.h"
#include "radeon_hwmc.h"

static int subpicture_index_list[] =
{
    // XXX, todo fourcc
    0x3
};

static XF86MCImageIDList subpicture_list = 
{
    1,
    subpicture_index_list
};

static XF86MCSurfaceInfoRec radeon_YV12_mpg2_surface =
{
    SURFACE_TYPE_MPEG2_MPML,
    XVMC_CHROMA_FORMAT_420,
    0,
    720,
    576,
    720,
    576,
    XVMC_MPEG_2,
    XVMC_OVERLAID_SURFACE | 
    XVMC_SUBPICTURE_INDEPENDENT_SCALING,
    &subpicture_list,
};

static XF86MCSurfaceInfoRec radeon_YV12_mpg1_surface =
{
    SURFACE_TYPE_MPEG1_MPML,
    XVMC_CHROMA_FORMAT_420,
    0,
    2048,
    2048,
    2048,
    2048,
    XVMC_MPEG_1,
    XVMC_INTRA_UNSIGNED | 
    XVMC_SUBPICTURE_INDEPENDENT_SCALING | 
    XVMC_BACKEND_SUBPICTURE,
    &subpicture_list,
};

static XF86MCSurfaceInfoPtr Surfaces[2] =
{
    (XF86MCSurfaceInfoPtr)&radeon_YV12_mpg2_surface,
    (XF86MCSurfaceInfoPtr)&radeon_YV12_mpg1_surface
};

static XF86ImageRec radeon_subpicture;

static XF86ImagePtr SubPictures[] =
{
    (XF86ImagePtr) &radeon_subpicture
};

static XF86MCAdaptorRec R100Adapt =
{
    .name               = "AMD(R) R100 XvMC Video",
    .num_surfaces       = ARRAY_SIZE(Surfaces),
    .surfaces           = Surfaces,
    .num_subpictures    = ARRAY_SIZE(SubPictures),
    .subpictures        = SubPictures,
    .CreateContext      = NULL,
    .DestroyContext     = NULL,
    .CreateSurface      = NULL,
    .DestroySurface     = NULL,
    .CreateSubpicture   = NULL,
    .DestroySubpicture  = NULL,
};

static XF86MCAdaptorRec R300Adapt =
{
    .name               = "AMD(R) R300 XvMC Video",
    .num_surfaces       = ARRAY_SIZE(Surfaces),
    .surfaces           = Surfaces,
    .num_subpictures    = ARRAY_SIZE(SubPictures),
    .subpictures        = SubPictures,
    .CreateContext      = NULL,
    .DestroyContext     = NULL,
    .CreateSurface      = NULL,
    .DestroySurface     = NULL,
    .CreateSubpicture   = NULL,
    .DestroySubpicture  = NULL,
};

XF86MCAdaptorPtr RADEONCreateAdaptor(ScreenPtr pScreen)
{
    ScrnInfoPtr    pScrn   = xf86Screens[pScreen->myNum];
    RADEONInfoPtr  info    = RADEONPTR(pScrn);
    XF86MCAdaptorPtr xv_adaptor;

    assert(pScreen);

    xv_adaptor = xf86XvMCCreateAdaptorRec();
    if (!xv_adaptor)
    {
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[XvMC] Create adaptor failed\n");
        return NULL;
    }

    if (info->ChipFamily >= CHIP_FAMILY_RV100 && 
        info->ChipFamily < CHIP_FAMILY_R300)
    {
        *xv_adaptor = R100Adapt;
    }
    else if (info->ChipFamily >= CHIP_FAMILY_R300 && 
             info->ChipFamily < CHIP_FAMILY_RS600)
    {
        *xv_adaptor = R300Adapt;
    }

    xf86DrvMsg(pScrn->scrnIndex, X_INFO, 
               "[XvMC] Create adaptor for %s\n", xv_adaptor->name);

    return xv_adaptor;
}

void RADEONDestroyAdaptor(XF86MCAdaptorPtr xv_adaptor)
{
    assert(xv_adaptor);
    xf86XvMCDestoryAdaptorRec(xv_adaptor);
}

Bool RADEONInitHwmc(ScreenPtr pScreen, unsigned int num_adaptors,
                                       XF86VideoAdaptorPtr *xv_adaptors)
{
    ScrnInfoPtr    pScrn   = xf86Screens[pScreen->myNum];
    RADEONInfoPtr  info    = RADEONPTR(pScrn);
    Bool           status  = FALSE;
    int i;

    assert(pScrn);
    assert(xv_adaptors);

    if (xf86XvMCScreenInit(pScreen, num_adaptors, xv_adaptors)) 
    {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[XvMC] Driver initialized\n");
        status = TRUE;
    } 
    else 
    {
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[XvMC] Failed to initialize\n");
    }


    xf86XvMCRegisterDRInfo(pScreen, RADEON_XVMC_LIBNAME,
                                    info->dri->pDRIInfo->busIdString,
                                    RADEON_XVMC_MAJOR, 
                                    RADEON_XVMC_MINOR, 
                                    RADEON_XVMC_PATCHLEVEL);

    return status;
}