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

Side by Side Diff: tests/YUVCacheTest.cpp

Issue 851273003: YUV planes cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static cast at the right spot Created 5 years, 11 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/SkYUVPlanesCache.h ('K') | « src/gpu/SkGr.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 "SkYUVPlanesCache.h"
10 #include "SkResourceCache.h"
11 #include "Test.h"
12
13 enum LockedState {
14 kUnlocked,
15 kLocked,
16 };
17
18 enum CachedState {
19 kNotInCache,
20 kInCache,
21 };
22
23 static void check_data(skiatest::Reporter* reporter, SkCachedData* data,
24 int refcnt, CachedState cacheState, LockedState lockedSta te) {
25 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
26 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac heState));
27 bool isLocked = (data->data() != NULL);
28 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
29 }
30
31 DEF_TEST(YUVPlanesCache, reporter) {
32 SkResourceCache cache(1024);
33
34 SkYUVPlanesCache::Info yuvInfo;
35 for (int i = 0; i < 3; ++i) {
36 yuvInfo.fSize[i].fWidth = 20 * i;
37 yuvInfo.fSize[i].fHeight = 10 * i;
38 yuvInfo.fSizeInMemory[i] = 800 * i;
39 yuvInfo.fRowBytes[i] = 80 * i;
40 }
41 yuvInfo.fColorSpace = kRec601_SkYUVColorSpace;
42
43 const uint32_t genID = 12345678;
44
45 SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfo, &cache);
46 REPORTER_ASSERT(reporter, NULL == data);
47
48 size_t size = 256;
49 data = cache.newCachedData(size);
50 memset(data->writable_data(), 0xff, size);
51
52 SkYUVPlanesCache::Add(genID, data, &yuvInfo, &cache);
53 check_data(reporter, data, 2, kInCache, kLocked);
54
55 data->unref();
56 check_data(reporter, data, 1, kInCache, kUnlocked);
57
58 SkYUVPlanesCache::Info yuvInfoRead;
59 data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfoRead, &cache);
60
61 REPORTER_ASSERT(reporter, data);
62 REPORTER_ASSERT(reporter, data->size() == size);
63 for (int i = 0; i < 3; ++i) {
64 REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fWidth == yuvInfoRead.fSize[i ].fWidth);
65 REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fHeight == yuvInfoRead.fSize[ i].fHeight);
66 REPORTER_ASSERT(reporter, yuvInfo.fSizeInMemory[i] == yuvInfoRead.fSizeI nMemory[i]);
67 REPORTER_ASSERT(reporter, yuvInfo.fRowBytes[i] == yuvInfoRead.fRowBytes[ i]);
68 }
69 REPORTER_ASSERT(reporter, yuvInfo.fColorSpace == yuvInfoRead.fColorSpace);
70
71 check_data(reporter, data, 2, kInCache, kLocked);
72
73 cache.purgeAll();
74 check_data(reporter, data, 1, kNotInCache, kLocked);
75 data->unref();
76 }
OLDNEW
« src/core/SkYUVPlanesCache.h ('K') | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698