/project/jni/sdl_blitpool/include/SDL_blitpool.h

https://github.com/aichunyu/FFPlayer · C Header · 258 lines · 84 code · 99 blank · 75 comment · 0 complexity · dfd7d9323cda082388ee3986a4c081e0 MD5 · raw file

  1. /*
  2. //
  3. // Blit operation pool for the SDL.
  4. // Copyright (C) 2005 Strangebug (S.Miura) [strangebug art hotmail.co.jp]
  5. //
  6. //
  7. // This library is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU Lesser General Public
  9. // License as published by the Free Software Foundation; either
  10. // version 2.1 of the License, or (at your option) any later version.
  11. //
  12. // This library is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. // Lesser General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU Lesser General Public
  18. // License along with this library; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. //
  21. //
  22. // SDL_BlitPool.c : 25/Feb/2005 : created
  23. //
  24. */
  25. #ifndef INCLUDED_SDL_BLITPOOL_H
  26. #define INCLUDED_SDL_BLITPOOL_H
  27. #include "SDL.h"
  28. #include "begin_code.h"
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #ifndef Optional
  33. # define Optional
  34. #endif
  35. typedef enum {
  36. /* BlitType */
  37. BLIT_TYPE_SURFACE = 1 << 0,
  38. BLIT_TYPE_COLORFILL = 1 << 1,
  39. BLIT_TYPE_EMPTY = 1 << 2,
  40. #define BLIT_TYPE_MASK (BLIT_TYPE_SURFACE | BLIT_TYPE_COLORFILL | BLIT_TYPE_EMPTY)
  41. /* BlitTransparency */
  42. BLIT_ALPHA_TRANSPARENT = 1 << 3, /* Surface have transparency pixel */
  43. BLIT_ALPHA_OPAQUE = 1 << 4, /* Surface not have transparency pixel */
  44. #define BLIT_ALPHA_MASK (BLIT_ALPHA_TRANSPARENT | BLIT_ALPHA_OPAQUE)
  45. /* BlitExecOption */
  46. BLIT_EXEC_OPTIMIZE = 1 << 7, /* do optimize */
  47. BLIT_EXEC_NO_OPTIMIZE = 1 << 8, /* do not optimize */
  48. #define BLIT_EXEC_MASK (BLIT_EXEC_OPTIMIZE | BLIT_EXEC_NO_OPTIMIZE)
  49. BLIT_FLAG_TERM = 1 << 9 /* terminater */
  50. } BlitEntryFlag;
  51. typedef enum {
  52. BLIT_OPT_REMOVEOVERLAP = 1 << 0, /* remove overlap area */
  53. BLIT_OPT_REMOVEOUTSIDE = 1 << 1, /* remove outside of destination surface */
  54. BLIT_OPT_ALL = BLIT_OPT_REMOVEOVERLAP | BLIT_OPT_REMOVEOUTSIDE
  55. } BlitOptimizeFlag;
  56. typedef struct BlitPool_tag BlitPool; /* Pool object */
  57. typedef void *(*allocator_func)(unsigned long nbyte);
  58. typedef void (*releaser_func)(void *p);
  59. typedef struct {
  60. /*
  61. // Box: (x0, y0) - (x1, y1)
  62. */
  63. Sint16 x0, y0, x1, y1;
  64. } BlitPool_BoundingBox;
  65. /*
  66. // Create/Delete a BlitPool object.
  67. */
  68. extern BlitPool *BlitPool_CreatePool(Optional SDL_Surface *destsurf);
  69. extern void BlitPool_DeletePool(BlitPool *pool);
  70. extern void BlitPool_SetAllocator(BlitPool *pool, allocator_func allocator, releaser_func releaser);
  71. /*
  72. // Release all of entries.
  73. */
  74. extern void BlitPool_ReleaseEntry(BlitPool *pool);
  75. /*
  76. // Blit/Fill operation post.
  77. */
  78. extern int BlitPool_Post(
  79. BlitPool *pool,
  80. BlitEntryFlag flag,
  81. SDL_Surface *src,
  82. Optional SDL_Rect *srcrect,
  83. Optional SDL_Rect *destrect,
  84. Uint32 color
  85. );
  86. #define BlitPool_PostSurface(pool, src, srcrect, destrect, flag) \
  87. BlitPool_Post(pool, BLIT_TYPE_SURFACE | (flag), src, srcrect, destrect, 0)
  88. #define BlitPool_PostFill(pool, destrect, color, flag) \
  89. BlitPool_Post(pool, BLIT_TYPE_COLORFILL | (flag), NULL, NULL, destrect, color)
  90. /*
  91. // Commit pool.
  92. // src_pool don't release.
  93. // offset use only (x, y).
  94. */
  95. extern void BlitPool_PostPool(
  96. BlitPool *dest_pool,
  97. BlitPool *src_pool,
  98. Optional SDL_Rect *offset
  99. );
  100. /*
  101. // Post separated surface/fill by area_description_str.
  102. //
  103. // area_description_str like: "pos=(45, 12):O:(0,0)-(12,12):(45,23)-(62, 24):pos=(0,0):col=(255,255,255,255):(12,98)-(1,65)"
  104. // pos=(x,y) : destination position. default=(0,0).
  105. // (x0,y0)-(x1,y1) : source surface rectangle.
  106. // O/T : T=Transparens(default), O=Opaque.
  107. // col=(r, g, b, a) : colorfill mode. it's format be surf->format.
  108. //
  109. // * Don't forget delimiter ':'.
  110. */
  111. extern int BlitPool_PostByDescription(
  112. BlitPool *pool,
  113. Optional SDL_Surface *surf,
  114. unsigned char *area_description_str
  115. );
  116. /*
  117. // Optimize the operations and execute blit.
  118. */
  119. extern void BlitPool_Optimize(BlitPool *pool, BlitOptimizeFlag flag);
  120. extern void BlitPool_Execute(BlitPool *pool);
  121. /*
  122. // For update.
  123. // example: {
  124. // int numrect;
  125. // SDL_Rect rectbuf[10];
  126. //
  127. // while ((numrect = BlitPool_GetUpdateRects(pool, rectbuf, sizeof(rectbuf)/sizeof(rectbuf[0]))) > 0) {
  128. // SDL_UpdateRects(screen, numrect, rectbuf);
  129. // }
  130. // }
  131. */
  132. extern int BlitPool_GetRectCount(BlitPool *pool);
  133. extern void *BlitPool_GetUpdateRectsObj(BlitPool *pool);
  134. extern int BlitPool_GetUpdateRects(BlitPool *pool, SDL_Rect *rectbuf, int size, void **update_rects_obj);
  135. /*
  136. // Get update area.
  137. */
  138. extern Uint32 BlitPool_GetArea(BlitPool *pool);
  139. /*
  140. // Utilities.
  141. */
  142. extern int BlitPoolUtil_GetOverlapCode(
  143. Uint8 *out_code, /* Must not NULL */
  144. BlitPool_BoundingBox *f,
  145. BlitPool_BoundingBox *b
  146. );
  147. extern void BlitPoolUtil_CalcOverlapArea(
  148. BlitPool_BoundingBox *out_overlap_box, /* Must not NULL */
  149. Uint8 code,
  150. BlitPool_BoundingBox *f,
  151. BlitPool_BoundingBox *b
  152. );
  153. extern void BlitPoolUtil_RectToBBox(SDL_Rect *src, BlitPool_BoundingBox *dest);
  154. extern void BlitPoolUtil_BBoxToRect(BlitPool_BoundingBox *src, SDL_Rect *dest);
  155. #ifdef __cplusplus
  156. } /* for extern "c" { */
  157. #endif
  158. #include "close_code.h"
  159. #endif /* INCLUDED_SDL_BLITPOOL_H */