OLD | NEW |
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 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 19 matching lines...) Expand all Loading... |
30 *actualValue = pixel; | 30 *actualValue = pixel; |
31 *failX = x + rect.fLeft; | 31 *failX = x + rect.fLeft; |
32 *failY = y + rect.fTop; | 32 *failY = y + rect.fTop; |
33 return false; | 33 return false; |
34 } | 34 } |
35 } | 35 } |
36 } | 36 } |
37 return true; | 37 return true; |
38 } | 38 } |
39 | 39 |
40 static bool reset_dc(sk_sp<GrDrawContext>* dc, GrContext* context, int w, int h)
{ | 40 // We only really need the DC, but currently the DC doesn't own the RT so we als
o ref it, but that |
| 41 // could be dropped when DC is a proper owner of its RT. |
| 42 static bool reset_dc(sk_sp<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAl
ive, |
| 43 GrContext* context, int w, int h) { |
41 SkDEBUGCODE(uint32_t oldID = 0;) | 44 SkDEBUGCODE(uint32_t oldID = 0;) |
42 if (*dc) { | 45 if (*dc) { |
43 SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->getUniqueID();) | 46 SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->getUniqueID();) |
| 47 rtKeepAlive->reset(nullptr); |
44 dc->reset(nullptr); | 48 dc->reset(nullptr); |
45 } | 49 } |
46 context->freeGpuResources(); | 50 context->freeGpuResources(); |
47 | 51 |
48 *dc = context->newDrawContext(GrContext::kTight_BackingFit, w, h, kRGBA_8888
_GrPixelConfig); | 52 GrTextureDesc desc; |
| 53 desc.fWidth = w; |
| 54 desc.fHeight = h; |
| 55 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 56 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
49 | 57 |
50 SkASSERT((*dc)->accessRenderTarget()->getUniqueID() != oldID); | 58 rtKeepAlive->reset(context->textureProvider()->createTexture(desc, SkBudgete
d::kYes)); |
51 | 59 if (!(*rtKeepAlive)) { |
| 60 return false; |
| 61 } |
| 62 GrRenderTarget* rt = (*rtKeepAlive)->asRenderTarget(); |
| 63 SkASSERT(rt->getUniqueID() != oldID); |
| 64 *dc = context->drawContext(sk_ref_sp(rt)); |
52 return *dc != nullptr; | 65 return *dc != nullptr; |
53 } | 66 } |
54 | 67 |
55 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { | 68 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { |
56 GrContext* context = ctxInfo.fGrContext; | 69 GrContext* context = ctxInfo.fGrContext; |
57 static const int kW = 10; | 70 static const int kW = 10; |
58 static const int kH = 10; | 71 static const int kH = 10; |
59 | 72 |
60 SkIRect fullRect = SkIRect::MakeWH(kW, kH); | 73 SkIRect fullRect = SkIRect::MakeWH(kW, kH); |
61 sk_sp<GrDrawContext> drawContext; | 74 sk_sp<GrDrawContext> drawContext; |
| 75 SkAutoTUnref<GrSurface> rtKeepAlive; |
62 | 76 |
63 // A rectangle that is inset by one on all sides and the 1-pixel wide rectan
gles that surround | 77 // A rectangle that is inset by one on all sides and the 1-pixel wide rectan
gles that surround |
64 // it. | 78 // it. |
65 SkIRect mid1Rect = SkIRect::MakeXYWH(1, 1, kW-2, kH-2); | 79 SkIRect mid1Rect = SkIRect::MakeXYWH(1, 1, kW-2, kH-2); |
66 SkIRect outerLeftEdge = SkIRect::MakeXYWH(0, 0, 1, kH); | 80 SkIRect outerLeftEdge = SkIRect::MakeXYWH(0, 0, 1, kH); |
67 SkIRect outerTopEdge = SkIRect::MakeXYWH(0, 0, kW, 1); | 81 SkIRect outerTopEdge = SkIRect::MakeXYWH(0, 0, kW, 1); |
68 SkIRect outerRightEdge = SkIRect::MakeXYWH(kW-1, 0, 1, kH); | 82 SkIRect outerRightEdge = SkIRect::MakeXYWH(kW-1, 0, 1, kH); |
69 SkIRect outerBottomEdge = SkIRect::MakeXYWH(0, kH-1, kW, 1); | 83 SkIRect outerBottomEdge = SkIRect::MakeXYWH(0, kH-1, kW, 1); |
70 | 84 |
71 // A rectangle that is inset by two on all sides and the 1-pixel wide rectan
gles that surround | 85 // A rectangle that is inset by two on all sides and the 1-pixel wide rectan
gles that surround |
72 // it. | 86 // it. |
73 SkIRect mid2Rect = SkIRect::MakeXYWH(2, 2, kW-4, kH-4); | 87 SkIRect mid2Rect = SkIRect::MakeXYWH(2, 2, kW-4, kH-4); |
74 SkIRect innerLeftEdge = SkIRect::MakeXYWH(1, 1, 1, kH-2); | 88 SkIRect innerLeftEdge = SkIRect::MakeXYWH(1, 1, 1, kH-2); |
75 SkIRect innerTopEdge = SkIRect::MakeXYWH(1, 1, kW-2, 1); | 89 SkIRect innerTopEdge = SkIRect::MakeXYWH(1, 1, kW-2, 1); |
76 SkIRect innerRightEdge = SkIRect::MakeXYWH(kW-2, 1, 1, kH-2); | 90 SkIRect innerRightEdge = SkIRect::MakeXYWH(kW-2, 1, 1, kH-2); |
77 SkIRect innerBottomEdge = SkIRect::MakeXYWH(1, kH-2, kW-2, 1); | 91 SkIRect innerBottomEdge = SkIRect::MakeXYWH(1, kH-2, kW-2, 1); |
78 | 92 |
79 uint32_t actualValue; | 93 uint32_t actualValue; |
80 int failX, failY; | 94 int failX, failY; |
81 | 95 |
82 static const GrColor kColor1 = 0xABCDEF01; | 96 static const GrColor kColor1 = 0xABCDEF01; |
83 static const GrColor kColor2 = ~kColor1; | 97 static const GrColor kColor2 = ~kColor1; |
84 | 98 |
85 if (!reset_dc(&drawContext, context, kW, kH)) { | 99 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
86 ERRORF(reporter, "Could not create draw context."); | 100 ERRORF(reporter, "Could not create draw context."); |
87 return; | 101 return; |
88 } | 102 } |
89 // Check a full clear | 103 // Check a full clear |
90 drawContext->clear(&fullRect, kColor1, false); | 104 drawContext->clear(&fullRect, kColor1, false); |
91 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { | 105 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { |
92 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 106 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
93 failX, failY); | 107 failX, failY); |
94 } | 108 } |
95 | 109 |
96 if (!reset_dc(&drawContext, context, kW, kH)) { | 110 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
97 ERRORF(reporter, "Could not create draw context."); | 111 ERRORF(reporter, "Could not create draw context."); |
98 return; | 112 return; |
99 } | 113 } |
100 // Check two full clears, same color | 114 // Check two full clears, same color |
101 drawContext->clear(&fullRect, kColor1, false); | 115 drawContext->clear(&fullRect, kColor1, false); |
102 drawContext->clear(&fullRect, kColor1, false); | 116 drawContext->clear(&fullRect, kColor1, false); |
103 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { | 117 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { |
104 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 118 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
105 failX, failY); | 119 failX, failY); |
106 } | 120 } |
107 | 121 |
108 if (!reset_dc(&drawContext, context, kW, kH)) { | 122 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
109 ERRORF(reporter, "Could not create draw context."); | 123 ERRORF(reporter, "Could not create draw context."); |
110 return; | 124 return; |
111 } | 125 } |
112 // Check two full clears, different colors | 126 // Check two full clears, different colors |
113 drawContext->clear(&fullRect, kColor1, false); | 127 drawContext->clear(&fullRect, kColor1, false); |
114 drawContext->clear(&fullRect, kColor2, false); | 128 drawContext->clear(&fullRect, kColor2, false); |
115 if (!check_rect(drawContext.get(), fullRect, kColor2, &actualValue, &failX,
&failY)) { | 129 if (!check_rect(drawContext.get(), fullRect, kColor2, &actualValue, &failX,
&failY)) { |
116 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, | 130 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, |
117 failX, failY); | 131 failX, failY); |
118 } | 132 } |
119 | 133 |
120 if (!reset_dc(&drawContext, context, kW, kH)) { | 134 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
121 ERRORF(reporter, "Could not create draw context."); | 135 ERRORF(reporter, "Could not create draw context."); |
122 return; | 136 return; |
123 } | 137 } |
124 // Test a full clear followed by a same color inset clear | 138 // Test a full clear followed by a same color inset clear |
125 drawContext->clear(&fullRect, kColor1, false); | 139 drawContext->clear(&fullRect, kColor1, false); |
126 drawContext->clear(&mid1Rect, kColor1, false); | 140 drawContext->clear(&mid1Rect, kColor1, false); |
127 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { | 141 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { |
128 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 142 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
129 failX, failY); | 143 failX, failY); |
130 } | 144 } |
131 | 145 |
132 if (!reset_dc(&drawContext, context, kW, kH)) { | 146 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
133 ERRORF(reporter, "Could not create draw context."); | 147 ERRORF(reporter, "Could not create draw context."); |
134 return; | 148 return; |
135 } | 149 } |
136 // Test a inset clear followed by same color full clear | 150 // Test a inset clear followed by same color full clear |
137 drawContext->clear(&mid1Rect, kColor1, false); | 151 drawContext->clear(&mid1Rect, kColor1, false); |
138 drawContext->clear(&fullRect, kColor1, false); | 152 drawContext->clear(&fullRect, kColor1, false); |
139 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { | 153 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { |
140 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 154 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
141 failX, failY); | 155 failX, failY); |
142 } | 156 } |
143 | 157 |
144 if (!reset_dc(&drawContext, context, kW, kH)) { | 158 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
145 ERRORF(reporter, "Could not create draw context."); | 159 ERRORF(reporter, "Could not create draw context."); |
146 return; | 160 return; |
147 } | 161 } |
148 // Test a full clear followed by a different color inset clear | 162 // Test a full clear followed by a different color inset clear |
149 drawContext->clear(&fullRect, kColor1, false); | 163 drawContext->clear(&fullRect, kColor1, false); |
150 drawContext->clear(&mid1Rect, kColor2, false); | 164 drawContext->clear(&mid1Rect, kColor2, false); |
151 if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX,
&failY)) { | 165 if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX,
&failY)) { |
152 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, | 166 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, |
153 failX, failY); | 167 failX, failY); |
154 } | 168 } |
155 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || | 169 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || |
156 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || | 170 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || |
157 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || | 171 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || |
158 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { | 172 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { |
159 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 173 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
160 failX, failY); | 174 failX, failY); |
161 } | 175 } |
162 | 176 |
163 if (!reset_dc(&drawContext, context, kW, kH)) { | 177 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
164 ERRORF(reporter, "Could not create draw context."); | 178 ERRORF(reporter, "Could not create draw context."); |
165 return; | 179 return; |
166 } | 180 } |
167 // Test a inset clear followed by a different full clear | 181 // Test a inset clear followed by a different full clear |
168 drawContext->clear(&mid1Rect, kColor2, false); | 182 drawContext->clear(&mid1Rect, kColor2, false); |
169 drawContext->clear(&fullRect, kColor1, false); | 183 drawContext->clear(&fullRect, kColor1, false); |
170 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { | 184 if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX,
&failY)) { |
171 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 185 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
172 failX, failY); | 186 failX, failY); |
173 } | 187 } |
174 | 188 |
175 if (!reset_dc(&drawContext, context, kW, kH)) { | 189 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
176 ERRORF(reporter, "Could not create draw context."); | 190 ERRORF(reporter, "Could not create draw context."); |
177 return; | 191 return; |
178 } | 192 } |
179 // Check three nested clears from largest to smallest where outermost and in
nermost are same | 193 // Check three nested clears from largest to smallest where outermost and in
nermost are same |
180 // color. | 194 // color. |
181 drawContext->clear(&fullRect, kColor1, false); | 195 drawContext->clear(&fullRect, kColor1, false); |
182 drawContext->clear(&mid1Rect, kColor2, false); | 196 drawContext->clear(&mid1Rect, kColor2, false); |
183 drawContext->clear(&mid2Rect, kColor1, false); | 197 drawContext->clear(&mid2Rect, kColor1, false); |
184 if (!check_rect(drawContext.get(), mid2Rect, kColor1, &actualValue, &failX,
&failY)) { | 198 if (!check_rect(drawContext.get(), mid2Rect, kColor1, &actualValue, &failX,
&failY)) { |
185 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 199 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
186 failX, failY); | 200 failX, failY); |
187 } | 201 } |
188 if (!check_rect(drawContext.get(), innerLeftEdge, kColor2, &actualValue, &fa
ilX, &failY) || | 202 if (!check_rect(drawContext.get(), innerLeftEdge, kColor2, &actualValue, &fa
ilX, &failY) || |
189 !check_rect(drawContext.get(), innerTopEdge, kColor2, &actualValue, &fai
lX, &failY) || | 203 !check_rect(drawContext.get(), innerTopEdge, kColor2, &actualValue, &fai
lX, &failY) || |
190 !check_rect(drawContext.get(), innerRightEdge, kColor2, &actualValue, &f
ailX, &failY) || | 204 !check_rect(drawContext.get(), innerRightEdge, kColor2, &actualValue, &f
ailX, &failY) || |
191 !check_rect(drawContext.get(), innerBottomEdge, kColor2, &actualValue, &
failX, &failY)) { | 205 !check_rect(drawContext.get(), innerBottomEdge, kColor2, &actualValue, &
failX, &failY)) { |
192 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, | 206 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, |
193 failX, failY); | 207 failX, failY); |
194 } | 208 } |
195 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || | 209 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || |
196 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || | 210 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || |
197 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || | 211 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || |
198 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { | 212 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { |
199 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 213 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
200 failX, failY); | 214 failX, failY); |
201 } | 215 } |
202 | 216 |
203 if (!reset_dc(&drawContext, context, kW, kH)) { | 217 if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { |
204 ERRORF(reporter, "Could not create draw context."); | 218 ERRORF(reporter, "Could not create draw context."); |
205 return; | 219 return; |
206 } | 220 } |
207 // Swap the order of the second two clears in the above test. | 221 // Swap the order of the second two clears in the above test. |
208 drawContext->clear(&fullRect, kColor1, false); | 222 drawContext->clear(&fullRect, kColor1, false); |
209 drawContext->clear(&mid2Rect, kColor1, false); | 223 drawContext->clear(&mid2Rect, kColor1, false); |
210 drawContext->clear(&mid1Rect, kColor2, false); | 224 drawContext->clear(&mid1Rect, kColor2, false); |
211 if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX,
&failY)) { | 225 if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX,
&failY)) { |
212 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, | 226 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2,
actualValue, |
213 failX, failY); | 227 failX, failY); |
214 } | 228 } |
215 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || | 229 if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &fa
ilX, &failY) || |
216 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || | 230 !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &fai
lX, &failY) || |
217 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || | 231 !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &f
ailX, &failY) || |
218 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { | 232 !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &
failX, &failY)) { |
219 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, | 233 ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1,
actualValue, |
220 failX, failY); | 234 failX, failY); |
221 } | 235 } |
222 } | 236 } |
223 #endif | 237 #endif |
OLD | NEW |