Clean up xfermodes3 gm.

Update temporary surface creation so that cpu and gpu are doing the same
thing, reducing confusion around what the test is doing.

Also clip to the bounds of the saved layer when a temporary surface cannot
be created. This prevents the underspecified behavior of drawing outside
the bounds of a saved layer.

Change-Id: Iad35b394f50b4e1867a8bffdc9f5b3d2ae9c1645
Reviewed-on: https://skia-review.googlesource.com/123741
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp
index 9c78658..e1b1c76 100644
--- a/gm/xfermodes3.cpp
+++ b/gm/xfermodes3.cpp
@@ -60,7 +60,7 @@
             0x80,
         };
 
-        auto tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize));
+        auto tempSurface(this->makeTempSurface(canvas, kSize, kSize));
 
         int test = 0;
         int x = 0, y = 0;
@@ -118,21 +118,13 @@
      * We are trying to test those. We could use saveLayer() to create small SkGpuDevices but
      * saveLayer() uses the texture cache. This means that the actual render target may be larger
      * than the layer. Because the clip will contain the layer's bounds, no draws will be full-RT.
-     * So when running on a GPU canvas we explicitly create a temporary canvas using a texture with
-     * dimensions exactly matching the layer size.
+     * So explicitly create a temporary canvas with dimensions exactly the layer size.
      */
-    sk_sp<SkSurface> possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) {
-#if SK_SUPPORT_GPU
-        GrContext* context = baseCanvas->getGrContext();
+    sk_sp<SkSurface> makeTempSurface(SkCanvas* baseCanvas, int w, int h) {
         SkImageInfo baseInfo = baseCanvas->imageInfo();
         SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(),
                                              baseInfo.refColorSpace());
-        SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
-        baseCanvas->getProps(&canvasProps);
-        return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &canvasProps);
-#else
-        return nullptr;
-#endif
+        return baseCanvas->makeSurface(info);
     }
 
     void drawMode(SkCanvas* canvas,
@@ -146,6 +138,7 @@
         SkCanvas* modeCanvas;
         if (nullptr == surface) {
             canvas->saveLayer(&r, nullptr);
+            canvas->clipRect(r);
             modeCanvas = canvas;
         } else {
             modeCanvas = surface->getCanvas();