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 "SkDevice.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #else | 23 #else |
| 24 class GrContextFactory; | 24 class GrContextFactory; |
| 25 class GrContext; | 25 class GrContext; |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 enum SurfaceType { | 28 enum SurfaceType { |
| 29 kRaster_SurfaceType, | 29 kRaster_SurfaceType, |
| 30 kRasterDirect_SurfaceType, | 30 kRasterDirect_SurfaceType, |
| 31 kGpu_SurfaceType, | 31 kGpu_SurfaceType, |
| 32 kGpuScratch_SurfaceType, | 32 kGpuScratch_SurfaceType, |
| 33 | |
| 34 kLastSurfaceType = kGpuScratch_SurfaceType | |
| 33 }; | 35 }; |
| 36 static const int kSurfaceTypeCnt = kLastSurfaceType + 1; | |
| 34 | 37 |
| 35 static void release_storage(void* pixels, void* context) { | 38 static void release_storage(void* pixels, void* context) { |
| 36 SkASSERT(pixels == context); | 39 SkASSERT(pixels == context); |
| 37 sk_free(pixels); | 40 sk_free(pixels); |
| 38 } | 41 } |
| 39 | 42 |
|
robertphillips
2015/06/23 19:48:09
create_surface ?
bsalomon
2015/06/25 21:47:18
Done.
| |
| 40 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, | 43 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, |
| 44 SkAlphaType at = kPremul_SkAlphaType, | |
| 41 SkImageInfo* requestedInfo = NULL) { | 45 SkImageInfo* requestedInfo = NULL) { |
| 42 static const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 46 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 43 | 47 |
| 44 if (requestedInfo) { | 48 if (requestedInfo) { |
| 45 *requestedInfo = info; | 49 *requestedInfo = info; |
| 46 } | 50 } |
| 47 | 51 |
| 48 switch (surfaceType) { | 52 switch (surfaceType) { |
| 49 case kRaster_SurfaceType: | 53 case kRaster_SurfaceType: |
| 50 return SkSurface::NewRaster(info); | 54 return SkSurface::NewRaster(info); |
| 51 case kRasterDirect_SurfaceType: { | 55 case kRasterDirect_SurfaceType: { |
| 52 const size_t rowBytes = info.minRowBytes(); | 56 const size_t rowBytes = info.minRowBytes(); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 context = factory->get(glCtxType); | 414 context = factory->get(glCtxType); |
| 411 | 415 |
| 412 if (NULL == context) { | 416 if (NULL == context) { |
| 413 continue; | 417 continue; |
| 414 } | 418 } |
| 415 #endif | 419 #endif |
| 416 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 420 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 417 SkImageInfo info, requestInfo; | 421 SkImageInfo info, requestInfo; |
| 418 size_t rowBytes; | 422 size_t rowBytes; |
| 419 | 423 |
| 420 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context , | 424 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context , |
|
robertphillips
2015/06/23 19:48:09
tab over ?
bsalomon
2015/06/25 21:47:18
Done.
| |
| 421 &requestInfo)); | 425 kPremul_SkAlphaType, &requestInfo)); |
| 422 surface->getCanvas()->clear(color); | 426 surface->getCanvas()->clear(color); |
| 423 | 427 |
| 424 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes ); | 428 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes ); |
| 425 bool success = SkToBool(addr); | 429 bool success = SkToBool(addr); |
| 426 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); | 430 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
| 427 | 431 |
| 428 SkImageInfo info2; | 432 SkImageInfo info2; |
| 429 size_t rb2; | 433 size_t rb2; |
| 430 const void* addr2 = surface->peekPixels(&info2, &rb2); | 434 const void* addr2 = surface->peekPixels(&info2, &rb2); |
| 431 | 435 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 } | 481 } |
| 478 context = factory->get(glCtxType); | 482 context = factory->get(glCtxType); |
| 479 | 483 |
| 480 if (NULL == context) { | 484 if (NULL == context) { |
| 481 continue; | 485 continue; |
| 482 } | 486 } |
| 483 #endif | 487 #endif |
| 484 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) { | 488 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) { |
| 485 SkImageInfo info, requestInfo; | 489 SkImageInfo info, requestInfo; |
| 486 | 490 |
| 487 SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context , | 491 SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context , |
|
robertphillips
2015/06/23 19:48:09
tab over ?
bsalomon
2015/06/25 21:47:18
Done.
| |
| 488 &requestInfo)); | 492 kPremul_SkAlphaType, &requestInfo)); |
| 489 SkCanvas* canvas = surface->getCanvas(); | 493 SkCanvas* canvas = surface->getCanvas(); |
| 490 canvas->clear(0); | 494 canvas->clear(0); |
| 491 | 495 |
| 492 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compati bility_testing(); | 496 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compati bility_testing(); |
| 493 SkBitmap bm = device->accessBitmap(false); | 497 SkBitmap bm = device->accessBitmap(false); |
| 494 uint32_t genID0 = bm.getGenerationID(); | 498 uint32_t genID0 = bm.getGenerationID(); |
| 495 // Now we draw something, which needs to "dirty" the genID (sorta li ke copy-on-write) | 499 // Now we draw something, which needs to "dirty" the genID (sorta li ke copy-on-write) |
| 496 canvas->drawColor(SK_ColorBLUE); | 500 canvas->drawColor(SK_ColorBLUE); |
| 497 // Now check that we get a different genID | 501 // Now check that we get a different genID |
| 498 uint32_t genID1 = bm.getGenerationID(); | 502 uint32_t genID1 = bm.getGenerationID(); |
| 499 REPORTER_ASSERT(reporter, genID0 != genID1); | 503 REPORTER_ASSERT(reporter, genID0 != genID1); |
| 500 } | 504 } |
| 501 } | 505 } |
| 502 } | 506 } |
| 503 | 507 |
| 508 static void test_snap_alphatype(skiatest::Reporter* reporter, GrContextFactory* factory) { | |
| 509 GrContext* context = NULL; | |
| 510 #if SK_SUPPORT_GPU | |
| 511 context = factory->get(GrContextFactory::kNative_GLContextType); | |
| 512 if (NULL == context) { | |
| 513 return; | |
| 514 } | |
| 515 #endif | |
| 516 for (int opaque = 0; opaque < 2; ++opaque) { | |
| 517 SkAlphaType atype = SkToBool(opaque) ? kOpaque_SkAlphaType : kPremul_SkA lphaType; | |
| 518 for (int st = 0; st < kSurfaceTypeCnt; ++st) { | |
| 519 SurfaceType stype = (SurfaceType)st; | |
| 520 SkAutoTUnref<SkSurface> surface(createSurface(stype, context, atype) ); | |
| 521 REPORTER_ASSERT(reporter, surface); | |
| 522 if (surface) { | |
| 523 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | |
| 524 REPORTER_ASSERT(reporter, image); | |
| 525 if (image) { | |
| 526 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(opaq ue)); | |
| 527 } | |
| 528 } | |
| 529 } | |
| 530 } | |
| 531 } | |
| 532 | |
| 504 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, | 533 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, |
| 505 GrContext* context) { | 534 GrContext* context) { |
| 506 // Verify that the right canvas commands trigger a copy on write | 535 // Verify that the right canvas commands trigger a copy on write |
| 507 SkSurface* surface = createSurface(surfaceType, context); | 536 SkSurface* surface = createSurface(surfaceType, context); |
| 508 SkAutoTUnref<SkSurface> aur_surface(surface); | 537 SkAutoTUnref<SkSurface> aur_surface(surface); |
| 509 SkCanvas* canvas = surface->getCanvas(); | 538 SkCanvas* canvas = surface->getCanvas(); |
| 510 | 539 |
| 511 const SkRect testRect = | 540 const SkRect testRect = |
| 512 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | 541 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 513 SkIntToScalar(4), SkIntToScalar(5)); | 542 SkIntToScalar(4), SkIntToScalar(5)); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); | 762 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); |
| 734 | 763 |
| 735 test_empty_image(reporter); | 764 test_empty_image(reporter); |
| 736 test_empty_surface(reporter, NULL); | 765 test_empty_surface(reporter, NULL); |
| 737 | 766 |
| 738 test_imagepeek(reporter, factory); | 767 test_imagepeek(reporter, factory); |
| 739 test_canvaspeek(reporter, factory); | 768 test_canvaspeek(reporter, factory); |
| 740 | 769 |
| 741 test_accessPixels(reporter, factory); | 770 test_accessPixels(reporter, factory); |
| 742 | 771 |
| 772 test_snap_alphatype(reporter, factory); | |
| 773 | |
| 743 #if SK_SUPPORT_GPU | 774 #if SK_SUPPORT_GPU |
| 744 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 775 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
| 745 if (factory) { | 776 if (factory) { |
| 746 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 777 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 747 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; | 778 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; |
| 748 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 779 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 749 continue; | 780 continue; |
| 750 } | 781 } |
| 751 GrContext* context = factory->get(glCtxType); | 782 GrContext* context = factory->get(glCtxType); |
| 752 if (context) { | 783 if (context) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color | 891 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color |
| 861 test_image_color(reporter, refImg, expected1); | 892 test_image_color(reporter, refImg, expected1); |
| 862 test_image_color(reporter, cpyImg, expected0); | 893 test_image_color(reporter, cpyImg, expected0); |
| 863 | 894 |
| 864 // Now exercise the release proc | 895 // Now exercise the release proc |
| 865 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); | 896 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); |
| 866 refImg.reset(NULL); // force a release of the image | 897 refImg.reset(NULL); // force a release of the image |
| 867 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); | 898 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); |
| 868 } | 899 } |
| 869 #endif | 900 #endif |
| OLD | NEW |