diff options
author | herb <herb@google.com> | 2016-04-14 11:16:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-14 11:16:44 -0700 |
commit | d5f2e2e7429b643943d2f8a532c65e2498223b5b (patch) | |
tree | a3409cec23f0654053b9fe9b5ee8b14a23637bb1 /src/core | |
parent | bc9517375685e452144751cfdcd714a51d736a3c (diff) |
Add F16 source to the linear pipelin.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1882893003
Review URL: https://codereview.chromium.org/1882893003
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapProcShader.cpp | 6 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline.cpp | 11 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline_sample.h | 54 |
3 files changed, 67 insertions, 4 deletions
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index 3b90704084..5e66bf1959 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -227,7 +227,8 @@ static bool choose_linear_pipeline(const SkShader::ContextRec& rec, const SkImag // if (srcInfo.colorType() != kRGBA_8888_SkColorType && srcInfo.colorType() != kBGRA_8888_SkColorType - && srcInfo.colorType() != kIndex_8_SkColorType) { + && srcInfo.colorType() != kIndex_8_SkColorType + && srcInfo.colorType() != kRGBA_F16_SkColorType) { return false; } @@ -280,7 +281,8 @@ SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader, } if (info->fPixmap.colorType() != kRGBA_8888_SkColorType && info->fPixmap.colorType() != kBGRA_8888_SkColorType - && info->fPixmap.colorType() != kIndex_8_SkColorType) { + && info->fPixmap.colorType() != kIndex_8_SkColorType + && info->fPixmap.colorType() != kRGBA_F16_SkColorType) { return nullptr; } return new (storage) LinearPipelineContext(shader, rec, info); diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp index cf69e974dd..415179a0b1 100644 --- a/src/core/SkLinearBitmapPipeline.cpp +++ b/src/core/SkLinearBitmapPipeline.cpp @@ -549,6 +549,9 @@ private: GeneralSampler<SourceStrategy, Next> fSampler; }; +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Specialized Samplers + // RGBA8888UnitRepeatSrc - A sampler that takes advantage of the fact the the src and destination // are the same format and do not need in transformations in pixel space. Therefore, there is no // need to convert them to HiFi pixel format. @@ -651,6 +654,9 @@ static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba sampleStage->initStage<Sampler<PixelIndex8LRGB, Blender>>(next, srcPixmap); } break; + case kRGBA_F16_SkColorType: + sampleStage->initStage<Sampler<PixelHalfLinear, Blender>>(next, srcPixmap); + break; default: SkFAIL("Not implemented. Unsupported src"); break; @@ -718,7 +724,7 @@ private: Sk4f fPostAlpha; }; -static SkLinearBitmapPipeline::BlendProcessorInterface* choose_blender( +static SkLinearBitmapPipeline::BlendProcessorInterface* choose_blender_for_shading( SkAlphaType alphaType, float postAlpha, SkLinearBitmapPipeline::BlenderStage* blenderStage) { @@ -730,6 +736,7 @@ static SkLinearBitmapPipeline::BlendProcessorInterface* choose_blender( } return blenderStage->get(); } + } // namespace //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -768,7 +775,7 @@ SkLinearBitmapPipeline::SkLinearBitmapPipeline( // As the stages are built, the chooser function may skip a stage. For example, with the // identity matrix, the matrix stage is skipped, and the tilerStage is the first stage. - auto blenderStage = choose_blender(alphaType, postAlpha, &fBlenderStage); + auto blenderStage = choose_blender_for_shading(alphaType, postAlpha, &fBlenderStage); auto samplerStage = choose_pixel_sampler(blenderStage, filterQuality, srcPixmap, &fSampleStage); auto tilerStage = choose_tiler(samplerStage, dimensions, xTile, yTile, filterQuality, dx, &fTileStage); diff --git a/src/core/SkLinearBitmapPipeline_sample.h b/src/core/SkLinearBitmapPipeline_sample.h index 7157ffc8ee..d436e39399 100644 --- a/src/core/SkLinearBitmapPipeline_sample.h +++ b/src/core/SkLinearBitmapPipeline_sample.h @@ -9,6 +9,7 @@ #define SkLinearBitmapPipeline_sampler_DEFINED #include "SkFixed.h" +#include "SkHalf.h" #include "SkLinearBitmapPipeline_core.h" #include <array> #include <tuple> @@ -734,6 +735,59 @@ private: using PixelIndex8SRGB = PixelIndex8<kSRGB_SkColorProfileType>; using PixelIndex8LRGB = PixelIndex8<kLinear_SkColorProfileType>; +class PixelHalfLinear { +public: + PixelHalfLinear(int width, const uint64_t* src) : fSrc{src}, fWidth{width}{ } + PixelHalfLinear(const SkPixmap& srcPixmap) + : fSrc{srcPixmap.addr64()} + , fWidth{static_cast<int>(srcPixmap.rowBytes() / 8)} { } + + void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) { + Sk4i XIs = SkNx_cast<int, SkScalar>(xs); + Sk4i YIs = SkNx_cast<int, SkScalar>(ys); + Sk4i bufferLoc = YIs * fWidth + XIs; + switch (n) { + case 3: + *px2 = this->getPixelAt(fSrc, bufferLoc[2]); + case 2: + *px1 = this->getPixelAt(fSrc, bufferLoc[1]); + case 1: + *px0 = this->getPixelAt(fSrc, bufferLoc[0]); + default: + break; + } + } + + void VECTORCALL get4Pixels(Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { + Sk4i XIs = SkNx_cast<int, SkScalar>(xs); + Sk4i YIs = SkNx_cast<int, SkScalar>(ys); + Sk4i bufferLoc = YIs * fWidth + XIs; + *px0 = this->getPixelAt(fSrc, bufferLoc[0]); + *px1 = this->getPixelAt(fSrc, bufferLoc[1]); + *px2 = this->getPixelAt(fSrc, bufferLoc[2]); + *px3 = this->getPixelAt(fSrc, bufferLoc[3]); + } + + void get4Pixels(const void* vsrc, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { + const uint32_t* src = static_cast<const uint32_t*>(vsrc); + *px0 = this->getPixelAt(src, index + 0); + *px1 = this->getPixelAt(src, index + 1); + *px2 = this->getPixelAt(src, index + 2); + *px3 = this->getPixelAt(src, index + 3); + } + + Sk4f getPixelAt(const void* vsrc, int index) { + const uint64_t* src = static_cast<const uint64_t*>(vsrc); + return SkHalfToFloat_01(*src); + } + + const void* row(int y) { return fSrc + y * fWidth[0]; } + +private: + const uint64_t* const fSrc; + const Sk4i fWidth; +}; + } // namespace #endif // SkLinearBitmapPipeline_sampler_DEFINED |