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

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
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 SkImageInfo info = src.info();
32 sk_tool_utils::config8888_to_imagetypes(config, &info.fColorType, &info.fAlp haType);
33
34 SkBitmap bm(src);
35 bm.lockPixels();
36 canvas->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y);
37 }
38
27 static void create(SkBitmap* bm, SkColor color) { 39 static void create(SkBitmap* bm, SkColor color) {
28 bm->allocN32Pixels(gWidth, gHeight); 40 bm->allocN32Pixels(gWidth, gHeight);
29 bm->eraseColor(color); 41 bm->eraseColor(color);
30 } 42 }
31 43
32 static SkSurface* createSurface(SkColor color) { 44 static SkSurface* createSurface(SkColor color) {
33 SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight); 45 SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight);
34 surface->getCanvas()->clear(color); 46 surface->getCanvas()->clear(color);
35 return surface; 47 return surface;
36 } 48 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 182 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
171 183
172 // Case 4: unpremultiplied opaque writePixels that entirely 184 // Case 4: unpremultiplied opaque writePixels that entirely
173 // covers the canvas 185 // covers the canvas
174 surface->clearCounts(); 186 surface->clearCounts();
175 SkAutoTUnref<SkImage> image4(canvas->newImageSnapshot()); 187 SkAutoTUnref<SkImage> image4(canvas->newImageSnapshot());
176 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 188 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
177 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 189 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
178 190
179 surface->clearCounts(); 191 surface->clearCounts();
180 canvas->writePixels(srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888); 192 callWritePixels(canvas, srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
181 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); 193 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount);
182 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 194 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
183 195
184 surface->clearCounts(); 196 surface->clearCounts();
185 canvas->flush(); 197 canvas->flush();
186 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 198 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
187 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 199 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
188 200
189 // Case 5: unpremultiplied opaque writePixels that partially 201 // Case 5: unpremultiplied opaque writePixels that partially
190 // covers the canvas 202 // covers the canvas
191 surface->clearCounts(); 203 surface->clearCounts();
192 SkAutoTUnref<SkImage> image5(canvas->newImageSnapshot()); 204 SkAutoTUnref<SkImage> image5(canvas->newImageSnapshot());
193 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 205 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
194 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 206 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
195 207
196 surface->clearCounts(); 208 surface->clearCounts();
197 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 209 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
198 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 210 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
199 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 211 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
200 212
201 surface->clearCounts(); 213 surface->clearCounts();
202 canvas->flush(); 214 canvas->flush();
203 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 215 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
204 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 216 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
205 217
206 // Case 6: unpremultiplied opaque writePixels that entirely 218 // Case 6: unpremultiplied opaque writePixels that entirely
207 // covers the canvas, preceded by clear 219 // covers the canvas, preceded by clear
208 surface->clearCounts(); 220 surface->clearCounts();
209 SkAutoTUnref<SkImage> image6(canvas->newImageSnapshot()); 221 SkAutoTUnref<SkImage> image6(canvas->newImageSnapshot());
210 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 222 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
211 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 223 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
212 224
213 surface->clearCounts(); 225 surface->clearCounts();
214 canvas->clear(SK_ColorWHITE); 226 canvas->clear(SK_ColorWHITE);
215 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 227 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
216 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 228 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
217 229
218 surface->clearCounts(); 230 surface->clearCounts();
219 canvas->writePixels(srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888); 231 callWritePixels(canvas, srcBitmap, 0, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
220 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); 232 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount);
221 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 233 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
222 234
223 surface->clearCounts(); 235 surface->clearCounts();
224 canvas->flush(); 236 canvas->flush();
225 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 237 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
226 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 238 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
227 239
228 // Case 7: unpremultiplied opaque writePixels that partially 240 // Case 7: unpremultiplied opaque writePixels that partially
229 // covers the canvas, preceeded by a clear 241 // covers the canvas, preceeded by a clear
230 surface->clearCounts(); 242 surface->clearCounts();
231 SkAutoTUnref<SkImage> image7(canvas->newImageSnapshot()); 243 SkAutoTUnref<SkImage> image7(canvas->newImageSnapshot());
232 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 244 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
233 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 245 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
234 246
235 surface->clearCounts(); 247 surface->clearCounts();
236 canvas->clear(SK_ColorWHITE); 248 canvas->clear(SK_ColorWHITE);
237 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 249 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
238 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 250 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
239 251
240 surface->clearCounts(); 252 surface->clearCounts();
241 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 253 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
242 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); // because of the cl ear 254 REPORTER_ASSERT(reporter, 1 == surface->fDiscardCount); // because of the cl ear
243 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 255 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
244 256
245 surface->clearCounts(); 257 surface->clearCounts();
246 canvas->flush(); 258 canvas->flush();
247 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 259 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
248 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 260 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
249 261
250 // Case 8: unpremultiplied opaque writePixels that partially 262 // Case 8: unpremultiplied opaque writePixels that partially
251 // covers the canvas, preceeded by a drawREct that partially 263 // covers the canvas, preceeded by a drawREct that partially
252 // covers the canvas 264 // covers the canvas
253 surface->clearCounts(); 265 surface->clearCounts();
254 SkAutoTUnref<SkImage> image8(canvas->newImageSnapshot()); 266 SkAutoTUnref<SkImage> image8(canvas->newImageSnapshot());
255 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 267 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
256 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 268 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
257 269
258 surface->clearCounts(); 270 surface->clearCounts();
259 SkPaint paint; 271 SkPaint paint;
260 canvas->drawRect(SkRect::MakeLTRB(0, 0, 5, 5), paint); 272 canvas->drawRect(SkRect::MakeLTRB(0, 0, 5, 5), paint);
261 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 273 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
262 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 274 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
263 275
264 surface->clearCounts(); 276 surface->clearCounts();
265 canvas->writePixels(srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888); 277 callWritePixels(canvas, srcBitmap, 5, 0, SkCanvas::kRGBA_Unpremul_Config8888 );
266 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 278 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
267 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); 279 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount);
268 280
269 surface->clearCounts(); 281 surface->clearCounts();
270 canvas->flush(); 282 canvas->flush();
271 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); 283 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount);
272 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); 284 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount);
273 } 285 }
274 286
275 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { 287 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) {
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 TestDeferredCanvasBitmapSizeThreshold(reporter); 844 TestDeferredCanvasBitmapSizeThreshold(reporter);
833 TestDeferredCanvasCreateCompatibleDevice(reporter); 845 TestDeferredCanvasCreateCompatibleDevice(reporter);
834 TestDeferredCanvasWritePixelsToSurface(reporter); 846 TestDeferredCanvasWritePixelsToSurface(reporter);
835 TestDeferredCanvasSurface(reporter, NULL); 847 TestDeferredCanvasSurface(reporter, NULL);
836 TestDeferredCanvasSetSurface(reporter, NULL); 848 TestDeferredCanvasSetSurface(reporter, NULL);
837 if (NULL != factory) { 849 if (NULL != factory) {
838 TestDeferredCanvasSurface(reporter, factory); 850 TestDeferredCanvasSurface(reporter, factory);
839 TestDeferredCanvasSetSurface(reporter, factory); 851 TestDeferredCanvasSetSurface(reporter, factory);
840 } 852 }
841 } 853 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698