Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: bench/subset/SubsetZoomBench.cpp

Issue 1213983003: Fix CodecSubset benches seg faults for kIndex8 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SubsetZoomBench.h" 8 #include "SubsetZoomBench.h"
9 #include "SubsetBenchPriv.h" 9 #include "SubsetBenchPriv.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return fName.c_str(); 48 return fName.c_str();
49 } 49 }
50 50
51 bool SubsetZoomBench::isSuitableFor(Backend backend) { 51 bool SubsetZoomBench::isSuitableFor(Backend backend) {
52 return kNonRendering_Backend == backend; 52 return kNonRendering_Backend == backend;
53 } 53 }
54 54
55 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) { 55 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) {
56 // When the color type is kIndex8, we will need to store the color table. I f it is 56 // When the color type is kIndex8, we will need to store the color table. I f it is
57 // used, it will be initialized by the codec. 57 // used, it will be initialized by the codec.
58 int colorCount; 58 int colorCount = 0;
59 SkPMColor colors[256]; 59 SkPMColor colors[256];
60 if (fUseCodec) { 60 if (fUseCodec) {
61 for (int count = 0; count < n; count++) { 61 for (int count = 0; count < n; count++) {
62 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); 62 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
63 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 63 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
64 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s())); 64 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s()));
65 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder( 65 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(
66 info, NULL, colors, &colorCount); 66 info, NULL, colors, &colorCount);
67 67
68 const int centerX = info.width() / 2; 68 const int centerX = info.width() / 2;
69 const int centerY = info.height() / 2; 69 const int centerY = info.height() / 2;
70 int w = fSubsetWidth; 70 int w = fSubsetWidth;
71 int h = fSubsetHeight; 71 int h = fSubsetHeight;
72 do { 72 do {
73 const int subsetStartX = SkTMax(0, centerX - w / 2); 73 const int subsetStartX = SkTMax(0, centerX - w / 2);
74 const int subsetStartY = SkTMax(0, centerY - h / 2); 74 const int subsetStartY = SkTMax(0, centerY - h / 2);
75 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); 75 const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
76 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ; 76 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ;
77 // Note that if we subsetted and scaled in a single step, we cou ld use the 77 // Note that if we subsetted and scaled in a single step, we cou ld use the
78 // same bitmap - as is often done in actual use cases. 78 // same bitmap - as is often done in actual use cases.
79 SkBitmap bitmap; 79 SkBitmap bitmap;
80 bitmap.allocPixels(info.makeWH(subsetWidth, subsetHeight)); 80 bitmap.allocPixels(info.makeWH(subsetWidth, subsetHeight), NULL,
81 SkNEW_ARGS(SkColorTable, (colors, colorCount)));
81 82
82 uint32_t bpp = info.bytesPerPixel(); 83 uint32_t bpp = info.bytesPerPixel();
83 scanlineDecoder->skipScanlines(subsetStartY); 84 scanlineDecoder->skipScanlines(subsetStartY);
84 for (int y = 0; y < subsetHeight; y++) { 85 for (int y = 0; y < subsetHeight; y++) {
85 scanlineDecoder->getScanlines(row.get(), 1, 0); 86 scanlineDecoder->getScanlines(row.get(), 1, 0);
86 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, 87 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp,
87 subsetWidth * bpp); 88 subsetWidth * bpp);
88 } 89 }
89 w <<= 1; 90 w <<= 1;
90 h <<= 1; 91 h <<= 1;
(...skipping 17 matching lines...) Expand all
108 SkBitmap bitmap; 109 SkBitmap bitmap;
109 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth, 110 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
110 subsetHeight); 111 subsetHeight);
111 decoder->decodeSubset(&bitmap, rect, fColorType); 112 decoder->decodeSubset(&bitmap, rect, fColorType);
112 w <<= 1; 113 w <<= 1;
113 h <<= 1; 114 h <<= 1;
114 } while (w < 2 * width || h < 2 * height); 115 } while (w < 2 * width || h < 2 * height);
115 } 116 }
116 } 117 }
117 } 118 }
OLDNEW
« bench/subset/SubsetTranslateBench.cpp ('K') | « bench/subset/SubsetTranslateBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698