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

Side by Side Diff: tests/ImageCacheTest.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 | « src/core/SkScaledImageCache.cpp ('k') | no next file » | 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 "Test.h"
9 #include "SkScaledImageCache.h"
10
11 static void make_bm(SkBitmap* bm, int w, int h) {
12 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
13 bm->allocPixels();
14 }
15
16 static void TestImageCache(skiatest::Reporter* reporter) {
17 static const int COUNT = 10;
18 static const int DIM = 256;
19 static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop
20 SkScaledImageCache cache(defLimit);
21 SkScaledImageCache::ID* id;
22
23 SkBitmap bm[COUNT];
24
25 SkScalar scale = 2;
26 for (size_t i = 0; i < COUNT; ++i) {
27 SkBitmap tmp;
28
29 make_bm(&bm[i], DIM, DIM);
30 id = cache.findAndLock(bm[i], scale, scale, &tmp);
31 REPORTER_ASSERT(reporter, NULL == id);
32
33 make_bm(&tmp, DIM, DIM);
34 id = cache.addAndLock(bm[i], scale, scale, tmp);
35 REPORTER_ASSERT(reporter, NULL != id);
36
37 SkBitmap tmp2;
38 SkScaledImageCache::ID* id2 = cache.findAndLock(bm[i], scale, scale,
39 &tmp2);
40 REPORTER_ASSERT(reporter, id == id2);
41 REPORTER_ASSERT(reporter, tmp.pixelRef() == tmp2.pixelRef());
42 REPORTER_ASSERT(reporter, tmp.width() == tmp2.width());
43 REPORTER_ASSERT(reporter, tmp.height() == tmp2.height());
44 cache.unlock(id2);
45
46 cache.unlock(id);
47 }
48
49 // stress test, should trigger purges
50 for (size_t i = 0; i < COUNT * 100; ++i) {
51 SkBitmap tmp;
52
53 make_bm(&tmp, DIM, DIM);
54 id = cache.addAndLock(bm[0], scale, scale, tmp);
55 REPORTER_ASSERT(reporter, NULL != id);
56 cache.unlock(id);
57
58 scale += 1;
59 }
60
61 cache.setByteLimit(0);
62 }
63
64 #include "TestClassDef.h"
65 DEFINE_TESTCLASS("ImageCache", TestImageCacheClass, TestImageCache)
OLDNEW
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698