Only use DeviceCM->fNext if the layer doesn't affect the clip

Before this, fNext always pointed at the next (prev) saveLayer in the stack.
Typically each layer is isolated, as it is defined to "consume" the current clip.
Android has an option to not affect/consume the clip, hence the support for looping
through this link-list in updateMC().

The current code always executes this loop, subtracting the current layer's clip from
the global clip, so typically the 2nd iteration will see an empty remaining clip and
draw nothing ... but we still pay for the subtract and the draw-overhead.

This change makes fNext point to the next layer ONLY if the current layer was marked
as non-consuming.

As a side-effect, this change also now detects the "last" restore by looking for
fMCRec == null, rather than fNext == nullptr. fMCRec was always null on the last
layer, so this change is safe, and could have landed independently.

BUG=skia:6214

Change-Id: I787574fa35c4869d3b884054aece925f457ad5bd
Reviewed-on: https://skia-review.googlesource.com/8348
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 6c6752e..562e0ae 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1257,7 +1257,8 @@
     DeviceCM* layer =
             new DeviceCM(newDevice.get(), paint, this, fConservativeRasterClip, stashedMatrix);
 
-    layer->fNext = fMCRec->fTopLayer;
+    // only have a "next" if this new layer doesn't affect the clip (rare)
+    layer->fNext = BoundsAffectsClip(saveLayerFlags) ? nullptr : fMCRec->fTopLayer;
     fMCRec->fLayer = layer;
     fMCRec->fTopLayer = layer;    // this field is NOT an owner of layer
 
@@ -1299,7 +1300,7 @@
         recorder will have already recorded the restore).
     */
     if (layer) {
-        if (layer->fNext) {
+        if (fMCRec) {
             const SkIPoint& origin = layer->fDevice->getOrigin();
             this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), layer->fPaint);
             // restore what we smashed in internalSaveLayer