OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkMathPriv.h" | 11 #include "SkMathPriv.h" |
12 #include "SkRegion.h" | 12 #include "SkRegion.h" |
| 13 #include "SkSurface.h" |
13 #include "Test.h" | 14 #include "Test.h" |
14 #include "sk_tool_utils.h" | 15 #include "sk_tool_utils.h" |
15 | 16 |
16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
17 #include "GrContextFactory.h" | 18 #include "GrContextFactory.h" |
18 #include "SkGpuDevice.h" | 19 #include "SkGpuDevice.h" |
19 #else | 20 #else |
20 class GrContext; | 21 class GrContext; |
21 class GrContextFactory; | 22 class GrContextFactory; |
22 #endif | 23 #endif |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 345 } |
345 SkAutoLockPixels alp(*bm); | 346 SkAutoLockPixels alp(*bm); |
346 for (int y = 0; y < h; ++y) { | 347 for (int y = 0; y < h; ++y) { |
347 for (int x = 0; x < w; ++x) { | 348 for (int x = 0; x < w; ++x) { |
348 *bm->getAddr32(x, y) = getBitmapColor(x, y, w, ct, at); | 349 *bm->getAddr32(x, y) = getBitmapColor(x, y, w, ct, at); |
349 } | 350 } |
350 } | 351 } |
351 return true; | 352 return true; |
352 } | 353 } |
353 | 354 |
| 355 static void call_writepixels(SkCanvas* canvas) { |
| 356 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 357 SkPMColor pixel = 0; |
| 358 canvas->writePixels(info, &pixel, sizeof(SkPMColor), 0, 0); |
| 359 } |
| 360 |
| 361 static void test_surface_genid(skiatest::Reporter* reporter) { |
| 362 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 363 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 364 uint32_t genID1 = surface->generationID(); |
| 365 call_writepixels(surface->getCanvas()); |
| 366 uint32_t genID2 = surface->generationID(); |
| 367 REPORTER_ASSERT(reporter, genID1 != genID2); |
| 368 } |
| 369 |
354 DEF_GPUTEST(WritePixels, reporter, factory) { | 370 DEF_GPUTEST(WritePixels, reporter, factory) { |
| 371 test_surface_genid(reporter); |
| 372 |
355 SkCanvas canvas; | 373 SkCanvas canvas; |
356 | 374 |
357 const SkIRect testRects[] = { | 375 const SkIRect testRects[] = { |
358 // entire thing | 376 // entire thing |
359 DEV_RECT, | 377 DEV_RECT, |
360 // larger on all sides | 378 // larger on all sides |
361 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10), | 379 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10), |
362 // fully contained | 380 // fully contained |
363 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4), | 381 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4), |
364 // outside top left | 382 // outside top left |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, | 480 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.f
Top, |
463 bmp.width(), bmp.h
eight()); | 481 bmp.width(), bmp.h
eight()); |
464 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; | 482 bool intersects = SkIRect::Intersects(canvasRect, writeR
ect) ; |
465 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); | 483 REPORTER_ASSERT(reporter, intersects == (idBefore != idA
fter)); |
466 } | 484 } |
467 } | 485 } |
468 } | 486 } |
469 } | 487 } |
470 } | 488 } |
471 } | 489 } |
OLD | NEW |