Index: src/core/SkLinearBitmapPipeline.cpp |
diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp |
index cfad6ec364042caeee02f67899a9bcb254302ed0..088e829345f016f3b06a84dc83cdef2f13dcbef2 100644 |
--- a/src/core/SkLinearBitmapPipeline.cpp |
+++ b/src/core/SkLinearBitmapPipeline.cpp |
@@ -567,62 +567,70 @@ private: |
using Blender = SkLinearBitmapPipeline::BlendProcessorInterface; |
-template <SkColorType colorType, template <SkColorType, SkGammaType, typename> class Sampler> |
-static void choose_specific_sampler( |
- Blender* next, |
- const SkPixmap& srcPixmap, |
- SkLinearBitmapPipeline::SampleStage* sampleStage) |
+template <SkColorType colorType> |
+static SkLinearBitmapPipeline::PixelAccessorInterface* choose_specific_accessor( |
+ const SkPixmap& srcPixmap, SkLinearBitmapPipeline::Accessor* accessor) |
{ |
if (srcPixmap.info().gammaCloseToSRGB()) { |
- using S = Sampler<colorType, kSRGB_SkGammaType, Blender>; |
- sampleStage->initStage<S>(next, srcPixmap); |
+ using PA = PixelAccessor<colorType, kSRGB_SkGammaType>; |
+ accessor->init<PA>(srcPixmap); |
+ return accessor->get(); |
} else { |
- using S = Sampler<colorType, kLinear_SkGammaType, Blender>; |
- sampleStage->initStage<S>(next, srcPixmap); |
+ using PA = PixelAccessor<colorType, kLinear_SkGammaType>; |
+ accessor->init<PA>(srcPixmap); |
+ return accessor->get(); |
} |
} |
-template<template <SkColorType, SkGammaType, typename> class Sampler> |
+template<template <typename, typename> class Sampler> |
static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_base( |
Blender* next, |
const SkPixmap& srcPixmap, |
const SkColor A8TintColor, |
- SkLinearBitmapPipeline::SampleStage* sampleStage) |
+ SkLinearBitmapPipeline::SampleStage* sampleStage, |
+ SkLinearBitmapPipeline::Accessor* accessor) |
{ |
const SkImageInfo& imageInfo = srcPixmap.info(); |
+ |
+ SkLinearBitmapPipeline::PixelAccessorInterface* pixelAccessor = nullptr; |
switch (imageInfo.colorType()) { |
case kAlpha_8_SkColorType: { |
- using S = Sampler<kAlpha_8_SkColorType, kLinear_SkGammaType, Blender>; |
- sampleStage->initStage<S>(next, srcPixmap, A8TintColor); |
+ using PA = PixelAccessor<kAlpha_8_SkColorType, kLinear_SkGammaType>; |
+ accessor->init<PA>(srcPixmap, A8TintColor); |
+ pixelAccessor = accessor->get(); |
} |
break; |
case kARGB_4444_SkColorType: |
- choose_specific_sampler<kARGB_4444_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kARGB_4444_SkColorType>(srcPixmap, accessor); |
break; |
case kRGB_565_SkColorType: |
- choose_specific_sampler<kRGB_565_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kRGB_565_SkColorType>(srcPixmap, accessor); |
break; |
case kRGBA_8888_SkColorType: |
- choose_specific_sampler<kRGBA_8888_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kRGBA_8888_SkColorType>(srcPixmap, accessor); |
break; |
case kBGRA_8888_SkColorType: |
- choose_specific_sampler<kBGRA_8888_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kBGRA_8888_SkColorType>(srcPixmap, accessor); |
break; |
case kIndex_8_SkColorType: |
- choose_specific_sampler<kIndex_8_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kIndex_8_SkColorType>(srcPixmap, accessor); |
break; |
case kGray_8_SkColorType: |
- choose_specific_sampler<kGray_8_SkColorType, Sampler>(next, srcPixmap, sampleStage); |
+ pixelAccessor = choose_specific_accessor<kGray_8_SkColorType>(srcPixmap, accessor); |
break; |
case kRGBA_F16_SkColorType: { |
- using S = Sampler<kRGBA_F16_SkColorType, kLinear_SkGammaType, Blender>; |
- sampleStage->initStage<S>(next, srcPixmap); |
+ using PA = PixelAccessor<kRGBA_F16_SkColorType, kLinear_SkGammaType>; |
+ accessor->init<PA>(srcPixmap); |
+ pixelAccessor = accessor->get(); |
} |
break; |
default: |
SkFAIL("Not implemented. Unsupported src"); |
break; |
} |
+ |
+ using S = Sampler<PixelAccessorShim, Blender>; |
+ sampleStage->initStage<S>(next, pixelAccessor); |
return sampleStage->get(); |
} |
@@ -631,13 +639,60 @@ SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler( |
SkFilterQuality filterQuality, |
const SkPixmap& srcPixmap, |
const SkColor A8TintColor, |
- SkLinearBitmapPipeline::SampleStage* sampleStage) |
-{ |
+ SkLinearBitmapPipeline::SampleStage* sampleStage, |
+ SkLinearBitmapPipeline::Accessor* accessor) { |
+ const SkImageInfo& imageInfo = srcPixmap.info(); |
+ |
+ // Special case samplers with fully expanded templates |
+ if (imageInfo.gammaCloseToSRGB()) { |
+ if (filterQuality == kNone_SkFilterQuality) { |
+ switch (imageInfo.colorType()) { |
+ case kN32_SkColorType: { |
+ using S = |
+ NearestNeighborSampler< |
+ PixelAccessor<kN32_SkColorType, kSRGB_SkGammaType>, Blender>; |
+ sampleStage->initStage<S>(next, srcPixmap); |
+ return sampleStage->get(); |
+ } |
+ case kIndex_8_SkColorType: { |
+ using S = |
+ NearestNeighborSampler< |
+ PixelAccessor<kIndex_8_SkColorType, kSRGB_SkGammaType>, Blender>; |
+ sampleStage->initStage<S>(next, srcPixmap); |
+ return sampleStage->get(); |
+ } |
+ default: |
+ break; |
+ } |
+ } else { |
+ switch (imageInfo.colorType()) { |
+ case kN32_SkColorType: { |
+ using S = |
+ BilerpSampler< |
+ PixelAccessor<kN32_SkColorType, kSRGB_SkGammaType>, Blender>; |
+ sampleStage->initStage<S>(next, srcPixmap); |
+ return sampleStage->get(); |
+ } |
+ case kIndex_8_SkColorType: { |
+ using S = |
+ BilerpSampler< |
+ PixelAccessor<kIndex_8_SkColorType, kSRGB_SkGammaType>, Blender>; |
+ sampleStage->initStage<S>(next, srcPixmap); |
+ return sampleStage->get(); |
+ } |
+ default: |
+ break; |
+ } |
+ } |
+ } |
+ |
+ // General cases. |
if (filterQuality == kNone_SkFilterQuality) { |
return choose_pixel_sampler_base<NearestNeighborSampler>( |
- next, srcPixmap, A8TintColor, sampleStage); |
+ next, srcPixmap, A8TintColor, sampleStage, accessor); |
} else { |
- return choose_pixel_sampler_base<BilerpSampler>(next, srcPixmap, A8TintColor, sampleStage); |
+ return choose_pixel_sampler_base<BilerpSampler>( |
+ next, srcPixmap, A8TintColor, sampleStage, accessor); |
} |
} |
@@ -742,7 +797,7 @@ SkLinearBitmapPipeline::SkLinearBitmapPipeline( |
// identity matrix, the matrix stage is skipped, and the tilerStage is the first stage. |
auto blenderStage = choose_blender_for_shading(alphaType, postAlpha, &fBlenderStage); |
auto samplerStage = choose_pixel_sampler( |
- blenderStage, filterQuality, srcPixmap, paintColor, &fSampleStage); |
+ blenderStage, filterQuality, srcPixmap, paintColor, &fSampleStage, &fAccessor); |
auto tilerStage = choose_tiler(samplerStage, dimensions, xTile, yTile, |
filterQuality, dx, &fTileStage); |
fFirstStage = choose_matrix(tilerStage, adjustedInverse, &fMatrixStage); |