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

Side by Side Diff: tests/ClipCacheTest.cpp

Issue 1377943003: Remove separate cache for clip mask textures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 2 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 | « tests/ClipBoundsTest.cpp ('k') | tests/ResourceCacheTest.cpp » ('j') | 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 2012 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 "Test.h"
9 // This is a GR test
10 #if SK_SUPPORT_GPU
11 #include "GrClipMaskManager.h"
12 #include "GrContextFactory.h"
13 #include "SkGpuDevice.h"
14
15 static const int X_SIZE = 12;
16 static const int Y_SIZE = 12;
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // note: this is unused
20 static GrTexture* create_texture(GrContext* context) {
21 unsigned char textureData[X_SIZE][Y_SIZE][4];
22
23 memset(textureData, 0, 4* X_SIZE * Y_SIZE);
24
25 GrSurfaceDesc desc;
26
27 // let Skia know we will be using this texture as a render target
28 desc.fFlags = kRenderTarget_GrSurfaceFlag;
29 desc.fConfig = kSkia8888_GrPixelConfig;
30 desc.fWidth = X_SIZE;
31 desc.fHeight = Y_SIZE;
32
33 // We are initializing the texture with zeros here
34 GrTexture* texture = context->textureProvider()->createTexture(desc, false, textureData, 0);
35 if (!texture) {
36 return nullptr;
37 }
38
39 return texture;
40 }
41
42 // Ensure that the 'getConservativeBounds' calls are returning bounds clamped
43 // to the render target
44 static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) {
45
46 static const int kXSize = 100;
47 static const int kYSize = 100;
48
49 GrSurfaceDesc desc;
50 desc.fFlags = kRenderTarget_GrSurfaceFlag;
51 desc.fConfig = kAlpha_8_GrPixelConfig;
52 desc.fWidth = kXSize;
53 desc.fHeight = kYSize;
54
55 GrTexture* texture = context->textureProvider()->createTexture(desc, false, nullptr, 0);
56 if (!texture) {
57 return;
58 }
59
60 SkAutoTUnref<GrTexture> au(texture);
61
62 SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
63 SkRect screen;
64
65 screen = SkRect::MakeWH(SkIntToScalar(kXSize),
66 SkIntToScalar(kYSize));
67
68 SkRect clipRect(screen);
69 clipRect.outset(10, 10);
70
71 // create a clip stack that will (trivially) reduce to a single rect that
72 // is larger than the screen
73 SkClipStack stack;
74 stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false);
75
76 bool isIntersectionOfRects = true;
77 SkRect devStackBounds;
78
79 stack.getConservativeBounds(0, 0, kXSize, kYSize,
80 &devStackBounds,
81 &isIntersectionOfRects);
82
83 // make sure that the SkClipStack is behaving itself
84 REPORTER_ASSERT(reporter, screen == devStackBounds);
85 REPORTER_ASSERT(reporter, isIntersectionOfRects);
86
87 // wrap the SkClipStack in a GrClip
88 GrClip clipData;
89 clipData.setClipStack(&stack);
90
91 SkIRect devGrClipBound;
92 clipData.getConservativeBounds(texture,
93 &devGrClipBound,
94 &isIntersectionOfRects);
95
96 // make sure that GrClip is behaving itself
97 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
98 REPORTER_ASSERT(reporter, isIntersectionOfRects);
99 }
100
101 ////////////////////////////////////////////////////////////////////////////////
102 // verify that the top state of the stack matches the passed in state
103 static void check_state(skiatest::Reporter* reporter,
104 const GrClipMaskCache& cache,
105 const SkClipStack& clip,
106 GrTexture* mask,
107 const SkIRect& bound) {
108 REPORTER_ASSERT(reporter, clip.getTopmostGenID() == cache.getLastClipGenID() );
109
110 REPORTER_ASSERT(reporter, mask == cache.getLastMask());
111
112 SkIRect cacheBound;
113 cache.getLastBound(&cacheBound);
114 REPORTER_ASSERT(reporter, bound == cacheBound);
115 }
116
117 static void check_empty_state(skiatest::Reporter* reporter,
118 const GrClipMaskCache& cache) {
119 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID == cache.getLastClipGen ID());
120 REPORTER_ASSERT(reporter, nullptr == cache.getLastMask());
121
122 SkIRect emptyBound;
123 emptyBound.setEmpty();
124
125 SkIRect cacheBound;
126 cache.getLastBound(&cacheBound);
127 REPORTER_ASSERT(reporter, emptyBound == cacheBound);
128 }
129
130 ////////////////////////////////////////////////////////////////////////////////
131 // basic test of the cache's base functionality:
132 // push, pop, set, canReuse & getters
133 static void test_cache(skiatest::Reporter* reporter, GrContext* context) {
134
135 if (false) { // avoid bit rot, suppress warning
136 create_texture(context);
137 }
138 GrClipMaskCache cache(context->resourceProvider());
139
140 // check initial state
141 check_empty_state(reporter, cache);
142
143 // set the current state
144 SkIRect bound1;
145 bound1.set(0, 0, 100, 100);
146
147 SkClipStack clip1(bound1);
148
149 GrSurfaceDesc desc;
150 desc.fFlags = kRenderTarget_GrSurfaceFlag;
151 desc.fWidth = X_SIZE;
152 desc.fHeight = Y_SIZE;
153 desc.fConfig = kSkia8888_GrPixelConfig;
154
155 cache.acquireMask(clip1.getTopmostGenID(), desc, bound1);
156
157 GrTexture* texture1 = cache.getLastMask();
158 REPORTER_ASSERT(reporter, texture1);
159 if (nullptr == texture1) {
160 return;
161 }
162
163 // check that the set took
164 check_state(reporter, cache, clip1, texture1, bound1);
165
166 // push the state
167 cache.push();
168
169 // verify that the pushed state is initially empty
170 check_empty_state(reporter, cache);
171
172 // modify the new state
173 SkIRect bound2;
174 bound2.set(-10, -10, 10, 10);
175
176 SkClipStack clip2(bound2);
177
178 cache.acquireMask(clip2.getTopmostGenID(), desc, bound2);
179
180 GrTexture* texture2 = cache.getLastMask();
181 REPORTER_ASSERT(reporter, texture2);
182 if (nullptr == texture2) {
183 return;
184 }
185
186 // check that the changes took
187 check_state(reporter, cache, clip2, texture2, bound2);
188
189 // check to make sure canReuse works
190 REPORTER_ASSERT(reporter, cache.canReuse(clip2.getTopmostGenID(), bound2));
191 REPORTER_ASSERT(reporter, !cache.canReuse(clip1.getTopmostGenID(), bound1));
192
193 // pop the state
194 cache.pop();
195
196 // verify that the old state is restored
197 check_state(reporter, cache, clip1, texture1, bound1);
198
199 // manually clear the state
200 cache.reset();
201
202 // verify it is now empty
203 check_empty_state(reporter, cache);
204
205 // pop again - so there is no state
206 cache.pop();
207
208 #if !defined(SK_DEBUG)
209 // verify that the getters don't crash
210 // only do in release since it generates asserts in debug
211 check_empty_state(reporter, cache);
212 #endif
213 }
214
215 DEF_GPUTEST(ClipCache, reporter, factory) {
216 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
217 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
218 if (!GrContextFactory::IsRenderingGLContext(glType)) {
219 continue;
220 }
221 GrContext* context = factory->get(glType);
222 if (nullptr == context) {
223 continue;
224 }
225
226 test_cache(reporter, context);
227 test_clip_bounds(reporter, context);
228 }
229 }
230
231 #endif
OLDNEW
« no previous file with comments | « tests/ClipBoundsTest.cpp ('k') | tests/ResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698