Add Android framework only util to get the SkSurface from SkCanvas
This API enables the framework to implement unclipped saveLayer
calls in a more efficient manner, by requiring fewer render target
switches on the GPU.
Bug: b/119222339
Change-Id: I7276675a4c1389f8493d2583ff7d6533b57a7b3b
Reviewed-on: https://skia-review.googlesource.com/c/173102
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
diff --git a/include/android/SkAndroidFrameworkUtils.h b/include/android/SkAndroidFrameworkUtils.h
index 04a1c39..9df1c84 100644
--- a/include/android/SkAndroidFrameworkUtils.h
+++ b/include/android/SkAndroidFrameworkUtils.h
@@ -9,10 +9,12 @@
#define SkAndroidFrameworkUtils_DEFINED
#include "SkTypes.h"
+#include "SkRefCnt.h"
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
class SkCanvas;
+class SkSurface;
/**
* SkAndroidFrameworkUtils expose private APIs used only by Android framework.
@@ -33,6 +35,8 @@
#endif //SK_SUPPORT_GPU
static void SafetyNetLog(const char*);
+
+ static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas);
};
#endif // SK_BUILD_FOR_ANDROID_ANDROID
diff --git a/src/android/SkAndroidFrameworkUtils.cpp b/src/android/SkAndroidFrameworkUtils.cpp
index f0a7b8a..8920e67 100644
--- a/src/android/SkAndroidFrameworkUtils.cpp
+++ b/src/android/SkAndroidFrameworkUtils.cpp
@@ -8,6 +8,7 @@
#include "SkAndroidFrameworkUtils.h"
#include "SkCanvas.h"
#include "SkDevice.h"
+#include "SkSurface_Base.h"
#if SK_SUPPORT_GPU
#include "GrStyle.h"
@@ -58,5 +59,9 @@
android_errorWriteLog(0x534e4554, bugNumber);
}
+sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) {
+ sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase()));
+ return surface;
+}
#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK