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

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

Issue 1852613002: First blitter for linear pipeline. (Closed) Base URL: https://skia.googlesource.com/skia.git@clone-the-pipeline
Patch Set: Moved check and construction of blitter pipeline to SkLinearBitmapPipeline. Created 4 years, 8 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 | « src/core/SkBitmapProcShader.h ('k') | 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Save things off in case we need to build a blitter pipeline.
125 fSrcPixmap = info->fPixmap;
126 fAlpha = SkColorGetA(info->fPaintColor) / 255.0f;
127 fXMode = info->fTileModeX;
128 fYMode = info->fTileModeY;
129 fFilterQuality = info->fFilterQuality;
130 fMatrixTypeMask = info->fRealInvMatrix.getType();
131
124 // 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
125 fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fStorage); 133 fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderSt orage);
126 float alpha = SkColorGetA(info->fPaintColor) / 255.0f; 134 new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info- >fFilterQuality,
127 new (fPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info->fFilt erQuality,
128 info->fTileModeX, info->fTileMode Y, 135 info->fTileModeX, info->fTileMode Y,
129 alpha, 136 fAlpha,
130 info->fPixmap); 137 info->fPixmap);
131 138
132 // 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
133 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. 140 // floats into SkPMColor. The SkXfermode::D32Procs do exactly that.
134 // 141 //
135 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); 142 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode));
136 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); 143 fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0);
137 } 144 }
138 145
139 ~LinearPipelineContext() override { 146 ~LinearPipelineContext() override {
140 // 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.
141 fPipeline->~SkLinearBitmapPipeline(); 148 fShaderPipeline->~SkLinearBitmapPipeline();
149 if (fBlitterPipeline != nullptr) {
150 fBlitterPipeline->~SkLinearBitmapPipeline();
151 }
142 } 152 }
143 153
144 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override { 154 void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override {
145 fPipeline->shadeSpan4f(x, y, dstC, count); 155 fShaderPipeline->shadeSpan4f(x, y, dstC, count);
146 } 156 }
147 157
148 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override { 158 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override {
149 const int N = 128; 159 const int N = 128;
150 SkPM4f tmp[N]; 160 SkPM4f tmp[N];
151 161
152 while (count > 0) { 162 while (count > 0) {
153 const int n = SkTMin(count, N); 163 const int n = SkTMin(count, N);
154 fPipeline->shadeSpan4f(x, y, tmp, n); 164 fShaderPipeline->shadeSpan4f(x, y, tmp, n);
155 fXferProc(nullptr, dstC, tmp, n, nullptr); 165 fXferProc(nullptr, dstC, tmp, n, nullptr);
156 dstC += n; 166 dstC += n;
157 x += n; 167 x += n;
158 count -= n; 168 count -= n;
159 } 169 }
160 } 170 }
161 171
172 bool onChooseBlitProcs(const SkImageInfo& dstInfo, BlitState* state) overrid e {
173 SkXfermode::Mode mode;
174 if (!SkXfermode::AsMode(state->fXfer, &mode)) { return false; }
175
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(
179 fBlitterPipeline, *fShaderPipeline,
180 fMatrixTypeMask,
181 fXMode, fYMode,
182 fFilterQuality, fSrcPixmap,
183 fAlpha, mode, dstInfo)) {
184
185 state->fStorage[0] = fBlitterPipeline;
186 state->fBlitBW = &LinearPipelineContext::ForwardToPipeline;
187
188 return true;
189 }
190
191 // Did not successfully create a pipeline so don't destruct it.
192 fBlitterPipeline = nullptr;
193 return false;
194 }
195
196 static void ForwardToPipeline(BlitState* state, int x, int y, const SkPixmap & dst, int count) {
197 SkLinearBitmapPipeline* pipeline = static_cast<SkLinearBitmapPipeline*>( state->fStorage[0]);
198 void* addr = dst.writable_addr32(x, y);
199 pipeline->blitSpan(x, y, addr, count);
200 }
201
202
162 private: 203 private:
163 enum { 204 enum {
164 kActualSize = sizeof(SkLinearBitmapPipeline), 205 kActualSize = sizeof(SkLinearBitmapPipeline),
165 kPaddedSize = SkAlignPtr(kActualSize + 12), 206 kPaddedSize = SkAlignPtr(kActualSize + 12),
166 }; 207 };
167 void* fStorage[kPaddedSize / sizeof(void*)]; 208 void* fShaderStorage[kPaddedSize / sizeof(void*)];
168 SkLinearBitmapPipeline* fPipeline; 209 SkLinearBitmapPipeline* fShaderPipeline;
210 void* fBlitterStorage[kPaddedSize / sizeof(void*)];
211 SkLinearBitmapPipeline* fBlitterPipeline{nullptr};
169 SkXfermode::D32Proc fXferProc; 212 SkXfermode::D32Proc fXferProc;
213 SkPixmap fSrcPixmap;
214 float fAlpha;
215 SkShader::TileMode fXMode;
216 SkShader::TileMode fYMode;
217 SkMatrix::TypeMask fMatrixTypeMask;
218 SkFilterQuality fFilterQuality;
170 219
171 typedef BitmapProcInfoContext INHERITED; 220 typedef BitmapProcInfoContext INHERITED;
172 }; 221 };
173 222
174 //////////////////////////////////////////////////////////////////////////////// /////////////////// 223 //////////////////////////////////////////////////////////////////////////////// ///////////////////
175 224
176 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) {
177 // These src attributes are not supported in the new 4f context (yet) 226 // These src attributes are not supported in the new 4f context (yet)
178 // 227 //
179 if (srcInfo.colorType() != kRGBA_8888_SkColorType 228 if (srcInfo.colorType() != kRGBA_8888_SkColorType
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); 503 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params));
455 } 504 }
456 505
457 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { 506 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
458 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); 507 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner);
459 } 508 }
460 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 509 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
461 } 510 }
462 511
463 #endif 512 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcShader.h ('k') | src/core/SkLinearBitmapPipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698