From 7f6283bdf8926f72b886389588e3e2d3bc0ea066 Mon Sep 17 00:00:00 2001 From: msarett Date: Tue, 30 Jun 2015 13:29:37 -0700 Subject: Fix CodecSubset benches seg faults for kIndex8 All of the CodecSubset benches fail when the color type is kIndex8. We need to pass a color table to allocPixels() when we want to decode to kIndex8 or it will throw a failure. BUG=skia: Review URL: https://codereview.chromium.org/1213983003 --- bench/subset/SubsetBenchPriv.h | 15 +++++++++++++++ bench/subset/SubsetSingleBench.cpp | 3 ++- bench/subset/SubsetTranslateBench.cpp | 3 ++- bench/subset/SubsetZoomBench.cpp | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) (limited to 'bench/subset') diff --git a/bench/subset/SubsetBenchPriv.h b/bench/subset/SubsetBenchPriv.h index e0eb2ff826..d2c3410e16 100644 --- a/bench/subset/SubsetBenchPriv.h +++ b/bench/subset/SubsetBenchPriv.h @@ -32,4 +32,19 @@ static const char* get_color_name(SkColorType colorType) { } } +/* + * If we plan to decode to kIndex8, we must create a color table and pass it to the + * bitmap when we allocate pixels. Otherwise, we simply allocate pixels using the + * decode info. + */ +static inline void alloc_pixels(SkBitmap* bitmap, const SkImageInfo& info, SkPMColor* colors, + int colorCount) { + if (kIndex_8_SkColorType == info.colorType()) { + SkAutoTUnref colorTable(SkNEW_ARGS(SkColorTable, (colors, colorCount))); + bitmap->allocPixels(info, NULL, colorTable); + } else { + bitmap->allocPixels(info); + } +} + #endif // SubsetBenchPriv_DEFINED diff --git a/bench/subset/SubsetSingleBench.cpp b/bench/subset/SubsetSingleBench.cpp index 68c94cd246..6c1da5c39e 100644 --- a/bench/subset/SubsetSingleBench.cpp +++ b/bench/subset/SubsetSingleBench.cpp @@ -70,7 +70,8 @@ void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) { info, NULL, colors, &colorCount); SkBitmap bitmap; - bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight)); + SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); + alloc_pixels(&bitmap, subsetInfo, colors, colorCount); scanlineDecoder->skipScanlines(fOffsetTop); uint32_t bpp = info.bytesPerPixel(); diff --git a/bench/subset/SubsetTranslateBench.cpp b/bench/subset/SubsetTranslateBench.cpp index 620b6f4903..076901515c 100644 --- a/bench/subset/SubsetTranslateBench.cpp +++ b/bench/subset/SubsetTranslateBench.cpp @@ -68,7 +68,8 @@ void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { SkBitmap bitmap; // Note that we use the same bitmap for all of the subsets. // It might be larger than necessary for the end subsets. - bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight)); + SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); + alloc_pixels(&bitmap, subsetInfo, colors, colorCount); for (int x = 0; x < info.width(); x += fSubsetWidth) { for (int y = 0; y < info.height(); y += fSubsetHeight) { diff --git a/bench/subset/SubsetZoomBench.cpp b/bench/subset/SubsetZoomBench.cpp index 3ce193b6ea..39f234a050 100644 --- a/bench/subset/SubsetZoomBench.cpp +++ b/bench/subset/SubsetZoomBench.cpp @@ -77,7 +77,8 @@ void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) { // Note that if we subsetted and scaled in a single step, we could use the // same bitmap - as is often done in actual use cases. SkBitmap bitmap; - bitmap.allocPixels(info.makeWH(subsetWidth, subsetHeight)); + SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); + alloc_pixels(&bitmap, subsetInfo, colors, colorCount); uint32_t bpp = info.bytesPerPixel(); scanlineDecoder->skipScanlines(subsetStartY); -- cgit v1.2.3