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