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

Side by Side Diff: bench/ImageCacheBench.cpp

Issue 322963002: hide SkBitmap::setConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « bench/GameBench.cpp ('k') | bench/MagnifierBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkScaledImageCache.h" 9 #include "SkScaledImageCache.h"
10 10
11 class ImageCacheBench : public SkBenchmark { 11 class ImageCacheBench : public SkBenchmark {
12 SkScaledImageCache fCache; 12 SkScaledImageCache fCache;
13 SkBitmap fBM; 13 SkBitmap fBM;
14 14
15 enum { 15 enum {
16 DIM = 1, 16 DIM = 1,
17 CACHE_COUNT = 500 17 CACHE_COUNT = 500
18 }; 18 };
19 public: 19 public:
20 ImageCacheBench() : fCache(CACHE_COUNT * 100) { 20 ImageCacheBench() : fCache(CACHE_COUNT * 100) {
21 fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM); 21 fBM.allocN32Pixels(DIM, DIM);
22 fBM.allocPixels();
23 } 22 }
24 23
25 void populateCache() { 24 void populateCache() {
26 SkScalar scale = 1; 25 SkScalar scale = 1;
27 for (int i = 0; i < CACHE_COUNT; ++i) { 26 for (int i = 0; i < CACHE_COUNT; ++i) {
28 SkBitmap tmp; 27 SkBitmap tmp;
29 tmp.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); 28 tmp.allocN32Pixels(1, 1);
30 tmp.allocPixels();
31 fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp)); 29 fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
32 scale += 1; 30 scale += 1;
33 } 31 }
34 } 32 }
35 33
36 protected: 34 protected:
37 virtual const char* onGetName() SK_OVERRIDE { 35 virtual const char* onGetName() SK_OVERRIDE {
38 return "imagecache"; 36 return "imagecache";
39 } 37 }
40 38
41 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 39 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
42 if (fCache.getBytesUsed() == 0) { 40 if (fCache.getBytesUsed() == 0) {
43 this->populateCache(); 41 this->populateCache();
44 } 42 }
45 43
46 SkBitmap tmp; 44 SkBitmap tmp;
47 // search for a miss (-1 scale) 45 // search for a miss (-1 scale)
48 for (int i = 0; i < loops; ++i) { 46 for (int i = 0; i < loops; ++i) {
49 (void)fCache.findAndLock(fBM, -1, -1, &tmp); 47 (void)fCache.findAndLock(fBM, -1, -1, &tmp);
50 } 48 }
51 } 49 }
52 50
53 private: 51 private:
54 typedef SkBenchmark INHERITED; 52 typedef SkBenchmark INHERITED;
55 }; 53 };
56 54
57 /////////////////////////////////////////////////////////////////////////////// 55 ///////////////////////////////////////////////////////////////////////////////
58 56
59 DEF_BENCH( return new ImageCacheBench(); ) 57 DEF_BENCH( return new ImageCacheBench(); )
OLDNEW
« no previous file with comments | « bench/GameBench.cpp ('k') | bench/MagnifierBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698