OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCachedData.h" | 8 #include "SkCachedData.h" |
9 #include "SkYUVPlanesCache.h" | 9 #include "SkYUVPlanesCache.h" |
10 #include "SkResourceCache.h" | 10 #include "SkResourceCache.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); | 25 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
26 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); | 26 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); |
27 bool isLocked = (data->data() != nullptr); | 27 bool isLocked = (data->data() != nullptr); |
28 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); | 28 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
29 } | 29 } |
30 | 30 |
31 DEF_TEST(YUVPlanesCache, reporter) { | 31 DEF_TEST(YUVPlanesCache, reporter) { |
32 SkResourceCache cache(1024); | 32 SkResourceCache cache(1024); |
33 | 33 |
34 SkYUVPlanesCache::Info yuvInfo; | 34 SkYUVPlanesCache::Info yuvInfo; |
35 for (int i = 0; i < 3; i++) { | 35 for (int i = 0; i < 3; ++i) { |
36 yuvInfo.fSizeInfo.fSizes[i].fWidth = 20 * i; | 36 yuvInfo.fSize[i].fWidth = 20 * i; |
37 yuvInfo.fSizeInfo.fSizes[i].fHeight = 10 * i; | 37 yuvInfo.fSize[i].fHeight = 10 * i; |
38 yuvInfo.fSizeInfo.fWidthBytes[i] = 80 * i; | 38 yuvInfo.fSizeInMemory[i] = 800 * i; |
| 39 yuvInfo.fRowBytes[i] = 80 * i; |
39 } | 40 } |
40 yuvInfo.fColorSpace = kRec601_SkYUVColorSpace; | 41 yuvInfo.fColorSpace = kRec601_SkYUVColorSpace; |
41 | 42 |
42 const uint32_t genID = 12345678; | 43 const uint32_t genID = 12345678; |
43 | 44 |
44 SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfo, &cache); | 45 SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfo, &cache); |
45 REPORTER_ASSERT(reporter, nullptr == data); | 46 REPORTER_ASSERT(reporter, nullptr == data); |
46 | 47 |
47 size_t size = 256; | 48 size_t size = 256; |
48 data = cache.newCachedData(size); | 49 data = cache.newCachedData(size); |
49 memset(data->writable_data(), 0xff, size); | 50 memset(data->writable_data(), 0xff, size); |
50 | 51 |
51 SkYUVPlanesCache::Add(genID, data, &yuvInfo, &cache); | 52 SkYUVPlanesCache::Add(genID, data, &yuvInfo, &cache); |
52 check_data(reporter, data, 2, kInCache, kLocked); | 53 check_data(reporter, data, 2, kInCache, kLocked); |
53 | 54 |
54 data->unref(); | 55 data->unref(); |
55 check_data(reporter, data, 1, kInCache, kUnlocked); | 56 check_data(reporter, data, 1, kInCache, kUnlocked); |
56 | 57 |
57 SkYUVPlanesCache::Info yuvInfoRead; | 58 SkYUVPlanesCache::Info yuvInfoRead; |
58 data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfoRead, &cache); | 59 data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfoRead, &cache); |
59 | 60 |
60 REPORTER_ASSERT(reporter, data); | 61 REPORTER_ASSERT(reporter, data); |
61 REPORTER_ASSERT(reporter, data->size() == size); | 62 REPORTER_ASSERT(reporter, data->size() == size); |
62 for (int i = 0; i < 3; ++i) { | 63 for (int i = 0; i < 3; ++i) { |
63 REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fWidth == | 64 REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fWidth == yuvInfoRead.fSize[i
].fWidth); |
64 yuvInfoRead.fSizeInfo.fSizes[i].fWidth); | 65 REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fHeight == yuvInfoRead.fSize[
i].fHeight); |
65 REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fHeight == | 66 REPORTER_ASSERT(reporter, yuvInfo.fSizeInMemory[i] == yuvInfoRead.fSizeI
nMemory[i]); |
66 yuvInfoRead.fSizeInfo.fSizes[i].fHeight); | 67 REPORTER_ASSERT(reporter, yuvInfo.fRowBytes[i] == yuvInfoRead.fRowBytes[
i]); |
67 REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fWidthBytes[i] == | |
68 yuvInfoRead.fSizeInfo.fWidthBytes[i]); | |
69 } | 68 } |
70 REPORTER_ASSERT(reporter, yuvInfo.fColorSpace == yuvInfoRead.fColorSpace); | 69 REPORTER_ASSERT(reporter, yuvInfo.fColorSpace == yuvInfoRead.fColorSpace); |
71 | 70 |
72 check_data(reporter, data, 2, kInCache, kLocked); | 71 check_data(reporter, data, 2, kInCache, kLocked); |
73 | 72 |
74 cache.purgeAll(); | 73 cache.purgeAll(); |
75 check_data(reporter, data, 1, kNotInCache, kLocked); | 74 check_data(reporter, data, 1, kNotInCache, kLocked); |
76 data->unref(); | 75 data->unref(); |
77 } | 76 } |
OLD | NEW |