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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 #include "SkLinearBitmapPipeline.h" | 114 #include "SkLinearBitmapPipeline.h" |
115 #include "SkPM4f.h" | 115 #include "SkPM4f.h" |
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 fSrcPixmap = info->fPixmap; | |
125 fAlpha = SkColorGetA(info->fPaintColor) / 255.0f; | |
126 fXMode = info->fTileModeX; | |
127 fYMode = info->fTileModeY; | |
128 fIsComplicated = info->fRealInvMatrix.getType() & ~SkMatrix::kTranslate_ Mask; | |
124 // Need to ensure that our pipeline is created at a 16byte aligned addre ss | 129 // Need to ensure that our pipeline is created at a 16byte aligned addre ss |
125 fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fStorage); | 130 fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderSt orage); |
126 float alpha = SkColorGetA(info->fPaintColor) / 255.0f; | 131 new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info- >fFilterQuality, |
127 new (fPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info->fFilt erQuality, | |
128 info->fTileModeX, info->fTileMode Y, | 132 info->fTileModeX, info->fTileMode Y, |
129 alpha, | 133 fAlpha, |
130 info->fPixmap); | 134 info->fPixmap); |
131 | 135 |
132 // To implement the old shadeSpan entry-point, we need to efficiently co nvert our native | 136 // To implement the old shadeSpan entry-point, we need to efficiently co nvert our native |
133 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. | 137 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. |
134 // | 138 // |
135 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); | 139 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); |
136 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); | 140 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); |
137 } | 141 } |
138 | 142 |
139 ~LinearPipelineContext() override { | 143 ~LinearPipelineContext() override { |
140 // since we did a manual new, we need to manually destroy as well. | 144 // since we did a manual new, we need to manually destroy as well. |
141 fPipeline->~SkLinearBitmapPipeline(); | 145 fShaderPipeline->~SkLinearBitmapPipeline(); |
146 if (fBlitterPipeline != nullptr) { | |
147 fBlitterPipeline->~SkLinearBitmapPipeline(); | |
148 } | |
142 } | 149 } |
143 | 150 |
144 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override { | 151 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override { |
145 fPipeline->shadeSpan4f(x, y, dstC, count); | 152 fShaderPipeline->shadeSpan4f(x, y, dstC, count); |
146 } | 153 } |
147 | 154 |
148 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override { | 155 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override { |
149 const int N = 128; | 156 const int N = 128; |
150 SkPM4f tmp[N]; | 157 SkPM4f tmp[N]; |
151 | 158 |
152 while (count > 0) { | 159 while (count > 0) { |
153 const int n = SkTMin(count, N); | 160 const int n = SkTMin(count, N); |
154 fPipeline->shadeSpan4f(x, y, tmp, n); | 161 fShaderPipeline->shadeSpan4f(x, y, tmp, n); |
155 fXferProc(nullptr, dstC, tmp, n, nullptr); | 162 fXferProc(nullptr, dstC, tmp, n, nullptr); |
156 dstC += n; | 163 dstC += n; |
157 x += n; | 164 x += n; |
158 count -= n; | 165 count -= n; |
159 } | 166 } |
160 } | 167 } |
161 | 168 |
169 bool onChooseBlitProcs(const SkImageInfo& dstInfo, BlitState* state) overrid e { | |
170 if (fIsComplicated) { return false; } | |
171 SkXfermode::Mode mode; | |
172 if (!SkXfermode::AsMode(state->fXfer, &mode)) { return false; } | |
173 if (fAlpha != 1.0f) { return false; } | |
174 if (fSrcPixmap.info().colorType() != kRGBA_8888_SkColorType | |
175 || dstInfo.colorType() != kRGBA_8888_SkColorType) { return false; } | |
176 | |
177 if (fXMode != SkShader::kRepeat_TileMode || fYMode != SkShader::kRepeat_ TileMode) { | |
178 return false; | |
179 } | |
180 | |
181 if (mode == SkXfermode::kSrcOver_Mode | |
mtklein
2016/04/11 16:43:25
This section here is not a constraint on when we c
herb_g
2016/04/12 20:03:49
Done.
| |
182 && fSrcPixmap.info().alphaType() == kOpaque_SkAlphaType) { | |
183 mode = SkXfermode::kSrc_Mode; | |
184 } | |
185 | |
186 if (mode != SkXfermode::kSrc_Mode) { return false; } | |
187 | |
188 // Need to ensure that our pipeline is created at a 16byte aligned addre ss | |
189 fBlitterPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fBlitter Storage); | |
190 new (fBlitterPipeline) SkLinearBitmapPipeline(*fShaderPipeline, mode, fS rcPixmap, dstInfo); | |
191 | |
192 state->fStorage[0] = fBlitterPipeline; | |
193 state->fBlitBW = &LinearPipelineContext::ForwardToPipeline; | |
194 | |
195 return true; | |
196 } | |
197 | |
198 static void ForwardToPipeline(BlitState* state, int x, int y, const SkPixmap & dst, int count) { | |
199 SkLinearBitmapPipeline* pipeline = static_cast<SkLinearBitmapPipeline*>( state->fStorage[0]); | |
200 void* addr = dst.writable_addr32(x, y); | |
201 pipeline->blitSpan(x, y, addr, count); | |
202 } | |
203 | |
204 | |
162 private: | 205 private: |
163 enum { | 206 enum { |
164 kActualSize = sizeof(SkLinearBitmapPipeline), | 207 kActualSize = sizeof(SkLinearBitmapPipeline), |
165 kPaddedSize = SkAlignPtr(kActualSize + 12), | 208 kPaddedSize = SkAlignPtr(kActualSize + 12), |
166 }; | 209 }; |
167 void* fStorage[kPaddedSize / sizeof(void*)]; | 210 void* fShaderStorage[kPaddedSize / sizeof(void*)]; |
168 SkLinearBitmapPipeline* fPipeline; | 211 SkLinearBitmapPipeline* fShaderPipeline; |
212 void* fBlitterStorage[kPaddedSize / sizeof(void*)]; | |
213 SkLinearBitmapPipeline* fBlitterPipeline{nullptr}; | |
169 SkXfermode::D32Proc fXferProc; | 214 SkXfermode::D32Proc fXferProc; |
215 SkPixmap fSrcPixmap; | |
216 float fAlpha; | |
217 SkShader::TileMode fXMode; | |
218 SkShader::TileMode fYMode; | |
219 bool fIsComplicated; | |
170 | 220 |
171 typedef BitmapProcInfoContext INHERITED; | 221 typedef BitmapProcInfoContext INHERITED; |
172 }; | 222 }; |
173 | 223 |
174 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
175 | 225 |
176 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) { | 226 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) { |
177 // These src attributes are not supported in the new 4f context (yet) | 227 // These src attributes are not supported in the new 4f context (yet) |
178 // | 228 // |
179 if (srcInfo.colorType() != kRGBA_8888_SkColorType | 229 if (srcInfo.colorType() != kRGBA_8888_SkColorType |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); | 504 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); |
455 } | 505 } |
456 | 506 |
457 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { | 507 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
458 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); | 508 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); |
459 } | 509 } |
460 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 510 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
461 } | 511 } |
462 | 512 |
463 #endif | 513 #endif |
OLD | NEW |