Reduce size of LinearBitmapPipeline from 281K to 134K, but keep the same speed.
Speed checked using top25desk SKPS. Size measured using: llvm-nm-3.6 -print-file-name -print-size -U out/Release/libskia_core.a | awk '{totals[$1] += strtonum("0x" $3)} END { for (i in totals) {print totals[i], i}}' | sort -n | column -t GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2100323002 Review-Url: https://codereview.chromium.org/2100323002
This commit is contained in:
parent
f3bc76a12a
commit
00dd4538a5
@ -56,7 +56,7 @@ private:
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
||||
enum {kSkBlitterContextSize = 3100};
|
||||
enum {kSkBlitterContextSize = 3200};
|
||||
|
||||
// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
|
||||
// bytes requested is calculated using one of our large shaders, its context size plus the size of
|
||||
|
@ -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);
|
||||
|
@ -91,16 +91,51 @@ public:
|
||||
mutable Space fSpace;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PolyMemory
|
||||
template <typename Base, size_t kSize>
|
||||
class PolyMemory {
|
||||
public:
|
||||
PolyMemory() : fIsInitialized{false} { }
|
||||
~PolyMemory() {
|
||||
if (fIsInitialized) {
|
||||
this->get()->~Base();
|
||||
}
|
||||
}
|
||||
template<typename Variant, typename... Args>
|
||||
void init(Args&& ... args) {
|
||||
SkASSERTF(sizeof(Variant) <= sizeof(fSpace),
|
||||
"Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSpace));
|
||||
|
||||
new (&fSpace) Variant(std::forward<Args>(args)...);
|
||||
fIsInitialized = true;
|
||||
}
|
||||
|
||||
Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
|
||||
Base* operator->() const { return this->get(); }
|
||||
Base& operator*() const { return *(this->get()); }
|
||||
|
||||
private:
|
||||
struct SK_STRUCT_ALIGN(16) Space {
|
||||
char space[kSize];
|
||||
};
|
||||
mutable Space fSpace;
|
||||
bool fIsInitialized;
|
||||
|
||||
};
|
||||
|
||||
class PointProcessorInterface;
|
||||
class SampleProcessorInterface;
|
||||
class BlendProcessorInterface;
|
||||
class DestinationInterface;
|
||||
class PixelAccessorInterface;
|
||||
|
||||
// These values were generated by the assert above in Stage::init{Sink|Stage}.
|
||||
using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInterface>;
|
||||
using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInterface>;
|
||||
using SampleStage = Stage<SampleProcessorInterface, 100, BlendProcessorInterface>;
|
||||
using BlenderStage = Stage<BlendProcessorInterface, 40>;
|
||||
using Accessor = PolyMemory<PixelAccessorInterface, 48>;
|
||||
|
||||
private:
|
||||
PointProcessorInterface* fFirstStage;
|
||||
@ -109,6 +144,7 @@ private:
|
||||
SampleStage fSampleStage;
|
||||
BlenderStage fBlenderStage;
|
||||
DestinationInterface* fLastStage;
|
||||
Accessor fAccessor;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef SkLinearBitmapPipeline_core_DEFINED
|
||||
#define SkLinearBitmapPipeline_core_DEFINED
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "SkNx.h"
|
||||
|
||||
@ -238,4 +239,23 @@ public:
|
||||
virtual void SK_VECTORCALL blend4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0;
|
||||
};
|
||||
|
||||
class SkLinearBitmapPipeline::PixelAccessorInterface {
|
||||
public:
|
||||
virtual ~PixelAccessorInterface() { }
|
||||
virtual void SK_VECTORCALL getFewPixels(
|
||||
int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) const = 0;
|
||||
|
||||
virtual void SK_VECTORCALL get4Pixels(
|
||||
Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const = 0;
|
||||
|
||||
virtual void get4Pixels(
|
||||
const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const = 0;
|
||||
|
||||
virtual Sk4f getPixelFromRow(const void* row, int index) const = 0;
|
||||
|
||||
virtual Sk4f getPixelAt(int index) const = 0;
|
||||
|
||||
virtual const void* row(int y) const = 0;
|
||||
};
|
||||
|
||||
#endif // SkLinearBitmapPipeline_core_DEFINED
|
||||
|
@ -53,23 +53,23 @@ static Sk4s SK_VECTORCALL bilerp4(Sk4s xs, Sk4s ys, Sk4f px00, Sk4f px10,
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PixelGetter is the lowest level interface to the source data. There is a PixelGetter for each
|
||||
// PixelGetter is the lowest level interface to the source data. There is a PixelConverter for each
|
||||
// of the different SkColorTypes.
|
||||
template <SkColorType, SkGammaType> class PixelGetter;
|
||||
template <SkColorType, SkGammaType> class PixelConverter;
|
||||
|
||||
// Alpha handling:
|
||||
// The alpha from the paint (tintColor) is used in the blend part of the pipeline to modulate
|
||||
// the entire bitmap. So, the tint color is given an alpha of 1.0 so that the later alpha can
|
||||
// modulate this color later.
|
||||
template <>
|
||||
class PixelGetter<kAlpha_8_SkColorType, kLinear_SkGammaType> {
|
||||
class PixelConverter<kAlpha_8_SkColorType, kLinear_SkGammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap, SkColor tintColor)
|
||||
PixelConverter(const SkPixmap& srcPixmap, SkColor tintColor)
|
||||
: fTintColor{set_alpha(Sk4f_from_SkColor(tintColor), 1.0f)} { }
|
||||
|
||||
Sk4f getPixelAt(const uint8_t* src) {
|
||||
return fTintColor * (*src * (1.0f/255.0f));
|
||||
Sk4f toSk4f(const Element pixel) const {
|
||||
return fTintColor * (pixel * (1.0f/255.0f));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -77,13 +77,40 @@ private:
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kRGB_565_SkColorType, gammaType> {
|
||||
class PixelConverter<kRGB_565_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint16_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint16_t* src) {
|
||||
SkPMColor pixel = SkPixel16ToPixel32(*src);
|
||||
Sk4f toSk4f(Element pixel) const {
|
||||
SkPMColor pixel32 = SkPixel16ToPixel32(pixel);
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel32)
|
||||
: Sk4f_fromL32(pixel32);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelConverter<kARGB_4444_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint16_t;
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f toSk4f(Element pixel) const {
|
||||
SkPMColor pixel32 = SkPixel4444ToPixel32(pixel);
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel32)
|
||||
: Sk4f_fromL32(pixel32);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelConverter<kRGBA_8888_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint32_t;
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f toSk4f(Element pixel) const {
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel)
|
||||
: Sk4f_fromL32(pixel);
|
||||
@ -91,51 +118,22 @@ public:
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kARGB_4444_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint16_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint16_t* src) {
|
||||
SkPMColor pixel = SkPixel4444ToPixel32(*src);
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel)
|
||||
: Sk4f_fromL32(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kRGBA_8888_SkColorType, gammaType> {
|
||||
class PixelConverter<kBGRA_8888_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint32_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint32_t* src) {
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(*src)
|
||||
: Sk4f_fromL32(*src);
|
||||
Sk4f toSk4f(Element pixel) const {
|
||||
return swizzle_rb(
|
||||
gammaType == kSRGB_SkGammaType ? Sk4f_fromS32(pixel) : Sk4f_fromL32(pixel));
|
||||
}
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kBGRA_8888_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint32_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint32_t* src) {
|
||||
Sk4f pixel = gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(*src)
|
||||
: Sk4f_fromL32(*src);
|
||||
return swizzle_rb(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kIndex_8_SkColorType, gammaType> {
|
||||
class PixelConverter<kIndex_8_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) {
|
||||
PixelConverter(const SkPixmap& srcPixmap) {
|
||||
SkColorTable* skColorTable = srcPixmap.ctable();
|
||||
SkASSERT(skColorTable != nullptr);
|
||||
|
||||
@ -145,7 +143,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
PixelGetter(const PixelGetter& strategy) {
|
||||
PixelConverter(const PixelConverter& strategy) {
|
||||
fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get());
|
||||
// TODO: figure out the count.
|
||||
for (int i = 0; i < 256; i++) {
|
||||
@ -153,8 +151,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Sk4f getPixelAt(const uint8_t* src) {
|
||||
return fColorTable[*src];
|
||||
Sk4f toSk4f(Element index) const {
|
||||
return fColorTable[index];
|
||||
}
|
||||
|
||||
private:
|
||||
@ -179,44 +177,81 @@ private:
|
||||
};
|
||||
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kGray_8_SkColorType, gammaType> {
|
||||
class PixelConverter<kGray_8_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint8_t* src) {
|
||||
float gray = *src * (1.0f/255.0f);
|
||||
Sk4f pixel = Sk4f{gray, gray, gray, 1.0f};
|
||||
Sk4f toSk4f(Element pixel) const {
|
||||
float gray = pixel * (1.0f/255.0f);
|
||||
Sk4f result = Sk4f{gray, gray, gray, 1.0f};
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? srgb_to_linear(pixel)
|
||||
: pixel;
|
||||
? srgb_to_linear(result)
|
||||
: result;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class PixelGetter<kRGBA_F16_SkColorType, kLinear_SkGammaType> {
|
||||
class PixelConverter<kRGBA_F16_SkColorType, kLinear_SkGammaType> {
|
||||
public:
|
||||
using Element = uint64_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
PixelConverter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint64_t* src) {
|
||||
return SkHalfToFloat_01(*src);
|
||||
Sk4f toSk4f(const Element pixel) const {
|
||||
return SkHalfToFloat_01(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
class PixelAccessorShim {
|
||||
public:
|
||||
explicit PixelAccessorShim(SkLinearBitmapPipeline::PixelAccessorInterface* accessor)
|
||||
: fPixelAccessor(accessor) { }
|
||||
|
||||
void SK_VECTORCALL getFewPixels(
|
||||
int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) const {
|
||||
fPixelAccessor->getFewPixels(n, xs, ys, px0, px1, px2);
|
||||
}
|
||||
|
||||
void SK_VECTORCALL get4Pixels(
|
||||
Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const {
|
||||
fPixelAccessor->get4Pixels(xs, ys, px0, px1, px2, px3);
|
||||
}
|
||||
|
||||
void get4Pixels(
|
||||
const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const {
|
||||
fPixelAccessor->get4Pixels(src, index, px0, px1, px2, px3);
|
||||
};
|
||||
|
||||
Sk4f getPixelFromRow(const void* row, int index) const {
|
||||
return fPixelAccessor->getPixelFromRow(row, index);
|
||||
}
|
||||
|
||||
Sk4f getPixelAt(int index) const {
|
||||
return fPixelAccessor->getPixelAt(index);
|
||||
}
|
||||
|
||||
const void* row(int y) const {
|
||||
return fPixelAccessor->row(y);
|
||||
}
|
||||
|
||||
private:
|
||||
SkLinearBitmapPipeline::PixelAccessorInterface* const fPixelAccessor;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PixelAccessor handles all the same plumbing for all the PixelGetters.
|
||||
template <SkColorType colorType, SkGammaType gammaType>
|
||||
class PixelAccessor {
|
||||
using Element = typename PixelGetter<colorType, gammaType>::Element;
|
||||
class PixelAccessor final : public SkLinearBitmapPipeline::PixelAccessorInterface {
|
||||
using Element = typename PixelConverter<colorType, gammaType>::Element;
|
||||
public:
|
||||
template <typename... Args>
|
||||
PixelAccessor(const SkPixmap& srcPixmap, Args&&... args)
|
||||
: fSrc{static_cast<const Element*>(srcPixmap.addr())}
|
||||
, fWidth{srcPixmap.rowBytesAsPixels()}
|
||||
, fGetter{srcPixmap, std::move<Args>(args)...} { }
|
||||
, fConverter{srcPixmap, std::move<Args>(args)...} { }
|
||||
|
||||
void SK_VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) {
|
||||
void SK_VECTORCALL getFewPixels (
|
||||
int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) const override {
|
||||
Sk4i XIs = SkNx_cast<int, SkScalar>(xs);
|
||||
Sk4i YIs = SkNx_cast<int, SkScalar>(ys);
|
||||
Sk4i bufferLoc = YIs * fWidth + XIs;
|
||||
@ -232,7 +267,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void SK_VECTORCALL get4Pixels(Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) {
|
||||
void SK_VECTORCALL get4Pixels(
|
||||
Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const override {
|
||||
Sk4i XIs = SkNx_cast<int, SkScalar>(xs);
|
||||
Sk4i YIs = SkNx_cast<int, SkScalar>(ys);
|
||||
Sk4i bufferLoc = YIs * fWidth + XIs;
|
||||
@ -242,28 +278,29 @@ public:
|
||||
*px3 = this->getPixelAt(bufferLoc[3]);
|
||||
}
|
||||
|
||||
void get4Pixels(const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) {
|
||||
void get4Pixels(
|
||||
const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const override {
|
||||
*px0 = this->getPixelFromRow(src, index + 0);
|
||||
*px1 = this->getPixelFromRow(src, index + 1);
|
||||
*px2 = this->getPixelFromRow(src, index + 2);
|
||||
*px3 = this->getPixelFromRow(src, index + 3);
|
||||
}
|
||||
|
||||
Sk4f getPixelFromRow(const void* row, int index) {
|
||||
Sk4f getPixelFromRow(const void* row, int index) const override {
|
||||
const Element* src = static_cast<const Element*>(row);
|
||||
return fGetter.getPixelAt(src + index);
|
||||
return fConverter.toSk4f(src[index]);
|
||||
}
|
||||
|
||||
Sk4f getPixelAt(int index) {
|
||||
Sk4f getPixelAt(int index) const override {
|
||||
return this->getPixelFromRow(fSrc, index);
|
||||
}
|
||||
|
||||
const void* row(int y) const { return fSrc + y * fWidth[0]; }
|
||||
const void* row(int y) const override { return fSrc + y * fWidth; }
|
||||
|
||||
private:
|
||||
const Element* const fSrc;
|
||||
const Sk4i fWidth;
|
||||
PixelGetter<colorType, gammaType> fGetter;
|
||||
const int fWidth;
|
||||
PixelConverter<colorType, gammaType> fConverter;
|
||||
};
|
||||
|
||||
// We're moving through source space at a rate of 1 source pixel per 1 dst pixel.
|
||||
@ -308,21 +345,21 @@ static void src_strategy_blend(Span span, Next* next, Strategy* strategy) {
|
||||
}
|
||||
|
||||
// NearestNeighborSampler - use nearest neighbor filtering to create runs of destination pixels.
|
||||
template<SkColorType colorType, SkGammaType gammaType, typename Next>
|
||||
template<typename Accessor, typename Next>
|
||||
class NearestNeighborSampler : public SkLinearBitmapPipeline::SampleProcessorInterface {
|
||||
public:
|
||||
template<typename... Args>
|
||||
NearestNeighborSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next, Args&& ... args)
|
||||
: fNext{next}, fStrategy{std::forward<Args>(args)...} { }
|
||||
: fNext{next}, fAccessor{std::forward<Args>(args)...} { }
|
||||
|
||||
NearestNeighborSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next,
|
||||
const NearestNeighborSampler& sampler)
|
||||
: fNext{next}, fStrategy{sampler.fStrategy} { }
|
||||
: fNext{next}, fAccessor{sampler.fAccessor} { }
|
||||
|
||||
void SK_VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override {
|
||||
SkASSERT(0 < n && n < 4);
|
||||
Sk4f px0, px1, px2;
|
||||
fStrategy.getFewPixels(n, xs, ys, &px0, &px1, &px2);
|
||||
fAccessor.getFewPixels(n, xs, ys, &px0, &px1, &px2);
|
||||
if (n >= 1) fNext->blendPixel(px0);
|
||||
if (n >= 2) fNext->blendPixel(px1);
|
||||
if (n >= 3) fNext->blendPixel(px2);
|
||||
@ -330,7 +367,7 @@ public:
|
||||
|
||||
void SK_VECTORCALL pointList4(Sk4s xs, Sk4s ys) override {
|
||||
Sk4f px0, px1, px2, px3;
|
||||
fStrategy.get4Pixels(xs, ys, &px0, &px1, &px2, &px3);
|
||||
fAccessor.get4Pixels(xs, ys, &px0, &px1, &px2, &px3);
|
||||
fNext->blend4Pixels(px0, px1, px2, px3);
|
||||
}
|
||||
|
||||
@ -344,7 +381,7 @@ public:
|
||||
if (absLength < (count - 1)) {
|
||||
this->spanSlowRate(span);
|
||||
} else if (absLength == (count - 1)) {
|
||||
src_strategy_blend(span, fNext, &fStrategy);
|
||||
src_strategy_blend(span, fNext, &fAccessor);
|
||||
} else {
|
||||
this->spanFastRate(span);
|
||||
}
|
||||
@ -378,19 +415,19 @@ private:
|
||||
SkScalar dx = length / (count - 1);
|
||||
SkFixed fdx = SkScalarToFixed(dx);
|
||||
|
||||
const void* row = fStrategy.row((int)std::floor(Y(start)));
|
||||
const void* row = fAccessor.row((int)std::floor(Y(start)));
|
||||
Next* next = fNext;
|
||||
|
||||
int ix = SkFixedFloorToInt(fx);
|
||||
int prevIX = ix;
|
||||
Sk4f fpixel = fStrategy.getPixelFromRow(row, ix);
|
||||
Sk4f fpixel = fAccessor.getPixelFromRow(row, ix);
|
||||
|
||||
// When dx is less than one, each pixel is used more than once. Using the fixed point fx
|
||||
// allows the code to quickly check that the same pixel is being used. The code uses this
|
||||
// same pixel check to do the sRGB and normalization only once.
|
||||
auto getNextPixel = [&]() {
|
||||
if (ix != prevIX) {
|
||||
fpixel = fStrategy.getPixelFromRow(row, ix);
|
||||
fpixel = fAccessor.getPixelFromRow(row, ix);
|
||||
prevIX = ix;
|
||||
}
|
||||
fx += fdx;
|
||||
@ -415,7 +452,7 @@ private:
|
||||
// We're moving through source space at a rate of 1 source pixel per 1 dst pixel.
|
||||
// We'll never re-use pixels, but we can at least load contiguous pixels.
|
||||
void spanUnitRate(Span span) {
|
||||
src_strategy_blend(span, fNext, &fStrategy);
|
||||
src_strategy_blend(span, fNext, &fAccessor);
|
||||
}
|
||||
|
||||
// We're moving through source space faster than dst (zoomed out),
|
||||
@ -425,21 +462,21 @@ private:
|
||||
}
|
||||
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, gammaType> fStrategy;
|
||||
Accessor fAccessor;
|
||||
};
|
||||
|
||||
// -- BilerpSampler --------------------------------------------------------------------------------
|
||||
// BilerpSampler - use a bilerp filter to create runs of destination pixels.
|
||||
template<SkColorType colorType, SkGammaType gammaType, typename Next>
|
||||
template<typename Accessor, typename Next>
|
||||
class BilerpSampler : public SkLinearBitmapPipeline::SampleProcessorInterface {
|
||||
public:
|
||||
template<typename... Args>
|
||||
BilerpSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next, Args&& ... args)
|
||||
: fNext{next}, fStrategy{std::forward<Args>(args)...} { }
|
||||
: fNext{next}, fAccessor{std::forward<Args>(args)...} { }
|
||||
|
||||
BilerpSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next,
|
||||
const BilerpSampler& sampler)
|
||||
: fNext{next}, fStrategy{sampler.fStrategy} { }
|
||||
: fNext{next}, fAccessor{sampler.fAccessor} { }
|
||||
|
||||
Sk4f bilerpNonEdgePixel(SkScalar x, SkScalar y) {
|
||||
Sk4f px00, px10, px01, px11;
|
||||
@ -449,7 +486,7 @@ public:
|
||||
Sk4f ys = Sk4f{y} - 0.5f;
|
||||
Sk4f sampleXs = xs + Sk4f{0.0f, 1.0f, 0.0f, 1.0f};
|
||||
Sk4f sampleYs = ys + Sk4f{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
fStrategy.get4Pixels(sampleXs, sampleYs, &px00, &px10, &px01, &px11);
|
||||
fAccessor.get4Pixels(sampleXs, sampleYs, &px00, &px10, &px01, &px11);
|
||||
return bilerp4(xs, ys, px00, px10, px01, px11);
|
||||
}
|
||||
|
||||
@ -486,7 +523,7 @@ public:
|
||||
Sk4f px00, px10, px01, px11;
|
||||
Sk4f xs = Sk4f{sampleXs[0]};
|
||||
Sk4f ys = Sk4f{sampleYs[0]};
|
||||
fStrategy.get4Pixels(sampleXs, sampleYs, &px00, &px10, &px01, &px11);
|
||||
fAccessor.get4Pixels(sampleXs, sampleYs, &px00, &px10, &px01, &px11);
|
||||
Sk4f pixel = bilerp4(xs, ys, px00, px10, px01, px11);
|
||||
fNext->blendPixel(pixel);
|
||||
}
|
||||
@ -505,7 +542,7 @@ public:
|
||||
} else if (absLength == (count - 1)) {
|
||||
if (std::fmod(span.startX() - 0.5f, 1.0f) == 0.0f) {
|
||||
if (std::fmod(span.startY() - 0.5f, 1.0f) == 0.0f) {
|
||||
src_strategy_blend(span, fNext, &fStrategy);
|
||||
src_strategy_blend(span, fNext, &fAccessor);
|
||||
} else {
|
||||
this->spanUnitRateAlignedX(span, y);
|
||||
}
|
||||
@ -526,8 +563,8 @@ private:
|
||||
SkScalar filterY0 = 1.0f - filterY1;
|
||||
int iy1 = SkScalarFloorToInt(y1);
|
||||
int ix = SkScalarFloorToInt(span.startX());
|
||||
Sk4f pixelY0 = fStrategy.getPixelFromRow(fStrategy.row(iy0), ix);
|
||||
Sk4f pixelY1 = fStrategy.getPixelFromRow(fStrategy.row(iy1), ix);
|
||||
Sk4f pixelY0 = fAccessor.getPixelFromRow(fAccessor.row(iy0), ix);
|
||||
Sk4f pixelY1 = fAccessor.getPixelFromRow(fAccessor.row(iy1), ix);
|
||||
Sk4f filterPixel = pixelY0 * filterY0 + pixelY1 * filterY1;
|
||||
int count = span.count();
|
||||
while (count >= 4) {
|
||||
@ -566,18 +603,18 @@ private:
|
||||
SkScalar yFloor = std::floor(ry0);
|
||||
Sk4f y1 = Sk4f{ry0 - yFloor};
|
||||
Sk4f y0 = Sk4f{1.0f} - y1;
|
||||
const void* const row0 = fStrategy.row(SkScalarFloorToInt(ry0));
|
||||
const void* const row1 = fStrategy.row(SkScalarFloorToInt(ry1));
|
||||
Sk4f fpixel00 = y0 * fStrategy.getPixelFromRow(row0, ix);
|
||||
Sk4f fpixel01 = y1 * fStrategy.getPixelFromRow(row1, ix);
|
||||
Sk4f fpixel10 = y0 * fStrategy.getPixelFromRow(row0, ix + 1);
|
||||
Sk4f fpixel11 = y1 * fStrategy.getPixelFromRow(row1, ix + 1);
|
||||
const void* const row0 = fAccessor.row(SkScalarFloorToInt(ry0));
|
||||
const void* const row1 = fAccessor.row(SkScalarFloorToInt(ry1));
|
||||
Sk4f fpixel00 = y0 * fAccessor.getPixelFromRow(row0, ix);
|
||||
Sk4f fpixel01 = y1 * fAccessor.getPixelFromRow(row1, ix);
|
||||
Sk4f fpixel10 = y0 * fAccessor.getPixelFromRow(row0, ix + 1);
|
||||
Sk4f fpixel11 = y1 * fAccessor.getPixelFromRow(row1, ix + 1);
|
||||
auto getNextPixel = [&]() {
|
||||
if (ix != ioldx) {
|
||||
fpixel00 = fpixel10;
|
||||
fpixel01 = fpixel11;
|
||||
fpixel10 = y0 * fStrategy.getPixelFromRow(row0, ix + 1);
|
||||
fpixel11 = y1 * fStrategy.getPixelFromRow(row1, ix + 1);
|
||||
fpixel10 = y0 * fAccessor.getPixelFromRow(row0, ix + 1);
|
||||
fpixel11 = y1 * fAccessor.getPixelFromRow(row1, ix + 1);
|
||||
ioldx = ix;
|
||||
x = x + xAdjust;
|
||||
}
|
||||
@ -618,25 +655,25 @@ private:
|
||||
SkScalar filterY1 = y0 - iy0;
|
||||
SkScalar filterY0 = 1.0f - filterY1;
|
||||
int iy1 = SkScalarFloorToInt(y1);
|
||||
const void* rowY0 = fStrategy.row(iy0);
|
||||
const void* rowY1 = fStrategy.row(iy1);
|
||||
const void* rowY0 = fAccessor.row(iy0);
|
||||
const void* rowY1 = fAccessor.row(iy1);
|
||||
SkScalar x0 = span.startX() - 0.5f;
|
||||
int ix0 = SkScalarFloorToInt(x0);
|
||||
SkScalar filterX1 = x0 - ix0;
|
||||
SkScalar filterX0 = 1.0f - filterX1;
|
||||
|
||||
auto getPixelY0 = [&]() {
|
||||
Sk4f px = fStrategy.getPixelFromRow(rowY0, ix0);
|
||||
Sk4f px = fAccessor.getPixelFromRow(rowY0, ix0);
|
||||
return px * filterY0;
|
||||
};
|
||||
|
||||
auto getPixelY1 = [&]() {
|
||||
Sk4f px = fStrategy.getPixelFromRow(rowY1, ix0);
|
||||
Sk4f px = fAccessor.getPixelFromRow(rowY1, ix0);
|
||||
return px * filterY1;
|
||||
};
|
||||
|
||||
auto get4PixelsY0 = [&](int ix, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) {
|
||||
fStrategy.get4Pixels(rowY0, ix, px0, px1, px2, px3);
|
||||
fAccessor.get4Pixels(rowY0, ix, px0, px1, px2, px3);
|
||||
*px0 = *px0 * filterY0;
|
||||
*px1 = *px1 * filterY0;
|
||||
*px2 = *px2 * filterY0;
|
||||
@ -644,7 +681,7 @@ private:
|
||||
};
|
||||
|
||||
auto get4PixelsY1 = [&](int ix, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) {
|
||||
fStrategy.get4Pixels(rowY1, ix, px0, px1, px2, px3);
|
||||
fAccessor.get4Pixels(rowY1, ix, px0, px1, px2, px3);
|
||||
*px0 = *px0 * filterY1;
|
||||
*px1 = *px1 * filterY1;
|
||||
*px2 = *px2 * filterY1;
|
||||
@ -678,8 +715,8 @@ private:
|
||||
count -= 4;
|
||||
}
|
||||
while (count > 0) {
|
||||
Sk4f pixelY0 = fStrategy.getPixelFromRow(rowY0, ix0);
|
||||
Sk4f pixelY1 = fStrategy.getPixelFromRow(rowY1, ix0);
|
||||
Sk4f pixelY0 = fAccessor.getPixelFromRow(rowY0, ix0);
|
||||
Sk4f pixelY1 = fAccessor.getPixelFromRow(rowY1, ix0);
|
||||
|
||||
fNext->blendPixel(lerp(pixelY0, pixelY1));
|
||||
ix0 += 1;
|
||||
@ -706,8 +743,8 @@ private:
|
||||
count -= 4;
|
||||
}
|
||||
while (count > 0) {
|
||||
Sk4f pixelY0 = fStrategy.getPixelFromRow(rowY0, ix0);
|
||||
Sk4f pixelY1 = fStrategy.getPixelFromRow(rowY1, ix0);
|
||||
Sk4f pixelY0 = fAccessor.getPixelFromRow(rowY0, ix0);
|
||||
Sk4f pixelY1 = fAccessor.getPixelFromRow(rowY1, ix0);
|
||||
|
||||
fNext->blendPixel(lerp(pixelY0, pixelY1));
|
||||
ix0 -= 1;
|
||||
@ -724,8 +761,8 @@ private:
|
||||
SkScalar filterY0 = 1.0f - filterY1;
|
||||
int iy1 = SkScalarFloorToInt(y1);
|
||||
int ix = SkScalarFloorToInt(span.startX());
|
||||
const void* rowY0 = fStrategy.row(iy0);
|
||||
const void* rowY1 = fStrategy.row(iy1);
|
||||
const void* rowY0 = fAccessor.row(iy0);
|
||||
const void* rowY1 = fAccessor.row(iy1);
|
||||
auto lerp = [&](Sk4f* pixelY0, Sk4f* pixelY1) {
|
||||
return *pixelY0 * filterY0 + *pixelY1 * filterY1;
|
||||
};
|
||||
@ -734,17 +771,17 @@ private:
|
||||
int count = span.count();
|
||||
while (count >= 4) {
|
||||
Sk4f px00, px10, px20, px30;
|
||||
fStrategy.get4Pixels(rowY0, ix, &px00, &px10, &px20, &px30);
|
||||
fAccessor.get4Pixels(rowY0, ix, &px00, &px10, &px20, &px30);
|
||||
Sk4f px01, px11, px21, px31;
|
||||
fStrategy.get4Pixels(rowY1, ix, &px01, &px11, &px21, &px31);
|
||||
fAccessor.get4Pixels(rowY1, ix, &px01, &px11, &px21, &px31);
|
||||
fNext->blend4Pixels(
|
||||
lerp(&px00, &px01), lerp(&px10, &px11), lerp(&px20, &px21), lerp(&px30, &px31));
|
||||
ix += 4;
|
||||
count -= 4;
|
||||
}
|
||||
while (count > 0) {
|
||||
Sk4f pixelY0 = fStrategy.getPixelFromRow(rowY0, ix);
|
||||
Sk4f pixelY1 = fStrategy.getPixelFromRow(rowY1, ix);
|
||||
Sk4f pixelY0 = fAccessor.getPixelFromRow(rowY0, ix);
|
||||
Sk4f pixelY1 = fAccessor.getPixelFromRow(rowY1, ix);
|
||||
|
||||
fNext->blendPixel(lerp(&pixelY0, &pixelY1));
|
||||
ix += 1;
|
||||
@ -754,17 +791,17 @@ private:
|
||||
int count = span.count();
|
||||
while (count >= 4) {
|
||||
Sk4f px00, px10, px20, px30;
|
||||
fStrategy.get4Pixels(rowY0, ix - 3, &px30, &px20, &px10, &px00);
|
||||
fAccessor.get4Pixels(rowY0, ix - 3, &px30, &px20, &px10, &px00);
|
||||
Sk4f px01, px11, px21, px31;
|
||||
fStrategy.get4Pixels(rowY1, ix - 3, &px31, &px21, &px11, &px01);
|
||||
fAccessor.get4Pixels(rowY1, ix - 3, &px31, &px21, &px11, &px01);
|
||||
fNext->blend4Pixels(
|
||||
lerp(&px00, &px01), lerp(&px10, &px11), lerp(&px20, &px21), lerp(&px30, &px31));
|
||||
ix -= 4;
|
||||
count -= 4;
|
||||
}
|
||||
while (count > 0) {
|
||||
Sk4f pixelY0 = fStrategy.getPixelFromRow(rowY0, ix);
|
||||
Sk4f pixelY1 = fStrategy.getPixelFromRow(rowY1, ix);
|
||||
Sk4f pixelY0 = fAccessor.getPixelFromRow(rowY0, ix);
|
||||
Sk4f pixelY1 = fAccessor.getPixelFromRow(rowY1, ix);
|
||||
|
||||
fNext->blendPixel(lerp(&pixelY0, &pixelY1));
|
||||
ix -= 1;
|
||||
@ -802,7 +839,7 @@ private:
|
||||
}
|
||||
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, gammaType> fStrategy;
|
||||
Accessor fAccessor;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user