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

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

Issue 1996683003: Srcover for sprite blitters. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove srgb default. Created 4 years, 7 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
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.h » ('j') | 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 "SkOpts.h"
8 #include "SkSmallAllocator.h" 9 #include "SkSmallAllocator.h"
9 #include "SkSpriteBlitter.h" 10 #include "SkSpriteBlitter.h"
10 11
11 SkSpriteBlitter::SkSpriteBlitter(const SkPixmap& source) : fSource(source) {} 12 SkSpriteBlitter::SkSpriteBlitter(const SkPixmap& source) : fSource(source) {}
12 13
13 void SkSpriteBlitter::setup(const SkPixmap& dst, int left, int top, const SkPain t& paint) { 14 void SkSpriteBlitter::setup(const SkPixmap& dst, int left, int top, const SkPain t& paint) {
14 fDst = dst; 15 fDst = dst;
15 fLeft = left; 16 fLeft = left;
16 fTop = top; 17 fTop = top;
17 fPaint = &paint; 18 fPaint = &paint;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 while (--height >= 0) { 93 while (--height >= 0) {
93 memcpy(dst, src, bytesToCopy); 94 memcpy(dst, src, bytesToCopy);
94 dst += dstRB; 95 dst += dstRB;
95 src += srcRB; 96 src += srcRB;
96 } 97 }
97 } 98 }
98 99
99 typedef SkSpriteBlitter INHERITED; 100 typedef SkSpriteBlitter INHERITED;
100 }; 101 };
101 102
103 class SkSpriteBlitter_SrcOver : public SkSpriteBlitter {
104 public:
105 static bool Supports(const SkPixmap& dst, const SkPixmap& src, const SkPaint & paint) {
106 if (dst.colorType() != src.colorType() || dst.colorType() != kN32_SkColo rType) {
107 return false;
108 }
109 if (dst.info().profileType() != src.info().profileType()
msarett 2016/05/20 15:46:58 Can you check the gDefaultProfileIsSRGB flag direc
110 || dst.info().profileType() != kSRGB_SkColorProfileType) {
111 return false;
112 }
113 if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFil ter()) {
114 return false;
115 }
116 if (0xFF != paint.getAlpha()) {
117 return false;
118 }
119 SkXfermode::Mode mode;
120 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
121 return false;
122 }
123 return SkXfermode::kSrcOver_Mode == mode;
124 }
125
126 SkSpriteBlitter_SrcOver(const SkPixmap& src) : INHERITED(src) {}
127
128 void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) ove rride {
129 SkASSERT(Supports(dst, fSource, paint));
130 this->INHERITED::setup(dst, left, top, paint);
131 SkXfermode::Mode mode;
132 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
133 SkFAIL("Should never happen.");
134 }
135 SkASSERT(SkXfermode::kSrcOver_Mode == mode);
136 }
137
138 void blitRect(int x, int y, int width, int height) override {
139 SkASSERT(fDst.colorType() == fSource.colorType());
140 SkASSERT(fDst.info().profileType() == fSource.info().profileType());
141 SkASSERT(width > 0 && height > 0);
142
143 uint32_t* dst = fDst.writable_addr32(x, y);
144 const uint32_t* src = fSource.addr32(x - fLeft, y - fTop);
145 const int dstRB = fDst.rowBytesAsPixels();
146 const int srcRB = fSource.rowBytesAsPixels();
147
148 while (height --> 0) {
149 SkOpts::srcover_srgb_srgb(dst, src, width, width);
150 dst += dstRB;
151 src += srcRB;
152 }
153 }
154
155 typedef SkSpriteBlitter INHERITED;
156 };
102 157
103 // returning null means the caller will call SkBlitter::Choose() and 158 // returning null means the caller will call SkBlitter::Choose() and
104 // have wrapped the source bitmap inside a shader 159 // have wrapped the source bitmap inside a shader
105 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint, 160 SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint,
106 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) { 161 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocato r) {
107 /* We currently ignore antialiasing and filtertype, meaning we will take ou r 162 /* We currently ignore antialiasing and filtertype, meaning we will take ou r
108 special blitters regardless of these settings. Ignoring filtertype seems fine 163 special blitters regardless of these settings. Ignoring filtertype seems fine
109 since by definition there is no scale in the matrix. Ignoring antialiasi ng is 164 since by definition there is no scale in the matrix. Ignoring antialiasi ng is
110 a bit of a hack, since we "could" pass in the fractional left/top for th e bitmap, 165 a bit of a hack, since we "could" pass in the fractional left/top for th e bitmap,
111 and respect that by blending the edges of the bitmap against the device. To support 166 and respect that by blending the edges of the bitmap against the device. To support
112 this we could either add more special blitters here, or detect antialias ing in the 167 this we could either add more special blitters here, or detect antialias ing in the
113 paint and return null if it is set, forcing the client to take the slow shader case 168 paint and return null if it is set, forcing the client to take the slow shader case
114 (which does respect soft edges). 169 (which does respect soft edges).
115 */ 170 */
116 SkASSERT(allocator != nullptr); 171 SkASSERT(allocator != nullptr);
117 172
118 SkSpriteBlitter* blitter; 173 SkSpriteBlitter* blitter = nullptr;
119 174
120 if (SkSpriteBlitter_memcpy::Supports(dst, source, paint)) { 175 if (SkSpriteBlitter_memcpy::Supports(dst, source, paint)) {
121 blitter = allocator->createT<SkSpriteBlitter_memcpy>(source); 176 blitter = allocator->createT<SkSpriteBlitter_memcpy>(source);
177 } else if (SkSpriteBlitter_SrcOver::Supports(dst, source, paint)) {
178 blitter = allocator->createT<SkSpriteBlitter_SrcOver>(source);
122 } else { 179 } else {
123 switch (dst.colorType()) { 180 switch (dst.colorType()) {
124 case kRGB_565_SkColorType: 181 case kRGB_565_SkColorType:
125 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); 182 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
126 break; 183 break;
127 case kN32_SkColorType: 184 case kN32_SkColorType:
128 if (dst.info().isSRGB()) { 185 if (dst.info().isSRGB()) {
129 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocato r); 186 blitter = SkSpriteBlitter::ChooseS32(source, paint, allocato r);
130 } else { 187 } else {
131 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocato r); 188 blitter = SkSpriteBlitter::ChooseL32(source, paint, allocato r);
132 } 189 }
133 break; 190 break;
134 case kRGBA_F16_SkColorType: 191 case kRGBA_F16_SkColorType:
135 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator); 192 blitter = SkSpriteBlitter::ChooseF16(source, paint, allocator);
136 break; 193 break;
137 default: 194 default:
138 blitter = nullptr;
139 break; 195 break;
140 } 196 }
141 } 197 }
142 198
143 if (blitter) { 199 if (blitter) {
144 blitter->setup(dst, left, top, paint); 200 blitter->setup(dst, left, top, paint);
145 } 201 }
146 return blitter; 202 return blitter;
147 } 203 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698