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

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

Issue 1775963002: Bilerp + mirror + perspective (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments. Created 4 years, 9 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 | « gyp/core.gypi ('k') | src/core/SkBitmapProcState.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 2011 Google Inc. 2 * Copyright 2011 Google Inc.
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 "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkBitmapProvider.h" 10 #include "SkBitmapProvider.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 if (1 == fInfo->fPixmap.height() && only_scale_and_translate(this->getTo talInverse())) { 41 if (1 == fInfo->fPixmap.height() && only_scale_and_translate(this->getTo talInverse())) {
42 fFlags |= SkShader::kConstInY32_Flag; 42 fFlags |= SkShader::kConstInY32_Flag;
43 } 43 }
44 } 44 }
45 45
46 ~BitmapProcInfoContext() override { 46 ~BitmapProcInfoContext() override {
47 fInfo->~SkBitmapProcInfo(); 47 fInfo->~SkBitmapProcInfo();
48 } 48 }
49 49
50 uint32_t getFlags() const override { return fFlags; } 50 uint32_t getFlags() const override { return fFlags; }
51 51
52 private: 52 private:
53 SkBitmapProcInfo* fInfo; 53 SkBitmapProcInfo* fInfo;
54 uint32_t fFlags; 54 uint32_t fFlags;
55 55
56 typedef SkShader::Context INHERITED; 56 typedef SkShader::Context INHERITED;
57 }; 57 };
58 58
59 //////////////////////////////////////////////////////////////////////////////// /////////////////// 59 //////////////////////////////////////////////////////////////////////////////// ///////////////////
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #include "SkXfermode.h" 116 #include "SkXfermode.h"
117 117
118 class LinearPipelineContext : public BitmapProcInfoContext { 118 class LinearPipelineContext : public BitmapProcInfoContext {
119 public: 119 public:
120 LinearPipelineContext(const SkShader& shader, const SkShader::ContextRec& re c, 120 LinearPipelineContext(const SkShader& shader, const SkShader::ContextRec& re c,
121 SkBitmapProcInfo* info) 121 SkBitmapProcInfo* info)
122 : INHERITED(shader, rec, info) 122 : INHERITED(shader, rec, info)
123 { 123 {
124 // Need to ensure that our pipeline is created at a 16byte aligned addre ss 124 // Need to ensure that our pipeline is created at a 16byte aligned addre ss
125 fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fStorage); 125 fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fStorage);
126 new (fPipeline) SkLinearBitmapPipeline(info->fInvMatrix, info->fFilterQu ality, 126 float alpha = SkColorGetA(info->fPaintColor) / 255.0f;
127 new (fPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info->fFilt erQuality,
127 info->fTileModeX, info->fTileMode Y, 128 info->fTileModeX, info->fTileMode Y,
129 alpha,
128 info->fPixmap); 130 info->fPixmap);
129 131
130 // To implement the old shadeSpan entry-point, we need to efficiently co nvert our native 132 // To implement the old shadeSpan entry-point, we need to efficiently co nvert our native
131 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. 133 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that.
132 // 134 //
133 sk_sp<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kSrc_Mode)); 135 sk_sp<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kSrc_Mode));
134 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); 136 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0);
135 } 137 }
136 138
137 ~LinearPipelineContext() override { 139 ~LinearPipelineContext() override {
(...skipping 30 matching lines...) Expand all
168 170
169 typedef BitmapProcInfoContext INHERITED; 171 typedef BitmapProcInfoContext INHERITED;
170 }; 172 };
171 173
172 //////////////////////////////////////////////////////////////////////////////// /////////////////// 174 //////////////////////////////////////////////////////////////////////////////// ///////////////////
173 175
174 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) { 176 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) {
175 // These src attributes are not supported in the new 4f context (yet) 177 // These src attributes are not supported in the new 4f context (yet)
176 // 178 //
177 if (srcInfo.bytesPerPixel() < 4 || 179 if (srcInfo.bytesPerPixel() < 4 ||
178 kRGBA_F16_SkColorType == srcInfo.colorType()) { 180 kRGBA_F16_SkColorType == srcInfo.colorType() ||
181 kIndex_8_SkColorType == srcInfo.colorType()) {
179 return false; 182 return false;
180 } 183 }
181 184
182 #if 0 // later we may opt-in to the new code even if the client hasn't request ed it... 185 #if 0 // later we may opt-in to the new code even if the client hasn't request ed it...
183 // These src attributes are only supported in the new 4f context 186 // These src attributes are only supported in the new 4f context
184 // 187 //
185 if (srcInfo.isSRGB() || 188 if (srcInfo.isSRGB() ||
186 kUnpremul_SkAlphaType == srcInfo.alphaType() || 189 kUnpremul_SkAlphaType == srcInfo.alphaType() ||
187 (4 == srcInfo.bytesPerPixel() && kN32_SkColorType != srcInfo.colorType() )) 190 (4 == srcInfo.bytesPerPixel() && kN32_SkColorType != srcInfo.colorType() ))
188 { 191 {
(...skipping 15 matching lines...) Expand all
204 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader, 207 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader,
205 TileMode tmx, TileMode tmy, 208 TileMode tmx, TileMode tmy,
206 const SkBitmapProvider& provi der, 209 const SkBitmapProvider& provi der,
207 const ContextRec& rec, void* storage) { 210 const ContextRec& rec, void* storage) {
208 SkMatrix totalInverse; 211 SkMatrix totalInverse;
209 // Do this first, so we know the matrix can be inverted. 212 // Do this first, so we know the matrix can be inverted.
210 if (!shader.computeTotalInverse(rec, &totalInverse)) { 213 if (!shader.computeTotalInverse(rec, &totalInverse)) {
211 return nullptr; 214 return nullptr;
212 } 215 }
213 216
214 // Decide if we can/want to use the new linear pipeine 217 // Decide if we can/want to use the new linear pipeline
215 bool useLinearPipeline = choose_linear_pipeline(rec, provider.info()); 218 bool useLinearPipeline = choose_linear_pipeline(rec, provider.info());
216 219
217 // New code doesn't support Mirror (YET), so we detect that here.
218 //
219 if (SkShader::kMirror_TileMode == tmx || SkShader::kMirror_TileMode == tmy) {
220 useLinearPipeline = false;
221 }
222
223 // New code doesn't support Mirror (YET), so we detect that here.
224 //
225 if (totalInverse.hasPerspective()) {
226 useLinearPipeline = false;
227 }
228
229 // 220 //
230 // For now, only enable locally since we are hitting some crashers on the te st bots 221 // For now, only enable locally since we are hitting some crashers on the te st bots
231 // 222 //
232 useLinearPipeline = false; 223 //useLinearPipeline = false;
233 224
234 if (useLinearPipeline) { 225 if (useLinearPipeline) {
235 void* infoStorage = (char*)storage + sizeof(LinearPipelineContext); 226 void* infoStorage = (char*)storage + sizeof(LinearPipelineContext);
236 SkBitmapProcInfo* info = new (infoStorage) SkBitmapProcInfo(provider, tm x, tmy); 227 SkBitmapProcInfo* info = new (infoStorage) SkBitmapProcInfo(provider, tm x, tmy);
237 if (!info->init(totalInverse, *rec.fPaint)) { 228 if (!info->init(totalInverse, *rec.fPaint)) {
238 info->~SkBitmapProcInfo(); 229 info->~SkBitmapProcInfo();
239 return nullptr; 230 return nullptr;
240 } 231 }
232 if (info->fPixmap.colorType() != kRGBA_8888_SkColorType
233 && info->fPixmap.colorType() != kBGRA_8888_SkColorType) {
234 return nullptr;
235 }
241 return new (storage) LinearPipelineContext(shader, rec, info); 236 return new (storage) LinearPipelineContext(shader, rec, info);
242 } else { 237 } else {
243 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); 238 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext);
244 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(provider , tmx, tmy); 239 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(provider , tmx, tmy);
245 if (!state->setup(totalInverse, *rec.fPaint)) { 240 if (!state->setup(totalInverse, *rec.fPaint)) {
246 state->~SkBitmapProcState(); 241 state->~SkBitmapProcState();
247 return nullptr; 242 return nullptr;
248 } 243 }
249 return new (storage) BitmapProcShaderContext(shader, rec, state); 244 return new (storage) BitmapProcShaderContext(shader, rec, state);
250 } 245 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); 453 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params));
459 } 454 }
460 455
461 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { 456 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
462 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); 457 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner);
463 } 458 }
464 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 459 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
465 } 460 }
466 461
467 #endif 462 #endif
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkBitmapProcState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698