Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "SkSpriteBlitter.h" |
michael@0 | 11 | #include "SkBlitRow.h" |
michael@0 | 12 | #include "SkColorFilter.h" |
michael@0 | 13 | #include "SkColorPriv.h" |
michael@0 | 14 | #include "SkTemplates.h" |
michael@0 | 15 | #include "SkUtils.h" |
michael@0 | 16 | #include "SkXfermode.h" |
michael@0 | 17 | |
michael@0 | 18 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 19 | |
michael@0 | 20 | class Sprite_D32_S32 : public SkSpriteBlitter { |
michael@0 | 21 | public: |
michael@0 | 22 | Sprite_D32_S32(const SkBitmap& src, U8CPU alpha) : INHERITED(src) { |
michael@0 | 23 | SkASSERT(src.colorType() == kPMColor_SkColorType); |
michael@0 | 24 | |
michael@0 | 25 | unsigned flags32 = 0; |
michael@0 | 26 | if (255 != alpha) { |
michael@0 | 27 | flags32 |= SkBlitRow::kGlobalAlpha_Flag32; |
michael@0 | 28 | } |
michael@0 | 29 | if (!src.isOpaque()) { |
michael@0 | 30 | flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | fProc32 = SkBlitRow::Factory32(flags32); |
michael@0 | 34 | fAlpha = alpha; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | virtual void blitRect(int x, int y, int width, int height) { |
michael@0 | 38 | SkASSERT(width > 0 && height > 0); |
michael@0 | 39 | uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
michael@0 | 40 | const uint32_t* SK_RESTRICT src = fSource->getAddr32(x - fLeft, |
michael@0 | 41 | y - fTop); |
michael@0 | 42 | size_t dstRB = fDevice->rowBytes(); |
michael@0 | 43 | size_t srcRB = fSource->rowBytes(); |
michael@0 | 44 | SkBlitRow::Proc32 proc = fProc32; |
michael@0 | 45 | U8CPU alpha = fAlpha; |
michael@0 | 46 | |
michael@0 | 47 | do { |
michael@0 | 48 | proc(dst, src, width, alpha); |
michael@0 | 49 | dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
michael@0 | 50 | src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); |
michael@0 | 51 | } while (--height != 0); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | private: |
michael@0 | 55 | SkBlitRow::Proc32 fProc32; |
michael@0 | 56 | U8CPU fAlpha; |
michael@0 | 57 | |
michael@0 | 58 | typedef SkSpriteBlitter INHERITED; |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 62 | |
michael@0 | 63 | class Sprite_D32_XferFilter : public SkSpriteBlitter { |
michael@0 | 64 | public: |
michael@0 | 65 | Sprite_D32_XferFilter(const SkBitmap& source, const SkPaint& paint) |
michael@0 | 66 | : SkSpriteBlitter(source) { |
michael@0 | 67 | fColorFilter = paint.getColorFilter(); |
michael@0 | 68 | SkSafeRef(fColorFilter); |
michael@0 | 69 | |
michael@0 | 70 | fXfermode = paint.getXfermode(); |
michael@0 | 71 | SkSafeRef(fXfermode); |
michael@0 | 72 | |
michael@0 | 73 | fBufferSize = 0; |
michael@0 | 74 | fBuffer = NULL; |
michael@0 | 75 | |
michael@0 | 76 | unsigned flags32 = 0; |
michael@0 | 77 | if (255 != paint.getAlpha()) { |
michael@0 | 78 | flags32 |= SkBlitRow::kGlobalAlpha_Flag32; |
michael@0 | 79 | } |
michael@0 | 80 | if (!source.isOpaque()) { |
michael@0 | 81 | flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | fProc32 = SkBlitRow::Factory32(flags32); |
michael@0 | 85 | fAlpha = paint.getAlpha(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | virtual ~Sprite_D32_XferFilter() { |
michael@0 | 89 | delete[] fBuffer; |
michael@0 | 90 | SkSafeUnref(fXfermode); |
michael@0 | 91 | SkSafeUnref(fColorFilter); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | virtual void setup(const SkBitmap& device, int left, int top, |
michael@0 | 95 | const SkPaint& paint) { |
michael@0 | 96 | this->INHERITED::setup(device, left, top, paint); |
michael@0 | 97 | |
michael@0 | 98 | int width = device.width(); |
michael@0 | 99 | if (width > fBufferSize) { |
michael@0 | 100 | fBufferSize = width; |
michael@0 | 101 | delete[] fBuffer; |
michael@0 | 102 | fBuffer = new SkPMColor[width]; |
michael@0 | 103 | } |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | protected: |
michael@0 | 107 | SkColorFilter* fColorFilter; |
michael@0 | 108 | SkXfermode* fXfermode; |
michael@0 | 109 | int fBufferSize; |
michael@0 | 110 | SkPMColor* fBuffer; |
michael@0 | 111 | SkBlitRow::Proc32 fProc32; |
michael@0 | 112 | U8CPU fAlpha; |
michael@0 | 113 | |
michael@0 | 114 | private: |
michael@0 | 115 | typedef SkSpriteBlitter INHERITED; |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 119 | |
michael@0 | 120 | class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { |
michael@0 | 121 | public: |
michael@0 | 122 | Sprite_D32_S32A_XferFilter(const SkBitmap& source, const SkPaint& paint) |
michael@0 | 123 | : Sprite_D32_XferFilter(source, paint) {} |
michael@0 | 124 | |
michael@0 | 125 | virtual void blitRect(int x, int y, int width, int height) { |
michael@0 | 126 | SkASSERT(width > 0 && height > 0); |
michael@0 | 127 | uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
michael@0 | 128 | const uint32_t* SK_RESTRICT src = fSource->getAddr32(x - fLeft, |
michael@0 | 129 | y - fTop); |
michael@0 | 130 | size_t dstRB = fDevice->rowBytes(); |
michael@0 | 131 | size_t srcRB = fSource->rowBytes(); |
michael@0 | 132 | SkColorFilter* colorFilter = fColorFilter; |
michael@0 | 133 | SkXfermode* xfermode = fXfermode; |
michael@0 | 134 | |
michael@0 | 135 | do { |
michael@0 | 136 | const SkPMColor* tmp = src; |
michael@0 | 137 | |
michael@0 | 138 | if (NULL != colorFilter) { |
michael@0 | 139 | colorFilter->filterSpan(src, width, fBuffer); |
michael@0 | 140 | tmp = fBuffer; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | if (NULL != xfermode) { |
michael@0 | 144 | xfermode->xfer32(dst, tmp, width, NULL); |
michael@0 | 145 | } else { |
michael@0 | 146 | fProc32(dst, tmp, width, fAlpha); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
michael@0 | 150 | src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); |
michael@0 | 151 | } while (--height != 0); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | private: |
michael@0 | 155 | typedef Sprite_D32_XferFilter INHERITED; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | static void fillbuffer(SkPMColor* SK_RESTRICT dst, |
michael@0 | 159 | const SkPMColor16* SK_RESTRICT src, int count) { |
michael@0 | 160 | SkASSERT(count > 0); |
michael@0 | 161 | |
michael@0 | 162 | do { |
michael@0 | 163 | *dst++ = SkPixel4444ToPixel32(*src++); |
michael@0 | 164 | } while (--count != 0); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { |
michael@0 | 168 | public: |
michael@0 | 169 | Sprite_D32_S4444_XferFilter(const SkBitmap& source, const SkPaint& paint) |
michael@0 | 170 | : Sprite_D32_XferFilter(source, paint) {} |
michael@0 | 171 | |
michael@0 | 172 | virtual void blitRect(int x, int y, int width, int height) { |
michael@0 | 173 | SkASSERT(width > 0 && height > 0); |
michael@0 | 174 | SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
michael@0 | 175 | const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, |
michael@0 | 176 | y - fTop); |
michael@0 | 177 | size_t dstRB = fDevice->rowBytes(); |
michael@0 | 178 | size_t srcRB = fSource->rowBytes(); |
michael@0 | 179 | SkPMColor* SK_RESTRICT buffer = fBuffer; |
michael@0 | 180 | SkColorFilter* colorFilter = fColorFilter; |
michael@0 | 181 | SkXfermode* xfermode = fXfermode; |
michael@0 | 182 | |
michael@0 | 183 | do { |
michael@0 | 184 | fillbuffer(buffer, src, width); |
michael@0 | 185 | |
michael@0 | 186 | if (NULL != colorFilter) { |
michael@0 | 187 | colorFilter->filterSpan(buffer, width, buffer); |
michael@0 | 188 | } |
michael@0 | 189 | if (NULL != xfermode) { |
michael@0 | 190 | xfermode->xfer32(dst, buffer, width, NULL); |
michael@0 | 191 | } else { |
michael@0 | 192 | fProc32(dst, buffer, width, fAlpha); |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
michael@0 | 196 | src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
michael@0 | 197 | } while (--height != 0); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | private: |
michael@0 | 201 | typedef Sprite_D32_XferFilter INHERITED; |
michael@0 | 202 | }; |
michael@0 | 203 | |
michael@0 | 204 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 205 | |
michael@0 | 206 | static void src_row(SkPMColor* SK_RESTRICT dst, |
michael@0 | 207 | const SkPMColor16* SK_RESTRICT src, int count) { |
michael@0 | 208 | do { |
michael@0 | 209 | *dst = SkPixel4444ToPixel32(*src); |
michael@0 | 210 | src += 1; |
michael@0 | 211 | dst += 1; |
michael@0 | 212 | } while (--count != 0); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { |
michael@0 | 216 | public: |
michael@0 | 217 | Sprite_D32_S4444_Opaque(const SkBitmap& source) : SkSpriteBlitter(source) {} |
michael@0 | 218 | |
michael@0 | 219 | virtual void blitRect(int x, int y, int width, int height) { |
michael@0 | 220 | SkASSERT(width > 0 && height > 0); |
michael@0 | 221 | SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
michael@0 | 222 | const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, |
michael@0 | 223 | y - fTop); |
michael@0 | 224 | size_t dstRB = fDevice->rowBytes(); |
michael@0 | 225 | size_t srcRB = fSource->rowBytes(); |
michael@0 | 226 | |
michael@0 | 227 | do { |
michael@0 | 228 | src_row(dst, src, width); |
michael@0 | 229 | dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
michael@0 | 230 | src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
michael@0 | 231 | } while (--height != 0); |
michael@0 | 232 | } |
michael@0 | 233 | }; |
michael@0 | 234 | |
michael@0 | 235 | static void srcover_row(SkPMColor* SK_RESTRICT dst, |
michael@0 | 236 | const SkPMColor16* SK_RESTRICT src, int count) { |
michael@0 | 237 | do { |
michael@0 | 238 | *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); |
michael@0 | 239 | src += 1; |
michael@0 | 240 | dst += 1; |
michael@0 | 241 | } while (--count != 0); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | class Sprite_D32_S4444 : public SkSpriteBlitter { |
michael@0 | 245 | public: |
michael@0 | 246 | Sprite_D32_S4444(const SkBitmap& source) : SkSpriteBlitter(source) {} |
michael@0 | 247 | |
michael@0 | 248 | virtual void blitRect(int x, int y, int width, int height) { |
michael@0 | 249 | SkASSERT(width > 0 && height > 0); |
michael@0 | 250 | SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
michael@0 | 251 | const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, |
michael@0 | 252 | y - fTop); |
michael@0 | 253 | size_t dstRB = fDevice->rowBytes(); |
michael@0 | 254 | size_t srcRB = fSource->rowBytes(); |
michael@0 | 255 | |
michael@0 | 256 | do { |
michael@0 | 257 | srcover_row(dst, src, width); |
michael@0 | 258 | dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
michael@0 | 259 | src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
michael@0 | 260 | } while (--height != 0); |
michael@0 | 261 | } |
michael@0 | 262 | }; |
michael@0 | 263 | |
michael@0 | 264 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 265 | |
michael@0 | 266 | SkSpriteBlitter* SkSpriteBlitter::ChooseD32(const SkBitmap& source, const SkPaint& paint, |
michael@0 | 267 | SkTBlitterAllocator* allocator) { |
michael@0 | 268 | SkASSERT(allocator != NULL); |
michael@0 | 269 | |
michael@0 | 270 | if (paint.getMaskFilter() != NULL) { |
michael@0 | 271 | return NULL; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | U8CPU alpha = paint.getAlpha(); |
michael@0 | 275 | SkXfermode* xfermode = paint.getXfermode(); |
michael@0 | 276 | SkColorFilter* filter = paint.getColorFilter(); |
michael@0 | 277 | SkSpriteBlitter* blitter = NULL; |
michael@0 | 278 | |
michael@0 | 279 | switch (source.colorType()) { |
michael@0 | 280 | case kARGB_4444_SkColorType: |
michael@0 | 281 | if (alpha != 0xFF) { |
michael@0 | 282 | return NULL; // we only have opaque sprites |
michael@0 | 283 | } |
michael@0 | 284 | if (xfermode || filter) { |
michael@0 | 285 | blitter = allocator->createT<Sprite_D32_S4444_XferFilter>(source, paint); |
michael@0 | 286 | } else if (source.isOpaque()) { |
michael@0 | 287 | blitter = allocator->createT<Sprite_D32_S4444_Opaque>(source); |
michael@0 | 288 | } else { |
michael@0 | 289 | blitter = allocator->createT<Sprite_D32_S4444>(source); |
michael@0 | 290 | } |
michael@0 | 291 | break; |
michael@0 | 292 | case kPMColor_SkColorType: |
michael@0 | 293 | if (xfermode || filter) { |
michael@0 | 294 | if (255 == alpha) { |
michael@0 | 295 | // this can handle xfermode or filter, but not alpha |
michael@0 | 296 | blitter = allocator->createT<Sprite_D32_S32A_XferFilter>(source, paint); |
michael@0 | 297 | } |
michael@0 | 298 | } else { |
michael@0 | 299 | // this can handle alpha, but not xfermode or filter |
michael@0 | 300 | blitter = allocator->createT<Sprite_D32_S32>(source, alpha); |
michael@0 | 301 | } |
michael@0 | 302 | break; |
michael@0 | 303 | default: |
michael@0 | 304 | break; |
michael@0 | 305 | } |
michael@0 | 306 | return blitter; |
michael@0 | 307 | } |