OSDN Git Service

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