OSDN Git Service

Explicit license text
[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_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_CreateContext(
414                 VADriverContextP ctx,
415                 VAConfigID config_id,
416                 int picture_width,
417                 int picture_height,
418                 int flag,
419                 VASurface *render_targets,
420                 int num_render_targets,
421                 VAContext *context              /* out */
422         )
423 {
424     INIT_DRIVER_DATA
425     VAStatus vaStatus = VA_STATUS_SUCCESS;
426     object_config_p obj_config;
427     int i;
428
429     obj_config = CONFIG(config_id);
430     if (NULL == obj_config)
431     {
432         vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
433         return vaStatus;
434     }
435     
436     /* Validate flag */
437     /* Validate picture dimensions */
438
439     int contextID = object_heap_allocate( &driver_data->context_heap );
440     object_context_p obj_context = CONTEXT(contextID);
441     if (NULL == obj_context)
442     {
443         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
444         return vaStatus;
445     }
446
447     obj_context->context = context;
448     obj_context->current_render_target = -1;
449     
450     obj_context->context->context_id = contextID;
451     obj_context->context->config_id = config_id;
452     obj_context->context->picture_width = picture_width;
453     obj_context->context->picture_height = picture_height;
454     obj_context->context->num_render_targets = num_render_targets;
455     obj_context->context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID));
456     for(i = 0; i < num_render_targets; i++)
457     {
458         if (NULL == SURFACE(render_targets[i].surface_id))
459         {
460             vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
461             break;
462         }
463         obj_context->context->render_targets[i] = render_targets[i].surface_id;
464     }
465     obj_context->context->flags = flag;
466     obj_context->context->privData = NULL;
467
468     /* Error recovery */
469     if (VA_STATUS_SUCCESS != vaStatus)
470     {
471         free(obj_context->context->render_targets);
472         obj_context->context->render_targets = NULL;
473         obj_context->context->context_id = -1;
474         obj_context->context->config_id = -1;
475         obj_context->context->picture_width = 0;
476         obj_context->context->picture_height = 0;
477         free(obj_context->context->render_targets);
478         obj_context->context->render_targets = NULL;
479         obj_context->context->num_render_targets = 0;
480         obj_context->context->flags = 0;
481         obj_context->context->privData = NULL;
482         object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
483     }
484
485         return vaStatus;
486 }
487
488
489 VAStatus dummy_DestroyContext(
490                 VADriverContextP ctx,
491                 VAContext *context
492         )
493 {
494     INIT_DRIVER_DATA
495     object_context_p obj_context = CONTEXT(context->context_id);
496     ASSERT(obj_context);
497     
498     obj_context->context->context_id = -1;
499     obj_context->context->config_id = -1;
500     obj_context->context->picture_width = 0;
501     obj_context->context->picture_height = 0;
502     if (obj_context->context->render_targets)
503     {
504         free(obj_context->context->render_targets);
505     }
506     obj_context->context->render_targets = NULL;
507     obj_context->context->num_render_targets = 0;
508     obj_context->context->flags = 0;
509     obj_context->context->privData = NULL;
510
511     obj_context->context = NULL;
512     obj_context->current_render_target = -1;
513
514     object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
515
516         return VA_STATUS_SUCCESS;
517 }
518
519
520 VAStatus dummy_CreateBuffer(
521                 VADriverContextP ctx,
522                 VABufferType type,  /* in */
523                 VABufferID *buf_desc    /* out */
524         )
525 {
526     INIT_DRIVER_DATA
527     VAStatus vaStatus = VA_STATUS_SUCCESS;
528     int bufferID;
529     object_buffer_p obj_buffer;
530     
531     /* Validate type */
532     switch (type)
533     {
534         case VAPictureParameterBufferType:
535         case VAIQMatrixBufferType:
536         case VASliceParameterBufferType:
537         case VASliceDataBufferType:
538         case VAMacroblockParameterBufferType:
539         case VAResidualDataBufferType:
540         case VADeblockingParameterBufferType:
541             /* Ok */
542             break;
543         default:
544             vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
545             return vaStatus;
546     }
547
548     bufferID = object_heap_allocate( &driver_data->buffer_heap );
549     obj_buffer = BUFFER(bufferID);
550     if (NULL == obj_buffer)
551     {
552         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
553         return vaStatus;
554     }
555
556     obj_buffer->buffer_data = NULL;
557     
558     *buf_desc = bufferID;
559
560         return vaStatus;
561 }
562
563 static VAStatus dummy__allocate_buffer(object_buffer_p obj_buffer, int size)
564 {
565     VAStatus vaStatus = VA_STATUS_SUCCESS;
566
567     obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size);
568     if (NULL == obj_buffer->buffer_data)
569     {
570         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
571     }
572     return vaStatus;
573 }
574
575 VAStatus dummy_BufferData(
576                 VADriverContextP ctx,
577                 VABufferID buf_id,      /* in */
578         unsigned int size,      /* in */
579         unsigned int num_elements,      /* in */
580         void *data              /* in */
581         )
582 {
583     INIT_DRIVER_DATA
584     VAStatus vaStatus = VA_STATUS_SUCCESS;
585     object_buffer_p obj_buffer = BUFFER(buf_id);
586     ASSERT(obj_buffer);
587     
588     vaStatus = dummy__allocate_buffer(obj_buffer, size * num_elements);
589     if (VA_STATUS_SUCCESS == vaStatus)
590     {
591         obj_buffer->max_num_elements = num_elements;
592         obj_buffer->num_elements = num_elements;
593         if (data)
594         {
595             memcpy(obj_buffer->buffer_data, data, size * num_elements);
596         }
597     }
598
599         return vaStatus;
600 }
601
602 VAStatus dummy_BufferSetNumElements(
603                 VADriverContextP ctx,
604                 VABufferID buf_id,      /* in */
605         unsigned int num_elements       /* in */
606         )
607 {
608     INIT_DRIVER_DATA
609     VAStatus vaStatus = VA_STATUS_SUCCESS;
610     object_buffer_p obj_buffer = BUFFER(buf_id);
611     ASSERT(obj_buffer);
612     
613     if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements))
614     {
615         vaStatus = VA_STATUS_ERROR_UNKNOWN;
616     }
617     if (VA_STATUS_SUCCESS == vaStatus)
618     {
619         obj_buffer->num_elements = num_elements;
620     }
621
622         return vaStatus;
623 }
624
625 VAStatus dummy_MapBuffer(
626                 VADriverContextP ctx,
627                 VABufferID buf_id,      /* in */
628                 void **pbuf         /* out */
629         )
630 {
631     INIT_DRIVER_DATA
632     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
633     object_buffer_p obj_buffer = BUFFER(buf_id);
634     ASSERT(obj_buffer);
635     if (NULL == obj_buffer)
636     {
637         vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
638         return vaStatus;
639     }
640     
641     if (NULL != obj_buffer->buffer_data)
642     {
643         *pbuf = obj_buffer->buffer_data;
644         vaStatus = VA_STATUS_SUCCESS;
645     }
646         return vaStatus;
647 }
648
649 VAStatus dummy_UnmapBuffer(
650                 VADriverContextP ctx,
651                 VABufferID buf_id       /* in */
652         )
653 {
654     /* Do nothing */
655         return VA_STATUS_SUCCESS;
656 }
657
658 static void dummy__destroy_buffer(struct dummy_driver_data *driver_data, object_buffer_p obj_buffer)
659 {
660     if (NULL != obj_buffer->buffer_data)
661     {
662         free(obj_buffer->buffer_data);
663         obj_buffer->buffer_data = NULL;
664     }
665     
666     object_heap_free( &driver_data->buffer_heap, (object_base_p) obj_buffer);
667 }
668
669 VAStatus dummy_DestroyBuffer(
670                 VADriverContextP ctx,
671                 VABufferID buffer_id
672         )
673 {
674     INIT_DRIVER_DATA
675     object_buffer_p obj_buffer = BUFFER(buffer_id);
676     ASSERT(obj_buffer);
677
678     dummy__destroy_buffer(driver_data, obj_buffer);
679         return VA_STATUS_SUCCESS;
680 }
681
682 VAStatus dummy_BeginPicture(
683                 VADriverContextP ctx,
684                 VAContext *context,
685                 VASurface *render_target
686         )
687 {
688     INIT_DRIVER_DATA
689     VAStatus vaStatus = VA_STATUS_SUCCESS;
690     object_context_p obj_context;
691     object_surface_p obj_surface;
692     
693     obj_context = CONTEXT(context->context_id);
694     ASSERT(obj_context);
695
696     obj_surface = SURFACE(render_target->surface_id);
697     ASSERT(obj_surface);
698
699     obj_context->current_render_target = obj_surface->base.id;
700     
701         return vaStatus;
702 }
703
704 VAStatus dummy_RenderPicture(
705                 VADriverContextP ctx,
706                 VAContext *context,
707                 VABufferID *buffers,
708                 int num_buffers
709         )
710 {
711     INIT_DRIVER_DATA
712     VAStatus vaStatus = VA_STATUS_SUCCESS;
713     object_context_p obj_context;
714     object_surface_p obj_surface;
715     int i;
716     
717     obj_context = CONTEXT(context->context_id);
718     ASSERT(obj_context);
719
720     obj_surface = SURFACE(obj_context->current_render_target);
721     ASSERT(obj_surface);
722     
723     /* verify that we got valid buffer references */
724     for(i = 0; i < num_buffers; i++)
725     {
726         object_buffer_p obj_buffer = BUFFER(buffers[i]);
727         ASSERT(obj_buffer);
728         if (NULL == obj_buffer)
729         {
730             vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
731             break;
732         }
733     }
734
735         return vaStatus;
736 }
737
738 VAStatus dummy_EndPicture(
739                 VADriverContextP ctx,
740                 VAContext *context
741         )
742 {
743     INIT_DRIVER_DATA
744     VAStatus vaStatus = VA_STATUS_SUCCESS;
745     object_context_p obj_context;
746     object_surface_p obj_surface;
747     
748     obj_context = CONTEXT(context->context_id);
749     ASSERT(obj_context);
750
751     obj_surface = SURFACE(obj_context->current_render_target);
752     ASSERT(obj_surface);
753     
754     // For now, assume that we are done with rendering right away
755     obj_context->current_render_target = -1;
756
757         return vaStatus;
758 }
759
760
761 VAStatus dummy_SyncSurface(
762                 VADriverContextP ctx,
763                 VAContext *context,
764                 VASurface *render_target
765         )
766 {
767     INIT_DRIVER_DATA
768     VAStatus vaStatus = VA_STATUS_SUCCESS;
769     object_context_p obj_context;
770     object_surface_p obj_surface;
771     
772     obj_context = CONTEXT(context->context_id);
773     ASSERT(obj_context);
774
775     obj_surface = SURFACE(render_target->surface_id);
776     ASSERT(obj_surface);
777
778     /* Assume that this shouldn't be called before vaEndPicture() */
779     ASSERT( obj_context->current_render_target != obj_surface->base.id );
780     
781         return vaStatus;
782 }
783
784 VAStatus dummy_QuerySurfaceStatus(
785                 VADriverContextP ctx,
786                 VAContext *context,
787                 VASurface *render_target,
788                 VASurfaceStatus *status /* out */
789         )
790 {
791     INIT_DRIVER_DATA
792     VAStatus vaStatus = VA_STATUS_SUCCESS;
793     object_context_p obj_context;
794     object_surface_p obj_surface;
795     
796     obj_context = CONTEXT(context->context_id);
797     ASSERT(obj_context);
798
799     obj_surface = SURFACE(render_target->surface_id);
800     ASSERT(obj_surface);
801
802     /* Assume that we are busy until vaEndPicture() is called */
803     if ( obj_context->current_render_target == obj_surface->base.id )
804     {
805         *status = VASurfaceRendering;
806     }
807     else
808     {
809         *status = VASurfaceReady;
810     }
811     
812         return vaStatus;
813 }
814
815 VAStatus dummy_PutSurface(
816                 VADriverContextP ctx,
817                 VASurface *surface,
818                 Drawable draw, /* X Drawable */
819                 short srcx,
820                 short srcy,
821                 unsigned short srcw,
822                 unsigned short srch,
823                 short destx,
824                 short desty,
825                 unsigned short destw,
826                 unsigned short desth,
827                 int flags /* de-interlacing flags */
828         )
829 {
830     /* TODO */
831         return VA_STATUS_ERROR_UNKNOWN;
832 }
833
834 VAStatus dummy_DbgCopySurfaceToBuffer(
835                 VADriverContextP ctx,
836                 VASurface *surface,
837                 void **buffer, /* out */
838                 unsigned int *stride /* out */
839         )
840 {
841     /* TODO */
842         return VA_STATUS_ERROR_UNKNOWN;
843 }
844
845 VAStatus dummy_Terminate( VADriverContextP ctx )
846 {
847     INIT_DRIVER_DATA
848     object_buffer_p obj_buffer;
849     object_surface_p obj_surface;
850     object_context_p obj_context;
851     object_config_p obj_config;
852     object_heap_iterator iter;
853
854     /* Clean up left over buffers */
855     obj_buffer = (object_buffer_p) object_heap_first( &driver_data->buffer_heap, &iter);
856     while (obj_buffer)
857     {
858         dummy__information_message("vaTerminate: bufferID %08x still allocated, destroying\n", obj_buffer->base.id);
859         dummy__destroy_buffer(driver_data, obj_buffer);
860         obj_buffer = (object_buffer_p) object_heap_next( &driver_data->buffer_heap, &iter);
861     }
862     object_heap_destroy( &driver_data->buffer_heap );
863
864     /* TODO cleanup */
865     object_heap_destroy( &driver_data->surface_heap );
866     
867     /* TODO cleanup */
868     object_heap_destroy( &driver_data->context_heap );
869
870     /* Clean up configIDs */
871     obj_config = (object_config_p) object_heap_first( &driver_data->config_heap, &iter);
872     while (obj_config)
873     {
874         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
875         obj_config = (object_config_p) object_heap_next( &driver_data->config_heap, &iter);
876     }
877     object_heap_destroy( &driver_data->config_heap );
878
879     free(ctx->pDriverData);
880     ctx->pDriverData = NULL;
881
882         return VA_STATUS_SUCCESS;
883 }
884
885 VAStatus __vaDriverInit_0_20(  VADriverContextP ctx )
886 {
887     object_base_p obj;
888     int result;
889     struct dummy_driver_data *driver_data;
890     int i;
891     
892     ctx->version_major = 0;
893     ctx->version_minor = 20;
894     ctx->max_profiles = DUMMY_MAX_PROFILES;
895     ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
896     ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
897
898         ctx->vtable.vaTerminate = dummy_Terminate;
899         ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
900         ctx->vtable.vaTerminate = dummy_Terminate;
901         ctx->vtable.vaQueryConfigProfiles = dummy_QueryConfigProfiles;
902         ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
903         ctx->vtable.vaQueryConfigAttributes = dummy_QueryConfigAttributes;
904         ctx->vtable.vaCreateConfig = dummy_CreateConfig;
905         ctx->vtable.vaGetConfigAttributes = dummy_GetConfigAttributes;
906         ctx->vtable.vaCreateSurfaces = dummy_CreateSurfaces;
907         ctx->vtable.vaDestroySurface = dummy_DestroySurface;
908         ctx->vtable.vaCreateContext = dummy_CreateContext;
909         ctx->vtable.vaDestroyContext = dummy_DestroyContext;
910         ctx->vtable.vaCreateBuffer = dummy_CreateBuffer;
911         ctx->vtable.vaBufferData = dummy_BufferData;
912         ctx->vtable.vaBufferSetNumElements = dummy_BufferSetNumElements;
913         ctx->vtable.vaMapBuffer = dummy_MapBuffer;
914         ctx->vtable.vaUnmapBuffer = dummy_UnmapBuffer;
915         ctx->vtable.vaDestroyBuffer = dummy_DestroyBuffer;
916         ctx->vtable.vaBeginPicture = dummy_BeginPicture;
917         ctx->vtable.vaRenderPicture = dummy_RenderPicture;
918         ctx->vtable.vaEndPicture = dummy_EndPicture;
919         ctx->vtable.vaSyncSurface = dummy_SyncSurface;
920         ctx->vtable.vaQuerySurfaceStatus = dummy_QuerySurfaceStatus;
921         ctx->vtable.vaPutSurface = dummy_PutSurface;
922         ctx->vtable.vaDbgCopySurfaceToBuffer = dummy_DbgCopySurfaceToBuffer;
923
924         driver_data = (struct dummy_driver_data *) malloc( sizeof(*driver_data) );
925     ctx->pDriverData = (void *) driver_data;
926     
927     result = object_heap_init( &driver_data->config_heap, sizeof(struct object_config), CONFIG_ID_OFFSET );
928     ASSERT( result == 0 );
929
930     result = object_heap_init( &driver_data->context_heap, sizeof(struct object_context), CONTEXT_ID_OFFSET );
931     ASSERT( result == 0 );
932
933     result = object_heap_init( &driver_data->surface_heap, sizeof(struct object_surface), SURFACE_ID_OFFSET );
934     ASSERT( result == 0 );
935
936     result = object_heap_init( &driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET );
937     ASSERT( result == 0 );
938
939
940     return VA_STATUS_SUCCESS;
941 }
942