OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 <functional> | 8 #include <functional> |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); | 169 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); |
170 REPORTER_ASSERT(reporter, decoded); | 170 REPORTER_ASSERT(reporter, decoded); |
171 assert_equal(reporter, image, &ir, decoded.get()); | 171 assert_equal(reporter, image, &ir, decoded.get()); |
172 } | 172 } |
173 | 173 |
174 DEF_TEST(ImageEncode, reporter) { | 174 DEF_TEST(ImageEncode, reporter) { |
175 test_encode(reporter, create_image().get()); | 175 test_encode(reporter, create_image().get()); |
176 } | 176 } |
177 | 177 |
178 #if SK_SUPPORT_GPU | 178 #if SK_SUPPORT_GPU |
179 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) { | 179 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) { |
180 test_encode(reporter, create_gpu_image(ctxInfo.fGrContext).get()); | 180 test_encode(reporter, create_gpu_image(ctxInfo.fGrContext).get()); |
181 } | 181 } |
182 #endif | 182 #endif |
183 | 183 |
184 namespace { | 184 namespace { |
185 | 185 |
186 const char* kSerializedData = "serialized"; | 186 const char* kSerializedData = "serialized"; |
187 | 187 |
188 class MockSerializer : public SkPixelSerializer { | 188 class MockSerializer : public SkPixelSerializer { |
189 public: | 189 public: |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 #include "SkBitmapCache.h" | 362 #include "SkBitmapCache.h" |
363 | 363 |
364 /* | 364 /* |
365 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. | 365 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. |
366 * We cache it for performance when drawing into a raster surface. | 366 * We cache it for performance when drawing into a raster surface. |
367 * | 367 * |
368 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, | 368 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, |
369 * but we don't have that facility (at the moment) so we use a little internal
knowledge | 369 * but we don't have that facility (at the moment) so we use a little internal
knowledge |
370 * of *how* the raster version is cached, and look for that. | 370 * of *how* the raster version is cached, and look for that. |
371 */ | 371 */ |
372 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, ctxInfo) { | 372 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, ctxInfo) { |
373 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 373 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
374 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); | 374 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); |
375 const uint32_t uniqueID = image->uniqueID(); | 375 const uint32_t uniqueID = image->uniqueID(); |
376 | 376 |
377 auto surface(SkSurface::MakeRaster(info)); | 377 auto surface(SkSurface::MakeRaster(info)); |
378 | 378 |
379 // now we can test drawing a gpu-backed image into a cpu-backed surface | 379 // now we can test drawing a gpu-backed image into a cpu-backed surface |
380 | 380 |
381 { | 381 { |
382 SkBitmap cachedBitmap; | 382 SkBitmap cachedBitmap; |
(...skipping 14 matching lines...) Expand all Loading... |
397 } | 397 } |
398 } | 398 } |
399 | 399 |
400 image.reset(nullptr); | 400 image.reset(nullptr); |
401 { | 401 { |
402 SkBitmap cachedBitmap; | 402 SkBitmap cachedBitmap; |
403 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 403 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, contextInf
o) { | 407 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, context
Info) { |
408 GrContext* context = contextInfo.fGrContext; | 408 GrContext* context = contextInfo.fGrContext; |
409 sk_gpu_test::GLTestContext* glContext = contextInfo.fGLContext; | 409 sk_gpu_test::GLTestContext* glContext = contextInfo.fGLContext; |
410 | 410 |
411 GrContextFactory otherFactory; | 411 GrContextFactory otherFactory; |
412 ContextInfo otherContextInfo = | 412 ContextInfo otherContextInfo = |
413 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); | 413 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); |
414 glContext->makeCurrent(); | 414 glContext->makeCurrent(); |
415 | 415 |
416 std::function<sk_sp<SkImage>()> imageFactories[] = { | 416 std::function<sk_sp<SkImage>()> imageFactories[] = { |
417 create_image, | 417 create_image, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 RasterDataHolder dataHolder; | 570 RasterDataHolder dataHolder; |
571 image = create_rasterproc_image(&dataHolder); | 571 image = create_rasterproc_image(&dataHolder); |
572 test_read_pixels(reporter, image.get()); | 572 test_read_pixels(reporter, image.get()); |
573 image.reset(); | 573 image.reset(); |
574 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 574 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
575 | 575 |
576 image = create_codec_image(); | 576 image = create_codec_image(); |
577 test_read_pixels(reporter, image.get()); | 577 test_read_pixels(reporter, image.get()); |
578 } | 578 } |
579 #if SK_SUPPORT_GPU | 579 #if SK_SUPPORT_GPU |
580 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) { | 580 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) { |
581 test_read_pixels(reporter, create_gpu_image(ctxInfo.fGrContext).get()); | 581 test_read_pixels(reporter, create_gpu_image(ctxInfo.fGrContext).get()); |
582 } | 582 } |
583 #endif | 583 #endif |
584 | 584 |
585 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima
ge, | 585 static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima
ge, |
586 const SkBitmap& bitmap, SkImage::LegacyBitmapMod
e mode) { | 586 const SkBitmap& bitmap, SkImage::LegacyBitmapMod
e mode) { |
587 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); | 587 REPORTER_ASSERT(reporter, image->width() == bitmap.width()); |
588 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); | 588 REPORTER_ASSERT(reporter, image->height() == bitmap.height()); |
589 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); | 589 REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque()); |
590 | 590 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 image = create_rasterproc_image(&dataHolder); | 633 image = create_rasterproc_image(&dataHolder); |
634 test_legacy_bitmap(reporter, image.get(), mode); | 634 test_legacy_bitmap(reporter, image.get(), mode); |
635 image.reset(); | 635 image.reset(); |
636 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 636 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
637 | 637 |
638 image = create_codec_image(); | 638 image = create_codec_image(); |
639 test_legacy_bitmap(reporter, image.get(), mode); | 639 test_legacy_bitmap(reporter, image.get(), mode); |
640 } | 640 } |
641 } | 641 } |
642 #if SK_SUPPORT_GPU | 642 #if SK_SUPPORT_GPU |
643 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, ctxInfo) { | 643 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, ctxInfo)
{ |
644 const SkImage::LegacyBitmapMode modes[] = { | 644 const SkImage::LegacyBitmapMode modes[] = { |
645 SkImage::kRO_LegacyBitmapMode, | 645 SkImage::kRO_LegacyBitmapMode, |
646 SkImage::kRW_LegacyBitmapMode, | 646 SkImage::kRW_LegacyBitmapMode, |
647 }; | 647 }; |
648 for (auto& mode : modes) { | 648 for (auto& mode : modes) { |
649 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); | 649 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); |
650 test_legacy_bitmap(reporter, image.get(), mode); | 650 test_legacy_bitmap(reporter, image.get(), mode); |
651 } | 651 } |
652 } | 652 } |
653 #endif | 653 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
677 RasterDataHolder dataHolder; | 677 RasterDataHolder dataHolder; |
678 image = create_rasterproc_image(&dataHolder); | 678 image = create_rasterproc_image(&dataHolder); |
679 test_peek(reporter, image.get(), true); | 679 test_peek(reporter, image.get(), true); |
680 image.reset(); | 680 image.reset(); |
681 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); | 681 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount); |
682 | 682 |
683 image = create_codec_image(); | 683 image = create_codec_image(); |
684 test_peek(reporter, image.get(), false); | 684 test_peek(reporter, image.get(), false); |
685 } | 685 } |
686 #if SK_SUPPORT_GPU | 686 #if SK_SUPPORT_GPU |
687 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) { | 687 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) { |
688 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); | 688 sk_sp<SkImage> image(create_gpu_image(ctxInfo.fGrContext)); |
689 test_peek(reporter, image.get(), false); | 689 test_peek(reporter, image.get(), false); |
690 } | 690 } |
691 #endif | 691 #endif |
692 | 692 |
693 #if SK_SUPPORT_GPU | 693 #if SK_SUPPORT_GPU |
694 struct TextureReleaseChecker { | 694 struct TextureReleaseChecker { |
695 TextureReleaseChecker() : fReleaseCount(0) {} | 695 TextureReleaseChecker() : fReleaseCount(0) {} |
696 int fReleaseCount; | 696 int fReleaseCount; |
697 static void Release(void* self) { | 697 static void Release(void* self) { |
698 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; | 698 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; |
699 } | 699 } |
700 }; | 700 }; |
701 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM
Color expected) { | 701 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM
Color expected) { |
702 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 702 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
703 SkPMColor pixel; | 703 SkPMColor pixel; |
704 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0,
0)); | 704 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0,
0)); |
705 REPORTER_ASSERT(reporter, pixel == expected); | 705 REPORTER_ASSERT(reporter, pixel == expected); |
706 } | 706 } |
707 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, ctxInfo) { | 707 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, ctxInfo)
{ |
708 GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); | 708 GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); |
709 const int w = 10; | 709 const int w = 10; |
710 const int h = 10; | 710 const int h = 10; |
711 SkPMColor storage[w * h]; | 711 SkPMColor storage[w * h]; |
712 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); | 712 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); |
713 sk_memset32(storage, expected0, w * h); | 713 sk_memset32(storage, expected0, w * h); |
714 GrSurfaceDesc desc; | 714 GrSurfaceDesc desc; |
715 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo
r readpixels(); | 715 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo
r readpixels(); |
716 desc.fOrigin = kDefault_GrSurfaceOrigin; | 716 desc.fOrigin = kDefault_GrSurfaceOrigin; |
717 desc.fWidth = w; | 717 desc.fWidth = w; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 uint32_t pixelB = *bpm.addr32(x, y); | 792 uint32_t pixelB = *bpm.addr32(x, y); |
793 if (pixelA != pixelB) { | 793 if (pixelA != pixelB) { |
794 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d
0x%08x != 0x%08x", | 794 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d
0x%08x != 0x%08x", |
795 x, y, pixelA, pixelB); | 795 x, y, pixelA, pixelB); |
796 return; | 796 return; |
797 } | 797 } |
798 } | 798 } |
799 } | 799 } |
800 } | 800 } |
801 | 801 |
802 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, ctxInfo) { | 802 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, ctxInfo) { |
803 for (auto create : {&create_image, | 803 for (auto create : {&create_image, |
804 &create_image_565, | 804 &create_image_565, |
805 &create_image_ct}) { | 805 &create_image_ct}) { |
806 sk_sp<SkImage> image((*create)()); | 806 sk_sp<SkImage> image((*create)()); |
807 if (!image) { | 807 if (!image) { |
808 ERRORF(reporter, "Could not create image"); | 808 ERRORF(reporter, "Could not create image"); |
809 return; | 809 return; |
810 } | 810 } |
811 | 811 |
812 SkPixmap pixmap; | 812 SkPixmap pixmap; |
813 if (!image->peekPixels(&pixmap)) { | 813 if (!image->peekPixels(&pixmap)) { |
814 ERRORF(reporter, "peek failed"); | 814 ERRORF(reporter, "peek failed"); |
815 } else { | 815 } else { |
816 sk_sp<SkImage> texImage(SkImage::MakeTextureFromPixmap(ctxInfo.fGrCo
ntext, pixmap, | 816 sk_sp<SkImage> texImage(SkImage::MakeTextureFromPixmap(ctxInfo.fGrCo
ntext, pixmap, |
817 SkBudgeted::k
No)); | 817 SkBudgeted::k
No)); |
818 if (!texImage) { | 818 if (!texImage) { |
819 ERRORF(reporter, "NewTextureFromPixmap failed."); | 819 ERRORF(reporter, "NewTextureFromPixmap failed."); |
820 } else { | 820 } else { |
821 check_images_same(reporter, image.get(), texImage.get()); | 821 check_images_same(reporter, image.get(), texImage.get()); |
822 } | 822 } |
823 } | 823 } |
824 } | 824 } |
825 } | 825 } |
826 | 826 |
827 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) { | 827 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) { |
828 GrContext* context = ctxInfo.fGrContext; | 828 GrContext* context = ctxInfo.fGrContext; |
829 sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext; | 829 sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext; |
830 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 830 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
831 | 831 |
832 GrContextFactory otherFactory; | 832 GrContextFactory otherFactory; |
833 ContextInfo otherContextInfo = | 833 ContextInfo otherContextInfo = |
834 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); | 834 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); |
835 | 835 |
836 glContext->makeCurrent(); | 836 glContext->makeCurrent(); |
837 REPORTER_ASSERT(reporter, proxy); | 837 REPORTER_ASSERT(reporter, proxy); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 otherContextInfo.fGrContext, buffer, budgeted)); | 891 otherContextInfo.fGrContext, buffer, budgeted)); |
892 REPORTER_ASSERT(reporter, !newImage2); | 892 REPORTER_ASSERT(reporter, !newImage2); |
893 glContext->makeCurrent(); | 893 glContext->makeCurrent(); |
894 } | 894 } |
895 } | 895 } |
896 sk_free(buffer); | 896 sk_free(buffer); |
897 } | 897 } |
898 } | 898 } |
899 } | 899 } |
900 #endif | 900 #endif |
OLD | NEW |