Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2011 LunarG Inc.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Chia-I Wu <olv@lunarg.com>
  26.  */
  27.  
  28. /**
  29.  * For NULL window system,
  30.  *
  31.  *  - the only valid native display is EGL_DEFAULT_DISPLAY
  32.  *  - there is no window or pixmap
  33.  */
  34.  
  35. #include "util/u_memory.h"
  36. #include "null/null_sw_winsys.h"
  37. #include "common/native.h"
  38.  
  39. struct null_display {
  40.    struct native_display base;
  41.  
  42.    const struct native_event_handler *event_handler;
  43.  
  44.    struct native_config *configs;
  45.    int num_configs;
  46. };
  47.  
  48. static INLINE struct null_display *
  49. null_display(const struct native_display *ndpy)
  50. {
  51.    return (struct null_display *) ndpy;
  52. }
  53.  
  54. static const struct native_config **
  55. null_display_get_configs(struct native_display *ndpy, int *num_configs)
  56. {
  57.    struct null_display *null = null_display(ndpy);
  58.    const struct native_config **configs;
  59.    int i;
  60.  
  61.    configs = MALLOC(sizeof(*configs) * null->num_configs);
  62.    if (configs) {
  63.       for (i = 0; i < null->num_configs; i++)
  64.          configs[i] = &null->configs[i];
  65.       if (num_configs)
  66.          *num_configs = null->num_configs;
  67.    }
  68.  
  69.    return configs;
  70. }
  71.  
  72. static int
  73. null_display_get_param(struct native_display *ndpy,
  74.                       enum native_param_type param)
  75. {
  76.    return 0;
  77. }
  78.  
  79. static void
  80. null_display_destroy(struct native_display *ndpy)
  81. {
  82.    struct null_display *null = null_display(ndpy);
  83.  
  84.    FREE(null->configs);
  85.    ndpy_uninit(&null->base);
  86.    FREE(null);
  87. }
  88.  
  89. static boolean
  90. null_display_init_config(struct native_display *ndpy)
  91. {
  92.    const enum pipe_format color_formats[] =  {
  93.       PIPE_FORMAT_B8G8R8A8_UNORM,
  94.       PIPE_FORMAT_B8G8R8X8_UNORM,
  95.       PIPE_FORMAT_B5G6R5_UNORM,
  96.       PIPE_FORMAT_NONE
  97.    };
  98.    struct null_display *null = null_display(ndpy);
  99.    int i;
  100.  
  101.    null->configs = CALLOC(Elements(color_formats) - 1, sizeof(*null->configs));
  102.    if (!null->configs)
  103.       return FALSE;
  104.  
  105.    /* add configs */
  106.    for (i = 0; color_formats[i] != PIPE_FORMAT_NONE; i++) {
  107.       if (null->base.screen->is_format_supported(null->base.screen,
  108.                color_formats[i], PIPE_TEXTURE_2D, 0,
  109.                PIPE_BIND_RENDER_TARGET)) {
  110.          struct native_config *nconf = &null->configs[null->num_configs];
  111.  
  112.          nconf->color_format = color_formats[i];
  113.          nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_BACK_LEFT;
  114.          null->num_configs++;
  115.       }
  116.    }
  117.  
  118.    return TRUE;
  119. }
  120.  
  121. static boolean
  122. null_display_init_screen(struct native_display *ndpy)
  123. {
  124.    struct null_display *null = null_display(ndpy);
  125.    struct sw_winsys *ws;
  126.  
  127.    ws = null_sw_create();
  128.    if (!ws)
  129.       return FALSE;
  130.  
  131.    null->base.screen = null->event_handler->new_sw_screen(&null->base, ws);
  132.    if (!null->base.screen) {
  133.       if (ws->destroy)
  134.          ws->destroy(ws);
  135.       return FALSE;
  136.    }
  137.  
  138.    if (!null_display_init_config(&null->base)) {
  139.       ndpy_uninit(&null->base);
  140.       return FALSE;
  141.    }
  142.  
  143.    return TRUE;
  144. }
  145.  
  146. static struct native_display *
  147. null_display_create(const struct native_event_handler *event_handler)
  148. {
  149.    struct null_display *null;
  150.  
  151.    null = CALLOC_STRUCT(null_display);
  152.    if (!null)
  153.       return NULL;
  154.  
  155.    null->event_handler = event_handler;
  156.  
  157.    null->base.init_screen = null_display_init_screen;
  158.    null->base.destroy = null_display_destroy;
  159.    null->base.get_param = null_display_get_param;
  160.    null->base.get_configs = null_display_get_configs;
  161.  
  162.    return &null->base;
  163. }
  164.  
  165. static const struct native_event_handler *null_event_handler;
  166.  
  167. static struct native_display *
  168. native_create_display(void *dpy, boolean use_sw)
  169. {
  170.    struct native_display *ndpy = NULL;
  171.  
  172.    /* the only valid display is NULL */
  173.    if (!dpy)
  174.       ndpy = null_display_create(null_event_handler);
  175.  
  176.    return ndpy;
  177. }
  178.  
  179. static const struct native_platform null_platform = {
  180.    "NULL", /* name */
  181.    native_create_display
  182. };
  183.  
  184. const struct native_platform *
  185. native_get_null_platform(const struct native_event_handler *event_handler)
  186. {
  187.    null_event_handler = event_handler;
  188.    return &null_platform;
  189. }
  190.