From d02b6f331bca054b0654e213ea6a7ddd94257bf7 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 17 Mar 2017 10:41:39 -0400 Subject: Make dstreadshuffle not crash in with --preAbandonGpuContext and look better in 565 BUG=skia:6386 Change-Id: I90578f57ba7076d65e6d8ebe61ec325ebba8e35d Reviewed-on: https://skia-review.googlesource.com/9828 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- gm/dstreadshuffle.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'gm/dstreadshuffle.cpp') diff --git a/gm/dstreadshuffle.cpp b/gm/dstreadshuffle.cpp index aea71ec6b1..371515334c 100644 --- a/gm/dstreadshuffle.cpp +++ b/gm/dstreadshuffle.cpp @@ -18,7 +18,7 @@ namespace skiagm { */ class DstReadShuffle : public GM { public: - DstReadShuffle() { this->setBGColor(SK_ColorLTGRAY); } + DstReadShuffle() { this->setBGColor(kBackground); } protected: enum ShapeType { @@ -97,7 +97,11 @@ protected: } static void DrawHairlines(SkCanvas* canvas) { - canvas->clear(SK_ColorTRANSPARENT); + if (canvas->imageInfo().alphaType() == kOpaque_SkAlphaType) { + canvas->clear(kBackground); + } else { + canvas->clear(SK_ColorTRANSPARENT); + } SkPaint hairPaint; hairPaint.setStyle(SkPaint::kStroke_Style); hairPaint.setStrokeWidth(0); @@ -139,16 +143,27 @@ protected: // Draw hairlines to a surface and then draw that to the main canvas with a zoom so that // it is easier to see how they blend. SkImageInfo info; - if (SkColorType::kUnknown_SkColorType != canvas->imageInfo().colorType()) { + // Recording canvases don't have a color type. + if (SkColorType::kUnknown_SkColorType == canvas->imageInfo().colorType()) { + info = SkImageInfo::MakeN32Premul(35, 35); + } else { info = SkImageInfo::Make(35, 35, canvas->imageInfo().colorType(), canvas->imageInfo().alphaType(), canvas->imageInfo().refColorSpace()); - } else { - info = SkImageInfo::MakeN32Premul(35, 35); } auto surf = canvas->makeSurface(info); if (!surf) { + // Fall back to raster. Raster supports only one of the 8 bit per-channel RGBA or BGRA + // formats. This fall back happens when running with --preAbandonGpuContext. + if ((info.colorType() == kRGBA_8888_SkColorType || + info.colorType() == kBGRA_8888_SkColorType) && + info.colorType() != kN32_SkColorType) { + info = SkImageInfo::Make(35, 35, + kN32_SkColorType, + canvas->imageInfo().alphaType(), + canvas->imageInfo().refColorSpace()); + } surf = SkSurface::MakeRaster(info); } canvas->scale(5.f, 5.f); @@ -158,6 +173,7 @@ protected: } private: + static constexpr SkColor kBackground = SK_ColorLTGRAY; SkPath fConcavePath; SkPath fConvexPath; typedef GM INHERITED; -- cgit v1.2.3