Add a way to get 'active' props from SkCanvas
This CL adds two new APIs to SkCanvas: getBaseProps, and getTopProps.
SkCavas::getBaseProps is functionally identical to getProps, but returns
the SkSurfaceProps by value, rather than via an 'out' parameter.
SkCanvas::getProps is now considered deprecated.
SkCanvas::getTopProps returns the 'currently active' SkSurfaceProps,
i.e., it returns the props from the "top device".  This is useful
because the SkSurfaceProps can change when creating new layers.
Bug: skia:13483
Change-Id: Ia1d9a10ffdd929427f1f2c0a7c4ba6965d4bd3c0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/554736
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: Ian Prest <iapres@microsoft.com>
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 9e33c57..a62f08b 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -10,6 +10,9 @@
   * SkImage::MakeFromPicture and SkImageGenerator::MakeFromPicture now take an optional
     SkSurfaceProps to use when rasterizing the picture.
   * skcms.h has been relocated to //modules/skcms/skcms.h (was //include/third_party/skcms/skcms.h)
+  * New functions SkCanvas::getBaseProps and SkCanvas::getTopProps; SkCanvas::getBaseProps is a
+    direct replacement for the (now deprecated) SkCanvas::getProps function, while getTopProps is
+    a variant that returns the SkSurfaceProps that are active in the current layer.
 
 * * *
 
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 0f9b26e..d46f65e 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -263,10 +263,27 @@
         @param props  storage for writable SkSurfaceProps
         @return       true if SkSurfaceProps was copied
 
+        DEPRECATED: Replace usage with getBaseProps() or getTopProps()
+
         example: https://fiddle.skia.org/c/@Canvas_getProps
     */
     bool getProps(SkSurfaceProps* props) const;
 
+    /** Returns the SkSurfaceProps associated with the canvas (i.e., at the base of the layer
+        stack).
+
+        @return  base SkSurfaceProps
+    */
+    SkSurfaceProps getBaseProps() const;
+
+    /** Returns the SkSurfaceProps associated with the canvas that are currently active (i.e., at
+        the top of the layer stack). This can differ from getBaseProps depending on the flags
+        passed to saveLayer (see SaveLayerFlagsSet).
+
+        @return  SkSurfaceProps active in the current/top layer
+    */
+    SkSurfaceProps getTopProps() const;
+
     /** Triggers the immediate execution of all pending draw operations.
         If SkCanvas is associated with GPU surface, resolves all pending GPU operations.
         If SkCanvas is associated with raster surface, has no effect; raster draw
@@ -2179,7 +2196,7 @@
     virtual bool onPeekPixels(SkPixmap* pixmap);
     virtual bool onAccessTopLayerPixels(SkPixmap* pixmap);
     virtual SkImageInfo onImageInfo() const;
-    virtual bool onGetProps(SkSurfaceProps* props) const;
+    virtual bool onGetProps(SkSurfaceProps* props, bool top) const;
     virtual void onFlush();
 
     // Subclass save/restore notifiers.
diff --git a/include/utils/SkPaintFilterCanvas.h b/include/utils/SkPaintFilterCanvas.h
index 52a725f..4e79a5b 100644
--- a/include/utils/SkPaintFilterCanvas.h
+++ b/include/utils/SkPaintFilterCanvas.h
@@ -124,7 +124,7 @@
     bool onPeekPixels(SkPixmap* pixmap) override;
     bool onAccessTopLayerPixels(SkPixmap* pixmap) override;
     SkImageInfo onImageInfo() const override;
-    bool onGetProps(SkSurfaceProps* props) const override;
+    bool onGetProps(SkSurfaceProps* props, bool top) const override;
 
 private:
     class AutoPaintFilter;
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 1189e3c..d7a62dd 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1284,12 +1284,24 @@
 }
 
 bool SkCanvas::getProps(SkSurfaceProps* props) const {
-    return this->onGetProps(props);
+    return this->onGetProps(props, /*top=*/false);
 }
 
-bool SkCanvas::onGetProps(SkSurfaceProps* props) const {
+SkSurfaceProps SkCanvas::getBaseProps() const {
+    SkSurfaceProps props;
+    this->onGetProps(&props, /*top=*/false);
+    return props;
+}
+
+SkSurfaceProps SkCanvas::getTopProps() const {
+    SkSurfaceProps props;
+    this->onGetProps(&props, /*top=*/true);
+    return props;
+}
+
+bool SkCanvas::onGetProps(SkSurfaceProps* props, bool top) const {
     if (props) {
-        *props = fProps;
+        *props = top ? topDevice()->surfaceProps() : fProps;
     }
     return true;
 }
diff --git a/src/utils/SkPaintFilterCanvas.cpp b/src/utils/SkPaintFilterCanvas.cpp
index 9702d8c..ba1a8f7 100644
--- a/src/utils/SkPaintFilterCanvas.cpp
+++ b/src/utils/SkPaintFilterCanvas.cpp
@@ -13,6 +13,7 @@
 #include "include/core/SkPoint.h"
 #include "include/core/SkRect.h"
 #include "include/core/SkSurface.h" // IWYU pragma: keep
+#include "include/core/SkSurfaceProps.h"
 
 #include <optional>
 
@@ -23,7 +24,6 @@
 class SkPicture;
 class SkRRect;
 class SkRegion;
-class SkSurfaceProps;
 class SkTextBlob;
 class SkVertices;
 struct SkDrawShadowRec;
@@ -292,6 +292,9 @@
     return this->proxy()->imageInfo();
 }
 
-bool SkPaintFilterCanvas::onGetProps(SkSurfaceProps* props) const {
-    return this->proxy()->getProps(props);
+bool SkPaintFilterCanvas::onGetProps(SkSurfaceProps* props, bool top) const {
+    if (props) {
+        *props = top ? this->proxy()->getTopProps() : this->proxy()->getBaseProps();
+    }
+    return true;
 }