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 "SkSmallAllocator.h" | 8 #include "SkSmallAllocator.h" |
9 #include "SkSpriteBlitter.h" | 9 #include "SkSpriteBlitter.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 SkDEBUGFAIL("how did we get here?"); | 31 SkDEBUGFAIL("how did we get here?"); |
32 } | 32 } |
33 | 33 |
34 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { | 34 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { |
35 SkDEBUGFAIL("how did we get here?"); | 35 SkDEBUGFAIL("how did we get here?"); |
36 } | 36 } |
37 #endif | 37 #endif |
38 | 38 |
39 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
41 // Only valid if... | |
42 // 1. src == dst format | |
43 // 2. paint has no modifiers (i.e. alpha, colorfilter, etc.) | |
44 // 3. xfermode needs no blending: e.g. kSrc_Mode or kSrcOver_Mode + opaque src | |
45 // | |
46 class SkSpriteBlitter_memcpy : public SkSpriteBlitter { | |
47 public: | |
48 static bool Supports(const SkPixmap& dst, const SkPixmap& src, const SkPaint & paint) { | |
49 if (dst.colorType() != src.colorType()) { | |
50 return false; | |
51 } | |
52 if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFil ter()) { | |
53 return false; | |
54 } | |
55 if (0xFF != paint.getAlpha()) { | |
56 return false; | |
57 } | |
58 SkXfermode::Mode mode; | |
59 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) { | |
60 return false; | |
61 } | |
62 if (SkXfermode::kSrc_Mode == mode) { | |
63 return true; | |
64 } | |
65 if (SkXfermode::kSrcOver_Mode == mode && src.isOpaque()) { | |
66 return true; | |
67 } | |
68 return false; | |
69 } | |
70 | |
71 SkSpriteBlitter_memcpy(const SkPixmap& src) : INHERITED(src) {} | |
72 | |
73 void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) ove rride { | |
74 SkASSERT(Supports(dst, fSource, paint)); | |
75 this->INHERITED::setup(dst, left, top, paint); | |
76 } | |
77 | |
78 void blitRect(int x, int y, int width, int height) override { | |
79 SkASSERT(fDst.colorType() == fSource.colorType()); | |
80 SkASSERT(width > 0 && height > 0); | |
81 | |
82 void* dst = fDst.writable_addr(x, y); | |
mtklein
2016/04/15 13:29:21
It might be clearer to cast to char* early:
au
reed1
2016/04/15 13:49:10
Done.
| |
83 const void* src = fSource.addr(x - fLeft, y - fTop); | |
84 size_t dstRB = fDst.rowBytes(); | |
85 size_t srcRB = fSource.rowBytes(); | |
86 size_t bytesToCopy = SkLeftShift(width, fSource.shiftPerPixel()); | |
mtklein
2016/04/15 13:29:21
Seems like it's not sensible for width to be negat
reed1
2016/04/15 13:49:10
Done.
| |
87 | |
88 do { | |
89 memcpy(dst, src, bytesToCopy); | |
90 dst = (char*)dst + dstRB; | |
91 src = (const char*)src + srcRB; | |
92 } while (--height != 0); | |
93 } | |
94 | |
95 typedef SkSpriteBlitter INHERITED; | |
96 }; | |
97 | |
98 | |
41 // returning null means the caller will call SkBlitter::Choose() and | 99 // returning null means the caller will call SkBlitter::Choose() and |
42 // have wrapped the source bitmap inside a shader | 100 // have wrapped the source bitmap inside a shader |
43 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint, | 101 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint, |
44 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) { | 102 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) { |
45 /* We currently ignore antialiasing and filtertype, meaning we will take ou r | 103 /* We currently ignore antialiasing and filtertype, meaning we will take ou r |
46 special blitters regardless of these settings. Ignoring filtertype seems fine | 104 special blitters regardless of these settings. Ignoring filtertype seems fine |
47 since by definition there is no scale in the matrix. Ignoring antialiasi ng is | 105 since by definition there is no scale in the matrix. Ignoring antialiasi ng is |
48 a bit of a hack, since we "could" pass in the fractional left/top for th e bitmap, | 106 a bit of a hack, since we "could" pass in the fractional left/top for th e bitmap, |
49 and respect that by blending the edges of the bitmap against the device. To support | 107 and respect that by blending the edges of the bitmap against the device. To support |
50 this we could either add more special blitters here, or detect antialias ing in the | 108 this we could either add more special blitters here, or detect antialias ing in the |
51 paint and return null if it is set, forcing the client to take the slow shader case | 109 paint and return null if it is set, forcing the client to take the slow shader case |
52 (which does respect soft edges). | 110 (which does respect soft edges). |
53 */ | 111 */ |
54 SkASSERT(allocator != nullptr); | 112 SkASSERT(allocator != nullptr); |
55 | 113 |
56 SkSpriteBlitter* blitter; | 114 SkSpriteBlitter* blitter; |
57 | 115 |
58 switch (dst.colorType()) { | 116 if (SkSpriteBlitter_memcpy::Supports(dst, source, paint)) { |
59 case kRGB_565_SkColorType: | 117 blitter = allocator->createT<SkSpriteBlitter_memcpy>(source); |
60 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); | 118 } else { |
61 break; | 119 switch (dst.colorType()) { |
62 case kN32_SkColorType: | 120 case kRGB_565_SkColorType: |
63 if (dst.info().isSRGB()) { | 121 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); |
64 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocator); | 122 break; |
65 } else { | 123 case kN32_SkColorType: |
66 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocator); | 124 if (dst.info().isSRGB()) { |
67 } | 125 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocato r); |
68 break; | 126 } else { |
69 case kRGBA_F16_SkColorType: | 127 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocato r); |
70 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator); | 128 } |
71 break; | 129 break; |
72 default: | 130 case kRGBA_F16_SkColorType: |
73 blitter = nullptr; | 131 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator); |
74 break; | 132 break; |
133 default: | |
134 blitter = nullptr; | |
135 break; | |
136 } | |
75 } | 137 } |
76 | 138 |
77 if (blitter) { | 139 if (blitter) { |
78 blitter->setup(dst, left, top, paint); | 140 blitter->setup(dst, left, top, paint); |
79 } | 141 } |
80 return blitter; | 142 return blitter; |
81 } | 143 } |
OLD | NEW |