| OLD | NEW | 
|---|
| 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 "CodecBenchPriv.h" | 8 #include "CodecBenchPriv.h" | 
| 9 #include "SubsetTranslateBench.h" | 9 #include "SubsetTranslateBench.h" | 
| 10 #include "SubsetBenchPriv.h" | 10 #include "SubsetBenchPriv.h" | 
| 11 #include "SkData.h" | 11 #include "SkData.h" | 
| 12 #include "SkCodec.h" | 12 #include "SkCodec.h" | 
| 13 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" | 
| 14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" | 
| 15 #include "SkStream.h" | 15 #include "SkStream.h" | 
| 16 | 16 | 
| 17 /* | 17 /* | 
| 18  * | 18  * | 
| 19  * This benchmark is designed to test the performance of subset decoding. | 19  * This benchmark is designed to test the performance of subset decoding. | 
| 20  * It uses input dimensions to decode the entire image where each block is susbe
     tW x subsetH. | 20  * It uses input dimensions to decode the entire image where each block is susbe
     tW x subsetH. | 
| 21  * | 21  * | 
| 22  */ | 22  */ | 
| 23 | 23 | 
| 24 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, | 24 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, | 
| 25                                            SkColorType colorType, | 25                                            SkColorType colorType, | 
| 26                                            uint32_t subsetWidth, | 26                                            uint32_t subsetWidth, | 
| 27                                            uint32_t subsetHeight, | 27                                            uint32_t subsetHeight) | 
| 28                                            bool useCodec) |  | 
| 29     : fColorType(colorType) | 28     : fColorType(colorType) | 
| 30     , fSubsetWidth(subsetWidth) | 29     , fSubsetWidth(subsetWidth) | 
| 31     , fSubsetHeight(subsetHeight) | 30     , fSubsetHeight(subsetHeight) | 
| 32     , fUseCodec(useCodec) |  | 
| 33 { | 31 { | 
| 34     // Parse the filename | 32     // Parse the filename | 
| 35     SkString baseName = SkOSPath::Basename(path.c_str()); | 33     SkString baseName = SkOSPath::Basename(path.c_str()); | 
| 36 | 34 | 
| 37     // Choose an informative color name | 35     // Choose an informative color name | 
| 38     const char* colorName = color_type_to_str(fColorType); | 36     const char* colorName = color_type_to_str(fColorType); | 
| 39 | 37 | 
| 40     fName.printf("%sSubsetTranslate_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image",
      fSubsetWidth, | 38     fName.printf("CodecSubsetTranslate_%dx%d_%s_%s", fSubsetWidth, | 
| 41             fSubsetHeight, baseName.c_str(), colorName); | 39             fSubsetHeight, baseName.c_str(), colorName); | 
| 42 | 40 | 
| 43     // Perform the decode setup | 41     // Perform the decode setup | 
| 44     SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 42     SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 
| 45     fStream.reset(new SkMemoryStream(encoded)); | 43     fStream.reset(new SkMemoryStream(encoded)); | 
| 46 } | 44 } | 
| 47 | 45 | 
| 48 const char* SubsetTranslateBench::onGetName() { | 46 const char* SubsetTranslateBench::onGetName() { | 
| 49     return fName.c_str(); | 47     return fName.c_str(); | 
| 50 } | 48 } | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 61     } | 59     } | 
| 62 | 60 | 
| 63     return const_cast<SkPMColor*>(ct->readColors()); | 61     return const_cast<SkPMColor*>(ct->readColors()); | 
| 64 } | 62 } | 
| 65 | 63 | 
| 66 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { | 64 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { | 
| 67     // When the color type is kIndex8, we will need to store the color table.  I
     f it is | 65     // When the color type is kIndex8, we will need to store the color table.  I
     f it is | 
| 68     // used, it will be initialized by the codec. | 66     // used, it will be initialized by the codec. | 
| 69     int colorCount = 256; | 67     int colorCount = 256; | 
| 70     SkPMColor colors[256]; | 68     SkPMColor colors[256]; | 
| 71     if (fUseCodec) { | 69     for (int count = 0; count < n; count++) { | 
| 72         for (int count = 0; count < n; count++) { | 70         SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()
     )); | 
| 73             SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
     te())); | 71         SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder
     ()); | 
| 74             SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO
     rder()); | 72         const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | 
