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