Make dummy driver compile & load
[platform/upstream/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_QueryConfigAttributes(
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_GetConfigAttributes(
316                 VADriverContextP ctx,
317                 VAConfigID config_id,
318                 VAProfile *profile,             /* out */
319                 VAEntrypoint *entrypoint,       /* out */
320                 VAConfigAttrib *attrib_list,    /* out */
321                 int *num_attribs                /* out */
322         )
323 {
324     INIT_DRIVER_DATA
325     VAStatus vaStatus = VA_STATUS_SUCCESS;
326     object_config_p obj_config;
327     int i;
328
329     obj_config = CONFIG(config_id);
330     ASSERT(obj_config);
331
332     *profile = obj_config->profile;
333     *entrypoint = obj_config->entrypoint;
334     *num_attribs =  obj_config->attrib_count;
335     for(i = 0; i < obj_config->attrib_count; i++)
336     {
337         attrib_list[i] = obj_config->attrib_list[i];
338     }
339
340     return vaStatus;
341 }
342
343 VAStatus dummy_CreateSurfaces(
344                 VADriverContextP ctx,
345                 int width,
346                 int height,
347                 int format,
348                 int num_surfaces,
349                 VASurface *surfaces             /* out */
350         )
351 {
352     INIT_DRIVER_DATA
353     VAStatus vaStatus = VA_STATUS_SUCCESS;
354     int i;
355
356     /* We only support one format */
357     if (VA_RT_FORMAT_YUV420 != format)
358     {
359         return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
360     }
361
362     for (i = 0; i < num_surfaces; i++)
363     {
364         int surfaceID = object_heap_allocate( &driver_data->surface_heap );
365         object_surface_p obj_surface = SURFACE(surfaceID);
366         if (NULL == obj_surface)
367         {
368             vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
369             break;
370         }
371         obj_surface->surface = &(surfaces[i]);
372         obj_surface->surface->surface_id = surfaceID;
373         obj_surface->surface->context_id = -1;
374         obj_surface->surface->width = width;
375         obj_surface->surface->height = height;
376         obj_surface->surface->format = format;
377         obj_surface->surface->privData = NULL;
378     }
379
380     /* Error recovery */
381     if (VA_STATUS_SUCCESS != vaStatus)
382     {
383         /* surfaces[i-1] was the last successful allocation */
384         for(; i--; )
385         {
386             object_surface_p obj_surface = SURFACE(surfaces[i].surface_id);
387             surfaces[i].surface_id = -1;
388             ASSERT(obj_surface);
389             object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
390         }
391     }
392
393     return vaStatus;
394 }
395
396 VAStatus dummy_DestroySurface(
397                 VADriverContextP ctx,
398                 VASurface *surface_list,
399                 int num_surfaces
400         )
401 {
402     INIT_DRIVER_DATA
403     int i;
404     for(i = num_surfaces; i--; )
405     {
406         object_surface_p obj_surface = SURFACE(surface_list[i].surface_id);
407         ASSERT(obj_surface);
408         object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
409     }
410     return VA_STATUS_SUCCESS;
411 }
412
413 VAStatus dummy_QueryImageFormats(
414         VADriverContextP ctx,
415         VAImageFormat *format_list,        /* out */
416         int *num_formats           /* out */
417 )
418 {
419     INIT_DRIVER_DATA
420     
421     /* TODO */
422     return VA_STATUS_SUCCESS;
423 }
424
425 VAStatus dummy_CreateImage(
426         VADriverContextP ctx,
427         VAImageFormat *format,
428         int width,
429         int height,
430         VAImage *image     /* out */
431 )
432 {
433     INIT_DRIVER_DATA
434     
435     /* TODO */
436     return VA_STATUS_SUCCESS;
437 }
438
439 VAStatus dummy_DestroyImage(
440         VADriverContextP ctx,
441         VAImage *image
442 )
443 {
444     INIT_DRIVER_DATA
445     
446     /* TODO */
447     return VA_STATUS_SUCCESS;
448 }
449
450 VAStatus dummy_GetImage(
451         VADriverContextP ctx,
452         VASurface *surface,
453         int x,     /* coordinates of the upper left source pixel */
454         int y,
455         unsigned int width, /* width and height of the region */
456         unsigned int height,
457         VAImage *image
458 )
459 {
460     INIT_DRIVER_DATA
461     
462     /* TODO */
463     return VA_STATUS_SUCCESS;
464 }
465
466 VAStatus dummy_PutImage(
467         VADriverContextP ctx,
468         VASurface *surface,
469         VAImage *image,
470         int src_x,
471         int src_y,
472         unsigned int width,
473         unsigned int height,
474         int dest_x,
475         int dest_y 
476 )
477 {
478     INIT_DRIVER_DATA
479     
480     /* TODO */
481     return VA_STATUS_SUCCESS;
482 }
483
484 VAStatus dummy_QuerySubpictureFormats(
485         VADriverContextP ctx,
486         VAImageFormat *format_list,        /* out */
487         unsigned int *flags,       /* out */
488         unsigned int *num_formats  /* out */
489 )
490 {
491     INIT_DRIVER_DATA
492     
493     /* TODO */
494     return VA_STATUS_SUCCESS;
495 }
496
497 VAStatus dummy_CreateSubpicture(
498         VADriverContextP ctx,
499         VAImage *image,
500         VASubpicture *subpicture   /* out */
501 )
502 {
503     INIT_DRIVER_DATA
504     
505     /* TODO */
506     return VA_STATUS_SUCCESS;
507 }
508
509 VAStatus dummy_DestroySubpicture(
510         VADriverContextP ctx,
511         VASubpicture *subpicture
512 )
513 {
514     INIT_DRIVER_DATA
515     
516     /* TODO */
517     return VA_STATUS_SUCCESS;
518 }
519
520 VAStatus dummy_SetSubpicturePalette(
521         VADriverContextP ctx,
522         VASubpicture *subpicture,
523         /*
524          * pointer to an array holding the palette data.  The size of the array is
525          * num_palette_entries * entry_bytes in size.  The order of the components
526          * in the palette is described by the component_order in VASubpicture struct
527          */
528         unsigned char *palette
529 )
530 {
531     INIT_DRIVER_DATA
532     
533     /* TODO */
534     return VA_STATUS_SUCCESS;
535 }
536
537 VAStatus dummy_SetSubpictureChromakey(
538         VADriverContextP ctx,
539         VASubpicture *subpicture,
540         unsigned int chromakey_min,
541         unsigned int chromakey_max
542 )
543 {
544     INIT_DRIVER_DATA
545     
546     /* TODO */
547     return VA_STATUS_SUCCESS;
548 }
549
550 VAStatus dummy_SetSubpictureGlobalAlpha(
551         VADriverContextP ctx,
552         VASubpicture *subpicture,
553         float global_alpha 
554 )
555 {
556     INIT_DRIVER_DATA
557     
558     /* TODO */
559     return VA_STATUS_SUCCESS;
560 }
561
562 VAStatus dummy_AssociateSubpicture(
563         VADriverContextP ctx,
564         VASurface *target_surface,
565         VASubpicture *subpicture,
566         short src_x, /* upper left offset in subpicture */
567         short src_y,
568         short dest_x, /* upper left offset in surface */
569         short dest_y,
570         unsigned short width,
571         unsigned short height,
572         /*
573          * whether to enable chroma-keying or global-alpha
574          * see VA_SUBPICTURE_XXX values
575          */
576         unsigned int flags
577 )
578 {
579     INIT_DRIVER_DATA
580     
581     /* TODO */
582     return VA_STATUS_SUCCESS;
583 }
584
585 VAStatus dummy_CreateContext(
586                 VADriverContextP ctx,
587                 VAConfigID config_id,
588                 int picture_width,
589                 int picture_height,
590                 int flag,
591                 VASurface *render_targets,
592                 int num_render_targets,
593                 VAContext *context              /* out */
594         )
595 {
596     INIT_DRIVER_DATA
597     VAStatus vaStatus = VA_STATUS_SUCCESS;
598     object_config_p obj_config;
599     int i;
600
601     obj_config = CONFIG(config_id);
602     if (NULL == obj_config)
603     {
604         vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
605         return vaStatus;
606     }
607
608     /* Validate flag */
609     /* Validate picture dimensions */
610
611     int contextID = object_heap_allocate( &driver_data->context_heap );
612     object_context_p obj_context = CONTEXT(contextID);
613     if (NULL == obj_context)
614     {
615         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
616         return vaStatus;
617     }
618
619     obj_context->context = context;
620     obj_context->current_render_target = -1;
621
622     obj_context->context->context_id = contextID;
623     obj_context->context->config_id = config_id;
624     obj_context->context->picture_width = picture_width;
625     obj_context->context->picture_height = picture_height;
626     obj_context->context->num_render_targets = num_render_targets;
627     obj_context->context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID));
628     for(i = 0; i < num_render_targets; i++)
629     {
630         if (NULL == SURFACE(render_targets[i].surface_id))
631         {
632             vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
633             break;
634         }
635         obj_context->context->render_targets[i] = render_targets[i].surface_id;
636     }
637     obj_context->context->flags = flag;
638     obj_context->context->privData = NULL;
639
640     /* Error recovery */
641     if (VA_STATUS_SUCCESS != vaStatus)
642     {
643         free(obj_context->context->render_targets);
644         obj_context->context->render_targets = NULL;
645         obj_context->context->context_id = -1;
646         obj_context->context->config_id = -1;
647         obj_context->context->picture_width = 0;
648         obj_context->context->picture_height = 0;
649         free(obj_context->context->render_targets);
650         obj_context->context->render_targets = NULL;
651         obj_context->context->num_render_targets = 0;
652         obj_context->context->flags = 0;
653         obj_context->context->privData = NULL;
654         object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
655     }
656
657     return vaStatus;
658 }
659
660
661 VAStatus dummy_DestroyContext(
662                 VADriverContextP ctx,
663                 VAContext *context
664         )
665 {
666     INIT_DRIVER_DATA
667     object_context_p obj_context = CONTEXT(context->context_id);
668     ASSERT(obj_context);
669
670     obj_context->context->context_id = -1;
671     obj_context->context->config_id = -1;
672     obj_context->context->picture_width = 0;
673     obj_context->context->picture_height = 0;
674     if (obj_context->context->render_targets)
675     {
676         free(obj_context->context->render_targets);
677     }
678     obj_context->context->render_targets = NULL;
679     obj_context->context->num_render_targets = 0;
680     obj_context->context->flags = 0;
681     obj_context->context->privData = NULL;
682
683     obj_context->context = NULL;
684     obj_context->current_render_target = -1;
685
686     object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
687
688     return VA_STATUS_SUCCESS;
689 }
690
691
692 VAStatus dummy_CreateBuffer(
693                 VADriverContextP ctx,
694                 VABufferType type,  /* in */
695                 VABufferID *buf_desc    /* out */
696         )
697 {
698     INIT_DRIVER_DATA
699     VAStatus vaStatus = VA_STATUS_SUCCESS;
700     int bufferID;
701     object_buffer_p obj_buffer;
702
703     /* Validate type */
704     switch (type)
705     {
706         case VAPictureParameterBufferType:
707         case VAIQMatrixBufferType:
708         case VASliceParameterBufferType:
709         case VASliceDataBufferType:
710         case VAMacroblockParameterBufferType:
711         case VAResidualDataBufferType:
712         case VADeblockingParameterBufferType:
713             /* Ok */
714             break;
715         default:
716             vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
717             return vaStatus;
718     }
719
720     bufferID = object_heap_allocate( &driver_data->buffer_heap );
721     obj_buffer = BUFFER(bufferID);
722     if (NULL == obj_buffer)
723     {
724         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
725         return vaStatus;
726     }
727
728     obj_buffer->buffer_data = NULL;
729
730     *buf_desc = bufferID;
731
732     return vaStatus;
733 }
734
735 static VAStatus dummy__allocate_buffer(object_buffer_p obj_buffer, int size)
736 {
737     VAStatus vaStatus = VA_STATUS_SUCCESS;
738
739     obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size);
740     if (NULL == obj_buffer->buffer_data)
741     {
742         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
743     }
744     return vaStatus;
745 }
746
747 VAStatus dummy_BufferData(
748                 VADriverContextP ctx,
749                 VABufferID buf_id,      /* in */
750         unsigned int size,      /* in */
751         unsigned int num_elements,      /* in */
752         void *data              /* in */
753         )
754 {
755     INIT_DRIVER_DATA
756     VAStatus vaStatus = VA_STATUS_SUCCESS;
757     object_buffer_p obj_buffer = BUFFER(buf_id);
758     ASSERT(obj_buffer);
759
760     vaStatus = dummy__allocate_buffer(obj_buffer, size * num_elements);
761     if (VA_STATUS_SUCCESS == vaStatus)
762     {
763         obj_buffer->max_num_elements = num_elements;
764         obj_buffer->num_elements = num_elements;
765         if (data)
766         {
767             memcpy(obj_buffer->buffer_data, data, size * num_elements);
768         }
769     }
770
771     return vaStatus;
772 }
773
774 VAStatus dummy_BufferSetNumElements(
775                 VADriverContextP ctx,
776                 VABufferID buf_id,      /* in */
777         unsigned int num_elements       /* in */
778         )
779 {
780     INIT_DRIVER_DATA
781     VAStatus vaStatus = VA_STATUS_SUCCESS;
782     object_buffer_p obj_buffer = BUFFER(buf_id);
783     ASSERT(obj_buffer);
784
785     if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements))
786     {
787         vaStatus = VA_STATUS_ERROR_UNKNOWN;
788     }
789     if (VA_STATUS_SUCCESS == vaStatus)
790     {
791         obj_buffer->num_elements = num_elements;
792     }
793
794     return vaStatus;
795 }
796
797 VAStatus dummy_MapBuffer(
798                 VADriverContextP ctx,
799                 VABufferID buf_id,      /* in */
800                 void **pbuf         /* out */
801         )
802 {
803     INIT_DRIVER_DATA
804     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
805     object_buffer_p obj_buffer = BUFFER(buf_id);
806     ASSERT(obj_buffer);
807     if (NULL == obj_buffer)
808     {
809         vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
810         return vaStatus;
811     }
812
813     if (NULL != obj_buffer->buffer_data)
814     {
815         *pbuf = obj_buffer->buffer_data;
816         vaStatus = VA_STATUS_SUCCESS;
817     }
818     return vaStatus;
819 }
820
821 VAStatus dummy_UnmapBuffer(
822                 VADriverContextP ctx,
823                 VABufferID buf_id       /* in */
824         )
825 {
826     /* Do nothing */
827     return VA_STATUS_SUCCESS;
828 }
829
830 static void dummy__destroy_buffer(struct dummy_driver_data *driver_data, object_buffer_p obj_buffer)
831 {
832     if (NULL != obj_buffer->buffer_data)
833     {
834         free(obj_buffer->buffer_data);
835         obj_buffer->buffer_data = NULL;
836     }
837
838     object_heap_free( &driver_data->buffer_heap, (object_base_p) obj_buffer);
839 }
840
841 VAStatus dummy_DestroyBuffer(
842                 VADriverContextP ctx,
843                 VABufferID buffer_id
844         )
845 {
846     INIT_DRIVER_DATA
847     object_buffer_p obj_buffer = BUFFER(buffer_id);
848     ASSERT(obj_buffer);
849
850     dummy__destroy_buffer(driver_data, obj_buffer);
851     return VA_STATUS_SUCCESS;
852 }
853
854 VAStatus dummy_BeginPicture(
855                 VADriverContextP ctx,
856                 VAContext *context,
857                 VASurface *render_target
858         )
859 {
860     INIT_DRIVER_DATA
861     VAStatus vaStatus = VA_STATUS_SUCCESS;
862     object_context_p obj_context;
863     object_surface_p obj_surface;
864
865     obj_context = CONTEXT(context->context_id);
866     ASSERT(obj_context);
867
868     obj_surface = SURFACE(render_target->surface_id);
869     ASSERT(obj_surface);
870
871     obj_context->current_render_target = obj_surface->base.id;
872
873     return vaStatus;
874 }
875
876 VAStatus dummy_RenderPicture(
877                 VADriverContextP ctx,
878                 VAContext *context,
879                 VABufferID *buffers,
880                 int num_buffers
881         )
882 {
883     INIT_DRIVER_DATA
884     VAStatus vaStatus = VA_STATUS_SUCCESS;
885     object_context_p obj_context;
886     object_surface_p obj_surface;
887     int i;
888
889     obj_context = CONTEXT(context->context_id);
890     ASSERT(obj_context);
891
892     obj_surface = SURFACE(obj_context->current_render_target);
893     ASSERT(obj_surface);
894
895     /* verify that we got valid buffer references */
896     for(i = 0; i < num_buffers; i++)
897     {
898         object_buffer_p obj_buffer = BUFFER(buffers[i]);
899         ASSERT(obj_buffer);
900         if (NULL == obj_buffer)
901         {
902             vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
903             break;
904         }
905     }
906
907     return vaStatus;
908 }
909
910 VAStatus dummy_EndPicture(
911                 VADriverContextP ctx,
912                 VAContext *context
913         )
914 {
915     INIT_DRIVER_DATA
916     VAStatus vaStatus = VA_STATUS_SUCCESS;
917     object_context_p obj_context;
918     object_surface_p obj_surface;
919
920     obj_context = CONTEXT(context->context_id);
921     ASSERT(obj_context);
922
923     obj_surface = SURFACE(obj_context->current_render_target);
924     ASSERT(obj_surface);
925
926     // For now, assume that we are done with rendering right away
927     obj_context->current_render_target = -1;
928
929     return vaStatus;
930 }
931
932
933 VAStatus dummy_SyncSurface(
934                 VADriverContextP ctx,
935                 VAContext *context,
936                 VASurface *render_target
937         )
938 {
939     INIT_DRIVER_DATA
940     VAStatus vaStatus = VA_STATUS_SUCCESS;
941     object_context_p obj_context;
942     object_surface_p obj_surface;
943
944     obj_context = CONTEXT(context->context_id);
945     ASSERT(obj_context);
946
947     obj_surface = SURFACE(render_target->surface_id);
948     ASSERT(obj_surface);
949
950     /* Assume that this shouldn't be called before vaEndPicture() */
951     ASSERT( obj_context->current_render_target != obj_surface->base.id );
952
953     return vaStatus;
954 }
955
956 VAStatus dummy_QuerySurfaceStatus(
957                 VADriverContextP ctx,
958                 VAContext *context,
959                 VASurface *render_target,
960                 VASurfaceStatus *status /* out */
961         )
962 {
963     INIT_DRIVER_DATA
964     VAStatus vaStatus = VA_STATUS_SUCCESS;
965     object_context_p obj_context;
966     object_surface_p obj_surface;
967
968     obj_context = CONTEXT(context->context_id);
969     ASSERT(obj_context);
970
971     obj_surface = SURFACE(render_target->surface_id);
972     ASSERT(obj_surface);
973
974     /* Assume that we are busy until vaEndPicture() is called */
975     if ( obj_context->current_render_target == obj_surface->base.id )
976     {
977         *status = VASurfaceRendering;
978     }
979     else
980     {
981         *status = VASurfaceReady;
982     }
983
984     return vaStatus;
985 }
986
987 VAStatus dummy_PutSurface(
988                 VADriverContextP ctx,
989                 VASurface *surface,
990                 Drawable draw, /* X Drawable */
991                 short srcx,
992                 short srcy,
993                 unsigned short srcw,
994                 unsigned short srch,
995                 short destx,
996                 short desty,
997                 unsigned short destw,
998                 unsigned short desth,
999                 VARectangle *cliprects, /* client supplied clip list */
1000                 unsigned int number_cliprects, /* number of clip rects in the clip list */
1001                 int flags /* de-interlacing flags */
1002         )
1003 {
1004     /* TODO */
1005     return VA_STATUS_ERROR_UNKNOWN;
1006 }
1007
1008 VAStatus dummy_DbgCopySurfaceToBuffer(
1009                 VADriverContextP ctx,
1010                 VASurface *surface,
1011                 void **buffer, /* out */
1012                 unsigned int *stride /* out */
1013         )
1014 {
1015     /* TODO */
1016     return VA_STATUS_ERROR_UNKNOWN;
1017 }
1018
1019 VAStatus dummy_Terminate( VADriverContextP ctx )
1020 {
1021     INIT_DRIVER_DATA
1022     object_buffer_p obj_buffer;
1023     object_surface_p obj_surface;
1024     object_context_p obj_context;
1025     object_config_p obj_config;
1026     object_heap_iterator iter;
1027
1028     /* Clean up left over buffers */
1029     obj_buffer = (object_buffer_p) object_heap_first( &driver_data->buffer_heap, &iter);
1030     while (obj_buffer)
1031     {
1032         dummy__information_message("vaTerminate: bufferID %08x still allocated, destroying\n", obj_buffer->base.id);
1033         dummy__destroy_buffer(driver_data, obj_buffer);
1034         obj_buffer = (object_buffer_p) object_heap_next( &driver_data->buffer_heap, &iter);
1035     }
1036     object_heap_destroy( &driver_data->buffer_heap );
1037
1038     /* TODO cleanup */
1039     object_heap_destroy( &driver_data->surface_heap );
1040
1041     /* TODO cleanup */
1042     object_heap_destroy( &driver_data->context_heap );
1043
1044     /* Clean up configIDs */
1045     obj_config = (object_config_p) object_heap_first( &driver_data->config_heap, &iter);
1046     while (obj_config)
1047     {
1048         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
1049         obj_config = (object_config_p) object_heap_next( &driver_data->config_heap, &iter);
1050     }
1051     object_heap_destroy( &driver_data->config_heap );
1052
1053     free(ctx->pDriverData);
1054     ctx->pDriverData = NULL;
1055
1056     return VA_STATUS_SUCCESS;
1057 }
1058
1059 VAStatus __vaDriverInit_0_22(  VADriverContextP ctx )
1060 {
1061     object_base_p obj;
1062     int result;
1063     struct dummy_driver_data *driver_data;
1064     int i;
1065
1066     ctx->version_major = 0;
1067     ctx->version_minor = 22;
1068     ctx->max_profiles = DUMMY_MAX_PROFILES;
1069     ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
1070     ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
1071     ctx->max_image_formats = DUMMY_MAX_IMAGE_FORMATS;
1072     ctx->max_subpic_formats = DUMMY_MAX_SUBPIC_FORMATS;
1073
1074     ctx->vtable.vaTerminate = dummy_Terminate;
1075     ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
1076     ctx->vtable.vaQueryConfigProfiles = dummy_QueryConfigProfiles;
1077     ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
1078     ctx->vtable.vaQueryConfigAttributes = dummy_QueryConfigAttributes;
1079     ctx->vtable.vaCreateConfig = dummy_CreateConfig;
1080     ctx->vtable.vaGetConfigAttributes = dummy_GetConfigAttributes;
1081     ctx->vtable.vaCreateSurfaces = dummy_CreateSurfaces;
1082     ctx->vtable.vaDestroySurface = dummy_DestroySurface;
1083     ctx->vtable.vaCreateContext = dummy_CreateContext;
1084     ctx->vtable.vaDestroyContext = dummy_DestroyContext;
1085     ctx->vtable.vaCreateBuffer = dummy_CreateBuffer;
1086     ctx->vtable.vaBufferData = dummy_BufferData;
1087     ctx->vtable.vaBufferSetNumElements = dummy_BufferSetNumElements;
1088     ctx->vtable.vaMapBuffer = dummy_MapBuffer;
1089     ctx->vtable.vaUnmapBuffer = dummy_UnmapBuffer;
1090     ctx->vtable.vaDestroyBuffer = dummy_DestroyBuffer;
1091     ctx->vtable.vaBeginPicture = dummy_BeginPicture;
1092     ctx->vtable.vaRenderPicture = dummy_RenderPicture;
1093     ctx->vtable.vaEndPicture = dummy_EndPicture;
1094     ctx->vtable.vaSyncSurface = dummy_SyncSurface;
1095     ctx->vtable.vaQuerySurfaceStatus = dummy_QuerySurfaceStatus;
1096     ctx->vtable.vaPutSurface = dummy_PutSurface;
1097     ctx->vtable.vaQueryImageFormats = dummy_QueryImageFormats;
1098     ctx->vtable.vaCreateImage = dummy_CreateImage;
1099     ctx->vtable.vaDestroyImage = dummy_DestroyImage;
1100     ctx->vtable.vaGetImage = dummy_GetImage;
1101     ctx->vtable.vaPutImage = dummy_PutImage;
1102     ctx->vtable.vaQuerySubpictureFormats = dummy_QuerySubpictureFormats;
1103     ctx->vtable.vaCreateSubpicture = dummy_CreateSubpicture;
1104     ctx->vtable.vaDestroySubpicture = dummy_DestroySubpicture;
1105     ctx->vtable.vaSetSubpicturePalette = dummy_SetSubpicturePalette;
1106     ctx->vtable.vaSetSubpictureChromakey = dummy_SetSubpictureChromakey;
1107     ctx->vtable.vaSetSubpictureGlobalAlpha = dummy_SetSubpictureGlobalAlpha;
1108     ctx->vtable.vaAssociateSubpicture = dummy_AssociateSubpicture;
1109     ctx->vtable.vaDbgCopySurfaceToBuffer = dummy_DbgCopySurfaceToBuffer;
1110
1111     driver_data = (struct dummy_driver_data *) malloc( sizeof(*driver_data) );
1112     ctx->pDriverData = (void *) driver_data;
1113
1114     result = object_heap_init( &driver_data->config_heap, sizeof(struct object_config), CONFIG_ID_OFFSET );
1115     ASSERT( result == 0 );
1116
1117     result = object_heap_init( &driver_data->context_heap, sizeof(struct object_context), CONTEXT_ID_OFFSET );
1118     ASSERT( result == 0 );
1119
1120     result = object_heap_init( &driver_data->surface_heap, sizeof(struct object_surface), SURFACE_ID_OFFSET );
1121     ASSERT( result == 0 );
1122
1123     result = object_heap_init( &driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET );
1124     ASSERT( result == 0 );
1125
1126
1127     return VA_STATUS_SUCCESS;
1128 }
1129