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

Side by Side Diff: bench/ImageCacheBench.cpp

Issue 20005003: add scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBenchmark.h"
9 #include "SkScaledImageCache.h"
10
11 class ImageCacheBench : public SkBenchmark {
12 SkScaledImageCache fCache;
13 SkBitmap fBM;
14
15 enum {
16 N = SkBENCHLOOP(1000),
17 DIM = 1,
18 CACHE_COUNT = 500
19 };
20 public:
21 ImageCacheBench(void* param) : INHERITED(param) , fCache(CACHE_COUNT * 100) {
22 fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM);
23 fBM.allocPixels();
24 }
25
26 void populateCache() {
27 SkScalar scale = 1;
28 for (int i = 0; i < CACHE_COUNT; ++i) {
29 SkBitmap tmp;
30 tmp.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
31 tmp.allocPixels();
32 fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
33 scale += 1;
34 }
35 }
36
37 protected:
38 virtual const char* onGetName() SK_OVERRIDE {
39 return "imagecache";
40 }
41
42 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
43 if (fCache.getBytesUsed() == 0) {
44 this->populateCache();
45 }
46
47 SkBitmap tmp;
48 // search for a miss (-1 scale)
49 for (int i = 0; i < N; ++i) {
50 (void)fCache.findAndLock(fBM, -1, -1, &tmp);
51 }
52 }
53
54 private:
55 typedef SkBenchmark INHERITED;
56 };
57
58 ///////////////////////////////////////////////////////////////////////////////
59
60 DEF_BENCH( return new ImageCacheBench(p); )
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698