OSDN Git Service

Update to VA API 0.26
[android-x86/hardware-intel-common-libva.git] / dummy_drv_video / dummy_drv_video.c
1 /*
2  * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "va_backend.h"
26
27 #include "dummy_drv_video.h"
28
29 #include "assert.h"
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdarg.h>
33
34 #define ASSERT  assert
35
36 #define INIT_DRIVER_DATA        struct dummy_driver_data *driver_data = (struct dummy_driver_data *) ctx->pDriverData;
37
38 #define CONFIG(id)  ((object_config_p) object_heap_lookup( &driver_data->config_heap, id ))
39 #define CONTEXT(id) ((object_context_p) object_heap_lookup( &driver_data->context_heap, id ))
40 #define SURFACE(id)     ((object_surface_p) object_heap_lookup( &driver_data->surface_heap, id ))
41 #define BUFFER(id)  ((object_buffer_p) object_heap_lookup( &driver_data->buffer_heap, id ))
42
43 #define CONFIG_ID_OFFSET                0x01000000
44 #define CONTEXT_ID_OFFSET               0x02000000
45 #define SURFACE_ID_OFFSET               0x04000000
46 #define BUFFER_ID_OFFSET                0x08000000
47
48 static void dummy__error_message(const char *msg, ...)
49 {
50     va_list args;
51
52     fprintf(stderr, "dummy_drv_video error: ");
53     va_start(args, msg);
54     vfprintf(stderr, msg, args);
55     va_end(args);
56 }
57
58 static void dummy__information_message(const char *msg, ...)
59 {
60     va_list args;
61
62     fprintf(stderr, "dummy_drv_video: ");
63     va_start(args, msg);
64     vfprintf(stderr, msg, args);
65     va_end(args);
66 }
67
68 VAStatus dummy_QueryConfigProfiles(
69                 VADriverContextP ctx,
70                 VAProfile *profile_list,        /* out */
71                 int *num_profiles                       /* out */
72         )
73 {
74     INIT_DRIVER_DATA
75     int i = 0;
76
77     profile_list[i++] = VAProfileMPEG2Simple;
78     profile_list[i++] = VAProfileMPEG2Main;
79     profile_list[i++] = VAProfileMPEG4Simple;
80     profile_list[i++] = VAProfileMPEG4AdvancedSimple;
81     profile_list[i++] = VAProfileMPEG4Main;
82     profile_list[i++] = VAProfileH264Baseline;
83     profile_list[i++] = VAProfileH264Main;
84     profile_list[i++] = VAProfileH264High;
85     profile_list[i++] = VAProfileVC1Simple;
86     profile_list[i++] = VAProfileVC1Main;
87     profile_list[i++] = VAProfileVC1Advanced;
88
89     /* If the assert fails then DUMMY_MAX_PROFILES needs to be bigger */
90     ASSERT(i <= DUMMY_MAX_PROFILES);
91     *num_profiles = i;
92
93     return VA_STATUS_SUCCESS;
94 }
95
96 VAStatus dummy_QueryConfigEntrypoints(
97                 VADriverContextP ctx,
98                 VAProfile profile,
99                 VAEntrypoint  *entrypoint_list, /* out */
100                 int *num_entrypoints            /* out */
101         )
102 {
103     INIT_DRIVER_DATA
104
105     switch (profile) {
106         case VAProfileMPEG2Simple:
107         case VAProfileMPEG2Main:
108                 *num_entrypoints = 2;
109                 entrypoint_list[0] = VAEntrypointVLD;
110                 entrypoint_list[1] = VAEntrypointMoComp;
111                 break;
112
113         case VAProfileMPEG4Simple:
114         case VAProfileMPEG4AdvancedSimple:
115         case VAProfileMPEG4Main:
116                 *num_entrypoints = 1;
117                 entrypoint_list[0] = VAEntrypointVLD;
118                 break;
119
120         case VAProfileH264Baseline:
121         case VAProfileH264Main:
122         case VAProfileH264High:
123                 *num_entrypoints = 1;
124                 entrypoint_list[0] = VAEntrypointVLD;
125                 break;
126
127         case VAProfileVC1Simple:
128         case VAProfileVC1Main:
129         case VAProfileVC1Advanced:
130                 *num_entrypoints = 1;
131                 entrypoint_list[0] = VAEntrypointVLD;
132                 break;
133
134         default:
135                 *num_entrypoints = 0;
136                 break;
137     }
138
139     /* If the assert fails then DUMMY_MAX_ENTRYPOINTS needs to be bigger */
140     ASSERT(*num_entrypoints <= DUMMY_MAX_ENTRYPOINTS);
141     return VA_STATUS_SUCCESS;
142 }
143
144 VAStatus dummy_GetConfigAttributes(
145                 VADriverContextP ctx,
146                 VAProfile profile,
147                 VAEntrypoint entrypoint,
148                 VAConfigAttrib *attrib_list,    /* in/out */
149                 int num_attribs
150         )
151 {
152     INIT_DRIVER_DATA
153
154     int i;
155
156     /* Other attributes don't seem to be defined */
157     /* What to do if we don't know the attribute? */
158     for (i = 0; i < num_attribs; i++)
159     {
160         switch (attrib_list[i].type)
161         {
162           case VAConfigAttribRTFormat:
163               attrib_list[i].value = VA_RT_FORMAT_YUV420;
164               break;
165
166           default:
167               /* Do nothing */
168               attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
169               break;
170         }
171     }
172
173     return VA_STATUS_SUCCESS;
174 }
175
176 static VAStatus dummy__update_attribute(object_config_p obj_config, VAConfigAttrib *attrib)
177 {
178     int i;
179     /* Check existing attrbiutes */
180     for(i = 0; obj_config->attrib_count < i; i++)
181     {
182         if (obj_config->attrib_list[i].type == attrib->type)
183         {
184             /* Update existing attribute */
185             obj_config->attrib_list[i].value = attrib->value;
186             return VA_STATUS_SUCCESS;
187         }
188     }
189     if (obj_config->attrib_count < DUMMY_MAX_CONFIG_ATTRIBUTES)
190     {
191         i = obj_config->attrib_count;
192         obj_config->attrib_list[i].type = attrib->type;
193         obj_config->attrib_list[i].value = attrib->value;
194         obj_config->attrib_count++;
195         return VA_STATUS_SUCCESS;
196     }
197     return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
198 }
199
200 VAStatus dummy_CreateConfig(
201                 VADriverContextP ctx,
202                 VAProfile profile,
203                 VAEntrypoint entrypoint,
204                 VAConfigAttrib *attrib_list,
205                 int num_attribs,
206                 VAConfigID *config_id           /* out */
207         )
208 {
209     INIT_DRIVER_DATA
210     VAStatus vaStatus;
211     int configID;
212     object_config_p obj_config;
213     int i;
214
215     /* Validate profile & entrypoint */
216     switch (profile) {
217         case VAProfileMPEG2Simple:
218         case VAProfileMPEG2Main:
219                 if ((VAEntrypointVLD == entrypoint) ||
220                     (VAEntrypointMoComp == entrypoint))
221                 {
222                     vaStatus = VA_STATUS_SUCCESS;
223                 }
224                 else
225                 {
226                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
227                 }
228                 break;
229
230         case VAProfileMPEG4Simple:
231         case VAProfileMPEG4AdvancedSimple:
232         case VAProfileMPEG4Main:
233                 if (VAEntrypointVLD == entrypoint)
234                 {
235                     vaStatus = VA_STATUS_SUCCESS;
236                 }
237                 else
238                 {
239                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
240                 }
241                 break;
242
243         case VAProfileH264Baseline:
244         case VAProfileH264Main:
245         case VAProfileH264High:
246                 if (VAEntrypointVLD == entrypoint)
247                 {
248                     vaStatus = VA_STATUS_SUCCESS;
249                 }
250                 else
251                 {
252                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
253                 }
254                 break;
255
256         case VAProfileVC1Simple:
257         case VAProfileVC1Main:
258         case VAProfileVC1Advanced:
259                 if (VAEntrypointVLD == entrypoint)
260                 {
261                     vaStatus = VA_STATUS_SUCCESS;
262                 }
263                 else
264                 {
265                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
266                 }
267                 break;
268
269         default:
270                 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
271                 break;
272     }
273
274     if (VA_STATUS_SUCCESS != vaStatus)
275     {
276         return vaStatus;
277     }
278
279     configID = object_heap_allocate( &driver_data->config_heap );
280     obj_config = CONFIG(configID);
281     if (NULL == obj_config)
282     {
283         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
284         return vaStatus;
285     }
286
287     obj_config->profile = profile;
288     obj_config->entrypoint = entrypoint;
289     obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
290     obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
291     obj_config->attrib_count = 1;
292
293     for(i = 0; i < num_attribs; i++)
294     {
295         vaStatus = dummy__update_attribute(obj_config, &(attrib_list[i]));
296         if (VA_STATUS_SUCCESS != vaStatus)
297         {
298             break;
299         }
300     }
301
302     /* Error recovery */
303     if (VA_STATUS_SUCCESS != vaStatus)
304     {
305         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
306     }
307     else
308     {
309         *config_id = configID;
310     }
311
312     return vaStatus;
313 }
314
315 VAStatus dummy_DestroyConfig(
316                 VADriverContextP ctx,
317                 VAConfigID config_id
318         )
319 {
320     INIT_DRIVER_DATA
321     VAStatus vaStatus;
322     object_config_p obj_config;
323
324     obj_config = CONFIG(config_id);
325     if (NULL == obj_config)
326     {
327         vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
328         return vaStatus;
329     }
330
331     object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
332     return VA_STATUS_SUCCESS;
333 }
334
335 VAStatus dummy_QueryConfigAttributes(
336                 VADriverContextP ctx,
337                 VAConfigID config_id,
338                 VAProfile *profile,             /* out */
339                 VAEntrypoint *entrypoint,       /* out */
340                 VAConfigAttrib *attrib_list,    /* out */
341                 int *num_attribs                /* out */
342         )
343 {
344     INIT_DRIVER_DATA
345     VAStatus vaStatus = VA_STATUS_SUCCESS;
346     object_config_p obj_config;
347     int i;
348
349     obj_config = CONFIG(config_id);
350     ASSERT(obj_config);
351
352     *profile = obj_config->profile;
353     *entrypoint = obj_config->entrypoint;
354     *num_attribs =  obj_config->attrib_count;
355     for(i = 0; i < obj_config->attrib_count; i++)
356     {
357         attrib_list[i] = obj_config->attrib_list[i];
358     }
359
360     return vaStatus;
361 }
362
363 VAStatus dummy_CreateSurfaces(
364                 VADriverContextP ctx,
365                 int width,
366                 int height,
367                 int format,
368                 int num_surfaces,
369                 VASurfaceID *surfaces           /* out */
370         )
371 {
372     INIT_DRIVER_DATA
373     VAStatus vaStatus = VA_STATUS_SUCCESS;
374     int i;
375
376     /* We only support one format */
377     if (VA_RT_FORMAT_YUV420 != format)
378     {
379         return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
380     }
381
382     for (i = 0; i < num_surfaces; i++)
383     {
384         int surfaceID = object_heap_allocate( &driver_data->surface_heap );
385         object_surface_p obj_surface = SURFACE(surfaceID);
386         if (NULL == obj_surface)
387         {
388             vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
389             break;
390         }
391         obj_surface->surface_id = surfaceID;
392         surfaces[i] = surfaceID;
393     }
394
395     /* Error recovery */
396     if (VA_STATUS_SUCCESS != vaStatus)
397     {
398         /* surfaces[i-1] was the last successful allocation */
399         for(; i--; )
400         {
401             object_surface_p obj_surface = SURFACE(surfaces[i]);
402             surfaces[i] = VA_INVALID_SURFACE;
403             ASSERT(obj_surface);
404             object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
405         }
406     }
407
408     return vaStatus;
409 }
410
411 VAStatus dummy_DestroySurfaces(
412                 VADriverContextP ctx,
413                 VASurfaceID *surface_list,
414                 int num_surfaces
415         )
416 {
417     INIT_DRIVER_DATA
418     int i;
419     for(i = num_surfaces; i--; )
420     {
421         object_surface_p obj_surface = SURFACE(surface_list[i]);
422         ASSERT(obj_surface);
423         object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
424     }
425     return VA_STATUS_SUCCESS;
426 }
427
428 VAStatus dummy_QueryImageFormats(
429         VADriverContextP ctx,
430         VAImageFormat *format_list,        /* out */
431         int *num_formats           /* out */
432 )
433 {
434     INIT_DRIVER_DATA
435     
436     /* TODO */
437     return VA_STATUS_SUCCESS;
438 }
439
440 VAStatus dummy_CreateImage(
441         VADriverContextP ctx,
442         VAImageFormat *format,
443         int width,
444         int height,
445         VAImage *image     /* out */
446 )
447 {
448     INIT_DRIVER_DATA
449     
450     /* TODO */
451     return VA_STATUS_SUCCESS;
452 }
453
454 VAStatus dummy_DestroyImage(
455         VADriverContextP ctx,
456         VAImageID image
457 )
458 {
459     INIT_DRIVER_DATA
460     
461     /* TODO */
462     return VA_STATUS_SUCCESS;
463 }
464
465 VAStatus dummy_SetImagePalette(
466         VADriverContextP ctx,
467         VAImageID image,
468         unsigned char *palette
469 )
470 {
471     INIT_DRIVER_DATA
472     
473     /* TODO */
474     return VA_STATUS_SUCCESS;
475 }
476
477 VAStatus dummy_GetImage(
478         VADriverContextP ctx,
479         VASurfaceID surface,
480         int x,     /* coordinates of the upper left source pixel */
481         int y,
482         unsigned int width, /* width and height of the region */
483         unsigned int height,
484         VAImageID image
485 )
486 {
487     INIT_DRIVER_DATA
488     
489     /* TODO */
490     return VA_STATUS_SUCCESS;
491 }
492
493 VAStatus dummy_PutImage(
494         VADriverContextP ctx,
495         VASurfaceID surface,
496         VAImageID image,
497         int src_x,
498         int src_y,
499         unsigned int width,
500         unsigned int height,
501         int dest_x,
502         int dest_y 
503 )
504 {
505     INIT_DRIVER_DATA
506     
507     /* TODO */
508     return VA_STATUS_SUCCESS;
509 }
510
511 VAStatus dummy_QuerySubpictureFormats(
512         VADriverContextP ctx,
513         VAImageFormat *format_list,        /* out */
514         unsigned int *flags,       /* out */
515         unsigned int *num_formats  /* out */
516 )
517 {
518     INIT_DRIVER_DATA
519     
520     /* TODO */
521     return VA_STATUS_SUCCESS;
522 }
523
524 VAStatus dummy_CreateSubpicture(
525         VADriverContextP ctx,
526         VAImageID image,
527         VASubpictureID *subpicture   /* out */
528 )
529 {
530     INIT_DRIVER_DATA
531     
532     /* TODO */
533     return VA_STATUS_SUCCESS;
534 }
535
536 VAStatus dummy_DestroySubpicture(
537         VADriverContextP ctx,
538         VASubpictureID subpicture
539 )
540 {
541     INIT_DRIVER_DATA
542     
543     /* TODO */
544     return VA_STATUS_SUCCESS;
545 }
546
547 VAStatus dummy_SetSubpictureImage(
548         VADriverContextP ctx,
549         VASubpictureID subpicture,
550         VAImageID image
551 )
552 {
553     INIT_DRIVER_DATA
554     
555     /* TODO */
556     return VA_STATUS_SUCCESS;
557 }
558
559 VAStatus dummy_SetSubpicturePalette(
560         VADriverContextP ctx,
561         VASubpictureID subpicture,
562         /*
563          * pointer to an array holding the palette data.  The size of the array is
564          * num_palette_entries * entry_bytes in size.  The order of the components
565          * in the palette is described by the component_order in VASubpicture struct
566          */
567         unsigned char *palette
568 )
569 {
570     INIT_DRIVER_DATA
571     
572     /* TODO */
573     return VA_STATUS_SUCCESS;
574 }
575
576 VAStatus dummy_SetSubpictureChromakey(
577         VADriverContextP ctx,
578         VASubpictureID subpicture,
579         unsigned int chromakey_min,
580         unsigned int chromakey_max,
581         unsigned int chromakey_mask
582 )
583 {
584     INIT_DRIVER_DATA
585     
586     /* TODO */
587     return VA_STATUS_SUCCESS;
588 }
589
590 VAStatus dummy_SetSubpictureGlobalAlpha(
591         VADriverContextP ctx,
592         VASubpictureID subpicture,
593         float global_alpha 
594 )
595 {
596     INIT_DRIVER_DATA
597     
598     /* TODO */
599     return VA_STATUS_SUCCESS;
600 }
601
602 VAStatus dummy_AssociateSubpicture(
603         VADriverContextP ctx,
604         VASubpictureID subpicture,
605         VASurfaceID *target_surfaces,
606         int num_surfaces,
607         short src_x, /* upper left offset in subpicture */
608         short src_y,
609         short dest_x, /* upper left offset in surface */
610         short dest_y,
611         unsigned short width,
612         unsigned short height,
613         /*
614          * whether to enable chroma-keying or global-alpha
615          * see VA_SUBPICTURE_XXX values
616          */
617         unsigned int flags
618 )
619 {
620     INIT_DRIVER_DATA
621     
622     /* TODO */
623     return VA_STATUS_SUCCESS;
624 }
625
626 VAStatus dummy_DeassociateSubpicture(
627         VADriverContextP ctx,
628         VASubpictureID subpicture,
629         VASurfaceID *target_surfaces,
630         int num_surfaces
631 )
632 {
633     INIT_DRIVER_DATA
634     
635     /* TODO */
636     return VA_STATUS_SUCCESS;
637 }
638
639 VAStatus dummy_CreateContext(
640                 VADriverContextP ctx,
641                 VAConfigID config_id,
642                 int picture_width,
643                 int picture_height,
644                 int flag,
645                 VASurfaceID *render_targets,
646                 int num_render_targets,
647                 VAContextID *context            /* out */
648         )
649 {
650     INIT_DRIVER_DATA
651     VAStatus vaStatus = VA_STATUS_SUCCESS;
652     object_config_p obj_config;
653     int i;
654
655     obj_config = CONFIG(config_id);
656     if (NULL == obj_config)
657     {
658         vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
659         return vaStatus;
660     }
661
662     /* Validate flag */
663     /* Validate picture dimensions */
664
665     int contextID = object_heap_allocate( &driver_data->context_heap );
666     object_context_p obj_context = CONTEXT(contextID);
667     if (NULL == obj_context)
668     {
669         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
670         return vaStatus;
671     }
672
673     obj_context->context_id  = contextID;
674     *context = contextID;
675     obj_context->current_render_target = -1;
676     obj_context->config_id = config_id;
677     obj_context->picture_width = picture_width;
678     obj_context->picture_height = picture_height;
679     obj_context->num_render_targets = num_render_targets;
680     obj_context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID));
681     for(i = 0; i < num_render_targets; i++)
682     {
683         if (NULL == SURFACE(render_targets[i]))
684         {
685             vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
686             break;
687         }
688         obj_context->render_targets[i] = render_targets[i];
689     }
690     obj_context->flags = flag;
691
692     /* Error recovery */
693     if (VA_STATUS_SUCCESS != vaStatus)
694     {
695         obj_context->context_id = -1;
696         obj_context->config_id = -1;
697         free(obj_context->render_targets);
698         obj_context->render_targets = NULL;
699         obj_context->num_render_targets = 0;
700         obj_context->flags = 0;
701         object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
702     }
703
704     return vaStatus;
705 }
706
707
708 VAStatus dummy_DestroyContext(
709                 VADriverContextP ctx,
710                 VAContextID context
711         )
712 {
713     INIT_DRIVER_DATA
714     object_context_p obj_context = CONTEXT(context);
715     ASSERT(obj_context);
716
717     obj_context->context_id = -1;
718     obj_context->config_id = -1;
719     obj_context->picture_width = 0;
720     obj_context->picture_height = 0;
721     if (obj_context->render_targets)
722     {
723         free(obj_context->render_targets);
724     }
725     obj_context->render_targets = NULL;
726     obj_context->num_render_targets = 0;
727     obj_context->flags = 0;
728
729     obj_context->current_render_target = -1;
730
731     object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
732
733     return VA_STATUS_SUCCESS;
734 }
735
736
737
738 static VAStatus dummy__allocate_buffer(object_buffer_p obj_buffer, int size)
739 {
740     VAStatus vaStatus = VA_STATUS_SUCCESS;
741
742     obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size);
743     if (NULL == obj_buffer->buffer_data)
744     {
745         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
746     }
747     return vaStatus;
748 }
749
750 VAStatus dummy_CreateBuffer(
751                 VADriverContextP ctx,
752                 VAContextID context,    /* in */
753                 VABufferType type,      /* in */
754                 unsigned int size,              /* in */
755                 unsigned int num_elements,      /* in */
756                 void *data,                     /* in */
757                 VABufferID *buf_id              /* out */
758 )
759 {
760     INIT_DRIVER_DATA
761     VAStatus vaStatus = VA_STATUS_SUCCESS;
762     int bufferID;
763     object_buffer_p obj_buffer;
764
765     /* Validate type */
766     switch (type)
767     {
768         case VAPictureParameterBufferType:
769         case VAIQMatrixBufferType:
770         case VABitPlaneBufferType:
771         case VASliceGroupMapBufferType:
772         case VASliceParameterBufferType:
773         case VASliceDataBufferType:
774         case VAMacroblockParameterBufferType:
775         case VAResidualDataBufferType:
776         case VADeblockingParameterBufferType:
777         case VAImageBufferType:
778             /* Ok */
779             break;
780         default:
781             vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
782             return vaStatus;
783     }
784
785     bufferID = object_heap_allocate( &driver_data->buffer_heap );
786     obj_buffer = BUFFER(bufferID);
787     if (NULL == obj_buffer)
788     {
789         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
790         return vaStatus;
791     }
792
793     obj_buffer->buffer_data = NULL;
794
795     vaStatus = dummy__allocate_buffer(obj_buffer, size * num_elements);
796     if (VA_STATUS_SUCCESS == vaStatus)
797     {
798         obj_buffer->max_num_elements = num_elements;
799         obj_buffer->num_elements = num_elements;
800         if (data)
801         {
802             memcpy(obj_buffer->buffer_data, data, size * num_elements);
803         }
804     }
805
806     if (VA_STATUS_SUCCESS == vaStatus)
807     {
808         *buf_id = bufferID;
809     }
810
811     return vaStatus;
812 }
813
814
815 VAStatus dummy_BufferSetNumElements(
816                 VADriverContextP ctx,
817                 VABufferID buf_id,      /* in */
818         unsigned int num_elements       /* in */
819         )
820 {
821     INIT_DRIVER_DATA
822     VAStatus vaStatus = VA_STATUS_SUCCESS;
823     object_buffer_p obj_buffer = BUFFER(buf_id);
824     ASSERT(obj_buffer);
825
826     if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements))
827     {
828         vaStatus = VA_STATUS_ERROR_UNKNOWN;
829     }
830     if (VA_STATUS_SUCCESS == vaStatus)
831     {
832         obj_buffer->num_elements = num_elements;
833     }
834
835     return vaStatus;
836 }
837
838 VAStatus dummy_MapBuffer(
839                 VADriverContextP ctx,
840                 VABufferID buf_id,      /* in */
841                 void **pbuf         /* out */
842         )
843 {
844     INIT_DRIVER_DATA
845     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
846     object_buffer_p obj_buffer = BUFFER(buf_id);
847     ASSERT(obj_buffer);
848     if (NULL == obj_buffer)
849     {
850         vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
851         return vaStatus;
852     }
853
854     if (NULL != obj_buffer->buffer_data)
855     {
856         *pbuf = obj_buffer->buffer_data;
857         vaStatus = VA_STATUS_SUCCESS;
858     }
859     return vaStatus;
860 }
861
862 VAStatus dummy_UnmapBuffer(
863                 VADriverContextP ctx,
864                 VABufferID buf_id       /* in */
865         )
866 {
867     /* Do nothing */
868     return VA_STATUS_SUCCESS;
869 }
870
871 static void dummy__destroy_buffer(struct dummy_driver_data *driver_data, object_buffer_p obj_buffer)
872 {
873     if (NULL != obj_buffer->buffer_data)
874     {
875         free(obj_buffer->buffer_data);
876         obj_buffer->buffer_data = NULL;
877     }
878
879     object_heap_free( &driver_data->buffer_heap, (object_base_p) obj_buffer);
880 }
881
882 VAStatus dummy_DestroyBuffer(
883                 VADriverContextP ctx,
884                 VABufferID buffer_id
885         )
886 {
887     INIT_DRIVER_DATA
888     object_buffer_p obj_buffer = BUFFER(buffer_id);
889     ASSERT(obj_buffer);
890
891     dummy__destroy_buffer(driver_data, obj_buffer);
892     return VA_STATUS_SUCCESS;
893 }
894
895 VAStatus dummy_BeginPicture(
896                 VADriverContextP ctx,
897                 VAContextID context,
898                 VASurfaceID render_target
899         )
900 {
901     INIT_DRIVER_DATA
902     VAStatus vaStatus = VA_STATUS_SUCCESS;
903     object_context_p obj_context;
904     object_surface_p obj_surface;
905
906     obj_context = CONTEXT(context);
907     ASSERT(obj_context);
908
909     obj_surface = SURFACE(render_target);
910     ASSERT(obj_surface);
911
912     obj_context->current_render_target = obj_surface->base.id;
913
914     return vaStatus;
915 }
916
917 VAStatus dummy_RenderPicture(
918                 VADriverContextP ctx,
919                 VAContextID context,
920                 VABufferID *buffers,
921                 int num_buffers
922         )
923 {
924     INIT_DRIVER_DATA
925     VAStatus vaStatus = VA_STATUS_SUCCESS;
926     object_context_p obj_context;
927     object_surface_p obj_surface;
928     int i;
929
930     obj_context = CONTEXT(context);
931     ASSERT(obj_context);
932
933     obj_surface = SURFACE(obj_context->current_render_target);
934     ASSERT(obj_surface);
935
936     /* verify that we got valid buffer references */
937     for(i = 0; i < num_buffers; i++)
938     {
939         object_buffer_p obj_buffer = BUFFER(buffers[i]);
940         ASSERT(obj_buffer);
941         if (NULL == obj_buffer)
942         {
943             vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
944             break;
945         }
946     }
947     
948     /* Release buffers */
949     for(i = 0; i < num_buffers; i++)
950     {
951         object_buffer_p obj_buffer = BUFFER(buffers[i]);
952         ASSERT(obj_buffer);
953         dummy__destroy_buffer(driver_data, obj_buffer);
954     }
955
956     return vaStatus;
957 }
958
959 VAStatus dummy_EndPicture(
960                 VADriverContextP ctx,
961                 VAContextID context
962         )
963 {
964     INIT_DRIVER_DATA
965     VAStatus vaStatus = VA_STATUS_SUCCESS;
966     object_context_p obj_context;
967     object_surface_p obj_surface;
968
969     obj_context = CONTEXT(context);
970     ASSERT(obj_context);
971
972     obj_surface = SURFACE(obj_context->current_render_target);
973     ASSERT(obj_surface);
974
975     // For now, assume that we are done with rendering right away
976     obj_context->current_render_target = -1;
977
978     return vaStatus;
979 }
980
981
982 VAStatus dummy_SyncSurface(
983                 VADriverContextP ctx,
984                 VAContextID context,
985                 VASurfaceID render_target
986         )
987 {
988     INIT_DRIVER_DATA
989     VAStatus vaStatus = VA_STATUS_SUCCESS;
990     object_context_p obj_context;
991     object_surface_p obj_surface;
992
993     obj_context = CONTEXT(context);
994     ASSERT(obj_context);
995
996     obj_surface = SURFACE(render_target);
997     ASSERT(obj_surface);
998
999     /* Assume that this shouldn't be called before vaEndPicture() */
1000     ASSERT( obj_context->current_render_target != obj_surface->base.id );
1001
1002     return vaStatus;
1003 }
1004
1005 VAStatus dummy_QuerySurfaceStatus(
1006                 VADriverContextP ctx,
1007                 VASurfaceID render_target,
1008                 VASurfaceStatus *status /* out */
1009         )
1010 {
1011     INIT_DRIVER_DATA
1012     VAStatus vaStatus = VA_STATUS_SUCCESS;
1013     object_surface_p obj_surface;
1014
1015     obj_surface = SURFACE(render_target);
1016     ASSERT(obj_surface);
1017
1018     *status = VASurfaceReady;
1019
1020     return vaStatus;
1021 }
1022
1023 VAStatus dummy_PutSurface(
1024                 VADriverContextP ctx,
1025                 VASurfaceID surface,
1026                 Drawable draw, /* X Drawable */
1027                 short srcx,
1028                 short srcy,
1029                 unsigned short srcw,
1030                 unsigned short srch,
1031                 short destx,
1032                 short desty,
1033                 unsigned short destw,
1034                 unsigned short desth,
1035                 VARectangle *cliprects, /* client supplied clip list */
1036                 unsigned int number_cliprects, /* number of clip rects in the clip list */
1037                 unsigned int flags /* de-interlacing flags */
1038         )
1039 {
1040     /* TODO */
1041     return VA_STATUS_ERROR_UNKNOWN;
1042 }
1043
1044 /* 
1045  * Query display attributes 
1046  * The caller must provide a "attr_list" array that can hold at
1047  * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1048  * returned in "attr_list" is returned in "num_attributes".
1049  */
1050 VAStatus dummy_QueryDisplayAttributes (
1051                 VADriverContextP ctx,
1052                 VADisplayAttribute *attr_list,  /* out */
1053                 int *num_attributes             /* out */
1054         )
1055 {
1056     /* TODO */
1057     return VA_STATUS_ERROR_UNKNOWN;
1058 }
1059
1060 /* 
1061  * Get display attributes 
1062  * This function returns the current attribute values in "attr_list".
1063  * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1064  * from vaQueryDisplayAttributes() can have their values retrieved.  
1065  */
1066 VAStatus dummy_GetDisplayAttributes (
1067                 VADriverContextP ctx,
1068                 VADisplayAttribute *attr_list,  /* in/out */
1069                 int num_attributes
1070         )
1071 {
1072     /* TODO */
1073     return VA_STATUS_ERROR_UNKNOWN;
1074 }
1075
1076 /* 
1077  * Set display attributes 
1078  * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1079  * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
1080  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1081  */
1082 VAStatus dummy_SetDisplayAttributes (
1083                 VADriverContextP ctx,
1084                 VADisplayAttribute *attr_list,
1085                 int num_attributes
1086         )
1087 {
1088     /* TODO */
1089     return VA_STATUS_ERROR_UNKNOWN;
1090 }
1091
1092
1093 VAStatus dummy_DbgCopySurfaceToBuffer(
1094                 VADriverContextP ctx,
1095                 VASurfaceID surface,
1096                 void **buffer, /* out */
1097                 unsigned int *stride /* out */
1098         )
1099 {
1100     /* TODO */
1101     return VA_STATUS_ERROR_UNKNOWN;
1102 }
1103
1104 VAStatus dummy_Terminate( VADriverContextP ctx )
1105 {
1106     INIT_DRIVER_DATA
1107     object_buffer_p obj_buffer;
1108     object_surface_p obj_surface;
1109     object_context_p obj_context;
1110     object_config_p obj_config;
1111     object_heap_iterator iter;
1112
1113     /* Clean up left over buffers */
1114     obj_buffer = (object_buffer_p) object_heap_first( &driver_data->buffer_heap, &iter);
1115     while (obj_buffer)
1116     {
1117         dummy__information_message("vaTerminate: bufferID %08x still allocated, destroying\n", obj_buffer->base.id);
1118         dummy__destroy_buffer(driver_data, obj_buffer);
1119         obj_buffer = (object_buffer_p) object_heap_next( &driver_data->buffer_heap, &iter);
1120     }
1121     object_heap_destroy( &driver_data->buffer_heap );
1122
1123     /* TODO cleanup */
1124     object_heap_destroy( &driver_data->surface_heap );
1125
1126     /* TODO cleanup */
1127     object_heap_destroy( &driver_data->context_heap );
1128
1129     /* Clean up configIDs */
1130     obj_config = (object_config_p) object_heap_first( &driver_data->config_heap, &iter);
1131     while (obj_config)
1132     {
1133         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
1134         obj_config = (object_config_p) object_heap_next( &driver_data->config_heap, &iter);
1135     }
1136     object_heap_destroy( &driver_data->config_heap );
1137
1138     free(ctx->pDriverData);
1139     ctx->pDriverData = NULL;
1140
1141     return VA_STATUS_SUCCESS;
1142 }
1143
1144 VAStatus __vaDriverInit_0_26(  VADriverContextP ctx )
1145 {
1146     object_base_p obj;
1147     int result;
1148     struct dummy_driver_data *driver_data;
1149     int i;
1150
1151     ctx->version_major = 0;
1152     ctx->version_minor = 26;
1153     ctx->max_profiles = DUMMY_MAX_PROFILES;
1154     ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
1155     ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
1156     ctx->max_image_formats = DUMMY_MAX_IMAGE_FORMATS;
1157     ctx->max_subpic_formats = DUMMY_MAX_SUBPIC_FORMATS;
1158     ctx->max_display_attributes = DUMMY_MAX_DISPLAY_ATTRIBUTES;
1159     ctx->str_vendor = DUMMY_STR_VENDOR;
1160
1161     ctx->vtable.vaTerminate = dummy_Terminate;
1162     ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
1163     ctx->vtable.vaQueryConfigProfiles = dummy_QueryConfigProfiles;
1164     ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
1165     ctx->vtable.vaQueryConfigAttributes = dummy_QueryConfigAttributes;
1166     ctx->vtable.vaCreateConfig = dummy_CreateConfig;
1167     ctx->vtable.vaDestroyConfig = dummy_DestroyConfig;
1168     ctx->vtable.vaGetConfigAttributes = dummy_GetConfigAttributes;
1169     ctx->vtable.vaCreateSurfaces = dummy_CreateSurfaces;
1170     ctx->vtable.vaDestroySurfaces = dummy_DestroySurfaces;
1171     ctx->vtable.vaCreateContext = dummy_CreateContext;
1172     ctx->vtable.vaDestroyContext = dummy_DestroyContext;
1173     ctx->vtable.vaCreateBuffer = dummy_CreateBuffer;
1174     ctx->vtable.vaBufferSetNumElements = dummy_BufferSetNumElements;
1175     ctx->vtable.vaMapBuffer = dummy_MapBuffer;
1176     ctx->vtable.vaUnmapBuffer = dummy_UnmapBuffer;
1177     ctx->vtable.vaDestroyBuffer = dummy_DestroyBuffer;
1178     ctx->vtable.vaBeginPicture = dummy_BeginPicture;
1179     ctx->vtable.vaRenderPicture = dummy_RenderPicture;
1180     ctx->vtable.vaEndPicture = dummy_EndPicture;
1181     ctx->vtable.vaSyncSurface = dummy_SyncSurface;
1182     ctx->vtable.vaQuerySurfaceStatus = dummy_QuerySurfaceStatus;
1183     ctx->vtable.vaPutSurface = dummy_PutSurface;
1184     ctx->vtable.vaQueryImageFormats = dummy_QueryImageFormats;
1185     ctx->vtable.vaCreateImage = dummy_CreateImage;
1186     ctx->vtable.vaDestroyImage = dummy_DestroyImage;
1187     ctx->vtable.vaSetImagePalette = dummy_SetImagePalette;
1188     ctx->vtable.vaGetImage = dummy_GetImage;
1189     ctx->vtable.vaPutImage = dummy_PutImage;
1190     ctx->vtable.vaQuerySubpictureFormats = dummy_QuerySubpictureFormats;
1191     ctx->vtable.vaCreateSubpicture = dummy_CreateSubpicture;
1192     ctx->vtable.vaDestroySubpicture = dummy_DestroySubpicture;
1193     ctx->vtable.vaSetSubpictureImage = dummy_SetSubpictureImage;
1194     ctx->vtable.vaSetSubpicturePalette = dummy_SetSubpicturePalette;
1195     ctx->vtable.vaSetSubpictureChromakey = dummy_SetSubpictureChromakey;
1196     ctx->vtable.vaSetSubpictureGlobalAlpha = dummy_SetSubpictureGlobalAlpha;
1197     ctx->vtable.vaAssociateSubpicture = dummy_AssociateSubpicture;
1198     ctx->vtable.vaDeassociateSubpicture = dummy_DeassociateSubpicture;
1199     ctx->vtable.vaQueryDisplayAttributes = dummy_QueryDisplayAttributes;
1200     ctx->vtable.vaGetDisplayAttributes = dummy_GetDisplayAttributes;
1201     ctx->vtable.vaSetDisplayAttributes = dummy_SetDisplayAttributes;
1202     
1203     ctx->vtable.vaDbgCopySurfaceToBuffer = dummy_DbgCopySurfaceToBuffer;
1204
1205     driver_data = (struct dummy_driver_data *) malloc( sizeof(*driver_data) );
1206     ctx->pDriverData = (void *) driver_data;
1207
1208     result = object_heap_init( &driver_data->config_heap, sizeof(struct object_config), CONFIG_ID_OFFSET );
1209     ASSERT( result == 0 );
1210
1211     result = object_heap_init( &driver_data->context_heap, sizeof(struct object_context), CONTEXT_ID_OFFSET );
1212     ASSERT( result == 0 );
1213
1214     result = object_heap_init( &driver_data->surface_heap, sizeof(struct object_surface), SURFACE_ID_OFFSET );
1215     ASSERT( result == 0 );
1216
1217     result = object_heap_init( &driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET );
1218     ASSERT( result == 0 );
1219
1220
1221     return VA_STATUS_SUCCESS;
1222 }
1223