class SkRasterPipelineBlitter final : public SkBlitter { public: // This is our common entrypoint for creating the blitter once we've sorted out shaders. static SkBlitter* Create(const SkPixmap& dst, const SkPaint& paint, const SkColor4f& dstPaintColor,
SkArenaAlloc* alloc, const SkRasterPipeline& shaderPipeline, bool is_opaque, bool is_constant, const SkShader* clipShader);
void blitH (int x, int y, int w) override; void blitAntiH (int x, int y, const SkAlpha[], const int16_t[]) override; void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; void blitMask (const SkMask&, const SkIRect& clip) override; void blitRect (int x, int y, int width, int height) override; void blitV (int x, int y, int height, SkAlpha alpha) override;
private: void blitRectWithTrace(int x, int y, int w, int h, bool trace); void appendLoadDst (SkRasterPipeline*) const; void appendStore (SkRasterPipeline*) const;
// these check internally, and only append if there was a native clipShader void appendClipScale (SkRasterPipeline*) const; void appendClipLerp (SkRasterPipeline*) const;
SkPixmap fDst;
SkArenaAlloc* fAlloc;
SkRasterPipeline fColorPipeline;
SkRasterPipeline fBlendPipeline; // If the blender is a blend-mode, we retain that information for late-stage optimizations
std::optional<SkBlendMode> fBlendMode; // set to pipeline storage (for alpha) if we have a clipShader void* fClipShaderBuffer = nullptr; // "native" : float or U16
SkRasterPipeline_MemoryCtx
fDstPtr = {nullptr,0}, // Always points to the top-left of fDst.
fMaskPtr = {nullptr,0}; // Updated each call to blitMask().
SkRasterPipeline_EmbossCtx fEmbossCtx; // Used only for k3D_Format masks.
// We may be able to specialize blitH() or blitRect() into a memset. void (*fMemset2D)(SkPixmap*, int x,int y, int w,int h, uint64_t color) = nullptr;
uint64_t fMemsetColor = 0; // Big enough for largest memsettable dst format, F16.
// Built lazily on first use.
std::function<void(size_t, size_t, size_t, size_t)> fBlitRect,
fBlitAntiH,
fBlitMaskA8,
fBlitMaskLCD16,
fBlitMask3D;
// These values are pointed to by the blit pipelines above, // which allows us to adjust them from call to call. float fCurrentCoverage = 0.0f; float fDitherRate = 0.0f;
SkRasterPipeline_<256> shaderPipeline; if (!shader) { // Having no shader makes things nice and easy... just use the paint color
shaderPipeline.appendConstantColor(alloc, dstPaintColor.premul().vec()); bool is_opaque = dstPaintColor.fA == 1.0f,
is_constant = true; return SkRasterPipelineBlitter::Create(dst, paint, dstPaintColor, alloc, shaderPipeline,
is_opaque, is_constant, clipShader.get());
}
// Our job in this factory is to fill out the blitter's color and blend pipelines. // The color pipeline is the common front of the full blit pipeline. The blend pipeline is just // the portion that does the actual blending math (and assumes that src and dst are already // loaded). // // The full blit pipelines are each constructed lazily on first use, and include the color // pipeline, reading the dst, the blend pipeline, coverage, dithering, and writing the dst.
// Start with the color pipeline auto colorPipeline = &blitter->fColorPipeline;
if (clipShader) { auto clipP = colorPipeline;
SkColorType clipCT = kRGBA_8888_SkColorType;
SkColorSpace* clipCS = nullptr;
SkSurfaceProps props{}; // default OK; clipShader doesn't render text
SkStageRec rec = {clipP, alloc, clipCT, clipCS, SkColors::kBlack, props}; if (as_SB(clipShader)->appendRootStages(rec, SkMatrix::I())) { struct Storage { // large enough for highp (float) or lowp(U16) float fA[SkRasterPipeline_kMaxStride];
}; auto storage = alloc->make<Storage>();
clipP->append(SkRasterPipelineOp::store_src_a, storage->fA);
blitter->fClipShaderBuffer = storage->fA;
is_constant = false;
} else { return nullptr;
}
}
// Let's get the shader in first.
colorPipeline->extend(shaderPipeline);
// If there's a color filter it comes next. if (auto colorFilter = paint.getColorFilter()) {
SkSurfaceProps props{}; // default OK; colorFilter doesn't render text
SkStageRec rec = {
colorPipeline, alloc, dst.colorType(), dst.colorSpace(), dstPaintColor, props}; if (!as_CFB(colorFilter)->appendStages(rec, is_opaque)) { return nullptr;
}
is_opaque = is_opaque && as_CFB(colorFilter)->isAlphaUnchanged();
}
// Not all formats make sense to dither (think, F16). We set their dither rate // to zero. We only dither non-constant shaders, so is_constant won't change here. if (paint.isDither() && !is_constant) { switch (dst.info().colorType()) { case kARGB_4444_SkColorType:
blitter->fDitherRate = 1 / 15.0f; break; case kRGB_565_SkColorType:
blitter->fDitherRate = 1 / 63.0f; break; case kGray_8_SkColorType: case kRGB_888x_SkColorType: case kRGBA_8888_SkColorType: case kBGRA_8888_SkColorType: case kSRGBA_8888_SkColorType: case kR8_unorm_SkColorType:
blitter->fDitherRate = 1 / 255.0f; break; case kRGB_101010x_SkColorType: case kRGBA_1010102_SkColorType: case kBGR_101010x_SkColorType: case kBGRA_1010102_SkColorType: case kBGRA_10101010_XR_SkColorType: case kRGBA_10x6_SkColorType:
blitter->fDitherRate = 1 / 1023.0f; break;
case kUnknown_SkColorType: case kAlpha_8_SkColorType: case kBGR_101010x_XR_SkColorType: case kRGBA_F16_SkColorType: case kRGB_F16F16F16x_SkColorType: case kRGBA_F16Norm_SkColorType: case kRGBA_F32_SkColorType: case kR8G8_unorm_SkColorType: case kA16_float_SkColorType: case kA16_unorm_SkColorType: case kR16G16_float_SkColorType: case kR16G16_unorm_SkColorType: case kR16G16B16A16_unorm_SkColorType:
blitter->fDitherRate = 0.0f; break;
} if (blitter->fDitherRate > 0.0f) {
colorPipeline->append(SkRasterPipelineOp::dither, &blitter->fDitherRate);
}
}
// Optimization: A pipeline that's still constant here can collapse back into a constant color. if (is_constant) {
SkColor4f constantColor;
SkRasterPipeline_MemoryCtx constantColorPtr = { &constantColor, 0 }; // We could remove this clamp entirely, but if the destination is 8888, doing the clamp // here allows the color pipeline to still run in lowp (we'll use uniform_color, rather than // unbounded_uniform_color).
colorPipeline->appendClampIfNormalized(dst.info());
colorPipeline->append(SkRasterPipelineOp::store_f32, &constantColorPtr);
colorPipeline->run(0,0,1,1);
colorPipeline->reset();
colorPipeline->appendConstantColor(alloc, constantColor);
is_opaque = constantColor.fA == 1.0f;
}
// Now we'll build the blend pipeline auto blendPipeline = &blitter->fBlendPipeline;
// We can strength-reduce SrcOver into Src when opaque. if (is_opaque && as_BB(blender)->asBlendMode() == SkBlendMode::kSrcOver) {
blender = SkBlender::Mode(SkBlendMode::kSrc);
}
// When we're drawing a constant color in Src mode, we can sometimes just memset. // (The previous two optimizations help find more opportunities for this one.) if (is_constant && as_BB(blender)->asBlendMode() == SkBlendMode::kSrc &&
dst.info().bytesPerPixel() <= static_cast<int>(sizeof(blitter->fMemsetColor))) { // Run our color pipeline all the way through to produce what we'd memset when we can. // Not all blits can memset, so we need to keep colorPipeline too.
SkRasterPipeline_<256> p;
p.extend(*colorPipeline);
blitter->fDstPtr = SkRasterPipeline_MemoryCtx{&blitter->fMemsetColor, 0};
blitter->appendStore(&p);
p.run(0,0,1,1);
switch (blitter->fDst.shiftPerPixel()) { case 0: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) { void* p = dst->writable_addr(x,y); while (h --> 0) {
memset(p, c, w);
p = SkTAddOffset<void>(p, dst->rowBytes());
}
}; break;
case 1: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
SkOpts::rect_memset16(dst->writable_addr16(x,y), c, w, dst->rowBytes(), h);
}; break;
case 2: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
SkOpts::rect_memset32(dst->writable_addr32(x,y), c, w, dst->rowBytes(), h);
}; break;
case 3: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
SkOpts::rect_memset64(dst->writable_addr64(x,y), c, w, dst->rowBytes(), h);
}; break;
void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
this->blitRect(x,y,w,1);
}
void SkRasterPipelineBlitter::blitRect(int x, int y, int w, int h) {
this->blitRectWithTrace(x, y, w, h, true);
}
void SkRasterPipelineBlitter::blitRectWithTrace(int x, int y, int w, int h, bool trace) { if (fMemset2D) {
fMemset2D(&fDst, x,y, w,h, fMemsetColor); return;
}
void SkRasterPipelineBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
SkIRect clip = {x,y, x+1,y+height};
SkMask mask(&alpha, clip,
0, // so we reuse the 1 "row" for all of height
SkMask::kA8_Format);
this->blitMask(mask, clip);
}
// ARGB and SDF masks shouldn't make it here.
SkASSERT(mask.fFormat == SkMask::kA8_Format
|| mask.fFormat == SkMask::kLCD16_Format
|| mask.fFormat == SkMask::k3D_Format);
auto extract_mask_plane = [&mask](int plane, SkRasterPipeline_MemoryCtx* ctx) { // LCD is 16-bit per pixel; A8 and 3D are 8-bit per pixel.
size_t bpp = mask.fFormat == SkMask::kLCD16_Format ? 2 : 1;
// Select the right mask plane. Usually plane == 0 and this is just mask.fImage. auto ptr = (uintptr_t)mask.fImage
+ plane * mask.computeImageSize();
// Update ctx to point "into" this current mask, but lined up with fDstPtr at (0,0). // This sort of trickery upsets UBSAN (pointer-overflow) so our ptr must be a uintptr_t. // mask.fRowBytes is a uint32_t, which would break our addressing math on 64-bit builds.
size_t rowBytes = mask.fRowBytes;
ctx->stride = rowBytes / bpp;
ctx->pixels = (void*)(ptr - mask.fBounds.left() * bpp
- mask.fBounds.top() * rowBytes);
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.