Fix compile
[profile/ivi/libva.git] / dummy_drv_video / dummy_drv_video.c
1 /*
2  * @COPYRIGHT@ Intel Confidential - Unreleased Software
3  */
4
5 #include "va_backend.h"
6
7 #include "dummy_drv_video.h"
8
9 #include "assert.h"
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdarg.h>
13
14 #define ASSERT  assert
15
16 #define INIT_DRIVER_DATA        struct dummy_driver_data *driver_data = (struct dummy_driver_data *) ctx->pDriverData;
17
18 #define CONFIG(id)  ((object_config_p) object_heap_lookup( &driver_data->config_heap, id ))
19 #define CONTEXT(id) ((object_context_p) object_heap_lookup( &driver_data->context_heap, id ))
20 #define SURFACE(id)     ((object_surface_p) object_heap_lookup( &driver_data->surface_heap, id ))
21 #define BUFFER(id)  ((object_buffer_p) object_heap_lookup( &driver_data->buffer_heap, id ))
22
23 #define CONFIG_ID_OFFSET                0x01000000
24 #define CONTEXT_ID_OFFSET               0x02000000
25 #define SURFACE_ID_OFFSET               0x04000000
26 #define BUFFER_ID_OFFSET                0x08000000
27
28 static void dummy__error_message(const char *msg, ...)
29 {
30     va_list args;
31
32     fprintf(stderr, "dummy_drv_video error: ");
33     va_start(args, msg);
34     vfprintf(stderr, msg, args);
35     va_end(args);
36 }
37
38 static void dummy__information_message(const char *msg, ...)
39 {
40     va_list args;
41
42     fprintf(stderr, "dummy_drv_video: ");
43     va_start(args, msg);
44     vfprintf(stderr, msg, args);
45     va_end(args);
46 }
47
48 VAStatus dummy_QueryConfigProfiles(
49                 VADriverContextP ctx,
50                 VAProfile *profile_list,        /* out */
51                 int *num_profiles                       /* out */
52         )
53 {
54     INIT_DRIVER_DATA
55     int i = 0;
56     
57     profile_list[i++] = VAProfileMPEG2Simple;
58     profile_list[i++] = VAProfileMPEG2Main;
59     profile_list[i++] = VAProfileMPEG4Simple;
60     profile_list[i++] = VAProfileMPEG4AdvancedSimple;
61     profile_list[i++] = VAProfileMPEG4Main;
62     profile_list[i++] = VAProfileH264Baseline;
63     profile_list[i++] = VAProfileH264Main;
64     profile_list[i++] = VAProfileH264High;
65     profile_list[i++] = VAProfileVC1Simple;
66     profile_list[i++] = VAProfileVC1Main;
67     profile_list[i++] = VAProfileVC1Advanced;
68
69     /* If the assert fails then DUMMY_MAX_PROFILES needs to be bigger */
70     ASSERT(i <= DUMMY_MAX_PROFILES);
71     *num_profiles = i;
72
73         return VA_STATUS_SUCCESS;
74 }
75
76 VAStatus dummy_QueryConfigEntrypoints(
77                 VADriverContextP ctx,
78                 VAProfile profile,
79                 VAEntrypoint  *entrypoint_list, /* out */
80                 int *num_entrypoints            /* out */
81         )
82 {
83     INIT_DRIVER_DATA
84     
85     switch (profile) {
86         case VAProfileMPEG2Simple:
87         case VAProfileMPEG2Main:
88                 *num_entrypoints = 2;
89                 entrypoint_list[0] = VAEntrypointVLD;
90                 entrypoint_list[1] = VAEntrypointMoComp;
91                 break;
92
93         case VAProfileMPEG4Simple:
94         case VAProfileMPEG4AdvancedSimple:
95         case VAProfileMPEG4Main:
96                 *num_entrypoints = 1;
97                 entrypoint_list[0] = VAEntrypointVLD;
98                 break;
99
100         case VAProfileH264Baseline:
101         case VAProfileH264Main:
102         case VAProfileH264High:
103                 *num_entrypoints = 1;
104                 entrypoint_list[0] = VAEntrypointVLD;
105                 break;
106
107         case VAProfileVC1Simple:
108         case VAProfileVC1Main:
109         case VAProfileVC1Advanced:
110                 *num_entrypoints = 1;
111                 entrypoint_list[0] = VAEntrypointVLD;
112                 break;
113
114         default:
115                 *num_entrypoints = 0;
116                 break;
117     }
118
119     /* If the assert fails then DUMMY_MAX_ENTRYPOINTS needs to be bigger */
120     ASSERT(*num_entrypoints <= DUMMY_MAX_ENTRYPOINTS);
121         return VA_STATUS_SUCCESS;
122 }
123
124 VAStatus dummy_QueryConfigAttributes(
125                 VADriverContextP ctx,
126                 VAProfile profile,
127                 VAEntrypoint entrypoint,
128                 VAConfigAttrib *attrib_list,    /* in/out */
129                 int num_attribs
130         )
131 {
132     INIT_DRIVER_DATA
133
134     int i;
135
136     /* Other attributes don't seem to be defined */
137     /* What to do if we don't know the attribute? */
138     for (i = 0; i < num_attribs; i++)
139     {
140         switch (attrib_list[i].type)
141         {
142           case VAConfigAttribRTFormat:
143               attrib_list[i].value = VA_RT_FORMAT_YUV420;
144               break;
145               
146           default:
147               /* Do nothing */
148               attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
149               break;
150         }
151     }
152
153         return VA_STATUS_SUCCESS;
154 }
155
156 static VAStatus dummy__update_attribute(object_config_p obj_config, VAConfigAttrib *attrib)
157 {
158     int i;
159     /* Check existing attrbiutes */
160     for(i = 0; obj_config->attrib_count < i; i++)
161     {
162         if (obj_config->attrib_list[i].type == attrib->type)
163         {
164             /* Update existing attribute */
165             obj_config->attrib_list[i].value = attrib->value;
166             return VA_STATUS_SUCCESS;
167         }
168     }
169     if (obj_config->attrib_count < DUMMY_MAX_CONFIG_ATTRIBUTES)
170     {
171         i = obj_config->attrib_count;
172         obj_config->attrib_list[i].type = attrib->type;
173         obj_config->attrib_list[i].value = attrib->value;
174         obj_config->attrib_count++;
175         return VA_STATUS_SUCCESS;
176     }
177     return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
178 }
179
180 VAStatus dummy_CreateConfig(
181                 VADriverContextP ctx,
182                 VAProfile profile, 
183                 VAEntrypoint entrypoint, 
184                 VAConfigAttrib *attrib_list,
185                 int num_attribs,
186                 VAConfigID *config_id           /* out */
187         )
188 {
189     INIT_DRIVER_DATA
190     VAStatus vaStatus;
191     int configID;
192     object_config_p obj_config;
193     int i;
194     
195     /* Validate profile & entrypoint */
196     switch (profile) {
197         case VAProfileMPEG2Simple:
198         case VAProfileMPEG2Main:
199                 if ((VAEntrypointVLD == entrypoint) ||
200                     (VAEntrypointMoComp == entrypoint))
201                 {
202                     vaStatus = VA_STATUS_SUCCESS;
203                 }
204                 else
205                 {
206                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
207                 }
208                 break;
209
210         case VAProfileMPEG4Simple:
211         case VAProfileMPEG4AdvancedSimple:
212         case VAProfileMPEG4Main:
213                 if (VAEntrypointVLD == entrypoint)
214                 {
215                     vaStatus = VA_STATUS_SUCCESS;
216                 }
217                 else
218                 {
219                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
220                 }
221                 break;
222
223         case VAProfileH264Baseline:
224         case VAProfileH264Main:
225         case VAProfileH264High:
226                 if (VAEntrypointVLD == entrypoint)
227                 {
228                     vaStatus = VA_STATUS_SUCCESS;
229                 }
230                 else
231                 {
232                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
233                 }
234                 break;
235
236         case VAProfileVC1Simple:
237         case VAProfileVC1Main:
238         case VAProfileVC1Advanced:
239                 if (VAEntrypointVLD == entrypoint)
240                 {
241                     vaStatus = VA_STATUS_SUCCESS;
242                 }
243                 else
244                 {
245                     vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
246                 }
247                 break;
248
249         default:
250                 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
251                 break;
252     }
253
254     if (VA_STATUS_SUCCESS != vaStatus)
255     {
256         return vaStatus;
257     }
258
259     configID = object_heap_allocate( &driver_data->config_heap );
260     obj_config = CONFIG(configID);
261     if (NULL == obj_config)
262     {
263         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
264         return vaStatus;
265     }
266
267     obj_config->profile = profile;
268     obj_config->entrypoint = entrypoint;
269     obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
270     obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
271     obj_config->attrib_count = 1;
272
273     for(i = 0; i < num_attribs; i++)
274     {
275         vaStatus = dummy__update_attribute(obj_config, &(attrib_list[i]));
276         if (VA_STATUS_SUCCESS != vaStatus)
277         {
278             break;
279         }
280     }
281     
282     /* Error recovery */
283     if (VA_STATUS_SUCCESS != vaStatus)
284     {
285         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
286     }
287     else
288     {
289         *config_id = configID;
290     }
291
292         return vaStatus;
293 }
294         
295 VAStatus dummy_GetConfigAttributes(
296                 VADriverContextP ctx,
297                 VAConfigID config_id, 
298                 VAProfile *profile,             /* out */
299                 VAEntrypoint *entrypoint,       /* out */
300                 VAConfigAttrib *attrib_list,    /* out */
301                 int *num_attribs                /* out */
302         )
303 {
304     INIT_DRIVER_DATA
305     VAStatus vaStatus = VA_STATUS_SUCCESS;
306     object_config_p obj_config;
307     int i;
308
309     obj_config = CONFIG(config_id);
310     ASSERT(obj_config);
311     
312     *profile = obj_config->profile;
313     *entrypoint = obj_config->entrypoint;
314     *num_attribs =  obj_config->attrib_count;
315     for(i = 0; i < obj_config->attrib_count; i++)
316     {
317         attrib_list[i] = obj_config->attrib_list[i];
318     }
319     
320         return vaStatus;
321 }
322
323 VAStatus dummy_CreateSurfaces(
324                 VADriverContextP ctx,
325                 int width,
326                 int height,
327                 int format,
328                 int num_surfaces,
329                 VASurface *surfaces             /* out */
330         )
331 {
332     INIT_DRIVER_DATA
333     VAStatus vaStatus = VA_STATUS_SUCCESS;
334     int i;
335     
336     /* We only support one format */
337     if (VA_RT_FORMAT_YUV420 != format)
338     {
339         return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
340     }
341     
342     for (i = 0; i < num_surfaces; i++)
343     {
344         int surfaceID = object_heap_allocate( &driver_data->surface_heap );
345         object_surface_p obj_surface = SURFACE(surfaceID);
346         if (NULL == obj_surface)
347         {
348             vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
349             break;
350         }
351         obj_surface->surface = &(surfaces[i]);
352         obj_surface->surface->surface_id = surfaceID;
353         obj_surface->surface->context_id = -1;
354         obj_surface->surface->width = width;
355         obj_surface->surface->height = height;
356         obj_surface->surface->format = format;
357         obj_surface->surface->privData = NULL;
358     }
359
360     /* Error recovery */
361     if (VA_STATUS_SUCCESS != vaStatus)
362     {
363         /* surfaces[i-1] was the last successful allocation */
364         for(; i--; )
365         {
366             object_surface_p obj_surface = SURFACE(surfaces[i].surface_id);
367             surfaces[i].surface_id = -1;
368             ASSERT(obj_surface);
369             object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
370         }
371     }
372
373         return vaStatus;
374 }
375         
376 VAStatus dummy_DestroySurface(
377                 VADriverContextP ctx,
378                 VASurface *surface_list,
379                 int num_surfaces
380         )
381 {
382     INIT_DRIVER_DATA
383     int i;
384     for(i = num_surfaces; i--; )
385     {
386         object_surface_p obj_surface = SURFACE(surface_list[i].surface_id);
387         ASSERT(obj_surface);
388         object_heap_free( &driver_data->surface_heap, (object_base_p) obj_surface);
389     }
390         return VA_STATUS_SUCCESS;
391 }
392
393 VAStatus dummy_CreateContext(
394                 VADriverContextP ctx,
395                 VAConfigID config_id,
396                 int picture_width,
397                 int picture_height,
398                 int flag,
399                 VASurface *render_targets,
400                 int num_render_targets,
401                 VAContext *context              /* out */
402         )
403 {
404     INIT_DRIVER_DATA
405     VAStatus vaStatus = VA_STATUS_SUCCESS;
406     object_config_p obj_config;
407     int i;
408
409     obj_config = CONFIG(config_id);
410     if (NULL == obj_config)
411     {
412         vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
413         return vaStatus;
414     }
415     
416     /* Validate flag */
417     /* Validate picture dimensions */
418
419     int contextID = object_heap_allocate( &driver_data->context_heap );
420     object_context_p obj_context = CONTEXT(contextID);
421     if (NULL == obj_context)
422     {
423         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
424         return vaStatus;
425     }
426
427     obj_context->context = context;
428     obj_context->current_render_target = -1;
429     
430     obj_context->context->context_id = contextID;
431     obj_context->context->config_id = config_id;
432     obj_context->context->picture_width = picture_width;
433     obj_context->context->picture_height = picture_height;
434     obj_context->context->num_render_targets = num_render_targets;
435     obj_context->context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID));
436     for(i = 0; i < num_render_targets; i++)
437     {
438         if (NULL == SURFACE(render_targets[i].surface_id))
439         {
440             vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
441             break;
442         }
443         obj_context->context->render_targets[i] = render_targets[i].surface_id;
444     }
445     obj_context->context->flags = flag;
446     obj_context->context->privData = NULL;
447
448     /* Error recovery */
449     if (VA_STATUS_SUCCESS != vaStatus)
450     {
451         free(obj_context->context->render_targets);
452         obj_context->context->render_targets = NULL;
453         obj_context->context->context_id = -1;
454         obj_context->context->config_id = -1;
455         obj_context->context->picture_width = 0;
456         obj_context->context->picture_height = 0;
457         free(obj_context->context->render_targets);
458         obj_context->context->render_targets = NULL;
459         obj_context->context->num_render_targets = 0;
460         obj_context->context->flags = 0;
461         obj_context->context->privData = NULL;
462         object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
463     }
464
465         return vaStatus;
466 }
467
468
469 VAStatus dummy_DestroyContext(
470                 VADriverContextP ctx,
471                 VAContext *context
472         )
473 {
474     INIT_DRIVER_DATA
475     object_context_p obj_context = CONTEXT(context->context_id);
476     ASSERT(obj_context);
477     
478     obj_context->context->context_id = -1;
479     obj_context->context->config_id = -1;
480     obj_context->context->picture_width = 0;
481     obj_context->context->picture_height = 0;
482     if (obj_context->context->render_targets)
483     {
484         free(obj_context->context->render_targets);
485     }
486     obj_context->context->render_targets = NULL;
487     obj_context->context->num_render_targets = 0;
488     obj_context->context->flags = 0;
489     obj_context->context->privData = NULL;
490
491     obj_context->context = NULL;
492     obj_context->current_render_target = -1;
493
494     object_heap_free( &driver_data->context_heap, (object_base_p) obj_context);
495
496         return VA_STATUS_SUCCESS;
497 }
498
499
500 VAStatus dummy_CreateBuffer(
501                 VADriverContextP ctx,
502                 VABufferType type,  /* in */
503                 VABufferID *buf_desc    /* out */
504         )
505 {
506     INIT_DRIVER_DATA
507     VAStatus vaStatus = VA_STATUS_SUCCESS;
508     int bufferID;
509     object_buffer_p obj_buffer;
510     
511     /* Validate type */
512     switch (type)
513     {
514         case VAPictureParameterBufferType:
515         case VAIQMatrixBufferType:
516         case VASliceParameterBufferType:
517         case VASliceDataBufferType:
518         case VAMacroblockParameterBufferType:
519         case VAResidualDataBufferType:
520         case VADeblockingParameterBufferType:
521             /* Ok */
522             break;
523         default:
524             vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
525             return vaStatus;
526     }
527
528     bufferID = object_heap_allocate( &driver_data->buffer_heap );
529     obj_buffer = BUFFER(bufferID);
530     if (NULL == obj_buffer)
531     {
532         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
533         return vaStatus;
534     }
535
536     obj_buffer->buffer_data = NULL;
537     
538     *buf_desc = bufferID;
539
540         return vaStatus;
541 }
542
543 static VAStatus dummy__allocate_buffer(object_buffer_p obj_buffer, int size)
544 {
545     VAStatus vaStatus = VA_STATUS_SUCCESS;
546
547     obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size);
548     if (NULL == obj_buffer->buffer_data)
549     {
550         vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
551     }
552     return vaStatus;
553 }
554
555 VAStatus dummy_BufferData(
556                 VADriverContextP ctx,
557                 VABufferID buf_id,      /* in */
558         unsigned int size,      /* in */
559         unsigned int num_elements,      /* in */
560         void *data              /* in */
561         )
562 {
563     INIT_DRIVER_DATA
564     VAStatus vaStatus = VA_STATUS_SUCCESS;
565     object_buffer_p obj_buffer = BUFFER(buf_id);
566     ASSERT(obj_buffer);
567     
568     vaStatus = dummy__allocate_buffer(obj_buffer, size * num_elements);
569     if (VA_STATUS_SUCCESS == vaStatus)
570     {
571         obj_buffer->max_num_elements = num_elements;
572         obj_buffer->num_elements = num_elements;
573         if (data)
574         {
575             memcpy(obj_buffer->buffer_data, data, size * num_elements);
576         }
577     }
578
579         return vaStatus;
580 }
581
582 VAStatus dummy_BufferSetNumElements(
583                 VADriverContextP ctx,
584                 VABufferID buf_id,      /* in */
585         unsigned int num_elements       /* in */
586         )
587 {
588     INIT_DRIVER_DATA
589     VAStatus vaStatus = VA_STATUS_SUCCESS;
590     object_buffer_p obj_buffer = BUFFER(buf_id);
591     ASSERT(obj_buffer);
592     
593     if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements))
594     {
595         vaStatus = VA_STATUS_ERROR_UNKNOWN;
596     }
597     if (VA_STATUS_SUCCESS == vaStatus)
598     {
599         obj_buffer->num_elements = num_elements;
600     }
601
602         return vaStatus;
603 }
604
605 VAStatus dummy_MapBuffer(
606                 VADriverContextP ctx,
607                 VABufferID buf_id,      /* in */
608                 void **pbuf         /* out */
609         )
610 {
611     INIT_DRIVER_DATA
612     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
613     object_buffer_p obj_buffer = BUFFER(buf_id);
614     ASSERT(obj_buffer);
615     if (NULL == obj_buffer)
616     {
617         vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
618         return vaStatus;
619     }
620     
621     if (NULL != obj_buffer->buffer_data)
622     {
623         *pbuf = obj_buffer->buffer_data;
624         vaStatus = VA_STATUS_SUCCESS;
625     }
626         return vaStatus;
627 }
628
629 VAStatus dummy_UnmapBuffer(
630                 VADriverContextP ctx,
631                 VABufferID buf_id       /* in */
632         )
633 {
634     /* Do nothing */
635         return VA_STATUS_SUCCESS;
636 }
637
638 static void dummy__destroy_buffer(struct dummy_driver_data *driver_data, object_buffer_p obj_buffer)
639 {
640     if (NULL != obj_buffer->buffer_data)
641     {
642         free(obj_buffer->buffer_data);
643         obj_buffer->buffer_data = NULL;
644     }
645     
646     object_heap_free( &driver_data->buffer_heap, (object_base_p) obj_buffer);
647 }
648
649 VAStatus dummy_DestroyBuffer(
650                 VADriverContextP ctx,
651                 VABufferID buffer_id
652         )
653 {
654     INIT_DRIVER_DATA
655     object_buffer_p obj_buffer = BUFFER(buffer_id);
656     ASSERT(obj_buffer);
657
658     dummy__destroy_buffer(driver_data, obj_buffer);
659         return VA_STATUS_SUCCESS;
660 }
661
662 VAStatus dummy_BeginPicture(
663                 VADriverContextP ctx,
664                 VAContext *context,
665                 VASurface *render_target
666         )
667 {
668     INIT_DRIVER_DATA
669     VAStatus vaStatus = VA_STATUS_SUCCESS;
670     object_context_p obj_context;
671     object_surface_p obj_surface;
672     
673     obj_context = CONTEXT(context->context_id);
674     ASSERT(obj_context);
675
676     obj_surface = SURFACE(render_target->surface_id);
677     ASSERT(obj_surface);
678
679     obj_context->current_render_target = obj_surface->base.id;
680     
681         return vaStatus;
682 }
683
684 VAStatus dummy_RenderPicture(
685                 VADriverContextP ctx,
686                 VAContext *context,
687                 VABufferID *buffers,
688                 int num_buffers
689         )
690 {
691     INIT_DRIVER_DATA
692     VAStatus vaStatus = VA_STATUS_SUCCESS;
693     object_context_p obj_context;
694     object_surface_p obj_surface;
695     int i;
696     
697     obj_context = CONTEXT(context->context_id);
698     ASSERT(obj_context);
699
700     obj_surface = SURFACE(obj_context->current_render_target);
701     ASSERT(obj_surface);
702     
703     /* verify that we got valid buffer references */
704     for(i = 0; i < num_buffers; i++)
705     {
706         object_buffer_p obj_buffer = BUFFER(buffers[i]);
707         ASSERT(obj_buffer);
708         if (NULL == obj_buffer)
709         {
710             vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
711             break;
712         }
713     }
714
715         return vaStatus;
716 }
717
718 VAStatus dummy_EndPicture(
719                 VADriverContextP ctx,
720                 VAContext *context
721         )
722 {
723     INIT_DRIVER_DATA
724     VAStatus vaStatus = VA_STATUS_SUCCESS;
725     object_context_p obj_context;
726     object_surface_p obj_surface;
727     
728     obj_context = CONTEXT(context->context_id);
729     ASSERT(obj_context);
730
731     obj_surface = SURFACE(obj_context->current_render_target);
732     ASSERT(obj_surface);
733     
734     // For now, assume that we are done with rendering right away
735     obj_context->current_render_target = -1;
736
737         return vaStatus;
738 }
739
740
741 VAStatus dummy_SyncSurface(
742                 VADriverContextP ctx,
743                 VAContext *context,
744                 VASurface *render_target
745         )
746 {
747     INIT_DRIVER_DATA
748     VAStatus vaStatus = VA_STATUS_SUCCESS;
749     object_context_p obj_context;
750     object_surface_p obj_surface;
751     
752     obj_context = CONTEXT(context->context_id);
753     ASSERT(obj_context);
754
755     obj_surface = SURFACE(render_target->surface_id);
756     ASSERT(obj_surface);
757
758     /* Assume that this shouldn't be called before vaEndPicture() */
759     ASSERT( obj_context->current_render_target != obj_surface->base.id );
760     
761         return vaStatus;
762 }
763
764 VAStatus dummy_QuerySurfaceStatus(
765                 VADriverContextP ctx,
766                 VAContext *context,
767                 VASurface *render_target,
768                 VASurfaceStatus *status /* out */
769         )
770 {
771     INIT_DRIVER_DATA
772     VAStatus vaStatus = VA_STATUS_SUCCESS;
773     object_context_p obj_context;
774     object_surface_p obj_surface;
775     
776     obj_context = CONTEXT(context->context_id);
777     ASSERT(obj_context);
778
779     obj_surface = SURFACE(render_target->surface_id);
780     ASSERT(obj_surface);
781
782     /* Assume that we are busy until vaEndPicture() is called */
783     if ( obj_context->current_render_target == obj_surface->base.id )
784     {
785         *status = VASurfaceRendering;
786     }
787     else
788     {
789         *status = VASurfaceReady;
790     }
791     
792         return vaStatus;
793 }
794
795 VAStatus dummy_PutSurface(
796                 VADriverContextP ctx,
797                 VASurface *surface,
798                 Drawable draw, /* X Drawable */
799                 short srcx,
800                 short srcy,
801                 unsigned short srcw,
802                 unsigned short srch,
803                 short destx,
804                 short desty,
805                 unsigned short destw,
806                 unsigned short desth,
807                 int flags /* de-interlacing flags */
808         )
809 {
810     /* TODO */
811         return VA_STATUS_ERROR_UNKNOWN;
812 }
813
814 VAStatus dummy_DbgCopySurfaceToBuffer(
815                 VADriverContextP ctx,
816                 VASurface *surface,
817                 void **buffer, /* out */
818                 unsigned int *stride /* out */
819         )
820 {
821     /* TODO */
822         return VA_STATUS_ERROR_UNKNOWN;
823 }
824
825 VAStatus dummy_Terminate( VADriverContextP ctx )
826 {
827     INIT_DRIVER_DATA
828     object_buffer_p obj_buffer;
829     object_surface_p obj_surface;
830     object_context_p obj_context;
831     object_config_p obj_config;
832     object_heap_iterator iter;
833
834     /* Clean up left over buffers */
835     obj_buffer = (object_buffer_p) object_heap_first( &driver_data->buffer_heap, &iter);
836     while (obj_buffer)
837     {
838         dummy__information_message("vaTerminate: bufferID %08x still allocated, destroying\n", obj_buffer->base.id);
839         dummy__destroy_buffer(driver_data, obj_buffer);
840         obj_buffer = (object_buffer_p) object_heap_next( &driver_data->buffer_heap, &iter);
841     }
842     object_heap_destroy( &driver_data->buffer_heap );
843
844     /* TODO cleanup */
845     object_heap_destroy( &driver_data->surface_heap );
846     
847     /* TODO cleanup */
848     object_heap_destroy( &driver_data->context_heap );
849
850     /* Clean up configIDs */
851     obj_config = (object_config_p) object_heap_first( &driver_data->config_heap, &iter);
852     while (obj_config)
853     {
854         object_heap_free( &driver_data->config_heap, (object_base_p) obj_config);
855         obj_config = (object_config_p) object_heap_next( &driver_data->config_heap, &iter);
856     }
857     object_heap_destroy( &driver_data->config_heap );
858
859     free(ctx->pDriverData);
860     ctx->pDriverData = NULL;
861
862         return VA_STATUS_SUCCESS;
863 }
864
865 VAStatus __vaDriverInit_0_18(  VADriverContextP ctx )
866 {
867     object_base_p obj;
868     int result;
869     struct dummy_driver_data *driver_data;
870     int i;
871     
872     ctx->version_major = 0;
873     ctx->version_minor = 18;
874     ctx->max_profiles = DUMMY_MAX_PROFILES;
875     ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
876     ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
877
878         ctx->vtable.vaTerminate = dummy_Terminate;
879         ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
880         ctx->vtable.vaTerminate = dummy_Terminate;
881         ctx->vtable.vaQueryConfigProfiles = dummy_QueryConfigProfiles;
882         ctx->vtable.vaQueryConfigEntrypoints = dummy_QueryConfigEntrypoints;
883         ctx->vtable.vaQueryConfigAttributes = dummy_QueryConfigAttributes;
884         ctx->vtable.vaCreateConfig = dummy_CreateConfig;
885         ctx->vtable.vaGetConfigAttributes = dummy_GetConfigAttributes;
886         ctx->vtable.vaCreateSurfaces = dummy_CreateSurfaces;
887         ctx->vtable.vaDestroySurface = dummy_DestroySurface;
888         ctx->vtable.vaCreateContext = dummy_CreateContext;
889         ctx->vtable.vaDestroyContext = dummy_DestroyContext;
890         ctx->vtable.vaCreateBuffer = dummy_CreateBuffer;
891         ctx->vtable.vaBufferData = dummy_BufferData;
892         ctx->vtable.vaBufferSetNumElements = dummy_BufferSetNumElements;
893         ctx->vtable.vaMapBuffer = dummy_MapBuffer;
894         ctx->vtable.vaUnmapBuffer = dummy_UnmapBuffer;
895         ctx->vtable.vaDestroyBuffer = dummy_DestroyBuffer;
896         ctx->vtable.vaBeginPicture = dummy_BeginPicture;
897         ctx->vtable.vaRenderPicture = dummy_RenderPicture;
898         ctx->vtable.vaEndPicture = dummy_EndPicture;
899         ctx->vtable.vaSyncSurface = dummy_SyncSurface;
900         ctx->vtable.vaQuerySurfaceStatus = dummy_QuerySurfaceStatus;
901         ctx->vtable.vaPutSurface = dummy_PutSurface;
902         ctx->vtable.vaDbgCopySurfaceToBuffer = dummy_DbgCopySurfaceToBuffer;
903
904         driver_data = (struct dummy_driver_data *) malloc( sizeof(*driver_data) );
905     ctx->pDriverData = (void *) driver_data;
906     
907     result = object_heap_init( &driver_data->config_heap, sizeof(struct object_config), CONFIG_ID_OFFSET );
908     ASSERT( result == 0 );
909
910     result = object_heap_init( &driver_data->context_heap, sizeof(struct object_context), CONTEXT_ID_OFFSET );
911     ASSERT( result == 0 );
912
913     result = object_heap_init( &driver_data->surface_heap, sizeof(struct object_surface), SURFACE_ID_OFFSET );
914     ASSERT( result == 0 );
915
916     result = object_heap_init( &driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET );
917     ASSERT( result == 0 );
918
919
920     return VA_STATUS_SUCCESS;
921 }
922