OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 8 |
9 #include "Test.h" | 9 #include "Test.h" |
10 // This is a GR test | 10 // This is a GR test |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 REPORTER_ASSERT(reporter, isIntersectionOfRects); | 99 REPORTER_ASSERT(reporter, isIntersectionOfRects); |
100 } | 100 } |
101 | 101 |
102 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
103 // verify that the top state of the stack matches the passed in state | 103 // verify that the top state of the stack matches the passed in state |
104 static void check_state(skiatest::Reporter* reporter, | 104 static void check_state(skiatest::Reporter* reporter, |
105 const GrClipMaskCache& cache, | 105 const GrClipMaskCache& cache, |
106 const SkClipStack& clip, | 106 const SkClipStack& clip, |
107 GrTexture* mask, | 107 GrTexture* mask, |
108 const SkIRect& bound) { | 108 const SkIRect& bound) { |
| 109 SkClipStack cacheClip; |
109 REPORTER_ASSERT(reporter, clip.getTopmostGenID() == cache.getLastClipGenID()
); | 110 REPORTER_ASSERT(reporter, clip.getTopmostGenID() == cache.getLastClipGenID()
); |
110 | 111 |
111 REPORTER_ASSERT(reporter, mask == cache.getLastMask()); | 112 REPORTER_ASSERT(reporter, mask == cache.getLastMask()); |
112 | 113 |
113 SkIRect cacheBound; | 114 SkIRect cacheBound; |
114 cache.getLastBound(&cacheBound); | 115 cache.getLastBound(&cacheBound); |
115 REPORTER_ASSERT(reporter, bound == cacheBound); | 116 REPORTER_ASSERT(reporter, bound == cacheBound); |
116 } | 117 } |
117 | 118 |
118 static void check_empty_state(skiatest::Reporter* reporter, | |
119 const GrClipMaskCache& cache) { | |
120 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID == cache.getLastClipGen
ID()); | |
121 REPORTER_ASSERT(reporter, NULL == cache.getLastMask()); | |
122 | |
123 SkIRect emptyBound; | |
124 emptyBound.setEmpty(); | |
125 | |
126 SkIRect cacheBound; | |
127 cache.getLastBound(&cacheBound); | |
128 REPORTER_ASSERT(reporter, emptyBound == cacheBound); | |
129 } | |
130 | |
131 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
132 // basic test of the cache's base functionality: | 120 // basic test of the cache's base functionality: |
133 // push, pop, set, canReuse & getters | 121 // push, pop, set, canReuse & getters |
134 static void test_cache(skiatest::Reporter* reporter, GrContext* context) { | 122 static void test_cache(skiatest::Reporter* reporter, GrContext* context) { |
135 | 123 |
136 if (false) { // avoid bit rot, suppress warning | 124 if (false) { // avoid bit rot, suppress warning |
137 createTexture(context); | 125 createTexture(context); |
138 } | 126 } |
139 GrClipMaskCache cache; | 127 GrClipMaskCache cache; |
140 | 128 |
141 cache.setContext(context); | 129 cache.setContext(context); |
142 | 130 |
| 131 SkClipStack emptyClip; |
| 132 emptyClip.reset(); |
| 133 |
| 134 SkIRect emptyBound; |
| 135 emptyBound.setEmpty(); |
| 136 |
143 // check initial state | 137 // check initial state |
144 check_empty_state(reporter, cache); | 138 check_state(reporter, cache, emptyClip, NULL, emptyBound); |
145 | 139 |
146 // set the current state | 140 // set the current state |
147 SkIRect bound1; | 141 SkIRect bound1; |
148 bound1.set(0, 0, 100, 100); | 142 bound1.set(0, 0, 100, 100); |
149 | 143 |
150 SkClipStack clip1(bound1); | 144 SkClipStack clip1(bound1); |
151 | 145 |
152 GrTextureDesc desc; | 146 GrTextureDesc desc; |
153 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 147 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
154 desc.fWidth = X_SIZE; | 148 desc.fWidth = X_SIZE; |
155 desc.fHeight = Y_SIZE; | 149 desc.fHeight = Y_SIZE; |
156 desc.fConfig = kSkia8888_GrPixelConfig; | 150 desc.fConfig = kSkia8888_GrPixelConfig; |
157 | 151 |
158 cache.acquireMask(clip1.getTopmostGenID(), desc, bound1); | 152 cache.acquireMask(clip1.getTopmostGenID(), desc, bound1); |
159 | 153 |
160 GrTexture* texture1 = cache.getLastMask(); | 154 GrTexture* texture1 = cache.getLastMask(); |
161 REPORTER_ASSERT(reporter, texture1); | 155 REPORTER_ASSERT(reporter, texture1); |
162 if (NULL == texture1) { | 156 if (NULL == texture1) { |
163 return; | 157 return; |
164 } | 158 } |
165 | 159 |
166 // check that the set took | 160 // check that the set took |
167 check_state(reporter, cache, clip1, texture1, bound1); | 161 check_state(reporter, cache, clip1, texture1, bound1); |
168 REPORTER_ASSERT(reporter, texture1->getRefCnt()); | 162 REPORTER_ASSERT(reporter, texture1->getRefCnt()); |
169 | 163 |
170 // push the state | 164 // push the state |
171 cache.push(); | 165 cache.push(); |
172 | 166 |
173 // verify that the pushed state is initially empty | 167 // verify that the pushed state is initially empty |
174 check_empty_state(reporter, cache); | 168 check_state(reporter, cache, emptyClip, NULL, emptyBound); |
175 REPORTER_ASSERT(reporter, texture1->getRefCnt()); | 169 REPORTER_ASSERT(reporter, texture1->getRefCnt()); |
176 | 170 |
177 // modify the new state | 171 // modify the new state |
178 SkIRect bound2; | 172 SkIRect bound2; |
179 bound2.set(-10, -10, 10, 10); | 173 bound2.set(-10, -10, 10, 10); |
180 | 174 |
181 SkClipStack clip2(bound2); | 175 SkClipStack clip2(bound2); |
182 | 176 |
183 cache.acquireMask(clip2.getTopmostGenID(), desc, bound2); | 177 cache.acquireMask(clip2.getTopmostGenID(), desc, bound2); |
184 | 178 |
(...skipping 16 matching lines...) Expand all Loading... |
201 cache.pop(); | 195 cache.pop(); |
202 | 196 |
203 // verify that the old state is restored | 197 // verify that the old state is restored |
204 check_state(reporter, cache, clip1, texture1, bound1); | 198 check_state(reporter, cache, clip1, texture1, bound1); |
205 REPORTER_ASSERT(reporter, texture1->getRefCnt()); | 199 REPORTER_ASSERT(reporter, texture1->getRefCnt()); |
206 | 200 |
207 // manually clear the state | 201 // manually clear the state |
208 cache.reset(); | 202 cache.reset(); |
209 | 203 |
210 // verify it is now empty | 204 // verify it is now empty |
211 check_empty_state(reporter, cache); | 205 check_state(reporter, cache, emptyClip, NULL, emptyBound); |
212 | 206 |
213 // pop again - so there is no state | 207 // pop again - so there is no state |
214 cache.pop(); | 208 cache.pop(); |
215 | 209 |
216 #if !defined(SK_DEBUG) | 210 #if !defined(SK_DEBUG) |
217 // verify that the getters don't crash | 211 // verify that the getters don't crash |
218 // only do in release since it generates asserts in debug | 212 // only do in release since it generates asserts in debug |
219 check_empty_state(reporter, cache); | 213 check_state(reporter, cache, emptyClip, NULL, emptyBound); |
220 #endif | 214 #endif |
221 } | 215 } |
222 | 216 |
223 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
224 static void TestClipCache(skiatest::Reporter* reporter, GrContextFactory* factor
y) { | 218 static void TestClipCache(skiatest::Reporter* reporter, GrContextFactory* factor
y) { |
225 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 219 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
226 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 220 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
227 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 221 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
228 continue; | 222 continue; |
229 } | 223 } |
230 GrContext* context = factory->get(glType); | 224 GrContext* context = factory->get(glType); |
231 if (NULL == context) { | 225 if (NULL == context) { |
232 continue; | 226 continue; |
233 } | 227 } |
234 | 228 |
235 test_cache(reporter, context); | 229 test_cache(reporter, context); |
236 test_clip_bounds(reporter, context); | 230 test_clip_bounds(reporter, context); |
237 } | 231 } |
238 } | 232 } |
239 | 233 |
240 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
241 #include "TestClassDef.h" | 235 #include "TestClassDef.h" |
242 DEFINE_GPUTESTCLASS("ClipCache", ClipCacheTestClass, TestClipCache) | 236 DEFINE_GPUTESTCLASS("ClipCache", ClipCacheTestClass, TestClipCache) |
243 | 237 |
244 #endif | 238 #endif |
OLD | NEW |