gfx/skia/trunk/src/core/SkBlitBWMaskTemplate.h

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial