SkBlitBWMaskTemplate.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkBitmap.h"
  8. #include "src/core/SkMask.h"
  9. #ifndef ClearLow3Bits_DEFINED
  10. #define ClearLow3Bits_DEFINED
  11. #define ClearLow3Bits(x) ((unsigned)(x) >> 3 << 3)
  12. #endif
  13. /*
  14. SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS)
  15. SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma
  16. SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y)
  17. SK_BLITBWMASK_GETADDR either writable_addr[8,16,32]
  18. SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8
  19. */
  20. static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask,
  21. const SkIRect& clip SK_BLITBWMASK_ARGS) {
  22. SkASSERT(clip.fRight <= srcMask.fBounds.fRight);
  23. int cx = clip.fLeft;
  24. int cy = clip.fTop;
  25. int maskLeft = srcMask.fBounds.fLeft;
  26. unsigned mask_rowBytes = srcMask.fRowBytes;
  27. size_t bitmap_rowBytes = dst.rowBytes();
  28. unsigned height = clip.height();
  29. SkASSERT(mask_rowBytes != 0);
  30. SkASSERT(bitmap_rowBytes != 0);
  31. SkASSERT(height != 0);
  32. const uint8_t* bits = srcMask.getAddr1(cx, cy);
  33. SK_BLITBWMASK_DEVTYPE* device = dst.SK_BLITBWMASK_GETADDR(cx, cy);
  34. if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight)
  35. {
  36. do {
  37. SK_BLITBWMASK_DEVTYPE* dst = device;
  38. unsigned rb = mask_rowBytes;
  39. do {
  40. U8CPU mask = *bits++;
  41. SK_BLITBWMASK_BLIT8(mask, dst);
  42. dst += 8;
  43. } while (--rb != 0);
  44. device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
  45. } while (--height != 0);
  46. }
  47. else
  48. {
  49. int left_edge = cx - maskLeft;
  50. SkASSERT(left_edge >= 0);
  51. int rite_edge = clip.fRight - maskLeft;
  52. SkASSERT(rite_edge > left_edge);
  53. int left_mask = 0xFF >> (left_edge & 7);
  54. int rite_mask = 0xFF << (8 - (rite_edge & 7));
  55. rite_mask &= 0xFF; // only want low-8 bits of mask
  56. int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3);
  57. // check for empty right mask, so we don't read off the end (or go slower than we need to)
  58. if (rite_mask == 0)
  59. {
  60. SkASSERT(full_runs >= 0);
  61. full_runs -= 1;
  62. rite_mask = 0xFF;
  63. }
  64. if (left_mask == 0xFF)
  65. full_runs -= 1;
  66. // back up manually so we can keep in sync with our byte-aligned src
  67. // and not trigger an assert from the getAddr## function
  68. device -= left_edge & 7;
  69. if (full_runs < 0)
  70. {
  71. left_mask &= rite_mask;
  72. SkASSERT(left_mask != 0);
  73. do {
  74. U8CPU mask = *bits & left_mask;
  75. SK_BLITBWMASK_BLIT8(mask, device);
  76. bits += mask_rowBytes;
  77. device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
  78. } while (--height != 0);
  79. }
  80. else
  81. {
  82. do {
  83. int runs = full_runs;
  84. SK_BLITBWMASK_DEVTYPE* dst = device;
  85. const uint8_t* b = bits;
  86. U8CPU mask;
  87. mask = *b++ & left_mask;
  88. SK_BLITBWMASK_BLIT8(mask, dst);
  89. dst += 8;
  90. while (--runs >= 0)
  91. {
  92. mask = *b++;
  93. SK_BLITBWMASK_BLIT8(mask, dst);
  94. dst += 8;
  95. }
  96. mask = *b & rite_mask;
  97. SK_BLITBWMASK_BLIT8(mask, dst);
  98. bits += mask_rowBytes;
  99. device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes);
  100. } while (--height != 0);
  101. }
  102. }
  103. }
  104. #undef SK_BLITBWMASK_NAME
  105. #undef SK_BLITBWMASK_ARGS
  106. #undef SK_BLITBWMASK_BLIT8
  107. #undef SK_BLITBWMASK_GETADDR
  108. #undef SK_BLITBWMASK_DEVTYPE
  109. #undef SK_BLITBWMASK_DOROWSETUP