Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkDevice.h" | |
| 10 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
| 11 #include "SkRRect.h" | 12 #include "SkRRect.h" |
| 12 #include "SkSurface.h" | 13 #include "SkSurface.h" |
| 13 #include "SkUtils.h" | 14 #include "SkUtils.h" |
| 14 #include "Test.h" | 15 #include "Test.h" |
| 15 | 16 |
| 16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 17 #include "GrContextFactory.h" | 18 #include "GrContextFactory.h" |
| 18 #else | 19 #else |
| 19 class GrContextFactory; | 20 class GrContextFactory; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 REPORTER_ASSERT(reporter, addr2 == addr); | 344 REPORTER_ASSERT(reporter, addr2 == addr); |
| 344 REPORTER_ASSERT(reporter, info2 == info); | 345 REPORTER_ASSERT(reporter, info2 == info); |
| 345 REPORTER_ASSERT(reporter, rb2 == rowBytes); | 346 REPORTER_ASSERT(reporter, rb2 == rowBytes); |
| 346 } else { | 347 } else { |
| 347 REPORTER_ASSERT(reporter, NULL == addr2); | 348 REPORTER_ASSERT(reporter, NULL == addr2); |
| 348 } | 349 } |
| 349 } | 350 } |
| 350 } | 351 } |
| 351 } | 352 } |
| 352 | 353 |
| 354 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump | |
| 355 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are | |
| 356 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this | |
| 357 // test. | |
| 358 static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa ctory) { | |
| 359 static const struct { | |
| 360 SurfaceType fType; | |
|
robertphillips
2015/06/09 19:02:44
fPeekShouldSucceed doesn't seem to be used ?
| |
| 361 bool fPeekShouldSucceed; | |
| 362 } gRec[] = { | |
| 363 { kRaster_SurfaceType, true }, | |
| 364 { kRasterDirect_SurfaceType, true }, | |
| 365 #if SK_SUPPORT_GPU | |
| 366 { kGpu_SurfaceType, false }, | |
| 367 { kGpuScratch_SurfaceType, false }, | |
| 368 #endif | |
| 369 }; | |
| 370 | |
| 371 int cnt; | |
| 372 #if SK_SUPPORT_GPU | |
| 373 cnt = GrContextFactory::kGLContextTypeCnt; | |
| 374 #else | |
| 375 cnt = 1; | |
| 376 #endif | |
| 377 | |
| 378 for (int i= 0; i < cnt; ++i) { | |
| 379 GrContext* context = NULL; | |
| 380 #if SK_SUPPORT_GPU | |
| 381 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; | |
| 382 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | |
| 383 continue; | |
| 384 } | |
| 385 context = factory->get(glCtxType); | |
| 386 | |
| 387 if (NULL == context) { | |
| 388 continue; | |
| 389 } | |
| 390 #endif | |
| 391 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) { | |
| 392 SkImageInfo info, requestInfo; | |
| 393 | |
| 394 SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context , | |
| 395 &requestInfo)); | |
| 396 SkCanvas* canvas = surface->getCanvas(); | |
| 397 canvas->clear(0); | |
| 398 | |
| 399 SkBitmap bm = canvas->getDevice_just_for_deprecated_compatibility_te sting()->accessBitmap(false); | |
| 400 uint32_t genID0 = bm.getGenerationID(); | |
| 401 canvas->drawColor(SK_ColorBLUE); | |
|
robertphillips
2015/06/09 19:06:15
// Thus draw call causes a call to ...
?
reed1
2015/06/09 19:11:12
Done.
| |
| 402 uint32_t genID1 = bm.getGenerationID(); | |
| 403 REPORTER_ASSERT(reporter, genID0 != genID1); | |
| 404 } | |
| 405 } | |
| 406 } | |
| 407 | |
| 353 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, | 408 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, |
| 354 GrContext* context) { | 409 GrContext* context) { |
| 355 // Verify that the right canvas commands trigger a copy on write | 410 // Verify that the right canvas commands trigger a copy on write |
| 356 SkSurface* surface = createSurface(surfaceType, context); | 411 SkSurface* surface = createSurface(surfaceType, context); |
| 357 SkAutoTUnref<SkSurface> aur_surface(surface); | 412 SkAutoTUnref<SkSurface> aur_surface(surface); |
| 358 SkCanvas* canvas = surface->getCanvas(); | 413 SkCanvas* canvas = surface->getCanvas(); |
| 359 | 414 |
| 360 const SkRect testRect = | 415 const SkRect testRect = |
| 361 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | 416 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 362 SkIntToScalar(4), SkIntToScalar(5)); | 417 SkIntToScalar(4), SkIntToScalar(5)); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; | 635 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; |
| 581 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); | 636 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); |
| 582 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); | 637 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); |
| 583 | 638 |
| 584 test_empty_image(reporter); | 639 test_empty_image(reporter); |
| 585 test_empty_surface(reporter, NULL); | 640 test_empty_surface(reporter, NULL); |
| 586 | 641 |
| 587 test_imagepeek(reporter, factory); | 642 test_imagepeek(reporter, factory); |
| 588 test_canvaspeek(reporter, factory); | 643 test_canvaspeek(reporter, factory); |
| 589 | 644 |
| 645 test_accessPixels(reporter, factory); | |
| 646 | |
| 590 #if SK_SUPPORT_GPU | 647 #if SK_SUPPORT_GPU |
| 591 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 648 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
| 592 if (factory) { | 649 if (factory) { |
| 593 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 650 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 594 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; | 651 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; |
| 595 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 652 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 596 continue; | 653 continue; |
| 597 } | 654 } |
| 598 GrContext* context = factory->get(glCtxType); | 655 GrContext* context = factory->get(glCtxType); |
| 599 if (context) { | 656 if (context) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 // Now lets jam new colors into our "external" texture, and see if the image s notice | 733 // Now lets jam new colors into our "external" texture, and see if the image s notice |
| 677 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); | 734 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); |
| 678 sk_memset32(storage, expected1, w * h); | 735 sk_memset32(storage, expected1, w * h); |
| 679 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); | 736 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); |
| 680 | 737 |
| 681 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color | 738 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color |
| 682 test_image_color(reporter, refImg, expected1); | 739 test_image_color(reporter, refImg, expected1); |
| 683 test_image_color(reporter, cpyImg, expected0); | 740 test_image_color(reporter, cpyImg, expected0); |
| 684 } | 741 } |
| 685 #endif | 742 #endif |
| OLD | NEW |