| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBlitter.h" | 8 #include "SkBlitter.h" |
| 9 #include "SkAntiRun.h" | 9 #include "SkAntiRun.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 this->blitRect(x, y, width, height); | 76 this->blitRect(x, y, width, height); |
| 77 x += width; | 77 x += width; |
| 78 } | 78 } |
| 79 this->blitV(x, y, height, rightAlpha); | 79 this->blitV(x, y, height, rightAlpha); |
| 80 } | 80 } |
| 81 | 81 |
| 82 ////////////////////////////////////////////////////////////////////////////// | 82 ////////////////////////////////////////////////////////////////////////////// |
| 83 | 83 |
| 84 static inline void bits_to_runs(SkBlitter* blitter, int x, int y, | 84 static inline void bits_to_runs(SkBlitter* blitter, int x, int y, |
| 85 const uint8_t bits[], | 85 const uint8_t bits[], |
| 86 U8CPU left_mask, int rowBytes, | 86 uint8_t left_mask, ptrdiff_t rowBytes, |
| 87 U8CPU right_mask) { | 87 uint8_t right_mask) { |
| 88 int inFill = 0; | 88 int inFill = 0; |
| 89 int pos = 0; | 89 int pos = 0; |
| 90 | 90 |
| 91 while (--rowBytes >= 0) { | 91 while (--rowBytes >= 0) { |
| 92 unsigned b = *bits++ & left_mask; | 92 uint8_t b = *bits++ & left_mask; |
| 93 if (rowBytes == 0) { | 93 if (rowBytes == 0) { |
| 94 b &= right_mask; | 94 b &= right_mask; |
| 95 } | 95 } |
| 96 | 96 |
| 97 for (unsigned test = 0x80; test != 0; test >>= 1) { | 97 for (uint8_t test = 0x80U; test != 0; test >>= 1) { |
| 98 if (b & test) { | 98 if (b & test) { |
| 99 if (!inFill) { | 99 if (!inFill) { |
| 100 pos = x; | 100 pos = x; |
| 101 inFill = true; | 101 inFill = true; |
| 102 } | 102 } |
| 103 } else { | 103 } else { |
| 104 if (inFill) { | 104 if (inFill) { |
| 105 blitter->blitH(pos, y, x - pos); | 105 blitter->blitH(pos, y, x - pos); |
| 106 inFill = false; | 106 inFill = false; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 x += 1; | 109 x += 1; |
| 110 } | 110 } |
| 111 left_mask = 0xFF; | 111 left_mask = 0xFFU; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // final cleanup | 114 // final cleanup |
| 115 if (inFill) { | 115 if (inFill) { |
| 116 blitter->blitH(pos, y, x - pos); | 116 blitter->blitH(pos, y, x - pos); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // maskBitCount is the number of 1's to place in the mask. It must be in the ran
ge between 1 and 8. |
| 121 static uint8_t generate_right_mask(int maskBitCount) { |
| 122 return static_cast<uint8_t>(0xFF00U >> maskBitCount); |
| 123 } |
| 124 |
| 120 void SkBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { | 125 void SkBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 121 SkASSERT(mask.fBounds.contains(clip)); | 126 SkASSERT(mask.fBounds.contains(clip)); |
| 122 | 127 |
| 123 if (mask.fFormat == SkMask::kBW_Format) { | 128 if (mask.fFormat == SkMask::kBW_Format) { |
| 124 int cx = clip.fLeft; | 129 int cx = clip.fLeft; |
| 125 int cy = clip.fTop; | 130 int cy = clip.fTop; |
| 126 int maskLeft = mask.fBounds.fLeft; | 131 int maskLeft = mask.fBounds.fLeft; |
| 127 int mask_rowBytes = mask.fRowBytes; | 132 int maskRowBytes = mask.fRowBytes; |
| 128 int height = clip.height(); | 133 int height = clip.height(); |
| 129 | 134 |
| 130 const uint8_t* bits = mask.getAddr1(cx, cy); | 135 const uint8_t* bits = mask.getAddr1(cx, cy); |
| 131 | 136 |
| 137 SkDEBUGCODE(const uint8_t* endOfImage = |
| 138 mask.fImage + (mask.fBounds.height() - 1) * maskRowBytes |
| 139 + ((mask.fBounds.width() + 7) >> 3)); |
| 140 |
| 132 if (cx == maskLeft && clip.fRight == mask.fBounds.fRight) { | 141 if (cx == maskLeft && clip.fRight == mask.fBounds.fRight) { |
| 133 while (--height >= 0) { | 142 while (--height >= 0) { |
| 134 bits_to_runs(this, cx, cy, bits, 0xFF, mask_rowBytes, 0xFF); | 143 int affectedRightBit = mask.fBounds.width() - 1; |
| 135 bits += mask_rowBytes; | 144 ptrdiff_t rowBytes = (affectedRightBit >> 3) + 1; |
| 145 SkASSERT(bits + rowBytes <= endOfImage); |
| 146 U8CPU rightMask = generate_right_mask((affectedRightBit & 7) + 1
); |
| 147 bits_to_runs(this, cx, cy, bits, 0xFF, rowBytes, rightMask); |
| 148 bits += maskRowBytes; |
| 136 cy += 1; | 149 cy += 1; |
| 137 } | 150 } |
| 138 } else { | 151 } else { |
| 139 int left_edge = cx - maskLeft; | 152 // Bits is calculated as the offset into the mask at the point {cx,
cy} therfore, all |
| 140 SkASSERT(left_edge >= 0); | 153 // addressing into the bit mask is relative to that point. Since thi
s is an address |
| 141 int rite_edge = clip.fRight - maskLeft; | 154 // calculated from a arbitrary bit in that byte, calculate the left
most bit. |
| 142 SkASSERT(rite_edge > left_edge); | 155 int bitsLeft = cx - ((cx - maskLeft) & 7); |
| 143 | 156 |
| 144 int left_mask = 0xFF >> (left_edge & 7); | 157 // Everything is relative to the bitsLeft. |
| 145 int rite_mask = 0xFF << (8 - (rite_edge & 7)); | 158 int leftEdge = cx - bitsLeft; |
| 146 int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3); | 159 SkASSERT(leftEdge >= 0); |
| 160 int rightEdge = clip.fRight - bitsLeft; |
| 161 SkASSERT(rightEdge > leftEdge); |
| 147 | 162 |
| 148 // check for empty right mask, so we don't read off the end (or go s
lower than we need to) | 163 // Calculate left byte and mask |
| 149 if (rite_mask == 0) { | 164 const uint8_t* leftByte = bits; |
| 150 SkASSERT(full_runs >= 0); | 165 U8CPU leftMask = 0xFFU >> (leftEdge & 7); |
| 151 full_runs -= 1; | |
| 152 rite_mask = 0xFF; | |
| 153 } | |
| 154 if (left_mask == 0xFF) { | |
| 155 full_runs -= 1; | |
| 156 } | |
| 157 | 166 |
| 158 // back up manually so we can keep in sync with our byte-aligned src | 167 // Calculate right byte and mask |
| 159 // have cx reflect our actual starting x-coord | 168 int affectedRightBit = rightEdge - 1; |
| 160 cx -= left_edge & 7; | 169 const uint8_t* rightByte = bits + (affectedRightBit >> 3); |
| 170 U8CPU rightMask = generate_right_mask((affectedRightBit & 7) + 1); |
| 161 | 171 |
| 162 if (full_runs < 0) { | 172 // leftByte and rightByte are byte locations therefore, to get a cou
nt of bytes the |
| 163 SkASSERT((left_mask & rite_mask) != 0); | 173 // code must add one. |
| 164 while (--height >= 0) { | 174 ptrdiff_t rowBytes = rightByte - leftByte + 1; |
| 165 bits_to_runs(this, cx, cy, bits, left_mask, 1, rite_mask); | 175 |
| 166 bits += mask_rowBytes; | 176 while (--height >= 0) { |
| 167 cy += 1; | 177 SkASSERT(bits + rowBytes <= endOfImage); |
| 168 } | 178 bits_to_runs(this, bitsLeft, cy, bits, leftMask, rowBytes, right
Mask); |
| 169 } else { | 179 bits += maskRowBytes; |
| 170 while (--height >= 0) { | 180 cy += 1; |
| 171 bits_to_runs(this, cx, cy, bits, left_mask, full_runs + 2, r
ite_mask); | |
| 172 bits += mask_rowBytes; | |
| 173 cy += 1; | |
| 174 } | |
| 175 } | 181 } |
| 176 } | 182 } |
| 177 } else { | 183 } else { |
| 178 int width = clip.width(); | 184 int width = clip.width(); |
| 179 SkAutoSTMalloc<64, int16_t> runStorage(width + 1); | 185 SkAutoSTMalloc<64, int16_t> runStorage(width + 1); |
| 180 int16_t* runs = runStorage.get(); | 186 int16_t* runs = runStorage.get(); |
| 181 const uint8_t* aa = mask.getAddr8(clip.fLeft, clip.fTop); | 187 const uint8_t* aa = mask.getAddr8(clip.fLeft, clip.fTop); |
| 182 | 188 |
| 183 sk_memset16((uint16_t*)runs, 1, width); | 189 sk_memset16((uint16_t*)runs, 1, width); |
| 184 runs[width] = 0; | 190 runs[width] = 0; |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 fShaderContext->~Context(); | 974 fShaderContext->~Context(); |
| 969 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 975 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 970 if (nullptr == ctx) { | 976 if (nullptr == ctx) { |
| 971 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 977 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 972 // the in-place destructor. | 978 // the in-place destructor. |
| 973 new (fShaderContext) SkZeroShaderContext(*fShader, rec); | 979 new (fShaderContext) SkZeroShaderContext(*fShader, rec); |
| 974 return false; | 980 return false; |
| 975 } | 981 } |
| 976 return true; | 982 return true; |
| 977 } | 983 } |
| OLD | NEW |