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

Side by Side Diff: src/effects/SkXfermodeImageFilter.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/effects/SkTableColorFilter.cpp ('k') | src/effects/gradients/SkLinearGradient.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 2013 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
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 "SkXfermodeImageFilter.h" 8 #include "SkXfermodeImageFilter.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (background) { 173 if (background) {
174 backgroundTex = background->asTextureRef(context); 174 backgroundTex = background->asTextureRef(context);
175 } 175 }
176 176
177 if (foreground) { 177 if (foreground) {
178 foregroundTex = foreground->asTextureRef(context); 178 foregroundTex = foreground->asTextureRef(context);
179 } 179 }
180 180
181 GrPaint paint; 181 GrPaint paint;
182 // SRGBTODO: AllowSRGBInputs? 182 // SRGBTODO: AllowSRGBInputs?
183 SkAutoTUnref<const GrFragmentProcessor> bgFP; 183 sk_sp<GrFragmentProcessor> bgFP;
184 184
185 if (backgroundTex) { 185 if (backgroundTex) {
186 SkMatrix backgroundMatrix; 186 SkMatrix backgroundMatrix;
187 backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height() ); 187 backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height() );
188 backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX), 188 backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX),
189 SkIntToScalar(-backgroundOffset.fY)); 189 SkIntToScalar(-backgroundOffset.fY));
190 bgFP.reset(GrTextureDomainEffect::Create( 190 bgFP = GrTextureDomainEffect::Make(
191 backgroundTex.get(), backgroundMatrix, 191 backgroundTex.get(), backgroundMatrix,
192 GrTextureDomain::MakeTexelDomain(backgroundTex.get() , 192 GrTextureDomain::MakeTexelDomain(backgroundTex.get() ,
193 background->subset( )), 193 background->subset( )),
194 GrTextureDomain::kDecal_Mode, 194 GrTextureDomain::kDecal_Mode,
195 GrTextureParams::kNone_FilterMode)); 195 GrTextureParams::kNone_FilterMode);
196 } else { 196 } else {
197 bgFP.reset(GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, 197 bgFP = GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK,
198 GrConstColorProcessor::kIgnore_ InputMode)); 198 GrConstColorProcessor::kIgnore_Inpu tMode);
199 } 199 }
200 200
201 if (foregroundTex) { 201 if (foregroundTex) {
202 SkMatrix foregroundMatrix; 202 SkMatrix foregroundMatrix;
203 foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height() ); 203 foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height() );
204 foregroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX), 204 foregroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX),
205 SkIntToScalar(-foregroundOffset.fY)); 205 SkIntToScalar(-foregroundOffset.fY));
206 206
207 SkAutoTUnref<const GrFragmentProcessor> foregroundFP; 207 sk_sp<GrFragmentProcessor> foregroundFP;
208 208
209 foregroundFP.reset(GrTextureDomainEffect::Create( 209 foregroundFP = GrTextureDomainEffect::Make(
210 foregroundTex.get(), foregroundMatrix, 210 foregroundTex.get(), foregroundMatrix,
211 GrTextureDomain::MakeTexelDomain(foregroundTex.get() , 211 GrTextureDomain::MakeTexelDomain(foregroundTex.get() ,
212 foreground->subset( )), 212 foreground->subset( )),
213 GrTextureDomain::kDecal_Mode, 213 GrTextureDomain::kDecal_Mode,
214 GrTextureParams::kNone_FilterMode)); 214 GrTextureParams::kNone_FilterMode);
215 215
216 paint.addColorFragmentProcessor(foregroundFP.get()); 216 paint.addColorFragmentProcessor(std::move(foregroundFP));
217 217
218 // A null fMode is interpreted to mean kSrcOver_Mode (to match raster). 218 // A null fMode is interpreted to mean kSrcOver_Mode (to match raster).
219 SkAutoTUnref<SkXfermode> mode(SkSafeRef(fMode.get())); 219 SkAutoTUnref<SkXfermode> mode(SkSafeRef(fMode.get()));
220 if (!mode) { 220 if (!mode) {
221 // It would be awesome to use SkXfermode::Create here but it knows b etter 221 // It would be awesome to use SkXfermode::Create here but it knows b etter
222 // than us and won't return a kSrcOver_Mode SkXfermode. That means w e 222 // than us and won't return a kSrcOver_Mode SkXfermode. That means w e
223 // have to get one the hard way. 223 // have to get one the hard way.
224 struct ProcCoeff rec; 224 struct ProcCoeff rec;
225 rec.fProc = SkXfermode::GetProc(SkXfermode::kSrcOver_Mode); 225 rec.fProc = SkXfermode::GetProc(SkXfermode::kSrcOver_Mode);
226 SkXfermode::ModeAsCoeff(SkXfermode::kSrcOver_Mode, &rec.fSC, &rec.fD C); 226 SkXfermode::ModeAsCoeff(SkXfermode::kSrcOver_Mode, &rec.fSC, &rec.fD C);
227 227
228 mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode)); 228 mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode));
229 } 229 }
230 230
231 sk_sp<const GrFragmentProcessor> xferFP(mode->getFragmentProcessorForIma geFilter(bgFP)); 231 sk_sp<GrFragmentProcessor> xferFP(
232 mode->makeFragmentProcessorForImageFilter(std::move(bgFP)));
232 233
233 // A null 'xferFP' here means kSrc_Mode was used in which case we can ju st proceed 234 // A null 'xferFP' here means kSrc_Mode was used in which case we can ju st proceed
234 if (xferFP) { 235 if (xferFP) {
235 paint.addColorFragmentProcessor(xferFP.get()); 236 paint.addColorFragmentProcessor(std::move(xferFP));
236 } 237 }
237 } else { 238 } else {
238 paint.addColorFragmentProcessor(bgFP); 239 paint.addColorFragmentProcessor(std::move(bgFP));
239 } 240 }
240 241
241 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 242 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
242 243
243 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kAppr ox, 244 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kAppr ox,
244 bounds.width(), bou nds.height(), 245 bounds.width(), bou nds.height(),
245 kSkia8888_GrPixelCo nfig)); 246 kSkia8888_GrPixelCo nfig));
246 if (!drawContext) { 247 if (!drawContext) {
247 return nullptr; 248 return nullptr;
248 } 249 }
249 250
250 SkMatrix matrix; 251 SkMatrix matrix;
251 matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top ())); 252 matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top ()));
252 drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds)); 253 drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds));
253 254
254 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.he ight()), 255 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.he ight()),
255 kNeedNewImageUniqueID_SpecialImage, 256 kNeedNewImageUniqueID_SpecialImage,
256 drawContext->asTexture()); 257 drawContext->asTexture());
257 } 258 }
258 259
259 #endif 260 #endif
OLDNEW
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | src/effects/gradients/SkLinearGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698