Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 Artur Wyszynski <harakash@gmail.com>
  4.  * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17.  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  18.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  21.  *
  22.  * The above copyright notice and this permission notice (including the
  23.  * next paragraph) shall be included in all copies or substantial portions
  24.  * of the Software.
  25.  *
  26.  **************************************************************************/
  27.  
  28.  
  29. #include "pipe/p_compiler.h"
  30. #include "pipe/p_format.h"
  31. #include "util/u_inlines.h"
  32. #include "util/u_format.h"
  33. #include "util/u_math.h"
  34. #include "util/u_memory.h"
  35.  
  36. #include "hgl_sw_winsys.h"
  37. #include "bitmap_wrapper.h"
  38.  
  39.  
  40. // Cast
  41. static INLINE struct haiku_displaytarget*
  42. hgl_sw_displaytarget(struct sw_displaytarget* target)
  43. {
  44.         return (struct haiku_displaytarget *)target;
  45. }
  46.  
  47.  
  48. static void
  49. hgl_winsys_destroy(struct sw_winsys* winsys)
  50. {
  51.         FREE(winsys);
  52. }
  53.  
  54.  
  55. static boolean
  56. hgl_winsys_is_displaytarget_format_supported(struct sw_winsys* winsys,
  57.         unsigned textureUsage, enum pipe_format format)
  58. {
  59.         // TODO STUB
  60.         return true;
  61. }
  62.  
  63.  
  64. static struct sw_displaytarget*
  65. hgl_winsys_displaytarget_create(struct sw_winsys* winsys,
  66.         unsigned textureUsage, enum pipe_format format, unsigned width,
  67.         unsigned height, unsigned alignment, unsigned* stride)
  68. {
  69.         struct haiku_displaytarget* haikuDisplayTarget
  70.                 = CALLOC_STRUCT(haiku_displaytarget);
  71.         assert(haikuDisplayTarget);
  72.  
  73.         haikuDisplayTarget->format = format;
  74.         haikuDisplayTarget->width = width;
  75.         haikuDisplayTarget->height = height;
  76.  
  77.         size_t formatStride = util_format_get_stride(format, width);
  78.         unsigned blockSize = util_format_get_nblocksy(format, height);
  79.  
  80.         haikuDisplayTarget->stride = align(formatStride, alignment);
  81.         haikuDisplayTarget->size = haikuDisplayTarget->stride * blockSize;
  82.  
  83.         haikuDisplayTarget->data
  84.                 = align_malloc(haikuDisplayTarget->size, alignment);
  85.  
  86.         assert(haikuDisplayTarget->data);
  87.  
  88.         *stride = haikuDisplayTarget->stride;
  89.  
  90.         // Cast to ghost sw_displaytarget type
  91.         return (struct sw_displaytarget*)haikuDisplayTarget;
  92. }
  93.  
  94.  
  95. static void
  96. hgl_winsys_displaytarget_destroy(struct sw_winsys* winsys,
  97.         struct sw_displaytarget* displayTarget)
  98. {
  99.         struct haiku_displaytarget* haikuDisplayTarget
  100.                 = hgl_sw_displaytarget(displayTarget);
  101.  
  102.         if (!haikuDisplayTarget)
  103.                 return;
  104.  
  105.         if (haikuDisplayTarget->data != NULL)
  106.                 align_free(haikuDisplayTarget->data);
  107.  
  108.         FREE(haikuDisplayTarget);
  109. }
  110.  
  111.  
  112. static struct sw_displaytarget*
  113. hgl_winsys_displaytarget_from_handle(struct sw_winsys* winsys,
  114.         const struct pipe_resource* templat, struct winsys_handle* whandle,
  115.         unsigned* stride)
  116. {
  117.         return NULL;
  118. }
  119.  
  120.  
  121. static boolean
  122. hgl_winsys_displaytarget_get_handle(struct sw_winsys* winsys,
  123.         struct sw_displaytarget* displayTarget, struct winsys_handle* whandle)
  124. {
  125.         return FALSE;
  126. }
  127.  
  128.  
  129. static void*
  130. hgl_winsys_displaytarget_map(struct sw_winsys* winsys,
  131.         struct sw_displaytarget* displayTarget, unsigned flags)
  132. {
  133.         struct haiku_displaytarget* haikuDisplayTarget
  134.                 = hgl_sw_displaytarget(displayTarget);
  135.  
  136.         return haikuDisplayTarget->data;
  137. }
  138.  
  139.  
  140. static void
  141. hgl_winsys_displaytarget_unmap(struct sw_winsys* winsys,
  142.         struct sw_displaytarget* disptarget)
  143. {
  144.         return;
  145. }
  146.  
  147.  
  148. static void
  149. hgl_winsys_displaytarget_display(struct sw_winsys* winsys,
  150.         struct sw_displaytarget* displayTarget, void* contextPrivate)
  151. {
  152.         assert(contextPrivate);
  153.  
  154.         Bitmap* bitmap = (Bitmap*)contextPrivate;
  155.  
  156.         struct haiku_displaytarget* haikuDisplayTarget
  157.                 = hgl_sw_displaytarget(displayTarget);
  158.  
  159.         copy_bitmap_bits(bitmap, haikuDisplayTarget->data,
  160.                 haikuDisplayTarget->size);
  161.  
  162.         return;
  163. }
  164.  
  165.  
  166. struct sw_winsys*
  167. hgl_create_sw_winsys()
  168. {
  169.         struct sw_winsys* winsys = CALLOC_STRUCT(sw_winsys);
  170.  
  171.         if (!winsys)
  172.                 return NULL;
  173.        
  174.         // Attach winsys hooks for Haiku
  175.         winsys->destroy = hgl_winsys_destroy;
  176.         winsys->is_displaytarget_format_supported
  177.                 = hgl_winsys_is_displaytarget_format_supported;
  178.         winsys->displaytarget_create = hgl_winsys_displaytarget_create;
  179.         winsys->displaytarget_from_handle = hgl_winsys_displaytarget_from_handle;
  180.         winsys->displaytarget_get_handle = hgl_winsys_displaytarget_get_handle;
  181.         winsys->displaytarget_map = hgl_winsys_displaytarget_map;
  182.         winsys->displaytarget_unmap = hgl_winsys_displaytarget_unmap;
  183.         winsys->displaytarget_display = hgl_winsys_displaytarget_display;
  184.         winsys->displaytarget_destroy = hgl_winsys_displaytarget_destroy;
  185.  
  186.         return winsys;
  187. }
  188.