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_surface.c 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  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 TUNGSTEN GRAPHICS 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 "pipe/p_defines.h"
  28. #include "pipe/p_util.h"
  29. #include "pipe/p_inlines.h"
  30. #include "pipe/p_winsys.h"
  31. #include "util/p_tile.h"
  32. #include "cell_context.h"
  33. #include "cell_surface.h"
  34. /* Upload data to a rectangular sub-region. Lots of choices how to do this:
  35. *
  36. * - memcpy by span to current destination
  37. * - upload data as new buffer and blit
  38. *
  39. * Currently always memcpy.
  40. */
  41. static void
  42. cell_surface_data(struct pipe_context *pipe,
  43. struct pipe_surface *dst,
  44. unsigned dstx, unsigned dsty,
  45. const void *src, unsigned src_pitch,
  46. unsigned srcx, unsigned srcy,
  47. unsigned width, unsigned height)
  48. {
  49. pipe_copy_rect(pipe_surface_map(dst),
  50. dst->cpp,
  51. dst->pitch,
  52. dstx, dsty, width, height, src, src_pitch, srcx, srcy);
  53. pipe_surface_unmap(dst);
  54. }
  55. static void
  56. cell_surface_copy(struct pipe_context *pipe,
  57. boolean do_flip,
  58. struct pipe_surface *dst,
  59. unsigned dstx, unsigned dsty,
  60. struct pipe_surface *src,
  61. unsigned srcx, unsigned srcy,
  62. unsigned width, unsigned height)
  63. {
  64. assert( dst->cpp == src->cpp );
  65. pipe_copy_rect(pipe_surface_map(dst),
  66. dst->cpp,
  67. dst->pitch,
  68. dstx, dsty,
  69. width, height,
  70. pipe_surface_map(src),
  71. do_flip ? -src->pitch : src->pitch,
  72. srcx, do_flip ? height - 1 - srcy : srcy);
  73. pipe_surface_unmap(src);
  74. pipe_surface_unmap(dst);
  75. }
  76. static void *
  77. get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
  78. {
  79. return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
  80. }
  81. #define UBYTE_TO_USHORT(B) ((B) | ((B) << 8))
  82. /**
  83. * Fill a rectangular sub-region. Need better logic about when to
  84. * push buffers into AGP - will currently do so whenever possible.
  85. */
  86. static void
  87. cell_surface_fill(struct pipe_context *pipe,
  88. struct pipe_surface *dst,
  89. unsigned dstx, unsigned dsty,
  90. unsigned width, unsigned height, unsigned value)
  91. {
  92. unsigned i, j;
  93. void *dst_map = pipe_surface_map(dst);
  94. assert(dst->pitch > 0);
  95. assert(width <= dst->pitch);
  96. switch (dst->cpp) {
  97. case 1:
  98. {
  99. ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
  100. for (i = 0; i < height; i++) {
  101. memset(row, value, width);
  102. row += dst->pitch;
  103. }
  104. }
  105. break;
  106. case 2:
  107. {
  108. ushort *row = get_pointer(dst, dst_map, dstx, dsty);
  109. for (i = 0; i < height; i++) {
  110. for (j = 0; j < width; j++)
  111. row[j] = (ushort) value;
  112. row += dst->pitch;
  113. }
  114. }
  115. break;
  116. case 4:
  117. {
  118. unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
  119. for (i = 0; i < height; i++) {
  120. for (j = 0; j < width; j++)
  121. row[j] = value;
  122. row += dst->pitch;
  123. }
  124. }
  125. break;
  126. case 8:
  127. {
  128. /* expand the 4-byte clear value to an 8-byte value */
  129. ushort *row = (ushort *) get_pointer(dst, dst_map, dstx, dsty);
  130. ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff);
  131. ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff);
  132. ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff);
  133. ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff);
  134. val0 = (val0 << 8) | val0;
  135. val1 = (val1 << 8) | val1;
  136. val2 = (val2 << 8) | val2;
  137. val3 = (val3 << 8) | val3;
  138. for (i = 0; i < height; i++) {
  139. for (j = 0; j < width; j++) {
  140. row[j*4+0] = val0;
  141. row[j*4+1] = val1;
  142. row[j*4+2] = val2;
  143. row[j*4+3] = val3;
  144. }
  145. row += dst->pitch * 4;
  146. }
  147. }
  148. break;
  149. default:
  150. assert(0);
  151. break;
  152. }
  153. pipe_surface_unmap( dst );
  154. }
  155. void
  156. cell_init_surface_functions(struct cell_context *cell)
  157. {
  158. cell->pipe.surface_copy = cell_surface_copy;
  159. cell->pipe.surface_fill = cell_surface_fill;
  160. }