From 46596ae50559e89a0a2462573ac9448cf309cf56 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 2 Jan 2018 15:40:29 -0500 Subject: use tool_utils to encapsulate checking for recording canvas and makeSurface Bug: skia: Change-Id: Ia93ee09dd213b8d6ad5c18e887add5ff3448c824 Reviewed-on: https://skia-review.googlesource.com/90243 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- tools/sk_tool_utils.cpp | 10 ++++++++++ tools/sk_tool_utils.h | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index bbb00bc123..9d1b4df56c 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -18,6 +18,7 @@ #include "SkPM4f.h" #include "SkPoint3.h" #include "SkShader.h" +#include "SkSurface.h" #include "SkTestScalerContext.h" #include "SkTextBlob.h" @@ -559,4 +560,13 @@ void copy_to_g8(SkBitmap* dst, const SkBitmap& src) { return a->peekPixels(&pm0) && b->peekPixels(&pm1) && equal_pixels(pm0, pm1, maxDiff, respectColorSpaces); } + + sk_sp makeSurface(SkCanvas* canvas, const SkImageInfo& info, + const SkSurfaceProps* props) { + auto surf = canvas->makeSurface(info, props); + if (!surf) { + surf = SkSurface::MakeRaster(info, props); + } + return surf; + } } // namespace sk_tool_utils diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h index 0741b19644..9081e3c56f 100644 --- a/tools/sk_tool_utils.h +++ b/tools/sk_tool_utils.h @@ -24,6 +24,8 @@ class SkPaint; class SkPath; class SkRRect; class SkShader; +class SkSurface; +class SkSurfaceProps; class SkTestFont; class SkTextBlobBuilder; @@ -112,6 +114,9 @@ namespace sk_tool_utils { SkBitmap create_string_bitmap(int w, int h, SkColor c, int x, int y, int textSize, const char* str); + // If the canvas does't make a surface (e.g. recording), make a raster surface + sk_sp makeSurface(SkCanvas*, const SkImageInfo&, const SkSurfaceProps* = nullptr); + // A helper for inserting a drawtext call into a SkTextBlobBuilder void add_to_text_blob_w_len(SkTextBlobBuilder* builder, const char* text, size_t len, const SkPaint& origPaint, SkScalar x, SkScalar y); @@ -245,7 +250,6 @@ namespace sk_tool_utils { bool copy_to(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src); void copy_to_g8(SkBitmap* dst, const SkBitmap& src); - } // namespace sk_tool_utils #endif // sk_tool_utils_DEFINED -- cgit v1.2.3