2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkSpriteBlitter.h"
9 #include "SkSpanProcs.h"
10 #include "SkTemplates.h"
11 #include "SkXfermode.h"
13 class Sprite_4f : public SkSpriteBlitter {
15 Sprite_4f(const SkPixmap& src, const SkPaint& paint) : INHERITED(src) {
16 fXfer = paint.getXfermode();
17 fLoader = SkLoadSpanProc_Choose(src.info());
18 fFilter = SkFilterSpanProc_Choose(paint);
19 fBuffer.reset(src.width());
24 SkLoadSpanProc fLoader;
25 SkFilterSpanProc fFilter;
26 SkAutoTMalloc<SkPM4f> fBuffer;
29 typedef SkSpriteBlitter INHERITED;
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
34 class Sprite_F16 : public Sprite_4f {
36 Sprite_F16(const SkPixmap& src, const SkPaint& paint) : INHERITED(src, paint) {
39 flags |= SkXfermode::kSrcIsOpaque_F16Flag;
41 fWriter = SkXfermode::GetF16Proc(fXfer, flags);
44 void blitRect(int x, int y, int width, int height) override {
45 SkASSERT(width > 0 && height > 0);
46 uint64_t* SK_RESTRICT dst = fDst.writable_addr64(x, y);
47 size_t dstRB = fDst.rowBytes();
49 for (int bottom = y + height; y < bottom; ++y) {
50 fLoader(fSource, x - fLeft, y - fTop, fBuffer, width);
51 fFilter(*fPaint, fBuffer, width);
52 fWriter(fXfer, dst, fBuffer, width, nullptr);
53 dst = (uint64_t* SK_RESTRICT)((char*)dst + dstRB);
58 SkXfermode::F16Proc fWriter;
60 typedef Sprite_4f INHERITED;
64 SkSpriteBlitter* SkSpriteBlitter::ChooseF16(const SkPixmap& source, const SkPaint& paint,
65 SkTBlitterAllocator* allocator) {
66 SkASSERT(allocator != nullptr);
68 if (paint.getMaskFilter() != nullptr) {
72 switch (source.colorType()) {
73 case kN32_SkColorType:
74 case kRGBA_F16_SkColorType:
75 return allocator->createT<Sprite_F16>(source, paint);
81 ///////////////////////////////////////////////////////////////////////////////////////////////////
83 class Sprite_sRGB : public Sprite_4f {
85 Sprite_sRGB(const SkPixmap& src, const SkPaint& paint) : INHERITED(src, paint) {
86 uint32_t flags = SkXfermode::kDstIsSRGB_D32Flag;
88 flags |= SkXfermode::kSrcIsOpaque_D32Flag;
90 fWriter = SkXfermode::GetD32Proc(fXfer, flags);
93 void blitRect(int x, int y, int width, int height) override {
94 SkASSERT(width > 0 && height > 0);
95 uint32_t* SK_RESTRICT dst = fDst.writable_addr32(x, y);
96 size_t dstRB = fDst.rowBytes();
98 for (int bottom = y + height; y < bottom; ++y) {
99 fLoader(fSource, x - fLeft, y - fTop, fBuffer, width);
100 fFilter(*fPaint, fBuffer, width);
101 fWriter(fXfer, dst, fBuffer, width, nullptr);
102 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB);
107 SkXfermode::D32Proc fWriter;
110 typedef Sprite_4f INHERITED;
114 SkSpriteBlitter* SkSpriteBlitter::ChooseS32(const SkPixmap& source, const SkPaint& paint,
115 SkTBlitterAllocator* allocator) {
116 SkASSERT(allocator != nullptr);
118 if (paint.getMaskFilter() != nullptr) {
122 switch (source.colorType()) {
123 case kN32_SkColorType:
124 case kRGBA_F16_SkColorType:
125 return allocator->createT<Sprite_sRGB>(source, paint);