| 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 |
|
| 8 |
#include "include/core/SkColorType.h" |
| 9 |
#include "include/core/SkPaint.h" |
| 10 |
#include "include/core/SkPixmap.h" |
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
#include "include/private/base/SkCPUTypes.h" |
| 13 |
#include "src/base/SkArenaAlloc.h" |
| 14 |
#include "src/core/SkBlitRow.h" |
| 15 |
#include "src/core/SkSpriteBlitter.h" |
| 16 |
|
| 17 |
#include <cstddef> |
| 18 |
#include <cstdint> |
| 19 |
|
| 20 |
/////////////////////////////////////////////////////////////////////////////// |
| 21 |
|
| 22 |
class Sprite_D32_S32 : public SkSpriteBlitter { |
| 23 |
public: |
| 24 |
Sprite_D32_S32(const SkPixmap& src, U8CPU alpha) : INHERITED(src) { |
| 25 |
SkASSERT(src.colorType() == kN32_SkColorType); |
| 26 |
|
| 27 |
unsigned flags32 = 0; |
| 28 |
if (255 != alpha) { |
| 29 |
flags32 |= SkBlitRow::kGlobalAlpha_Flag32; |
| 30 |
} |
| 31 |
if (!src.isOpaque()) { |
| 32 |
flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; |
| 33 |
} |
| 34 |
|
| 35 |
fProc32 = SkBlitRow::Factory32(flags32); |
| 36 |
fAlpha = alpha; |
| 37 |
} |
| 38 |
|
| 39 |
void blitRect(int x, int y, int width, int height) override { |
| 40 |
SkASSERT(width > 0 && height > 0); |
| 41 |
uint32_t* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 42 |
const uint32_t* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop); |
| 43 |
size_t dstRB = fDst.rowBytes(); |
| 44 |
size_t srcRB = fSource.rowBytes(); |
| 45 |
SkBlitRow::Proc32 proc = fProc32; |
| 46 |
U8CPU alpha = fAlpha; |
| 47 |
|
| 48 |
do { |
| 49 |
proc(dst, src, width, alpha); |
| 50 |
dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
| 51 |
src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); |
| 52 |
} while (--height != 0); |
| 53 |
} |
| 54 |
|
| 55 |
private: |
| 56 |
SkBlitRow::Proc32 fProc32; |
| 57 |
U8CPU fAlpha; |
| 58 |
|
| 59 |
using INHERITED = SkSpriteBlitter; |
| 60 |
}; |
| 61 |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////// |
| 63 |
|
| 64 |
SkSpriteBlitter* SkSpriteBlitter::ChooseL32(const SkPixmap& source, const SkPaint& paint, |
| 65 |
SkArenaAlloc* allocator) { |
| 66 |
SkASSERT(allocator != nullptr); |
| 67 |
|
| 68 |
if (paint.getColorFilter() != nullptr) { |
| 69 |
return nullptr; |
| 70 |
} |
| 71 |
if (paint.getMaskFilter() != nullptr) { |
| 72 |
return nullptr; |
| 73 |
} |
| 74 |
if (source.colorType() == kN32_SkColorType && paint.isSrcOver()) { |
| 75 |
// this can handle alpha, but not xfermode |
| 76 |
return allocator->make<Sprite_D32_S32>(source, paint.getAlpha()); |
| 77 |
} |
| 78 |
return nullptr; |
| 79 |
} |