| 75             const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |  | 
| 76 | 73 | 
| 77             SkBitmap bitmap; | 74         SkBitmap bitmap; | 
| 78             // Note that we use the same bitmap for all of the subsets. | 75         // Note that we use the same bitmap for all of the subsets. | 
| 79             // It might be larger than necessary for the end subsets. | 76         // It might be larger than necessary for the end subsets. | 
| 80             SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 77         SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 
| 81             alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 78         alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 
| 82 | 79 | 
| 83             for (int x = 0; x < info.width(); x += fSubsetWidth) { | 80         for (int x = 0; x < info.width(); x += fSubsetWidth) { | 
| 84                 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 81             for (int y = 0; y < info.height(); y += fSubsetHeight) { | 
| 85                     const uint32_t currSubsetWidth = | 82                 const uint32_t currSubsetWidth = | 
| 86                             x + (int) fSubsetWidth > info.width() ? | 83                         x + (int) fSubsetWidth > info.width() ? | 
| 87                             info.width() - x : fSubsetWidth; | 84                         info.width() - x : fSubsetWidth; | 
| 88                     const uint32_t currSubsetHeight = | 85                 const uint32_t currSubsetHeight = | 
| 89                             y + (int) fSubsetHeight > info.height() ? | 86                         y + (int) fSubsetHeight > info.height() ? | 
| 90                             info.height() - y : fSubsetHeight; | 87                         info.height() - y : fSubsetHeight; | 
| 91 | 88 | 
| 92                     // The scanline decoder will handle subsetting in the x-dime
     nsion. | 89                 // The scanline decoder will handle subsetting in the x-dimensio
     n. | 
| 93                     SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth, | 90                 SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth, | 
| 94                             codec->getInfo().height()); | 91                         codec->getInfo().height()); | 
| 95                     SkCodec::Options options; | 92                 SkCodec::Options options; | 
| 96                     options.fSubset = ⊂ | 93                 options.fSubset = ⊂ | 
| 97 | 94 | 
| 98                     SkDEBUGCODE(SkCodec::Result result =) | 95                 SkDEBUGCODE(SkCodec::Result result =) | 
| 99                     codec->startScanlineDecode(info, &options, get_colors(&bitma
     p), &colorCount); | 96                 codec->startScanlineDecode(info, &options, get_colors(&bitmap), 
     &colorCount); | 
| 100                     SkASSERT(SkCodec::kSuccess == result); | 97                 SkASSERT(SkCodec::kSuccess == result); | 
| 101 | 98 | 
| 102                     SkDEBUGCODE(bool success =) codec->skipScanlines(y); | 99                 SkDEBUGCODE(bool success =) codec->skipScanlines(y); | 
| 103                     SkASSERT(success); | 100                 SkASSERT(success); | 
| 104 | 101 | 
| 105                     SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.get
     Pixels(), | 102                 SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.getPixe
     ls(), | 
| 106                             currSubsetHeight, bitmap.rowBytes()); | 103                         currSubsetHeight, bitmap.rowBytes()); | 
| 107                     SkASSERT(currSubsetHeight == lines); | 104                 SkASSERT(currSubsetHeight == lines); | 
| 108                 } |  | 
| 109             } |  | 
| 110         } |  | 
| 111     } else { |  | 
| 112         // We create a color table here to satisfy allocPixels() when the output |  | 
| 113         // type is kIndex8.  It's okay that this is uninitialized since we never |  | 
| 114         // use it. |  | 
| 115         SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0)); |  | 
| 116         for (int count = 0; count < n; count++) { |  | 
| 117             int width, height; |  | 
| 118             SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
     m)); |  | 
| 119             SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
      &height)); |  | 
| 120             SkBitmap bitmap; |  | 
| 121             // Note that we use the same bitmap for all of the subsets. |  | 
| 122             // It might be larger than necessary for the end subsets. |  | 
| 123             // If we do not include this step, decodeSubset() would allocate spa
     ce |  | 
| 124             // for the pixels automatically, but this would not allow us to reus
     e the |  | 
| 125             // same bitmap as the other subsets.  We want to reuse the same bitm
     ap |  | 
| 126             // because it gives a more fair comparison with SkCodec and is a com
     mon |  | 
| 127             // use case of BitmapRegionDecoder. |  | 
| 128             bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, |  | 
| 129                     fColorType, kOpaque_SkAlphaType), nullptr, colorTable); |  | 
| 130 |  | 
| 131             for (int x = 0; x < width; x += fSubsetWidth) { |  | 
| 132                 for (int y = 0; y < height; y += fSubsetHeight) { |  | 
| 133                     const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi
     dth ? |  | 
| 134                             width - x : fSubsetWidth; |  | 
| 135                     const uint32_t currSubsetHeight = y + (int) fSubsetHeight > 
     height ? |  | 
| 136                             height - y : fSubsetHeight; |  | 
| 137                     SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |  | 
| 138                             currSubsetHeight); |  | 
| 139                     SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy
     pe)); |  | 
| 140                 } |  | 
| 141             } | 105             } | 
| 142         } | 106         } | 
| 143     } | 107     } | 
| 144 } | 108 } | 
| OLD | NEW | 
|---|