From fb7c83a946ef3977d4860e1647f3f2dc78d2cb89 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 26 Jul 2017 13:57:33 -0400 Subject: [PATCH] Compose and YUV fragment processor clone implementations Change-Id: If4d9f1aaf0e5939afb5ad5825d7198db18541926 Reviewed-on: https://skia-review.googlesource.com/27060 Reviewed-by: Robert Phillips Commit-Queue: Brian Salomon --- .../effects/GrXfermodeFragmentProcessor.cpp | 37 +++++++++++++++---- src/gpu/effects/GrYUVEffect.cpp | 33 +++++++++++++++++ 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp index 94491c976e..80de68f4c2 100644 --- a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp +++ b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp @@ -50,9 +50,7 @@ public: return str; } - void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { - b->add32((int)fMode); - } + sk_sp clone() const override; SkBlendMode getMode() const { return fMode; } @@ -140,6 +138,10 @@ private: return flags; } + void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { + b->add32((int)fMode); + } + bool onIsEqual(const GrFragmentProcessor& other) const override { const ComposeTwoFragmentProcessor& cs = other.cast(); return fMode == cs.fMode; @@ -194,6 +196,16 @@ sk_sp ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe } #endif +sk_sp ComposeTwoFragmentProcessor::clone() const { + auto src = this->childProcessor(0).clone(); + auto dst = this->childProcessor(1).clone(); + if (!src || !dst) { + return nullptr; + } + return sk_sp( + new ComposeTwoFragmentProcessor(std::move(src), std::move(dst), fMode)); +} + GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLSLInstance() const{ return new GLComposeTwoFragmentProcessor; } @@ -281,10 +293,7 @@ public: return str; } - void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { - GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & SK_MaxU16) == (int)SkBlendMode::kLastMode); - b->add32((int)fMode | (fChild << 16)); - } + sk_sp clone() const override; SkBlendMode mode() const { return fMode; } @@ -386,6 +395,11 @@ private: return flags; } + void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { + GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & SK_MaxU16) == (int)SkBlendMode::kLastMode); + b->add32((int)fMode | (fChild << 16)); + } + bool onIsEqual(const GrFragmentProcessor& that) const override { return fMode == that.cast().fMode; } @@ -483,6 +497,15 @@ GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLSLInstance() con return new GLComposeOneFragmentProcessor; } +sk_sp ComposeOneFragmentProcessor::clone() const { + auto child = this->childProcessor(0).clone(); + if (!child) { + return nullptr; + } + return sk_sp( + new ComposeOneFragmentProcessor(std::move(child), fMode, fChild)); +} + ////////////////////////////////////////////////////////////////////////////// // It may seems as though when the input FP is the dst and the mode is kDst (or same for src/kSrc) diff --git a/src/gpu/effects/GrYUVEffect.cpp b/src/gpu/effects/GrYUVEffect.cpp index 7a18b02c4f..0d7f218e20 100644 --- a/src/gpu/effects/GrYUVEffect.cpp +++ b/src/gpu/effects/GrYUVEffect.cpp @@ -92,6 +92,10 @@ public: const char* name() const override { return "YUV to RGB"; } + sk_sp clone() const override { + return sk_sp(new YUVtoRGBEffect(*this)); + } + SkYUVColorSpace getColorSpace() const { return fColorSpace; } bool isNV12() const { @@ -175,6 +179,27 @@ private: } } + YUVtoRGBEffect(const YUVtoRGBEffect& that) + : INHERITED(kPreservesOpaqueInput_OptimizationFlag) + , fYTransform(that.fYTransform) + , fYSampler(that.fYSampler) + , fUTransform(that.fUTransform) + , fUSampler(that.fUSampler) + , fVTransform(that.fVTransform) + , fVSampler(that.fVSampler) + , fColorSpace(that.fColorSpace) + , fNV12(that.fNV12) { + this->initClassID(); + this->addCoordTransform(&fYTransform); + this->addTextureSampler(&fYSampler); + this->addCoordTransform(&fUTransform); + this->addTextureSampler(&fUSampler); + if (!fNV12) { + this->addCoordTransform(&fVTransform); + this->addTextureSampler(&fVSampler); + } + } + GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLProcessor; } @@ -224,6 +249,14 @@ public: const char* name() const override { return "RGBToYUV"; } + sk_sp clone() const override { + auto child = this->childProcessor(0).clone(); + if (!child) { + return nullptr; + } + return Make(std::move(child), fColorSpace, fOutputChannels); + } + SkYUVColorSpace getColorSpace() const { return fColorSpace; } OutputChannels outputChannels() const { return fOutputChannels; }