aboutsummaryrefslogtreecommitdiffstats
path: root/bench/subset
diff options
context:
space:
mode:
authormsarett <msarett@google.com>2015-06-30 13:29:37 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-30 13:29:37 -0700
commit7f6283bdf8926f72b886389588e3e2d3bc0ea066 (patch)
tree84977e601181d660f3736f2124c292765bbb6fa1 /bench/subset
parentd3e259a16cf85454f629f5fe75b60b9863c1e138 (diff)
downloadplatform_external_skqp-7f6283bdf8926f72b886389588e3e2d3bc0ea066.tar.gz
platform_external_skqp-7f6283bdf8926f72b886389588e3e2d3bc0ea066.tar.bz2
platform_external_skqp-7f6283bdf8926f72b886389588e3e2d3bc0ea066.zip
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
Diffstat (limited to 'bench/subset')
-rw-r--r--bench/subset/SubsetBenchPriv.h15
-rw-r--r--bench/subset/SubsetSingleBench.cpp3
-rw-r--r--bench/subset/SubsetTranslateBench.cpp3
-rw-r--r--bench/subset/SubsetZoomBench.cpp3
4 files changed, 21 insertions, 3 deletions
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<SkColorTable> 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);