Skip to content

Commit

Permalink
Miscellaneous blitter cleanup
Browse files Browse the repository at this point in the history
- Remove the incredibly unlikely constant-in-y flag/optimization
- Remove manual ref-counting (!)

Change-Id: Iaba7813f0a6b9db07a2477ab60eec9b0f1b2806b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/683076
Reviewed-by: John Stiles <[email protected]>
Commit-Queue: Brian Osman <[email protected]>
  • Loading branch information
brianosman authored and SkCQ committed Apr 26, 2023
1 parent 83e6f1c commit 7c1f1eb
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 79 deletions.
10 changes: 2 additions & 8 deletions src/core/SkBlitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,19 +800,13 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
SkShaderBase::Context* shaderContext)
: INHERITED(device)
, fShader(paint.getShader())
, fShader(paint.refShader())
, fShaderContext(shaderContext) {
SkASSERT(fShader);
SkASSERT(fShaderContext);

fShader->ref();
fShaderFlags = fShaderContext->getFlags();
fConstInY = SkToBool(fShaderFlags & SkShaderBase::kConstInY32_Flag);
}

SkShaderBlitter::~SkShaderBlitter() {
fShader->unref();
}
SkShaderBlitter::~SkShaderBlitter() = default;

///////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
48 changes: 0 additions & 48 deletions src/core/SkBlitter_ARGB32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,6 @@ SkARGB32_Shader_Blitter::SkARGB32_Shader_Blitter(const SkPixmap& device,

fShadeDirectlyIntoDevice =
SkToBool(shaderContext->getFlags() & SkShaderBase::kOpaqueAlpha_Flag);
fConstInY = SkToBool(shaderContext->getFlags() & SkShaderBase::kConstInY32_Flag);
}

SkARGB32_Shader_Blitter::~SkARGB32_Shader_Blitter() {
Expand Down Expand Up @@ -998,27 +997,6 @@ void SkARGB32_Shader_Blitter::blitRect(int x, int y, int width, int height) {
auto* shaderContext = fShaderContext;
SkPMColor* span = fBuffer;

if (fConstInY) {
if (fShadeDirectlyIntoDevice) {
// shade the first row directly into the device
shaderContext->shadeSpan(x, y, device, width);
span = device;
while (--height > 0) {
device = (uint32_t*)((char*)device + deviceRB);
memcpy(device, span, width << 2);
}
} else {
shaderContext->shadeSpan(x, y, span, width);
SkBlitRow::Proc32 proc = fProc32;
do {
proc(device, span, width, 255);
y += 1;
device = (uint32_t*)((char*)device + deviceRB);
} while (--height > 0);
}
return;
}

if (fShadeDirectlyIntoDevice) {
do {
shaderContext->shadeSpan(x, y, device, width);
Expand Down Expand Up @@ -1256,32 +1234,6 @@ void SkARGB32_Shader_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
uint32_t* device = fDevice.writable_addr32(x, y);
size_t deviceRB = fDevice.rowBytes();

if (fConstInY) {
SkPMColor c;
fShaderContext->shadeSpan(x, y, &c, 1);

if (fShadeDirectlyIntoDevice) {
if (255 == alpha) {
do {
*device = c;
device = (uint32_t*)((char*)device + deviceRB);
} while (--height > 0);
} else {
do {
*device = SkFourByteInterp(c, *device, alpha);
device = (uint32_t*)((char*)device + deviceRB);
} while (--height > 0);
}
} else {
SkBlitRow::Proc32 proc = (255 == alpha) ? fProc32 : fProc32Blend;
do {
proc(device, &c, 1, alpha);
device = (uint32_t*)((char*)device + deviceRB);
} while (--height > 0);
}
return;
}

if (fShadeDirectlyIntoDevice) {
if (255 == alpha) {
do {
Expand Down
4 changes: 1 addition & 3 deletions src/core/SkCoreBlitters.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class SkShaderBlitter : public SkRasterBlitter {
~SkShaderBlitter() override;

protected:
uint32_t fShaderFlags;
const SkShader* fShader;
sk_sp<SkShader> fShader;
SkShaderBase::Context* fShaderContext;
bool fConstInY;

private:
// illegal
Expand Down
9 changes: 0 additions & 9 deletions src/shaders/SkBitmapProcShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ class BitmapProcShaderContext : public SkShaderBase::Context {
if (fState->fPixmap.isOpaque() && (255 == this->getPaintAlpha())) {
fFlags |= SkShaderBase::kOpaqueAlpha_Flag;
}

auto only_scale_and_translate = [](const SkMatrix& matrix) {
unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask;
return (matrix.getType() & ~mask) == 0;
};

if (1 == fState->fPixmap.height() && only_scale_and_translate(this->getTotalInverse())) {
fFlags |= SkShaderBase::kConstInY32_Flag;
}
}

uint32_t getFlags() const override { return fFlags; }
Expand Down
11 changes: 0 additions & 11 deletions src/shaders/SkShaderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,6 @@ class SkShaderBase : public SkShader {
enum Flags {
//!< set if all of the colors will be opaque
kOpaqueAlpha_Flag = 1 << 0,

/** set if the spans only vary in X (const in Y).
e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient
that varies from left-to-right. This flag specifies this for
shadeSpan().
*/
kConstInY32_Flag = 1 << 1,

/** hint for the blitter that 4f is the preferred shading mode.
*/
kPrefers4f_Flag = 1 << 2,
};

/**
Expand Down

0 comments on commit 7c1f1eb

Please sign in to comment.