From 65044bfe021e9c0023d78080583e9acb3bdb5ce7 Mon Sep 17 00:00:00 2001 From: scroggo Date: Tue, 3 Jun 2014 13:12:51 -0700 Subject: Return NULL when building empty LayerRasterizer. In SkLayerRasterizer::snapshotRasterizer() and ::detachRasterizer(), if no layers have been added, do not attempt to create an SkLayerRasterizer. Instead, return NULL. This fixes an error when running tests on Android. Update dox to state that NULL may be returned. Add tests. R=reed@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/313653006 --- src/effects/SkLayerRasterizer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/effects') diff --git a/src/effects/SkLayerRasterizer.cpp b/src/effects/SkLayerRasterizer.cpp index ca611d5385..90fd59b585 100644 --- a/src/effects/SkLayerRasterizer.cpp +++ b/src/effects/SkLayerRasterizer.cpp @@ -213,12 +213,21 @@ void SkLayerRasterizer::Builder::addLayer(const SkPaint& paint, SkScalar dx, } SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() { - SkLayerRasterizer* rasterizer = SkNEW_ARGS(SkLayerRasterizer, (fLayers)); + SkLayerRasterizer* rasterizer; + if (0 == fLayers->count()) { + rasterizer = NULL; + SkDELETE(fLayers); + } else { + rasterizer = SkNEW_ARGS(SkLayerRasterizer, (fLayers)); + } fLayers = NULL; return rasterizer; } SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const { + if (0 == fLayers->count()) { + return NULL; + } SkDeque* layers = SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec), fLayers->count())); SkDeque::F2BIter iter(*fLayers); const SkLayerRasterizer_Rec* recOrig; -- cgit v1.2.3