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

Side by Side Diff: tests/ClearTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698