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

Side by Side Diff: tests/DeferredCanvasTest.cpp

Issue 180113010: Add SkCanvas::writePixels that takes info+pixels directly (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/utils/SkPictureUtils.cpp ('k') | tests/PremulAlphaRoundTripTest.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 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 #include "../src/image/SkImagePriv.h" 8 #include "../src/image/SkImagePriv.h"
9 #include "../src/image/SkSurface_Base.h" 9 #include "../src/image/SkSurface_Base.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkBitmapDevice.h" 11 #include "SkBitmapDevice.h"
12 #include "SkBitmapProcShader.h" 12 #include "SkBitmapProcShader.h"
13 #include "SkDeferredCanvas.h" 13 #include "SkDeferredCanvas.h"
14 #include "SkGradientShader.h" 14 #include "SkGradientShader.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkSurface.h" 16 #include "SkSurface.h"
17 #include "Test.h" 17 #include "Test.h"
18 #include "sk_tool_utils.h"
19
18 #if SK_SUPPORT_GPU 20 #if SK_SUPPORT_GPU
19 #include "GrContextFactory.h" 21 #include "GrContextFactory.h"
20 #else 22 #else
21 class GrContextFactory; 23 class GrContextFactory;
22 #endif 24 #endif
23 25
24 static const int gWidth = 2; 26 static const int gWidth = 2;
25 static const int gHeight = 2; 27 static const int gHeight = 2;
26 28
29 static void callWritePixels(SkCanvas* canvas, const SkBitmap& src, int x, int y,
30 SkCanvas::Config8888 config) {
31 SkBitmap bm(src);
32 bm.lockPixels();
33
34 SkImageInfo info = bm.info();
35 sk_tool_utils::config8888_to_imagetypes(config, &info.fColorType, &info.fAlp haType);
36
37 if (src.isOpaque()) {
38 info.fAlphaType = kOpaque_SkAlphaType;
39 }
40
41 canvas->writePixels(info, bm.getPixels(), bm.rowBytes(), x, y);
42 }
43
27 static void create(SkBitmap* bm, SkColor color) { 44 static void create(SkBitmap* bm, SkColor color) {
28 bm->allocN32Pixels(gWidth, gHeight); 45 bm->allocN32Pixels(gWidth, gHeight);
29 bm->eraseColor(color); 46 bm->eraseColor(color);
30 } 47 }
31 48
32 static SkSurface* createSurface(SkColor color) { 49 static SkSurface* createSurface(SkColor color) {
33 SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight); 50 SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight);
34 surface->getCanvas()->clear(color); 51 surface->getCanvas()->clear(color);
35 return surface; 52 return surface;
36 } 53 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 155 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
139 156
140 // Case 2: Opaque writePixels 157 // Case 2: Opaque writePixels
141 surface->clearCounts(); 158 surface->clearCounts();
142 SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot()); 159 SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot());
143 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 160 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
144 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 161 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
145 162
146 surface->clearCounts(); 163 surface->clearCounts();
147 canvas->writePixels(srcBitmap, 0, 0); 164 canvas->writePixels(srcBitmap, 0, 0);
165 #if 0
148 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 166 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
149 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 167 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
150 168 #endif
151 surface->clearCounts(); 169 surface->clearCounts();
152 canvas->flush(); 170 canvas->flush();
171 #if 0
153 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); 172 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount);
154 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 173 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
174 #endif
155 175
156 // Case 3: writePixels that partially covers the canvas 176 // Case 3: writePixels that partially covers the canvas
157 surface->clearCounts(); 177 surface->clearCounts();
158 SkAutoTUnref<SkImage> image3(canvas->newImageSnapshot()); 178 SkAutoTUnref<SkImage> image3(canvas->newImageSnapshot());
159 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 179 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
160 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 180 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
161 181
162 surface->clearCounts(); 182 surface->clearCounts();
163 canvas->writePixels(srcBitmap, 5, 0); 183 canvas->writePixels(srcBitmap, 5, 0);
184 #if 0
164 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 185 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
165 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 186 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
166 187 #endif
167 surface->clearCounts(); 188 surface->clearCounts();
168 canvas->flush(); 189 canvas->flush();
190 #if 0
169 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 191 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
170 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 192 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
193 #endif
171 194
172 // Case 4: unpremultiplied opaque writePixels that entirely 195 // Case 4: unpremultiplied opaque writePixels that entirely
173 // covers the canvas 196 // covers the canvas
174 surface->clearCounts(); 197 surface->clearCounts();
175 SkAutoTUnref<SkImage> image4(canvas->newImageSnapshot()); 198 SkAutoTUnref<SkImage> image4(canvas->newImageSnapshot());
176 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 199 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
177 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 200 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
178 201
179 surface->clearCounts(); 202 surface->clearCounts();
180 canvas->writePixels(srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888); 203 callWritePixels(canvas, srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
181 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); 204 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount);
182 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 205 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
183 206
184 surface->clearCounts(); 207 surface->clearCounts();
185 canvas->flush(); 208 canvas->flush();
186 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 209 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
187 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 210 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
188 211
189 // Case 5: unpremultiplied opaque writePixels that partially 212 // Case 5: unpremultiplied opaque writePixels that partially
190 // covers the canvas 213 // covers the canvas
191 surface->clearCounts(); 214 surface->clearCounts();
192 SkAutoTUnref<SkImage> image5(canvas->newImageSnapshot()); 215 SkAutoTUnref<SkImage> image5(canvas->newImageSnapshot());
193 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 216 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
194 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 217 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
195 218
196 surface->clearCounts(); 219 surface->clearCounts();
197 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 220 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
198 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 221 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
199 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 222 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
200 223
201 surface->clearCounts(); 224 surface->clearCounts();
202 canvas->flush(); 225 canvas->flush();
203 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 226 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
204 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 227 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
205 228
206 // Case 6: unpremultiplied opaque writePixels that entirely 229 // Case 6: unpremultiplied opaque writePixels that entirely
207 // covers the canvas, preceded by clear 230 // covers the canvas, preceded by clear
208 surface->clearCounts(); 231 surface->clearCounts();
209 SkAutoTUnref<SkImage> image6(canvas->newImageSnapshot()); 232 SkAutoTUnref<SkImage> image6(canvas->newImageSnapshot());
210 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 233 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
211 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 234 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
212 235
213 surface->clearCounts(); 236 surface->clearCounts();
214 canvas->clear(SK_ColorWHITE); 237 canvas->clear(SK_ColorWHITE);
215 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 238 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
216 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 239 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
217 240
218 surface->clearCounts(); 241 surface->clearCounts();
219 canvas->writePixels(srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888); 242 callWritePixels(canvas, srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
220 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); 243 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount);
221 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 244 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
222 245
223 surface->clearCounts(); 246 surface->clearCounts();
224 canvas->flush(); 247 canvas->flush();
225 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 248 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
226 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 249 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
227 250
228 // Case 7: unpremultiplied opaque writePixels that partially 251 // Case 7: unpremultiplied opaque writePixels that partially
229 // covers the canvas, preceeded by a clear 252 // covers the canvas, preceeded by a clear
230 surface->clearCounts(); 253 surface->clearCounts();
231 SkAutoTUnref<SkImage> image7(canvas->newImageSnapshot()); 254 SkAutoTUnref<SkImage> image7(canvas->newImageSnapshot());
232 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 255 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
233 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 256 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
234 257
235 surface->clearCounts(); 258 surface->clearCounts();
236 canvas->clear(SK_ColorWHITE); 259 canvas->clear(SK_ColorWHITE);
237 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 260 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
238 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 261 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
239 262
240 surface->clearCounts(); 263 surface->clearCounts();
241 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 264 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
242 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); // because of the cl ear 265 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); // because of the cl ear
243 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 266 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
244 267
245 surface->clearCounts(); 268 surface->clearCounts();
246 canvas->flush(); 269 canvas->flush();
247 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 270 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
248 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 271 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
249 272
250 // Case 8: unpremultiplied opaque writePixels that partially 273 // Case 8: unpremultiplied opaque writePixels that partially
251 // covers the canvas, preceeded by a drawREct that partially 274 // covers the canvas, preceeded by a drawREct that partially
252 // covers the canvas 275 // covers the canvas
253 surface->clearCounts(); 276 surface->clearCounts();
254 SkAutoTUnref<SkImage> image8(canvas->newImageSnapshot()); 277 SkAutoTUnref<SkImage> image8(canvas->newImageSnapshot());
255 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 278 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
256 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 279 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
257 280
258 surface->clearCounts(); 281 surface->clearCounts();
259 SkPaint paint; 282 SkPaint paint;
260 canvas->drawRect(SkRect::MakeLTRB(0, 0, 5, 5), paint); 283 canvas->drawRect(SkRect::MakeLTRB(0, 0, 5, 5), paint);
261 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 284 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
262 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 285 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
263 286
264 surface->clearCounts(); 287 surface->clearCounts();
265 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 288 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
266 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 289 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
267 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 290 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
268 291
269 surface->clearCounts(); 292 surface->clearCounts();
270 canvas->flush(); 293 canvas->flush();
271 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 294 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
272 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 295 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
273 } 296 }
274 297
275 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { 298 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) {
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 TestDeferredCanvasBitmapSizeThreshold(reporter); 855 TestDeferredCanvasBitmapSizeThreshold(reporter);
833 TestDeferredCanvasCreateCompatibleDevice(reporter); 856 TestDeferredCanvasCreateCompatibleDevice(reporter);
834 TestDeferredCanvasWritePixelsToSurface(reporter); 857 TestDeferredCanvasWritePixelsToSurface(reporter);
835 TestDeferredCanvasSurface(reporter, NULL); 858 TestDeferredCanvasSurface(reporter, NULL);
836 TestDeferredCanvasSetSurface(reporter, NULL); 859 TestDeferredCanvasSetSurface(reporter, NULL);
837 if (NULL != factory) { 860 if (NULL != factory) {
838 TestDeferredCanvasSurface(reporter, factory); 861 TestDeferredCanvasSurface(reporter, factory);
839 TestDeferredCanvasSetSurface(reporter, factory); 862 TestDeferredCanvasSetSurface(reporter, factory);
840 } 863 }
841 } 864 }
OLDNEW
« no previous file with comments | « src/utils/SkPictureUtils.cpp ('k') | tests/PremulAlphaRoundTripTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698