Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cell_buffer.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**************************************************************************
  2. *
  3. * Copyright 2009 VMware, Inc.
  4. * All Rights Reserved.
  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 above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "util/u_inlines.h"
  28. #include "util/u_memory.h"
  29. #include "util/u_math.h"
  30. #include "cell_screen.h"
  31. #include "cell_buffer.h"
  32. static void *
  33. cell_buffer_map(struct pipe_screen *screen,
  34. struct pipe_buffer *buf,
  35. unsigned flags)
  36. {
  37. struct cell_buffer *cell_buf = cell_buffer(buf);
  38. return cell_buf->data;
  39. }
  40. static void
  41. cell_buffer_unmap(struct pipe_screen *screen,
  42. struct pipe_buffer *buf)
  43. {
  44. }
  45. static void
  46. cell_buffer_destroy(struct pipe_buffer *buf)
  47. {
  48. struct cell_buffer *sbuf = cell_buffer(buf);
  49. if (!sbuf->userBuffer)
  50. align_free(sbuf->data);
  51. FREE(sbuf);
  52. }
  53. static struct pipe_buffer *
  54. cell_buffer_create(struct pipe_screen *screen,
  55. unsigned alignment,
  56. unsigned usage,
  57. unsigned size)
  58. {
  59. struct cell_buffer *buffer = CALLOC_STRUCT(cell_buffer);
  60. pipe_reference_init(&buffer->base.reference, 1);
  61. buffer->base.screen = screen;
  62. buffer->base.alignment = MAX2(alignment, 16);
  63. buffer->base.usage = usage;
  64. buffer->base.size = size;
  65. buffer->data = align_malloc(size, alignment);
  66. return &buffer->base;
  67. }
  68. /**
  69. * Create buffer which wraps user-space data.
  70. */
  71. static struct pipe_buffer *
  72. cell_user_buffer_create(struct pipe_screen *screen,
  73. void *ptr,
  74. unsigned bytes)
  75. {
  76. struct cell_buffer *buffer;
  77. buffer = CALLOC_STRUCT(cell_buffer);
  78. if(!buffer)
  79. return NULL;
  80. pipe_reference_init(&buffer->base.reference, 1);
  81. buffer->base.screen = screen;
  82. buffer->base.size = bytes;
  83. buffer->userBuffer = TRUE;
  84. buffer->data = ptr;
  85. return &buffer->base;
  86. }
  87. void
  88. cell_init_screen_buffer_funcs(struct pipe_screen *screen)
  89. {
  90. screen->buffer_create = cell_buffer_create;
  91. screen->user_buffer_create = cell_user_buffer_create;
  92. screen->buffer_map = cell_buffer_map;
  93. screen->buffer_unmap = cell_buffer_unmap;
  94. screen->buffer_destroy = cell_buffer_destroy;
  95. }