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

Side by Side Diff: tests/ImageFilterCacheTest.cpp

Issue 1919063002: Image filters: de-nest SkImageFilter::Cache and Cache::Key. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix copyright Created 4 years, 7 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
« no previous file with comments | « src/svg/SkSVGDevice.h ('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
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 "Test.h" 8 #include "Test.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkImageFilter.h" 12 #include "SkImageFilter.h"
13 #include "SkImageFilterCacheKey.h" 13 #include "SkImageFilterCache.h"
14 #include "SkMatrix.h" 14 #include "SkMatrix.h"
15 #include "SkSpecialImage.h" 15 #include "SkSpecialImage.h"
16 16
17 static const int kSmallerSize = 10; 17 static const int kSmallerSize = 10;
18 static const int kPad = 3; 18 static const int kPad = 3;
19 static const int kFullSize = kSmallerSize + 2 * kPad; 19 static const int kFullSize = kSmallerSize + 2 * kPad;
20 20
21 static SkBitmap create_bm() { 21 static SkBitmap create_bm() {
22 SkBitmap bm; 22 SkBitmap bm;
23 bm.allocN32Pixels(kFullSize, kFullSize, true); 23 bm.allocN32Pixels(kFullSize, kFullSize, true);
24 bm.eraseColor(SK_ColorTRANSPARENT); 24 bm.eraseColor(SK_ColorTRANSPARENT);
25 return bm; 25 return bm;
26 } 26 }
27 27
28 // Ensure the cache can return a cached image 28 // Ensure the cache can return a cached image
29 static void test_find_existing(skiatest::Reporter* reporter, 29 static void test_find_existing(skiatest::Reporter* reporter,
30 const sk_sp<SkSpecialImage>& image, 30 const sk_sp<SkSpecialImage>& image,
31 const sk_sp<SkSpecialImage>& subset) { 31 const sk_sp<SkSpecialImage>& subset) {
32 static const size_t kCacheSize = 1000000; 32 static const size_t kCacheSize = 1000000;
33 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCache Size)); 33 SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize ));
34 34
35 SkIRect clip = SkIRect::MakeWH(100, 100); 35 SkIRect clip = SkIRect::MakeWH(100, 100);
36 SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), im age->subset()); 36 SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image- >subset());
37 SkImageFilter::Cache::Key key2(0, SkMatrix::I(), clip, subset->uniqueID(), s ubset->subset()); 37 SkImageFilterCacheKey key2(0, SkMatrix::I(), clip, subset->uniqueID(), subse t->subset());
38 38
39 SkIPoint offset = SkIPoint::Make(3, 4); 39 SkIPoint offset = SkIPoint::Make(3, 4);
40 cache->set(key1, image.get(), offset); 40 cache->set(key1, image.get(), offset);
41 41
42 SkIPoint foundOffset; 42 SkIPoint foundOffset;
43 43
44 SkSpecialImage* foundImage = cache->get(key1, &foundOffset); 44 SkSpecialImage* foundImage = cache->get(key1, &foundOffset);
45 REPORTER_ASSERT(reporter, foundImage); 45 REPORTER_ASSERT(reporter, foundImage);
46 REPORTER_ASSERT(reporter, offset == foundOffset); 46 REPORTER_ASSERT(reporter, offset == foundOffset);
47 47
48 REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); 48 REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset));
49 } 49 }
50 50
51 // If either id is different or the clip or the matrix are different the 51 // If either id is different or the clip or the matrix are different the
52 // cached image won't be found. Even if it is caching the same bitmap. 52 // cached image won't be found. Even if it is caching the same bitmap.
53 static void test_dont_find_if_diff_key(skiatest::Reporter* reporter, 53 static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
54 const sk_sp<SkSpecialImage>& image, 54 const sk_sp<SkSpecialImage>& image,
55 const sk_sp<SkSpecialImage>& subset) { 55 const sk_sp<SkSpecialImage>& subset) {
56 static const size_t kCacheSize = 1000000; 56 static const size_t kCacheSize = 1000000;
57 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCache Size)); 57 SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize ));
58 58
59 SkIRect clip1 = SkIRect::MakeWH(100, 100); 59 SkIRect clip1 = SkIRect::MakeWH(100, 100);
60 SkIRect clip2 = SkIRect::MakeWH(200, 200); 60 SkIRect clip2 = SkIRect::MakeWH(200, 200);
61 SkImageFilter::Cache::Key key0(0, SkMatrix::I(), clip1, image->uniqueID(), i mage->subset()); 61 SkImageFilterCacheKey key0(0, SkMatrix::I(), clip1, image->uniqueID(), image ->subset());
62 SkImageFilter::Cache::Key key1(1, SkMatrix::I(), clip1, image->uniqueID(), i mage->subset()); 62 SkImageFilterCacheKey key1(1, SkMatrix::I(), clip1, image->uniqueID(), image ->subset());
63 SkImageFilter::Cache::Key key2(0, SkMatrix::MakeTrans(5, 5), clip1, 63 SkImageFilterCacheKey key2(0, SkMatrix::MakeTrans(5, 5), clip1,
64 image->uniqueID(), image->subset()); 64 image->uniqueID(), image->subset());
65 SkImageFilter::Cache::Key key3(0, SkMatrix::I(), clip2, image->uniqueID(), i mage->subset()); 65 SkImageFilterCacheKey key3(0, SkMatrix::I(), clip2, image->uniqueID(), image ->subset());
66 SkImageFilter::Cache::Key key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset()); 66 SkImageFilterCacheKey key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subs et->subset());
67 67
68 SkIPoint offset = SkIPoint::Make(3, 4); 68 SkIPoint offset = SkIPoint::Make(3, 4);
69 cache->set(key0, image.get(), offset); 69 cache->set(key0, image.get(), offset);
70 70
71 SkIPoint foundOffset; 71 SkIPoint foundOffset;
72 REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); 72 REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset));
73 REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); 73 REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset));
74 REPORTER_ASSERT(reporter, !cache->get(key3, &foundOffset)); 74 REPORTER_ASSERT(reporter, !cache->get(key3, &foundOffset));
75 REPORTER_ASSERT(reporter, !cache->get(key4, &foundOffset)); 75 REPORTER_ASSERT(reporter, !cache->get(key4, &foundOffset));
76 } 76 }
77 77
78 // Test purging when the max cache size is exceeded 78 // Test purging when the max cache size is exceeded
79 static void test_internal_purge(skiatest::Reporter* reporter, const sk_sp<SkSpec ialImage>& image) { 79 static void test_internal_purge(skiatest::Reporter* reporter, const sk_sp<SkSpec ialImage>& image) {
80 SkASSERT(image->getSize()); 80 SkASSERT(image->getSize());
81 const size_t kCacheSize = image->getSize() + 10; 81 const size_t kCacheSize = image->getSize() + 10;
82 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCache Size)); 82 SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize ));
83 83
84 SkIRect clip = SkIRect::MakeWH(100, 100); 84 SkIRect clip = SkIRect::MakeWH(100, 100);
85 SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), im age->subset()); 85 SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image- >subset());
86 SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, image->uniqueID(), im age->subset()); 86 SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, image->uniqueID(), image- >subset());
87 87
88 SkIPoint offset = SkIPoint::Make(3, 4); 88 SkIPoint offset = SkIPoint::Make(3, 4);
89 cache->set(key1, image.get(), offset); 89 cache->set(key1, image.get(), offset);
90 90
91 SkIPoint foundOffset; 91 SkIPoint foundOffset;
92 92
93 REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset)); 93 REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset));
94 94
95 // This should knock the first one out of the cache 95 // This should knock the first one out of the cache
96 cache->set(key2, image.get(), offset); 96 cache->set(key2, image.get(), offset);
97 97
98 REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset)); 98 REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset));
99 REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); 99 REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset));
100 } 100 }
101 101
102 // Exercise the purgeByKeys and purge methods 102 // Exercise the purgeByKeys and purge methods
103 static void test_explicit_purging(skiatest::Reporter* reporter, 103 static void test_explicit_purging(skiatest::Reporter* reporter,
104 const sk_sp<SkSpecialImage>& image, 104 const sk_sp<SkSpecialImage>& image,
105 const sk_sp<SkSpecialImage>& subset) { 105 const sk_sp<SkSpecialImage>& subset) {
106 static const size_t kCacheSize = 1000000; 106 static const size_t kCacheSize = 1000000;
107 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCache Size)); 107 SkAutoTUnref<SkImageFilterCache> cache(SkImageFilterCache::Create(kCacheSize ));
108 108
109 SkIRect clip = SkIRect::MakeWH(100, 100); 109 SkIRect clip = SkIRect::MakeWH(100, 100);
110 SkImageFilter::Cache::Key key1(0, SkMatrix::I(), clip, image->uniqueID(), im age->subset()); 110 SkImageFilterCacheKey key1(0, SkMatrix::I(), clip, image->uniqueID(), image- >subset());
111 SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, subset->uniqueID(), i mage->subset()); 111 SkImageFilterCacheKey key2(1, SkMatrix::I(), clip, subset->uniqueID(), image ->subset());
112 112
113 SkIPoint offset = SkIPoint::Make(3, 4); 113 SkIPoint offset = SkIPoint::Make(3, 4);
114 cache->set(key1, image.get(), offset); 114 cache->set(key1, image.get(), offset);
115 cache->set(key2, image.get(), offset); 115 cache->set(key2, image.get(), offset);
116 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->count());) 116 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->count());)
117 117
118 SkIPoint foundOffset; 118 SkIPoint foundOffset;
119 119
120 REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset)); 120 REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset));
121 REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset)); 121 REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromGpu(subset, 229 sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromGpu(subset,
230 kNeedNewImageUni queID_SpecialImage, 230 kNeedNewImageUni queID_SpecialImage,
231 srcTexture)); 231 srcTexture));
232 232
233 test_find_existing(reporter, fullImg, subsetImg); 233 test_find_existing(reporter, fullImg, subsetImg);
234 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); 234 test_dont_find_if_diff_key(reporter, fullImg, subsetImg);
235 test_internal_purge(reporter, fullImg); 235 test_internal_purge(reporter, fullImg);
236 test_explicit_purging(reporter, fullImg, subsetImg); 236 test_explicit_purging(reporter, fullImg, subsetImg);
237 } 237 }
238 #endif 238 #endif
OLDNEW
« no previous file with comments | « src/svg/SkSVGDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698