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/SkDisplacementMapEffect.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/SkColorCubeFilter.cpp ('k') | src/effects/SkGpuBlurUtils.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 Google Inc. 2 * Copyright 2013 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 "SkDisplacementMapEffect.h" 8 #include "SkDisplacementMapEffect.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const { 207 void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const {
208 this->INHERITED::flatten(buffer); 208 this->INHERITED::flatten(buffer);
209 buffer.writeInt((int) fXChannelSelector); 209 buffer.writeInt((int) fXChannelSelector);
210 buffer.writeInt((int) fYChannelSelector); 210 buffer.writeInt((int) fYChannelSelector);
211 buffer.writeScalar(fScale); 211 buffer.writeScalar(fScale);
212 } 212 }
213 213
214 #if SK_SUPPORT_GPU 214 #if SK_SUPPORT_GPU
215 class GrDisplacementMapEffect : public GrFragmentProcessor { 215 class GrDisplacementMapEffect : public GrFragmentProcessor {
216 public: 216 public:
217 static GrFragmentProcessor* Create( 217 static sk_sp<GrFragmentProcessor> Make(
218 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, 218 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
219 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, S kVector scale, 219 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, S kVector scale,
220 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture * color, 220 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture * color,
221 const SkISize& colorDimensions) { 221 const SkISize& colorDimensions) {
222 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, s cale, displacement, 222 return sk_sp<GrFragmentProcessor>(
223 offsetMatrix, color, colorDimensions) ; 223 new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, scal e, displacement,
224 offsetMatrix, color, colorDimensions));
224 } 225 }
225 226
226 virtual ~GrDisplacementMapEffect(); 227 virtual ~GrDisplacementMapEffect();
227 228
228 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const { 229 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const {
229 return fXChannelSelector; 230 return fXChannelSelector;
230 } 231 }
231 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const { 232 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const {
232 return fYChannelSelector; 233 return fYChannelSelector;
233 } 234 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (!colorTexture || !displTexture) { 317 if (!colorTexture || !displTexture) {
317 return nullptr; 318 return nullptr;
318 } 319 }
319 320
320 GrPaint paint; 321 GrPaint paint;
321 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displ Texture.get()); 322 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displ Texture.get());
322 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX) , 323 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX) ,
323 SkIntToScalar(colorOffset.fY - displOffset.fY) ); 324 SkIntToScalar(colorOffset.fY - displOffset.fY) );
324 325
325 paint.addColorFragmentProcessor( 326 paint.addColorFragmentProcessor(
326 GrDisplacementMapEffect::Create(fXChannelSelector, 327 GrDisplacementMapEffect::Make(fXChannelSelector,
327 fYChannelSelector, 328 fYChannelSelector,
328 scale, 329 scale,
329 displTexture.get(), 330 displTexture.get(),
330 offsetMatrix, 331 offsetMatrix,
331 colorTexture.get(), 332 colorTexture.get(),
332 SkISize::Make(color->width(), 333 SkISize::Make(color->width(), color->h eight())));
333 color->height())))->un ref();
334 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 334 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
335 SkMatrix matrix; 335 SkMatrix matrix;
336 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo rBounds.y())); 336 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo rBounds.y()));
337 337
338 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::k Approx, 338 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::k Approx,
339 bounds.width(), bounds.height(), 339 bounds.width(), bounds.height(),
340 kSkia8888_GrPix elConfig)); 340 kSkia8888_GrPix elConfig));
341 if (!drawContext) { 341 if (!drawContext) {
342 return nullptr; 342 return nullptr;
343 } 343 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // and no displacement offset push any texture coordinates out of bounds OR if the constant 497 // and no displacement offset push any texture coordinates out of bounds OR if the constant
498 // alpha is 0. Since this isn't trivial to compute at this point, let's assu me the output is 498 // alpha is 0. Since this isn't trivial to compute at this point, let's assu me the output is
499 // not of constant color when a displacement effect is applied. 499 // not of constant color when a displacement effect is applied.
500 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); 500 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
501 } 501 }
502 502
503 /////////////////////////////////////////////////////////////////////////////// 503 ///////////////////////////////////////////////////////////////////////////////
504 504
505 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); 505 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect);
506 506
507 const GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(GrProcessorTestDa ta* d) { 507 sk_sp<GrFragmentProcessor> GrDisplacementMapEffect::TestCreate(GrProcessorTestDa ta* d) {
508 int texIdxDispl = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextu reIdx : 508 int texIdxDispl = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextu reIdx :
509 GrProcessorUnitTest::kAlphaTextur eIdx; 509 GrProcessorUnitTest::kAlphaTextur eIdx;
510 int texIdxColor = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextu reIdx : 510 int texIdxColor = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextu reIdx :
511 GrProcessorUnitTest::kAlphaTextur eIdx; 511 GrProcessorUnitTest::kAlphaTextur eIdx;
512 static const int kMaxComponent = 4; 512 static const int kMaxComponent = 4;
513 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector = 513 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector =
514 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( 514 static_cast<SkDisplacementMapEffect::ChannelSelectorType>(
515 d->fRandom->nextRangeU(1, kMaxComponent)); 515 d->fRandom->nextRangeU(1, kMaxComponent));
516 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = 516 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector =
517 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( 517 static_cast<SkDisplacementMapEffect::ChannelSelectorType>(
518 d->fRandom->nextRangeU(1, kMaxComponent)); 518 d->fRandom->nextRangeU(1, kMaxComponent));
519 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f), 519 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f),
520 d->fRandom->nextRangeScalar(0, 100.0f)); 520 d->fRandom->nextRangeScalar(0, 100.0f));
521 SkISize colorDimensions; 521 SkISize colorDimensions;
522 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor] ->width()); 522 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor] ->width());
523 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor ]->height()); 523 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor ]->height());
524 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s cale, 524 return GrDisplacementMapEffect::Make(xChannelSelector, yChannelSelector, sca le,
525 d->fTextures[texIdxDispl], SkMatrix:: I(), 525 d->fTextures[texIdxDispl], SkMatrix::I( ),
526 d->fTextures[texIdxColor], colorDimen sions); 526 d->fTextures[texIdxColor], colorDimensi ons);
527 } 527 }
528 528
529 /////////////////////////////////////////////////////////////////////////////// 529 ///////////////////////////////////////////////////////////////////////////////
530 530
531 void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) { 531 void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
532 const GrDisplacementMapEffect& displacementMap = args.fFp.cast<GrDisplacemen tMapEffect>(); 532 const GrDisplacementMapEffect& displacementMap = args.fFp.cast<GrDisplacemen tMapEffect>();
533 const GrTextureDomain& domain = displacementMap.domain(); 533 const GrTextureDomain& domain = displacementMap.domain();
534 534
535 fScaleUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, 535 fScaleUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
536 kVec2f_GrSLType, kDefault_GrSLP recision, "Scale"); 536 kVec2f_GrSLType, kDefault_GrSLP recision, "Scale");
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, 617 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc,
618 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { 618 const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
619 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 619 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
620 620
621 uint32_t xKey = displacementMap.xChannelSelector(); 621 uint32_t xKey = displacementMap.xChannelSelector();
622 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 622 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
623 623
624 b->add32(xKey | yKey); 624 b->add32(xKey | yKey);
625 } 625 }
626 #endif 626 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorCubeFilter.cpp ('k') | src/effects/SkGpuBlurUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698