1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkBlitBWMaskTemplate.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkBitmap.h" 1.14 +#include "SkMask.h" 1.15 + 1.16 +#ifndef ClearLow3Bits_DEFINED 1.17 +#define ClearLow3Bits_DEFINED 1.18 + #define ClearLow3Bits(x) ((unsigned)(x) >> 3 << 3) 1.19 +#endif 1.20 + 1.21 +/* 1.22 + SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS) 1.23 + SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma 1.24 + SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y) 1.25 + SK_BLITBWMASK_GETADDR either getAddr32 or getAddr16 or getAddr8 1.26 + SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8 1.27 +*/ 1.28 + 1.29 +static void SK_BLITBWMASK_NAME(const SkBitmap& bitmap, const SkMask& srcMask, const SkIRect& clip SK_BLITBWMASK_ARGS) 1.30 +{ 1.31 + SkASSERT(clip.fRight <= srcMask.fBounds.fRight); 1.32 + 1.33 + int cx = clip.fLeft; 1.34 + int cy = clip.fTop; 1.35 + int maskLeft = srcMask.fBounds.fLeft; 1.36 + unsigned mask_rowBytes = srcMask.fRowBytes; 1.37 + size_t bitmap_rowBytes = bitmap.rowBytes(); 1.38 + unsigned height = clip.height(); 1.39 + 1.40 + SkASSERT(mask_rowBytes != 0); 1.41 + SkASSERT(bitmap_rowBytes != 0); 1.42 + SkASSERT(height != 0); 1.43 + 1.44 + const uint8_t* bits = srcMask.getAddr1(cx, cy); 1.45 + SK_BLITBWMASK_DEVTYPE* device = bitmap.SK_BLITBWMASK_GETADDR(cx, cy); 1.46 + 1.47 + if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight) 1.48 + { 1.49 + do { 1.50 + SK_BLITBWMASK_DEVTYPE* dst = device; 1.51 + unsigned rb = mask_rowBytes; 1.52 + do { 1.53 + U8CPU mask = *bits++; 1.54 + SK_BLITBWMASK_BLIT8(mask, dst); 1.55 + dst += 8; 1.56 + } while (--rb != 0); 1.57 + device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); 1.58 + } while (--height != 0); 1.59 + } 1.60 + else 1.61 + { 1.62 + int left_edge = cx - maskLeft; 1.63 + SkASSERT(left_edge >= 0); 1.64 + int rite_edge = clip.fRight - maskLeft; 1.65 + SkASSERT(rite_edge > left_edge); 1.66 + 1.67 + int left_mask = 0xFF >> (left_edge & 7); 1.68 + int rite_mask = 0xFF << (8 - (rite_edge & 7)); 1.69 + rite_mask &= 0xFF; // only want low-8 bits of mask 1.70 + int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3); 1.71 + 1.72 + // check for empty right mask, so we don't read off the end (or go slower than we need to) 1.73 + if (rite_mask == 0) 1.74 + { 1.75 + SkASSERT(full_runs >= 0); 1.76 + full_runs -= 1; 1.77 + rite_mask = 0xFF; 1.78 + } 1.79 + if (left_mask == 0xFF) 1.80 + full_runs -= 1; 1.81 + 1.82 + // back up manually so we can keep in sync with our byte-aligned src 1.83 + // and not trigger an assert from the getAddr## function 1.84 + device -= left_edge & 7; 1.85 + 1.86 + if (full_runs < 0) 1.87 + { 1.88 + left_mask &= rite_mask; 1.89 + SkASSERT(left_mask != 0); 1.90 + do { 1.91 + U8CPU mask = *bits & left_mask; 1.92 + SK_BLITBWMASK_BLIT8(mask, device); 1.93 + bits += mask_rowBytes; 1.94 + device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); 1.95 + } while (--height != 0); 1.96 + } 1.97 + else 1.98 + { 1.99 + do { 1.100 + int runs = full_runs; 1.101 + SK_BLITBWMASK_DEVTYPE* dst = device; 1.102 + const uint8_t* b = bits; 1.103 + U8CPU mask; 1.104 + 1.105 + mask = *b++ & left_mask; 1.106 + SK_BLITBWMASK_BLIT8(mask, dst); 1.107 + dst += 8; 1.108 + 1.109 + while (--runs >= 0) 1.110 + { 1.111 + mask = *b++; 1.112 + SK_BLITBWMASK_BLIT8(mask, dst); 1.113 + dst += 8; 1.114 + } 1.115 + 1.116 + mask = *b & rite_mask; 1.117 + SK_BLITBWMASK_BLIT8(mask, dst); 1.118 + 1.119 + bits += mask_rowBytes; 1.120 + device = (SK_BLITBWMASK_DEVTYPE*)((char*)device + bitmap_rowBytes); 1.121 + } while (--height != 0); 1.122 + } 1.123 + } 1.124 +} 1.125 + 1.126 +#undef SK_BLITBWMASK_NAME 1.127 +#undef SK_BLITBWMASK_ARGS 1.128 +#undef SK_BLITBWMASK_BLIT8 1.129 +#undef SK_BLITBWMASK_GETADDR 1.130 +#undef SK_BLITBWMASK_DEVTYPE 1.131 +#undef SK_BLITBWMASK_DOROWSETUP