2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkScaledImageCache.h"
11 class ImageCacheBench : public Benchmark {
12 SkScaledImageCache fCache;
20 ImageCacheBench() : fCache(CACHE_COUNT * 100) {
21 fBM.allocN32Pixels(DIM, DIM);
24 void populateCache() {
26 for (int i = 0; i < CACHE_COUNT; ++i) {
28 tmp.allocN32Pixels(1, 1);
29 fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
35 virtual const char* onGetName() SK_OVERRIDE {
39 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
40 if (fCache.getBytesUsed() == 0) {
41 this->populateCache();
45 // search for a miss (-1 scale)
46 for (int i = 0; i < loops; ++i) {
47 (void)fCache.findAndLock(fBM, -1, -1, &tmp);
52 typedef Benchmark INHERITED;
55 ///////////////////////////////////////////////////////////////////////////////
57 DEF_BENCH( return new ImageCacheBench(); )