| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "Resources.h" | 9 #include "Resources.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkImageGenerator.h" | 12 #include "SkImageGenerator.h" |
| 13 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
| 14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
| 15 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
| 16 | 16 |
| 17 #ifndef SK_IGNORE_ETC1_SUPPORT | 17 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 18 | 18 |
| 19 #include "etc1.h" | 19 #include "etc1.h" |
| 20 | 20 |
| 21 // This takes the etc1 data pointed to by orig, and copies it `factor` times in
each | 21 // This takes the etc1 data pointed to by orig, and copies it `factor` times in
each |
| 22 // dimension. The return value is the new data or NULL on error. | 22 // dimension. The return value is the new data or nullptr on error. |
| 23 static etc1_byte* create_expanded_etc1_bitmap(const uint8_t* orig, int factor) { | 23 static etc1_byte* create_expanded_etc1_bitmap(const uint8_t* orig, int factor) { |
| 24 SkASSERT(orig); | 24 SkASSERT(orig); |
| 25 SkASSERT(factor > 1); | 25 SkASSERT(factor > 1); |
| 26 | 26 |
| 27 const etc1_byte* origData = reinterpret_cast<const etc1_byte*>(orig); | 27 const etc1_byte* origData = reinterpret_cast<const etc1_byte*>(orig); |
| 28 if (!etc1_pkm_is_valid(orig)) { | 28 if (!etc1_pkm_is_valid(orig)) { |
| 29 return NULL; | 29 return nullptr; |
| 30 } | 30 } |
| 31 | 31 |
| 32 etc1_uint32 origWidth = etc1_pkm_get_width(origData); | 32 etc1_uint32 origWidth = etc1_pkm_get_width(origData); |
| 33 etc1_uint32 origHeight = etc1_pkm_get_height(origData); | 33 etc1_uint32 origHeight = etc1_pkm_get_height(origData); |
| 34 | 34 |
| 35 // The width and height must be aligned along block boundaries | 35 // The width and height must be aligned along block boundaries |
| 36 static const etc1_uint32 kETC1BlockWidth = 4; | 36 static const etc1_uint32 kETC1BlockWidth = 4; |
| 37 static const etc1_uint32 kETC1BlockHeight = 4; | 37 static const etc1_uint32 kETC1BlockHeight = 4; |
| 38 if ((origWidth % kETC1BlockWidth) != 0 || | 38 if ((origWidth % kETC1BlockWidth) != 0 || |
| 39 (origHeight % kETC1BlockHeight) != 0) { | 39 (origHeight % kETC1BlockHeight) != 0) { |
| 40 return NULL; | 40 return nullptr; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // The picture must be at least as large as a block. | 43 // The picture must be at least as large as a block. |
| 44 if (origWidth <= kETC1BlockWidth || origHeight <= kETC1BlockHeight) { | 44 if (origWidth <= kETC1BlockWidth || origHeight <= kETC1BlockHeight) { |
| 45 return NULL; | 45 return nullptr; |
| 46 } | 46 } |
| 47 | 47 |
| 48 etc1_uint32 newWidth = origWidth * factor; | 48 etc1_uint32 newWidth = origWidth * factor; |
| 49 etc1_uint32 newHeight = origHeight * factor; | 49 etc1_uint32 newHeight = origHeight * factor; |
| 50 | 50 |
| 51 etc1_uint32 newDataSz = etc1_get_encoded_data_size(newWidth, newHeight); | 51 etc1_uint32 newDataSz = etc1_get_encoded_data_size(newWidth, newHeight); |
| 52 etc1_byte* newData = reinterpret_cast<etc1_byte *>( | 52 etc1_byte* newData = reinterpret_cast<etc1_byte *>( |
| 53 sk_malloc_throw(newDataSz + ETC_PKM_HEADER_SIZE)); | 53 sk_malloc_throw(newDataSz + ETC_PKM_HEADER_SIZE)); |
| 54 etc1_pkm_format_header(newData, newWidth, newHeight); | 54 etc1_pkm_format_header(newData, newWidth, newHeight); |
| 55 | 55 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 73 return newData; | 73 return newData; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // This is the base class for all of the benches in this file. In general | 76 // This is the base class for all of the benches in this file. In general |
| 77 // the ETC1 benches should all be working on the same data. Due to the | 77 // the ETC1 benches should all be working on the same data. Due to the |
| 78 // simplicity of the PKM file, that data is the 128x128 mandrill etc1 | 78 // simplicity of the PKM file, that data is the 128x128 mandrill etc1 |
| 79 // compressed texture repeated by some factor (currently 8 -> 1024x1024) | 79 // compressed texture repeated by some factor (currently 8 -> 1024x1024) |
| 80 class ETCBitmapBenchBase : public Benchmark { | 80 class ETCBitmapBenchBase : public Benchmark { |
| 81 public: | 81 public: |
| 82 ETCBitmapBenchBase() : fPKMData(loadPKM()) { | 82 ETCBitmapBenchBase() : fPKMData(loadPKM()) { |
| 83 if (NULL == fPKMData) { | 83 if (nullptr == fPKMData) { |
| 84 SkDebugf("Could not load PKM data!"); | 84 SkDebugf("Could not load PKM data!"); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 protected: | 88 protected: |
| 89 SkAutoDataUnref fPKMData; | 89 SkAutoDataUnref fPKMData; |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 SkData* loadPKM() { | 92 SkData* loadPKM() { |
| 93 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); | 93 SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); |
| 94 // Expand the data | 94 // Expand the data |
| 95 SkAutoDataUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); | 95 SkAutoDataUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); |
| 96 if (NULL == fileData) { | 96 if (nullptr == fileData) { |
| 97 SkDebugf("Could not open the file. Did you forget to set the resourc
ePath?\n"); | 97 SkDebugf("Could not open the file. Did you forget to set the resourc
ePath?\n"); |
| 98 return NULL; | 98 return nullptr; |
| 99 } | 99 } |
| 100 | 100 |
| 101 const etc1_uint32 kExpansionFactor = 8; | 101 const etc1_uint32 kExpansionFactor = 8; |
| 102 etc1_byte* expandedETC1 = | 102 etc1_byte* expandedETC1 = |
| 103 create_expanded_etc1_bitmap(fileData->bytes(), kExpansionFactor); | 103 create_expanded_etc1_bitmap(fileData->bytes(), kExpansionFactor); |
| 104 if (NULL == expandedETC1) { | 104 if (nullptr == expandedETC1) { |
| 105 SkDebugf("Error expanding ETC1 data by factor of %d\n", kExpansionFa
ctor); | 105 SkDebugf("Error expanding ETC1 data by factor of %d\n", kExpansionFa
ctor); |
| 106 return NULL; | 106 return nullptr; |
| 107 } | 107 } |
| 108 | 108 |
| 109 etc1_uint32 width = etc1_pkm_get_width(expandedETC1); | 109 etc1_uint32 width = etc1_pkm_get_width(expandedETC1); |
| 110 etc1_uint32 height = etc1_pkm_get_width(expandedETC1); | 110 etc1_uint32 height = etc1_pkm_get_width(expandedETC1); |
| 111 etc1_uint32 dataSz = ETC_PKM_HEADER_SIZE + etc1_get_encoded_data_size(wi
dth, height); | 111 etc1_uint32 dataSz = ETC_PKM_HEADER_SIZE + etc1_get_encoded_data_size(wi
dth, height); |
| 112 return SkData::NewFromMalloc(expandedETC1, dataSz); | 112 return SkData::NewFromMalloc(expandedETC1, dataSz); |
| 113 } | 113 } |
| 114 | 114 |
| 115 typedef Benchmark INHERITED; | 115 typedef Benchmark INHERITED; |
| 116 }; | 116 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 SkASSERT(kRaster_Backend == this->fBackend); | 138 SkASSERT(kRaster_Backend == this->fBackend); |
| 139 if (this->fDecompress) { | 139 if (this->fDecompress) { |
| 140 return "etc1bitmap_render_raster_decompressed"; | 140 return "etc1bitmap_render_raster_decompressed"; |
| 141 } else { | 141 } else { |
| 142 return "etc1bitmap_render_raster_compressed"; | 142 return "etc1bitmap_render_raster_compressed"; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void onPreDraw() override { | 147 void onPreDraw() override { |
| 148 if (NULL == fPKMData) { | 148 if (nullptr == fPKMData) { |
| 149 SkDebugf("Failed to load PKM data!\n"); | 149 SkDebugf("Failed to load PKM data!\n"); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Install pixel ref | 153 // Install pixel ref |
| 154 if (!SkInstallDiscardablePixelRef(fPKMData, &(this->fBitmap))) { | 154 if (!SkInstallDiscardablePixelRef(fPKMData, &(this->fBitmap))) { |
| 155 SkDebugf("Could not install discardable pixel ref.\n"); | 155 SkDebugf("Could not install discardable pixel ref.\n"); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Decompress it if necessary | 159 // Decompress it if necessary |
| 160 if (this->fDecompress) { | 160 if (this->fDecompress) { |
| 161 this->fBitmap.lockPixels(); | 161 this->fBitmap.lockPixels(); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 void onDraw(const int loops, SkCanvas* canvas) override { | 165 void onDraw(const int loops, SkCanvas* canvas) override { |
| 166 for (int i = 0; i < loops; ++i) { | 166 for (int i = 0; i < loops; ++i) { |
| 167 canvas->drawBitmap(this->fBitmap, 0, 0, NULL); | 167 canvas->drawBitmap(this->fBitmap, 0, 0, nullptr); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 protected: | 171 protected: |
| 172 SkBitmap fBitmap; | 172 SkBitmap fBitmap; |
| 173 bool decompress() const { return fDecompress; } | 173 bool decompress() const { return fDecompress; } |
| 174 Backend backend() const { return fBackend; } | 174 Backend backend() const { return fBackend; } |
| 175 private: | 175 private: |
| 176 const bool fDecompress; | 176 const bool fDecompress; |
| 177 const Backend fBackend; | 177 const Backend fBackend; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void onDraw(const int loops, SkCanvas* canvas) override { | 207 void onDraw(const int loops, SkCanvas* canvas) override { |
| 208 SkPixelRef* pr = fBitmap.pixelRef(); | 208 SkPixelRef* pr = fBitmap.pixelRef(); |
| 209 for (int i = 0; i < loops; ++i) { | 209 for (int i = 0; i < loops; ++i) { |
| 210 if (pr) { | 210 if (pr) { |
| 211 pr->notifyPixelsChanged(); | 211 pr->notifyPixelsChanged(); |
| 212 } | 212 } |
| 213 canvas->drawBitmap(this->fBitmap, 0, 0, NULL); | 213 canvas->drawBitmap(this->fBitmap, 0, 0, nullptr); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 typedef ETCBitmapBench INHERITED; | 218 typedef ETCBitmapBench INHERITED; |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 DEF_BENCH(return new ETCBitmapBench(false, Benchmark::kRaster_Backend);) | 221 DEF_BENCH(return new ETCBitmapBench(false, Benchmark::kRaster_Backend);) |
| 222 DEF_BENCH(return new ETCBitmapBench(true, Benchmark::kRaster_Backend);) | 222 DEF_BENCH(return new ETCBitmapBench(true, Benchmark::kRaster_Backend);) |
| 223 | 223 |
| 224 DEF_BENCH(return new ETCBitmapBench(false, Benchmark::kGPU_Backend);) | 224 DEF_BENCH(return new ETCBitmapBench(false, Benchmark::kGPU_Backend);) |
| 225 DEF_BENCH(return new ETCBitmapBench(true, Benchmark::kGPU_Backend);) | 225 DEF_BENCH(return new ETCBitmapBench(true, Benchmark::kGPU_Backend);) |
| 226 | 226 |
| 227 DEF_BENCH(return new ETCBitmapUploadBench(false, Benchmark::kRaster_Backend);) | 227 DEF_BENCH(return new ETCBitmapUploadBench(false, Benchmark::kRaster_Backend);) |
| 228 DEF_BENCH(return new ETCBitmapUploadBench(true, Benchmark::kRaster_Backend);) | 228 DEF_BENCH(return new ETCBitmapUploadBench(true, Benchmark::kRaster_Backend);) |
| 229 | 229 |
| 230 DEF_BENCH(return new ETCBitmapUploadBench(false, Benchmark::kGPU_Backend);) | 230 DEF_BENCH(return new ETCBitmapUploadBench(false, Benchmark::kGPU_Backend);) |
| 231 DEF_BENCH(return new ETCBitmapUploadBench(true, Benchmark::kGPU_Backend);) | 231 DEF_BENCH(return new ETCBitmapUploadBench(true, Benchmark::kGPU_Backend);) |
| 232 | 232 |
| 233 #endif // SK_IGNORE_ETC1_SUPPORT | 233 #endif // SK_IGNORE_ETC1_SUPPORT |
| OLD | NEW |