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

Side by Side Diff: tests/MaskCacheTest.cpp

Issue 592843003: Add SkCachedData and use it for SkMipMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: uses low-bit of refcnt to known when we're in the cache Created 6 years, 3 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
« src/core/SkCachedData.cpp ('K') | « src/core/SkResourceCache.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 2014 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 "SkCachedData.h"
9 #include "SkMaskCache.h"
10 #include "SkResourceCache.h"
11 #include "Test.h"
12
13 enum LockedState {
14 kUnlocked,
15 kLocked
16 };
17
18 static void check_data(skiatest::Reporter* reporter, SkCachedData* data,
19 int refcnt, bool isInCache, LockedState lockedState) {
20 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
21 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == isInCache);
22 bool isLocked = (data->data() != NULL);
23 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
24 }
25
26 DEF_TEST(MaskCache, reporter) {
27
28 SkResourceCache cache(1024);
29
30 SkScalar sigma = 2;
31 SkRect r = SkRect::MakeWH(10, 10);
32 SkMask mask;
33
34 SkCachedData* data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache);
35 REPORTER_ASSERT(reporter, NULL == data);
36
37 size_t size = 100;
38 data = cache.newCachedData(size);
39 check_data(reporter, data, 1, false, kLocked);
40
41 memset(data->writable_data(), 0x80, size); // just to use writable_data()
42 mask.fBounds.setXYWH(1, 2, 3, 4);
43 SkMaskCache::Add(sigma, r, mask, data, &cache);
44 check_data(reporter, data, 2, true, kLocked);
45
46 data->unref();
47 check_data(reporter, data, 1, true, kUnlocked);
48
49 sk_bzero(&mask, sizeof(mask));
50 data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache);
51 check_data(reporter, data, 2, true, kLocked);
52
53 REPORTER_ASSERT(reporter, data);
54 REPORTER_ASSERT(reporter, data->size() == size);
55 REPORTER_ASSERT(reporter, mask.fBounds.top() == 2);
56 REPORTER_ASSERT(reporter, data->data() == (const void*)mask.fImage);
57
58 cache.purgeAll();
59 check_data(reporter, data, 1, false, kLocked);
60 data->unref();
61 }
62
OLDNEW
« src/core/SkCachedData.cpp ('K') | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698