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

Side by Side Diff: tests/ClearTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698