fb_draw.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #ifndef _FB_DRAW_H
  2. #define _FB_DRAW_H
  3. #include <asm/types.h>
  4. #include <linux/fb.h>
  5. /*
  6. * Compose two values, using a bitmask as decision value
  7. * This is equivalent to (a & mask) | (b & ~mask)
  8. */
  9. static inline unsigned long
  10. comp(unsigned long a, unsigned long b, unsigned long mask)
  11. {
  12. return ((a ^ b) & mask) ^ b;
  13. }
  14. /*
  15. * Create a pattern with the given pixel's color
  16. */
  17. #if BITS_PER_LONG == 64
  18. static inline unsigned long
  19. pixel_to_pat( u32 bpp, u32 pixel)
  20. {
  21. switch (bpp) {
  22. case 1:
  23. return 0xfffffffffffffffful*pixel;
  24. case 2:
  25. return 0x5555555555555555ul*pixel;
  26. case 4:
  27. return 0x1111111111111111ul*pixel;
  28. case 8:
  29. return 0x0101010101010101ul*pixel;
  30. case 12:
  31. return 0x1001001001001001ul*pixel;
  32. case 16:
  33. return 0x0001000100010001ul*pixel;
  34. case 24:
  35. return 0x0001000001000001ul*pixel;
  36. case 32:
  37. return 0x0000000100000001ul*pixel;
  38. default:
  39. panic("pixel_to_pat(): unsupported pixelformat\n");
  40. }
  41. }
  42. #else
  43. static inline unsigned long
  44. pixel_to_pat( u32 bpp, u32 pixel)
  45. {
  46. switch (bpp) {
  47. case 1:
  48. return 0xfffffffful*pixel;
  49. case 2:
  50. return 0x55555555ul*pixel;
  51. case 4:
  52. return 0x11111111ul*pixel;
  53. case 8:
  54. return 0x01010101ul*pixel;
  55. case 12:
  56. return 0x01001001ul*pixel;
  57. case 16:
  58. return 0x00010001ul*pixel;
  59. case 24:
  60. return 0x01000001ul*pixel;
  61. case 32:
  62. return 0x00000001ul*pixel;
  63. default:
  64. panic("pixel_to_pat(): unsupported pixelformat\n");
  65. }
  66. }
  67. #endif
  68. #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
  69. #if BITS_PER_LONG == 64
  70. #define REV_PIXELS_MASK1 0x5555555555555555ul
  71. #define REV_PIXELS_MASK2 0x3333333333333333ul
  72. #define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful
  73. #else
  74. #define REV_PIXELS_MASK1 0x55555555ul
  75. #define REV_PIXELS_MASK2 0x33333333ul
  76. #define REV_PIXELS_MASK4 0x0f0f0f0ful
  77. #endif
  78. static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
  79. u32 bswapmask)
  80. {
  81. if (bswapmask & 1)
  82. val = comp(val >> 1, val << 1, REV_PIXELS_MASK1);
  83. if (bswapmask & 2)
  84. val = comp(val >> 2, val << 2, REV_PIXELS_MASK2);
  85. if (bswapmask & 3)
  86. val = comp(val >> 4, val << 4, REV_PIXELS_MASK4);
  87. return val;
  88. }
  89. static inline u32 fb_shifted_pixels_mask_u32(struct fb_info *p, u32 index,
  90. u32 bswapmask)
  91. {
  92. u32 mask;
  93. if (!bswapmask) {
  94. mask = FB_SHIFT_HIGH(p, ~(u32)0, index);
  95. } else {
  96. mask = 0xff << FB_LEFT_POS(p, 8);
  97. mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask;
  98. mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask));
  99. #if defined(__i386__) || defined(__x86_64__)
  100. /* Shift argument is limited to 0 - 31 on x86 based CPU's */
  101. if(index + bswapmask < 32)
  102. #endif
  103. mask |= FB_SHIFT_HIGH(p, ~(u32)0,
  104. (index + bswapmask) & ~(bswapmask));
  105. }
  106. return mask;
  107. }
  108. static inline unsigned long fb_shifted_pixels_mask_long(struct fb_info *p,
  109. u32 index,
  110. u32 bswapmask)
  111. {
  112. unsigned long mask;
  113. if (!bswapmask) {
  114. mask = FB_SHIFT_HIGH(p, ~0UL, index);
  115. } else {
  116. mask = 0xff << FB_LEFT_POS(p, 8);
  117. mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask;
  118. mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask));
  119. #if defined(__i386__) || defined(__x86_64__)
  120. /* Shift argument is limited to 0 - 31 on x86 based CPU's */
  121. if(index + bswapmask < BITS_PER_LONG)
  122. #endif
  123. mask |= FB_SHIFT_HIGH(p, ~0UL,
  124. (index + bswapmask) & ~(bswapmask));
  125. }
  126. return mask;
  127. }
  128. static inline u32 fb_compute_bswapmask(struct fb_info *info)
  129. {
  130. u32 bswapmask = 0;
  131. unsigned bpp = info->var.bits_per_pixel;
  132. if ((bpp < 8) && (info->var.nonstd & FB_NONSTD_REV_PIX_IN_B)) {
  133. /*
  134. * Reversed order of pixel layout in bytes
  135. * works only for 1, 2 and 4 bpp
  136. */
  137. bswapmask = 7 - bpp + 1;
  138. }
  139. return bswapmask;
  140. }
  141. #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
  142. static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
  143. u32 bswapmask)
  144. {
  145. return val;
  146. }
  147. #define fb_shifted_pixels_mask_u32(p, i, b) FB_SHIFT_HIGH((p), ~(u32)0, (i))
  148. #define fb_shifted_pixels_mask_long(p, i, b) FB_SHIFT_HIGH((p), ~0UL, (i))
  149. #define fb_compute_bswapmask(...) 0
  150. #endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
  151. #define cpu_to_le_long _cpu_to_le_long(BITS_PER_LONG)
  152. #define _cpu_to_le_long(x) __cpu_to_le_long(x)
  153. #define __cpu_to_le_long(x) cpu_to_le##x
  154. #define le_long_to_cpu _le_long_to_cpu(BITS_PER_LONG)
  155. #define _le_long_to_cpu(x) __le_long_to_cpu(x)
  156. #define __le_long_to_cpu(x) le##x##_to_cpu
  157. static inline unsigned long rolx(unsigned long word, unsigned int shift, unsigned int x)
  158. {
  159. return (word << shift) | (word >> (x - shift));
  160. }
  161. #endif /* FB_DRAW_H */