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

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

Issue 1998793002: Make an embeddable container to hold linear pipelines. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove unused defs 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 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 : INHERITED(shader, rec, info) 122 : INHERITED(shader, rec, info)
123 { 123 {
124 // Save things off in case we need to build a blitter pipeline. 124 // Save things off in case we need to build a blitter pipeline.
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 fShaderPipeline.init(
133 fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderSt orage); 133 info->fRealInvMatrix, info->fFilterQuality,
134 new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info- >fFilterQuality, 134 info->fTileModeX, info->fTileModeY,
135 info->fTileModeX, info->fTi leModeY, 135 info->fPaintColor,
136 info->fPaintColor, 136 info->fPixmap);
137 info->fPixmap);
138 137
139 // To implement the old shadeSpan entry-point, we need to efficiently co nvert our native 138 // 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. 139 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that.
141 // 140 //
142 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); 141 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode));
143 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); 142 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0);
144 } 143 }
145 144
146 ~LinearPipelineContext() override {
147 // since we did a manual new, we need to manually destroy as well.
148 fShaderPipeline->~SkLinearBitmapPipeline();
149 if (fBlitterPipeline != nullptr) {
150 fBlitterPipeline->~SkLinearBitmapPipeline();
151 }
152 }
153
154 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override { 145 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override {
155 fShaderPipeline->shadeSpan4f(x, y, dstC, count); 146 fShaderPipeline->shadeSpan4f(x, y, dstC, count);
156 } 147 }
157 148
158 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override { 149 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override {
159 const int N = 128; 150 const int N = 128;
160 SkPM4f tmp[N]; 151 SkPM4f tmp[N];
161 152
162 while (count > 0) { 153 while (count > 0) {
163 const int n = SkTMin(count, N); 154 const int n = SkTMin(count, N);
164 fShaderPipeline->shadeSpan4f(x, y, tmp, n); 155 fShaderPipeline->shadeSpan4f(x, y, tmp, n);
165 fXferProc(nullptr, dstC, tmp, n, nullptr); 156 fXferProc(nullptr, dstC, tmp, n, nullptr);
166 dstC += n; 157 dstC += n;
167 x += n; 158 x += n;
168 count -= n; 159 count -= n;
169 } 160 }
170 } 161 }
171 162
172 bool onChooseBlitProcs(const SkImageInfo& dstInfo, BlitState* state) overrid e { 163 bool onChooseBlitProcs(const SkImageInfo& dstInfo, BlitState* state) overrid e {
173 SkXfermode::Mode mode; 164 SkXfermode::Mode mode;
174 if (!SkXfermode::AsMode(state->fXfer, &mode)) { return false; } 165 if (!SkXfermode::AsMode(state->fXfer, &mode)) { return false; }
175 166
176 // Need to ensure that our pipeline is created at a 16byte aligned addre ss
177 fBlitterPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fBlitter Storage);
178 if (SkLinearBitmapPipeline::ClonePipelineForBlitting( 167 if (SkLinearBitmapPipeline::ClonePipelineForBlitting(
179 fBlitterPipeline, *fShaderPipeline, 168 &fBlitterPipeline, *fShaderPipeline,
180 fMatrixTypeMask, 169 fMatrixTypeMask,
181 fXMode, fYMode, 170 fXMode, fYMode,
182 fFilterQuality, fSrcPixmap, 171 fFilterQuality, fSrcPixmap,
183 fAlpha, mode, dstInfo)) 172 fAlpha, mode, dstInfo))
184 { 173 {
185 state->fStorage[0] = fBlitterPipeline; 174 state->fStorage[0] = fBlitterPipeline.get();
186 state->fBlitBW = &LinearPipelineContext::ForwardToPipeline; 175 state->fBlitBW = &LinearPipelineContext::ForwardToPipeline;
187 176
188 return true; 177 return true;
189 } 178 }
190 179
191 // Did not successfully create a pipeline so don't destruct it.
192 fBlitterPipeline = nullptr;
193 return false; 180 return false;
194 } 181 }
195 182
196 static void ForwardToPipeline(BlitState* state, int x, int y, const SkPixmap & dst, int count) { 183 static void ForwardToPipeline(BlitState* state, int x, int y, const SkPixmap & dst, int count) {
197 SkLinearBitmapPipeline* pipeline = static_cast<SkLinearBitmapPipeline*>( state->fStorage[0]); 184 SkLinearBitmapPipeline* pipeline = static_cast<SkLinearBitmapPipeline*>( state->fStorage[0]);
198 void* addr = dst.writable_addr32(x, y); 185 void* addr = dst.writable_addr32(x, y);
199 pipeline->blitSpan(x, y, addr, count); 186 pipeline->blitSpan(x, y, addr, count);
200 } 187 }
201 188
202
203 private: 189 private:
204 enum { 190 SkEmbeddableLinearPipeline fShaderPipeline;
205 kActualSize = sizeof(SkLinearBitmapPipeline), 191 SkEmbeddableLinearPipeline fBlitterPipeline;
206 kPaddedSize = SkAlignPtr(kActualSize + 12), 192 SkXfermode::D32Proc fXferProc;
207 }; 193 SkPixmap fSrcPixmap;
208 void* fShaderStorage[kPaddedSize / sizeof(void*)]; 194 float fAlpha;
209 SkLinearBitmapPipeline* fShaderPipeline; 195 SkShader::TileMode fXMode;
210 void* fBlitterStorage[kPaddedSize / sizeof(void*)]; 196 SkShader::TileMode fYMode;
211 SkLinearBitmapPipeline* fBlitterPipeline{nullptr}; 197 SkMatrix::TypeMask fMatrixTypeMask;
212 SkXfermode::D32Proc fXferProc; 198 SkFilterQuality fFilterQuality;
213 SkPixmap fSrcPixmap;
214 float fAlpha;
215 SkShader::TileMode fXMode;
216 SkShader::TileMode fYMode;
217 SkMatrix::TypeMask fMatrixTypeMask;
218 SkFilterQuality fFilterQuality;
219 199
220 typedef BitmapProcInfoContext INHERITED; 200 typedef BitmapProcInfoContext INHERITED;
221 }; 201 };
222 202
223 //////////////////////////////////////////////////////////////////////////////// /////////////////// 203 //////////////////////////////////////////////////////////////////////////////// ///////////////////
224 204
225 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) { 205 static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag eInfo& srcInfo) {
226 // If we get here, we can reasonably use either context, respect the caller' s preference 206 // If we get here, we can reasonably use either context, respect the caller' s preference
227 // 207 //
228 return SkShader::ContextRec::kPM4f_DstType == rec.fPreferredDstType; 208 return SkShader::ContextRec::kPM4f_DstType == rec.fPreferredDstType;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); 455 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params));
476 } 456 }
477 457
478 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { 458 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
479 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); 459 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner);
480 } 460 }
481 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 461 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
482 } 462 }
483 463
484 #endif 464 #endif
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