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

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

Issue 1334293003: Create fragment processor for performing input color blend with child processor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 3 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/gpu/GrBlend.cpp » ('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 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkXfermode.h" 14 #include "SkXfermode.h"
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #include "GrDrawContext.h" 17 #include "GrDrawContext.h"
18 #include "effects/GrTextureDomain.h" 18 #include "effects/GrTextureDomain.h"
19 #include "effects/GrSimpleTextureEffect.h"
19 #include "SkGr.h" 20 #include "SkGr.h"
20 #endif 21 #endif
21 22
22 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
23 24
24 SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode, 25 SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode,
25 SkImageFilter* inputs[2], 26 SkImageFilter* inputs[2],
26 const CropRect* cropRect) 27 const CropRect* cropRect)
27 : INHERITED(2, inputs, cropRect), fMode(mode) { 28 : INHERITED(2, inputs, cropRect), fMode(mode) {
28 SkSafeRef(fMode); 29 SkSafeRef(fMode);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 147
147 SkBitmap foreground = src; 148 SkBitmap foreground = src;
148 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); 149 SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
149 if (this->getInput(1) && 150 if (this->getInput(1) &&
150 !this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &for egroundOffset)) { 151 !this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &for egroundOffset)) {
151 return false; 152 return false;
152 } 153 }
153 GrTexture* foregroundTex = foreground.getTexture(); 154 GrTexture* foregroundTex = foreground.getTexture();
154 GrContext* context = foregroundTex->getContext(); 155 GrContext* context = foregroundTex->getContext();
155 156
156 GrFragmentProcessor* xferProcessor = nullptr; 157 const GrFragmentProcessor* xferFP = nullptr;
157 158
158 GrSurfaceDesc desc; 159 GrSurfaceDesc desc;
159 desc.fFlags = kRenderTarget_GrSurfaceFlag; 160 desc.fFlags = kRenderTarget_GrSurfaceFlag;
160 desc.fWidth = src.width(); 161 desc.fWidth = src.width();
161 desc.fHeight = src.height(); 162 desc.fHeight = src.height();
162 desc.fConfig = kSkia8888_GrPixelConfig; 163 desc.fConfig = kSkia8888_GrPixelConfig;
163 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture( desc)); 164 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture( desc));
164 if (!dst) { 165 if (!dst) {
165 return false; 166 return false;
166 } 167 }
167 168
168 GrPaint paint; 169 GrPaint paint;
169 if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, paint.getProcessor DataManager(), 170 SkMatrix bgMatrix;
170 backgroundTex)) { 171 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height());
172 SkAutoTUnref<const GrFragmentProcessor> bgFP(
173 GrSimpleTextureEffect::Create(paint.getProcessorDataManager(), backgroun dTex, bgMatrix));
174 if (!fMode || !fMode->asFragmentProcessor(&xferFP, paint.getProcessorDataMan ager(), bgFP)) {
171 // canFilterImageGPU() should've taken care of this 175 // canFilterImageGPU() should've taken care of this
172 SkASSERT(false); 176 SkASSERT(false);
173 return false; 177 return false;
174 } 178 }
175 179
176 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg roundTex); 180 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg roundTex);
177 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf fset.fX), 181 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf fset.fX),
178 SkIntToScalar(backgroundOffset.fY-foregroundOf fset.fY)); 182 SkIntToScalar(backgroundOffset.fY-foregroundOf fset.fY));
179 183
180 184
181 SkRect srcRect; 185 SkRect srcRect;
182 src.getBounds(&srcRect); 186 src.getBounds(&srcRect);
183 187
184 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr eate( 188 SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Cr eate(
185 paint.getProcessorDataManager(), 189 paint.getProcessorDataManager(),
186 foregroundTex, foregroundMatrix, 190 foregroundTex, foregroundMatrix,
187 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), 191 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()),
188 GrTextureDomain::kDecal_Mode, 192 GrTextureDomain::kDecal_Mode,
189 GrTextureParams::kNone_FilterMode) 193 GrTextureParams::kNone_FilterMode)
190 ); 194 );
191 195
192 paint.addColorFragmentProcessor(foregroundDomain.get()); 196 paint.addColorFragmentProcessor(foregroundDomain.get());
193 paint.addColorFragmentProcessor(xferProcessor)->unref(); 197 if (xferFP) {
198 paint.addColorFragmentProcessor(xferFP)->unref();
199 }
194 200
195 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); 201 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
196 if (!drawContext) { 202 if (!drawContext) {
197 return false; 203 return false;
198 } 204 }
199 205
200 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, 206 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint,
201 SkMatrix::I(), srcRect); 207 SkMatrix::I(), srcRect);
202 208
203 offset->fX = backgroundOffset.fX; 209 offset->fX = backgroundOffset.fX;
204 offset->fY = backgroundOffset.fY; 210 offset->fY = backgroundOffset.fY;
205 WrapTexture(dst, src.width(), src.height(), result); 211 WrapTexture(dst, src.width(), src.height(), result);
206 return true; 212 return true;
207 } 213 }
208 214
209 #endif 215 #endif
210 216
OLDNEW
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | src/gpu/GrBlend.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698