Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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