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