Defensively reset aa[] value when we call a blitter repeatedly
The blitAntiH() entry point for blitters takes (sparse) arrays for
coverage (aa) and run lengths (runs). These are marked as "const", but
some blitter "helpers" like SkRgnClipBlitter modify their contents
in-place (to efficiently handle subsets of the runs).
This is normally fine, but if the caller is repeatedly using the same
buffers (as we do in call_hline_blitter, which has a finite sized
tmp buffer), we need to defensively reset the starter values each time
through the local loop.
Bug: skia:9915
Change-Id: I0e701b74da2a57a3f5ddc0ae4b44550f8f75ad95
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271036
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkScan_Antihair.cpp b/src/core/SkScan_Antihair.cpp
index 18657cc..2837df3 100644
--- a/src/core/SkScan_Antihair.cpp
+++ b/src/core/SkScan_Antihair.cpp
@@ -74,8 +74,14 @@
int16_t runs[HLINE_STACK_BUFFER + 1];
uint8_t aa[HLINE_STACK_BUFFER];
- aa[0] = ApplyGamma(gGammaTable, alpha);
do {
+ // In theory, we should be able to just do this once (outside of the loop),
+ // since aa[] and runs[] are supposed" to be const when we call the blitter.
+ // In reality, some wrapper-blitters (e.g. SkRgnClipBlitter) cast away that
+ // constness, and modify the buffers in-place. Hence the need to be defensive
+ // here and reseed the aa value.
+ aa[0] = ApplyGamma(gGammaTable, alpha);
+
int n = count;
if (n > HLINE_STACK_BUFFER) {
n = HLINE_STACK_BUFFER;