| OLD | NEW |
| 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" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkSpecialImage.h" | 12 #include "SkSpecialImage.h" |
| 13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
| 14 #include "SkUnPreMultiply.h" | 14 #include "SkUnPreMultiply.h" |
| 15 #include "SkColorPriv.h" | 15 #include "SkColorPriv.h" |
| 16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrRenderTargetContext.h" | 18 #include "GrRenderTargetContext.h" |
| 19 #include "GrCoordTransform.h" | 19 #include "GrCoordTransform.h" |
| 20 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
| 21 #include "GrTextureProxy.h" |
| 21 #include "SkGr.h" | 22 #include "SkGr.h" |
| 22 #include "SkGrPriv.h" | 23 #include "SkGrPriv.h" |
| 23 #include "effects/GrTextureDomain.h" | 24 #include "effects/GrTextureDomain.h" |
| 24 #include "glsl/GrGLSLFragmentProcessor.h" | 25 #include "glsl/GrGLSLFragmentProcessor.h" |
| 25 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 26 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 26 #include "glsl/GrGLSLProgramDataManager.h" | 27 #include "glsl/GrGLSLProgramDataManager.h" |
| 27 #include "glsl/GrGLSLUniformHandler.h" | 28 #include "glsl/GrGLSLUniformHandler.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 displTexture.get(), | 343 displTexture.get(), |
| 343 offsetMatrix, | 344 offsetMatrix, |
| 344 colorTexture.get(), | 345 colorTexture.get(), |
| 345 SkISize::Make(color->width(), color->h
eight()))); | 346 SkISize::Make(color->width(), color->h
eight()))); |
| 346 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); | 347 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 347 SkMatrix matrix; | 348 SkMatrix matrix; |
| 348 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo
rBounds.y())); | 349 matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colo
rBounds.y())); |
| 349 | 350 |
| 350 SkColorSpace* colorSpace = ctx.outputProperties().colorSpace(); | 351 SkColorSpace* colorSpace = ctx.outputProperties().colorSpace(); |
| 351 sk_sp<GrRenderTargetContext> renderTargetContext( | 352 sk_sp<GrRenderTargetContext> renderTargetContext( |
| 352 context->makeRenderTargetContext(SkBackingFit::kApprox, bounds.width
(), bounds.height(), | 353 context->makeDeferredRenderTargetContext(SkBackingFit::kApprox, boun
ds.width(), bounds.height(), |
| 353 GrRenderableConfigForColorSpace(col
orSpace), | 354 GrRenderableConfigForColorSpace(col
orSpace), |
| 354 sk_ref_sp(colorSpace))); | 355 sk_ref_sp(colorSpace))); |
| 355 if (!renderTargetContext) { | 356 if (!renderTargetContext) { |
| 356 return nullptr; | 357 return nullptr; |
| 357 } | 358 } |
| 358 paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); | 359 paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); |
| 359 | 360 |
| 360 renderTargetContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(co
lorBounds)); | 361 renderTargetContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(co
lorBounds)); |
| 361 | 362 |
| 362 offset->fX = bounds.left(); | 363 offset->fX = bounds.left(); |
| 363 offset->fY = bounds.top(); | 364 offset->fY = bounds.top(); |
| 364 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bound
s.height()), | 365 return SkSpecialImage::MakeDeferredFromGpu(SkIRect::MakeWH(bounds.width(
), bounds.height()), |
| 365 kNeedNewImageUniqueID_SpecialImage, | 366 kNeedNewImageUniqueID_Special
Image, |
| 366 renderTargetContext->asTexture(), | 367 renderTargetContext->asDeferr
edTexture(), |
| 367 sk_ref_sp(renderTargetContext->getCol
orSpace())); | 368 sk_ref_sp(renderTargetContext
->getColorSpace())); |
| 368 } | 369 } |
| 369 #endif | 370 #endif |
| 370 | 371 |
| 371 SkBitmap colorBM, displBM; | 372 SkBitmap colorBM, displBM; |
| 372 | 373 |
| 373 if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) { | 374 if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) { |
| 374 return nullptr; | 375 return nullptr; |
| 375 } | 376 } |
| 376 | 377 |
| 377 if ((colorBM.colorType() != kN32_SkColorType) || | 378 if ((colorBM.colorType() != kN32_SkColorType) || |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, | 477 SkDisplacementMapEffect::ChannelSelectorType xChann
elSelector, |
| 477 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, | 478 SkDisplacementMapEffect::ChannelSelectorType yChann
elSelector, |
| 478 const SkVector& scale, | 479 const SkVector& scale, |
| 479 GrTexture* displacement, | 480 GrTexture* displacement, |
| 480 const SkMatrix& offsetMatrix, | 481 const SkMatrix& offsetMatrix, |
| 481 GrTexture* color, | 482 GrTexture* color, |
| 482 const SkISize& colorDimensions) | 483 const SkISize& colorDimensions) |
| 483 : fDisplacementTransform(offsetMatrix, displacement, GrTextureParams::kNone_
FilterMode) | 484 : fDisplacementTransform(offsetMatrix, displacement, GrTextureParams::kNone_
FilterMode) |
| 484 , fDisplacementAccess(displacement) | 485 , fDisplacementAccess(displacement) |
| 485 , fColorTransform(color, GrTextureParams::kNone_FilterMode) | 486 , fColorTransform(color, GrTextureParams::kNone_FilterMode) |
| 486 , fDomain(GrTextureDomain::MakeTexelDomain(color, SkIRect::MakeSize(colorDim
ensions)), | 487 , fDomain(GrTextureDomain::MakeTexelDomain(color->width(), color->height(), |
| 488 SkIRect::MakeSize(colorDimensions
)), |
| 487 GrTextureDomain::kDecal_Mode) | 489 GrTextureDomain::kDecal_Mode) |
| 488 , fColorAccess(color) | 490 , fColorAccess(color) |
| 489 , fXChannelSelector(xChannelSelector) | 491 , fXChannelSelector(xChannelSelector) |
| 490 , fYChannelSelector(yChannelSelector) | 492 , fYChannelSelector(yChannelSelector) |
| 491 , fScale(scale) { | 493 , fScale(scale) { |
| 492 this->initClassID<GrDisplacementMapEffect>(); | 494 this->initClassID<GrDisplacementMapEffect>(); |
| 493 this->addCoordTransform(&fDisplacementTransform); | 495 this->addCoordTransform(&fDisplacementTransform); |
| 494 this->addTextureAccess(&fDisplacementAccess); | 496 this->addTextureAccess(&fDisplacementAccess); |
| 495 this->addCoordTransform(&fColorTransform); | 497 this->addCoordTransform(&fColorTransform); |
| 496 this->addTextureAccess(&fColorAccess); | 498 this->addTextureAccess(&fColorAccess); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 634 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 633 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 635 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 634 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 636 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 635 | 637 |
| 636 uint32_t xKey = displacementMap.xChannelSelector(); | 638 uint32_t xKey = displacementMap.xChannelSelector(); |
| 637 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 639 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 638 | 640 |
| 639 b->add32(xKey | yKey); | 641 b->add32(xKey | yKey); |
| 640 } | 642 } |
| 641 #endif | 643 #endif |
| OLD | NEW |