OLD | NEW |
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 fSrcPixmap = info->fPixmap; | 125 fSrcPixmap = info->fPixmap; |
126 fAlpha = SkColorGetA(info->fPaintColor) / 255.0f; | 126 fAlpha = SkColorGetA(info->fPaintColor) / 255.0f; |
127 fXMode = info->fTileModeX; | 127 fXMode = info->fTileModeX; |
128 fYMode = info->fTileModeY; | 128 fYMode = info->fTileModeY; |
129 fFilterQuality = info->fFilterQuality; | 129 fFilterQuality = info->fFilterQuality; |
130 fMatrixTypeMask = info->fRealInvMatrix.getType(); | 130 fMatrixTypeMask = info->fRealInvMatrix.getType(); |
131 | 131 |
132 // Need to ensure that our pipeline is created at a 16byte aligned addre
ss | 132 // Need to ensure that our pipeline is created at a 16byte aligned addre
ss |
133 fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderSt
orage); | 133 fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderSt
orage); |
134 new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info-
>fFilterQuality, | 134 new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info-
>fFilterQuality, |
135 info->fTileModeX, info->fTileMode
Y, | 135 info->fTileModeX, info->fTi
leModeY, |
136 fAlpha, | 136 info->fPaintColor, |
137 info->fPixmap); | 137 info->fPixmap); |
138 | 138 |
139 // To implement the old shadeSpan entry-point, we need to efficiently co
nvert our native | 139 // To implement the old shadeSpan entry-point, we need to efficiently co
nvert our native |
140 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. | 140 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. |
141 // | 141 // |
142 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); | 142 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); |
143 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); | 143 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); |
144 } | 144 } |
145 | 145 |
146 ~LinearPipelineContext() override { | 146 ~LinearPipelineContext() override { |
147 // since we did a manual new, we need to manually destroy as well. | 147 // since we did a manual new, we need to manually destroy as well. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 SkShader::TileMode fYMode; | 216 SkShader::TileMode fYMode; |
217 SkMatrix::TypeMask fMatrixTypeMask; | 217 SkMatrix::TypeMask fMatrixTypeMask; |
218 SkFilterQuality fFilterQuality; | 218 SkFilterQuality fFilterQuality; |
219 | 219 |
220 typedef BitmapProcInfoContext INHERITED; | 220 typedef BitmapProcInfoContext INHERITED; |
221 }; | 221 }; |
222 | 222 |
223 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 223 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
224 | 224 |
225 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag
eInfo& srcInfo) { | 225 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag
eInfo& srcInfo) { |
226 // These src attributes are not supported in the new 4f context (yet) | |
227 // | |
228 if (srcInfo.profileType() != kSRGB_SkColorProfileType) { return false; } | |
229 if (srcInfo.colorType() != kRGBA_8888_SkColorType | |
230 && srcInfo.colorType() != kBGRA_8888_SkColorType | |
231 && srcInfo.colorType() != kIndex_8_SkColorType | |
232 && srcInfo.colorType() != kRGBA_F16_SkColorType) { | |
233 return false; | |
234 } | |
235 | |
236 // If we get here, we can reasonably use either context, respect the caller'
s preference | 226 // If we get here, we can reasonably use either context, respect the caller'
s preference |
237 // | 227 // |
238 return SkShader::ContextRec::kPM4f_DstType == rec.fPreferredDstType; | 228 return SkShader::ContextRec::kPM4f_DstType == rec.fPreferredDstType; |
239 } | 229 } |
240 | 230 |
241 size_t SkBitmapProcShader::ContextSize(const ContextRec& rec, const SkImageInfo&
srcInfo) { | 231 size_t SkBitmapProcShader::ContextSize(const ContextRec& rec, const SkImageInfo&
srcInfo) { |
242 size_t size0 = sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); | 232 size_t size0 = sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); |
243 size_t size1 = sizeof(LinearPipelineContext) + sizeof(SkBitmapProcInfo); | 233 size_t size1 = sizeof(LinearPipelineContext) + sizeof(SkBitmapProcInfo); |
244 return SkTMax(size0, size1); | 234 return SkTMax(size0, size1); |
245 } | 235 } |
(...skipping 11 matching lines...) Expand all Loading... |
257 // Decide if we can/want to use the new linear pipeline | 247 // Decide if we can/want to use the new linear pipeline |
258 bool useLinearPipeline = choose_linear_pipeline(rec, provider.info()); | 248 bool useLinearPipeline = choose_linear_pipeline(rec, provider.info()); |
259 | 249 |
260 if (useLinearPipeline) { | 250 if (useLinearPipeline) { |
261 void* infoStorage = (char*)storage + sizeof(LinearPipelineContext); | 251 void* infoStorage = (char*)storage + sizeof(LinearPipelineContext); |
262 SkBitmapProcInfo* info = new (infoStorage) SkBitmapProcInfo(provider, tm
x, tmy); | 252 SkBitmapProcInfo* info = new (infoStorage) SkBitmapProcInfo(provider, tm
x, tmy); |
263 if (!info->init(totalInverse, *rec.fPaint)) { | 253 if (!info->init(totalInverse, *rec.fPaint)) { |
264 info->~SkBitmapProcInfo(); | 254 info->~SkBitmapProcInfo(); |
265 return nullptr; | 255 return nullptr; |
266 } | 256 } |
267 if (info->fPixmap.colorType() != kRGBA_8888_SkColorType | 257 |
268 && info->fPixmap.colorType() != kBGRA_8888_SkColorType | |
269 && info->fPixmap.colorType() != kIndex_8_SkColorType | |
270 && info->fPixmap.colorType() != kRGBA_F16_SkColorType) { | |
271 return nullptr; | |
272 } | |
273 return new (storage) LinearPipelineContext(shader, rec, info); | 258 return new (storage) LinearPipelineContext(shader, rec, info); |
274 } else { | 259 } else { |
275 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); | 260 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); |
276 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(provider
, tmx, tmy); | 261 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(provider
, tmx, tmy); |
277 if (!state->setup(totalInverse, *rec.fPaint)) { | 262 if (!state->setup(totalInverse, *rec.fPaint)) { |
278 state->~SkBitmapProcState(); | 263 state->~SkBitmapProcState(); |
279 return nullptr; | 264 return nullptr; |
280 } | 265 } |
281 return new (storage) BitmapProcShaderContext(shader, rec, state); | 266 return new (storage) BitmapProcShaderContext(shader, rec, state); |
282 } | 267 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); | 475 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); |
491 } | 476 } |
492 | 477 |
493 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { | 478 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
494 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); | 479 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); |
495 } | 480 } |
496 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 481 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
497 } | 482 } |
498 | 483 |
499 #endif | 484 #endif |
OLD | NEW |