Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/core/SkBlitter_Sprite.cpp

Issue 1887103003: spriteblitter for memcpy case (for all configs) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/core/SkImageInfo.h ('K') | « include/core/SkPixmap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (dst.info().profileType() != src.info().profileType()) {
53 return false;
54 }
55 if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFil ter()) {
56 return false;
57 }
58 if (0xFF != paint.getAlpha()) {
59 return false;
60 }
61 SkXfermode::Mode mode;
62 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
63 return false;
64 }
65 if (SkXfermode::kSrc_Mode == mode) {
66 return true;
67 }
68 if (SkXfermode::kSrcOver_Mode == mode && src.isOpaque()) {
69 return true;
70 }
71 return false;
72 }
73
74 SkSpriteBlitter_memcpy(const SkPixmap& src) : INHERITED(src) {}
75
76 void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) ove rride {
77 SkASSERT(Supports(dst, fSource, paint));
78 this->INHERITED::setup(dst, left, top, paint);
79 }
80
81 void blitRect(int x, int y, int width, int height) override {
82 SkASSERT(fDst.colorType() == fSource.colorType());
83 SkASSERT(width > 0 && height > 0);
84
85 void* dst = fDst.writable_addr(x, y);
86 const void* src = fSource.addr(x - fLeft, y - fTop);
87 size_t dstRB = fDst.rowBytes();
88 size_t srcRB = fSource.rowBytes();
89 size_t bytesToCopy = SkLeftShift(width, fSource.shiftPerPixel());
90
91 do {
92 memcpy(dst, src, bytesToCopy);
93 dst = (char*)dst + dstRB;
94 src = (const char*)src + srcRB;
95 } while (--height != 0);
96 }
97
98 typedef SkSpriteBlitter INHERITED;
99 };
100
101
41 // returning null means the caller will call SkBlitter::Choose() and 102 // returning null means the caller will call SkBlitter::Choose() and
42 // have wrapped the source bitmap inside a shader 103 // have wrapped the source bitmap inside a shader
43 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint, 104 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint,
44 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) { 105 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) {
45 /* We currently ignore antialiasing and filtertype, meaning we will take ou r 106 /* We currently ignore antialiasing and filtertype, meaning we will take ou r
46 special blitters regardless of these settings. Ignoring filtertype seems fine 107 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 108 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, 109 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 110 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 111 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 112 paint and return null if it is set, forcing the client to take the slow shader case
52 (which does respect soft edges). 113 (which does respect soft edges).
53 */ 114 */
54 SkASSERT(allocator != nullptr); 115 SkASSERT(allocator != nullptr);
55 116
56 SkSpriteBlitter* blitter; 117 SkSpriteBlitter* blitter;
57 118
58 switch (dst.colorType()) { 119 if (SkSpriteBlitter_memcpy::Supports(dst, source, paint)) {
59 case kRGB_565_SkColorType: 120 blitter = allocator->createT<SkSpriteBlitter_memcpy>(source);
60 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); 121 } else {
61 break; 122 switch (dst.colorType()) {
62 case kN32_SkColorType: 123 case kRGB_565_SkColorType:
63 if (dst.info().isSRGB()) { 124 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
64 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocator); 125 break;
65 } else { 126 case kN32_SkColorType:
66 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocator); 127 if (dst.info().isSRGB()) {
67 } 128 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocato r);
68 break; 129 } else {
69 case kRGBA_F16_SkColorType: 130 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocato r);
70 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator); 131 }
71 break; 132 break;
72 default: 133 case kRGBA_F16_SkColorType:
73 blitter = nullptr; 134 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator);
74 break; 135 break;
136 default:
137 blitter = nullptr;
138 break;
139 }
75 } 140 }
76 141
77 if (blitter) { 142 if (blitter) {
78 blitter->setup(dst, left, top, paint); 143 blitter->setup(dst, left, top, paint);
79 } 144 }
80 return blitter; 145 return blitter;
81 } 146 }
OLDNEW
« include/core/SkImageInfo.h ('K') | « include/core/SkPixmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698