From 21aa3d0e66fdcae5347f7555640bc8e0b4894204 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Wed, 30 Nov 2016 16:40:56 -0500 Subject: fold more in SkRasterPipelineBlitter No change in behavior. This just moves the responsibility for this optimization to the blitter (which knows what it's doing) rather than to compile_pipeline(), which sort of has to guess. CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD Change-Id: I93ad0ac896075deab995b865b188b42de637f0f7 Reviewed-on: https://skia-review.googlesource.com/5398 Commit-Queue: Mike Klein Reviewed-by: Herb Derby --- src/core/SkRasterPipelineBlitter.cpp | 48 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/core/SkRasterPipelineBlitter.cpp') diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp index d7d66cfc72..8adb328315 100644 --- a/src/core/SkRasterPipelineBlitter.cpp +++ b/src/core/SkRasterPipelineBlitter.cpp @@ -26,6 +26,7 @@ public: : fDst(dst) , fBlend(blend) , fPaintColor(paintColor) + , fShaderIsConstant(true) , fScratchAlloc(fScratch, sizeof(fScratch)) , fScratchFallback(&fScratchAlloc) {} @@ -39,15 +40,18 @@ public: // blits using something like a SkRasterPipeline::runFew() method. private: - void append_load_d(SkRasterPipeline*) const; - void append_store (SkRasterPipeline*) const; - void append_blend (SkRasterPipeline*) const; - void maybe_clamp (SkRasterPipeline*) const; + void append_load_d (SkRasterPipeline*) const; + void append_blend (SkRasterPipeline*) const; + void maybe_clamp (SkRasterPipeline*) const; + void append_swizzles(SkRasterPipeline*) const; + void append_store (SkRasterPipeline*) const; SkPixmap fDst; SkBlendMode fBlend; SkPM4f fPaintColor; SkRasterPipeline fShader; + bool fShaderIsConstant; + SkPM4f fTrivialBlendColor; // These functions are compiled lazily when first used. std::function fBlitH = nullptr, @@ -99,9 +103,10 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, return nullptr; }; - SkBlendMode* blend = &blitter->fBlend; - SkPM4f* paintColor = &blitter->fPaintColor; - SkRasterPipeline* pipeline = &blitter->fShader; + SkBlendMode* blend = &blitter->fBlend; + SkPM4f* paintColor = &blitter->fPaintColor; + SkRasterPipeline* pipeline = &blitter->fShader; + bool* is_constant = &blitter->fShaderIsConstant; SkShader* shader = paint.getShader(); SkColorFilter* colorFilter = paint.getColorFilter(); @@ -111,9 +116,7 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, return earlyOut(); } - bool is_opaque = paintColor->a() == 1.0f, - is_constant = true; - + bool is_opaque = paintColor->a() == 1.0f; if (shader) { if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback, ctm, paint)) { @@ -125,7 +128,7 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, } is_opaque = is_opaque && shader->isOpaque(); - is_constant = shader->isConstant(); + *is_constant = shader->isConstant(); } else { pipeline->append(SkRasterPipeline::constant_color, paintColor); } @@ -138,7 +141,7 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); } - if (is_constant) { + if (*is_constant) { pipeline->append(SkRasterPipeline::store_f32, &paintColor); pipeline->run(0,0, 1); @@ -173,15 +176,18 @@ void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { } } -void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { - SkASSERT(supported(fDst.info())); - +void SkRasterPipelineBlitter::append_swizzles(SkRasterPipeline* p) const { if (fDst.info().gammaCloseToSRGB()) { p->append(SkRasterPipeline::to_srgb); } if (fDst.info().colorType() == kBGRA_8888_SkColorType) { p->append(SkRasterPipeline::swap_rb); } +} + +void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { + SkASSERT(supported(fDst.info())); + switch (fDst.info().colorType()) { case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break; case kBGRA_8888_SkColorType: @@ -210,6 +216,15 @@ void SkRasterPipelineBlitter::blitH(int x, int y, int w) { this->append_blend(&p); this->maybe_clamp(&p); } + this->append_swizzles(&p); + if (fBlend == SkBlendMode::kSrc && fShaderIsConstant) { + auto trivial = &fTrivialBlendColor; + p.append(SkRasterPipeline::store_f32, &trivial); + p.run(0,0, 1); + + p = SkRasterPipeline(); + p.append(SkRasterPipeline::constant_color, trivial); + } this->append_store(&p); fBlitH = p.compile(); } @@ -232,6 +247,7 @@ void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage); } this->maybe_clamp(&p); + this->append_swizzles(&p); this->append_store(&p); fBlitAntiH = p.compile(); } @@ -270,6 +286,7 @@ void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) p.append(SkRasterPipeline::lerp_u8, &fMaskPtr); } this->maybe_clamp(&p); + this->append_swizzles(&p); this->append_store(&p); fBlitMaskA8 = p.compile(); } @@ -281,6 +298,7 @@ void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) this->append_blend(&p); p.append(SkRasterPipeline::lerp_565, &fMaskPtr); this->maybe_clamp(&p); + this->append_swizzles(&p); this->append_store(&p); fBlitMaskLCD16 = p.compile(); } -- cgit v1.2.3