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