// One-stop-shop shader for, // - nearest-neighbor sampling (_nofilter_), // - clamp tiling in X and Y both (Clamp_), // - with at most a scale and translate matrix (_DX_), // - and no extra alpha applied (_opaque_), // - sampling from 8888 (_S32_) and drawing to 8888 (_S32_). staticvoid Clamp_S32_opaque_D32_nofilter_DX_shaderproc(constvoid* sIn, int x, int y,
SkPMColor* dst, int count) { const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isScaleTranslate());
SkASSERT(s.fAlphaScale == 256);
// true iff the matrix has a scale and no more than an optional translate. staticbool matrix_only_scale_translate(const SkMatrix& m) { return (m.getType() & ~SkMatrix::kTranslate_Mask) == SkMatrix::kScale_Mask;
}
staticbool valid_for_filtering(unsigned dimension) { // for filtering, width and height must fit in 14bits, since we use steal // 2 bits from each to store our 4bit subpixel data return (dimension & ~0x3FFF) == 0;
}
bool integral_translate_only = just_trans_integral(fInvMatrix); if (!integral_translate_only) { // Most of the scanline procs deal with "unit" texture coordinates, as this // makes it easy to perform tiling modes (repeat = (x & 0xFFFF)). To generate // those, we divide the matrix by its dimensions here. // // We don't do this if we're either trivial (can ignore the matrix) or clamping // in both X and Y since clamping to width,height is just as easy as to 0xFFFF.
// Now that all possible changes to the matrix have taken place, check // to see if we're really close to a no-scale matrix. If so, explicitly // set it to be so. Subsequent code may inspect this matrix to choose // a faster path in this case.
// This code will only execute if the matrix has some scale component; // if it's already pure translate then we won't do this inversion.
if (matrix_only_scale_translate(fInvMatrix)) { if (auto forward = fInvMatrix.invert()) { if (just_trans_general(*forward)) {
fInvMatrix.setTranslate(-forward->getTranslateX(), -forward->getTranslateY());
}
}
}
// Recompute the flag after matrix adjustments.
integral_translate_only = just_trans_integral(fInvMatrix);
}
// our special-case shaderprocs // TODO: move this one into chooseShaderProc32() or pull all that in here. if (fAlphaScale == 256
&& !fBilerp
&& SkTileMode::kClamp == fTileModeX
&& SkTileMode::kClamp == fTileModeY
&& fInvMatrix.isScaleTranslate()) {
fShaderProc32 = Clamp_S32_opaque_D32_nofilter_DX_shaderproc;
} else {
fShaderProc32 = this->chooseShaderProc32();
}
return true;
}
staticvoid Clamp_S32_D32_nofilter_trans_shaderproc(constvoid* sIn, int x, int y,
SkPMColor* colors, int count) { const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isTranslate());
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(!s.fBilerp);
constint maxX = s.fPixmap.width() - 1; constint maxY = s.fPixmap.height() - 1; int ix = s.fFilterOneX + x; int iy = SkTPin(s.fFilterOneY + y, 0, maxY); const SkPMColor* row = s.fPixmap.addr32(0, iy);
// clamp to the left if (ix < 0) { int n = std::min(-ix, count);
SkOpts::memset32(colors, row[0], n);
count -= n; if (0 == count) { return;
}
colors += n;
SkASSERT(-ix == n);
ix = 0;
} // copy the middle if (ix <= maxX) { int n = std::min(maxX - ix + 1, count);
memcpy(colors, row + ix, n * sizeof(SkPMColor));
count -= n; if (0 == count) { return;
}
colors += n;
}
SkASSERT(count > 0); // clamp to the right
SkOpts::memset32(colors, row[maxX], count);
}
staticinlineint sk_int_mod(int x, int n) {
SkASSERT(n > 0); if ((unsigned)x >= (unsigned)n) { if (x < 0) {
x = n + ~(~x % n);
} else {
x = x % n;
}
} return x;
}
staticinlineint sk_int_mirror(int x, int n) {
x = sk_int_mod(x, 2 * n); if (x >= n) {
x = n + ~(x - n);
} return x;
}
staticvoid Repeat_S32_D32_nofilter_trans_shaderproc(constvoid* sIn, int x, int y,
SkPMColor* colors, int count) { const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isTranslate());
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(!s.fBilerp);
constint stopX = s.fPixmap.width(); constint stopY = s.fPixmap.height(); int ix = s.fFilterOneX + x; int iy = sk_int_mod(s.fFilterOneY + y, stopY); const SkPMColor* row = s.fPixmap.addr32(0, iy);
ix = sk_int_mod(ix, stopX); for (;;) { int n = std::min(stopX - ix, count);
memcpy(colors, row + ix, n * sizeof(SkPMColor));
count -= n; if (0 == count) { return;
}
colors += n;
ix = 0;
}
}
int scale = 256 - 16*t;
uint32_t lo = (color0 & mask) * scale;
uint32_t hi = ((color0 >> 8) & mask) * scale;
scale = 16*t;
lo += (color1 & mask) * scale;
hi += ((color1 >> 8) & mask) * scale;
// TODO: if (alphaScale < 256) ...
lo = ((lo >> 8) & mask) * alphaScale;
hi = ((hi >> 8) & mask) * alphaScale;
*dstColor = ((lo >> 8) & mask) | (hi & ~mask);
}
staticvoid S32_D32_constX_shaderproc(constvoid* sIn, int x, int y,
SkPMColor* colors, int count) { const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isScaleTranslate());
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(1 == s.fPixmap.width());
int iY0; int iY1 SK_INIT_TO_AVOID_WARNING; int iSubY SK_INIT_TO_AVOID_WARNING;
if (s.fBilerp) {
SkBitmapProcState::MatrixProc mproc = s.getMatrixProc();
uint32_t xy[2];
// When the matrix has a scale component the setup code in // chooseProcs multiples the inverse matrix by the inverse of the // bitmap's width and height. Since this method is going to do // its own tiling and sampling we need to undo that here. if (SkTileMode::kClamp != s.fTileModeX || SkTileMode::kClamp != s.fTileModeY) {
yTemp = SkFixed3232ToInt(mapper.fixed3232Y() * s.fPixmap.height());
} else {
yTemp = mapper.intY();
}
}
constint stopY = s.fPixmap.height(); switch (s.fTileModeY) { case SkTileMode::kClamp:
iY0 = SkTPin(yTemp, 0, stopY-1); break; case SkTileMode::kRepeat:
iY0 = sk_int_mod(yTemp, stopY); break; case SkTileMode::kMirror: default:
iY0 = sk_int_mirror(yTemp, stopY); break;
}
#ifdef SK_DEBUG
{ const SkBitmapProcStateAutoMapper mapper(s, x, y); int iY2;
if (s.fBilerp) { const SkPMColor* row1 = s.fPixmap.addr32(0, iY1);
filter_32_alpha(iSubY, *row0, *row1, &color, s.fAlphaScale);
} else { if (s.fAlphaScale < 256) {
color = SkAlphaMulQ(*row0, s.fAlphaScale);
} else {
color = *row0;
}
}
SkOpts::memset32(colors, color, count);
}
staticvoid DoNothing_shaderproc(constvoid*, int x, int y,
SkPMColor* colors, int count) { // if we get called, the matrix is too tricky, so we just draw nothing
SkOpts::memset32(colors, 0, count);
}
// Since we know we're not filtered, we re-purpose these fields allow // us to go from device -> src coordinates w/ just an integer add, // rather than running through the inverse-matrix
fFilterOneX = mapper.intX();
fFilterOneY = mapper.intY();
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.