Fix persistent Canvas clip handling
Partial Canvas save semantics (clip or matrix persisting after restore) are currently emulated in the native canvas wrapper (SkiaCanvas.cpp). Persistent clips (save w/ MATRIX_SAVE_FLAG only) in particular are emulated using the SkCanvas clip stack. There are two problems with the current implementation: 1) The canvas save count is used to identify the clip stack topmost frame, on the assumption that it is the same as the actual clip stack save count. But with the introduction of lazy SkCanvas saves in Skia, the two values can diverge: the clip stack save count only reflects *committed* saves, while the canvas save count includes both committed and pending saves. This means that we can no longer compare canvas and clip stack save counts directly. While we're looking at addressing the save count discrepancy in Skia proper, we can also refactor the partial save emulation to no longer rely on the two values being synchronized: instead of using the canvas save count to locate the top clip stack frame, simply use the clip stack save count for the same purpose - getClipStack()->getSaveCount() always points to the correct top clip stack frame. With this patch: * we use SkCanvas::getSaveCount() to track *canvas* save frames which require persistent matrix/clip handling (mSaveRecStack) * we use SkClipStack::getSaveCount() to extract the clips from the top clip stack frame Also, since we're no longer mixing/comparing the two save counts, we don't have to decrement the canvas value anymore (to make it zero-based like its clip stack counterpart). 2) When iterating over clip stack elements, we currently start at kTopIterStart and advance using next(). This is incorrect as next() moves up the stack, so we only iterate over the topmost element => if there are multiple (non-consolidated) clip elements in the top frame, we only get to see one. We need to iterate using prev() instead. Change-Id: Ic2d8cad684018925e749b9172fbf7c6202d9fb62
Loading
Please register or sign in to comment