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 <functional> | 8 #include <functional> |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 | 699 |
700 // Try some illegal rowByte values | 700 // Try some illegal rowByte values |
701 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a
t least 400 | 701 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a
t least 400 |
702 REPORTER_ASSERT(reporter, nullptr == s); | 702 REPORTER_ASSERT(reporter, nullptr == s); |
703 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large | 703 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large |
704 REPORTER_ASSERT(reporter, nullptr == s); | 704 REPORTER_ASSERT(reporter, nullptr == s); |
705 } | 705 } |
706 | 706 |
707 #if SK_SUPPORT_GPU | 707 #if SK_SUPPORT_GPU |
708 | 708 |
709 void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surface, | 709 void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surfacePtr, |
710 std::function<GrSurface*(SkSurface*)> grSurfaceGetter, | 710 std::function<GrSurface*(SkSurface*)> grSurfaceGetter, |
711 uint32_t expectedValue) { | 711 uint32_t expectedValue) { |
| 712 SkAutoTUnref<SkSurface> surface(surfacePtr); |
712 if (!surface) { | 713 if (!surface) { |
713 ERRORF(reporter, "Could not create GPU SkSurface."); | 714 ERRORF(reporter, "Could not create GPU SkSurface."); |
714 return; | 715 return; |
715 } | 716 } |
716 int w = surface->width(); | 717 int w = surface->width(); |
717 int h = surface->height(); | 718 int h = surface->height(); |
718 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); | 719 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); |
719 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); | 720 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); |
720 | 721 |
721 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface))); | 722 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface))); |
722 if (!grSurface) { | 723 if (!grSurface) { |
723 ERRORF(reporter, "Could access render target of GPU SkSurface."); | 724 ERRORF(reporter, "Could access render target of GPU SkSurface."); |
724 return; | 725 return; |
725 } | 726 } |
726 SkASSERT(surface->unique()); | 727 SkASSERT(surface->unique()); |
727 surface->unref(); | 728 surface.reset(); |
728 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); | 729 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); |
729 for (int y = 0; y < h; ++y) { | 730 for (int y = 0; y < h; ++y) { |
730 for (int x = 0; x < w; ++x) { | 731 for (int x = 0; x < w; ++x) { |
731 uint32_t pixel = pixels.get()[y * w + x]; | 732 uint32_t pixel = pixels.get()[y * w + x]; |
732 if (pixel != expectedValue) { | 733 if (pixel != expectedValue) { |
733 SkString msg; | 734 SkString msg; |
734 if (expectedValue) { | 735 if (expectedValue) { |
735 msg = "SkSurface should have left render target unmodified"; | 736 msg = "SkSurface should have left render target unmodified"; |
736 } else { | 737 } else { |
737 msg = "SkSurface should have cleared the render target"; | 738 msg = "SkSurface should have cleared the render target"; |
738 } | 739 } |
739 ERRORF(reporter, | 740 ERRORF(reporter, |
740 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, | 741 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, |
741 expectedValue, x, y); | 742 expectedValue, x, y); |
742 return; | 743 return; |
743 } | 744 } |
744 } | 745 } |
745 } | 746 } |
746 } | 747 } |
747 | 748 |
748 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { | 749 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { |
749 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { | 750 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { |
750 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget();}, | 751 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, |
751 [] (SkSurface* s){ | 752 [] (SkSurface* s){ |
752 SkBaseDevice* d = | 753 SkBaseDevice* d = |
753 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); | 754 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); |
754 return d->accessRenderTarget(); }, | 755 return d->accessRenderTarget(); }, |
755 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot(); | 756 [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); |
756 return i->getTexture(); }, | 757 return i->getTexture(); }, |
757 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot(); | 758 [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); |
758 return as_IB(i)->peekTexture(); }, | 759 return as_IB(i)->peekTexture(); }, |
759 }; | 760 }; |
760 for (auto grSurfaceGetter : grSurfaceGetters) { | 761 for (auto grSurfaceGetter : grSurfaceGetters) { |
761 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { | 762 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { |
762 SkSurface* surface(surface_func(context, kPremul_SkAlphaType, nullpt
r)); | 763 SkSurface* surface = surface_func(context, kPremul_SkAlphaType, null
ptr); |
763 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); | 764 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); |
764 } | 765 } |
765 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). | 766 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). |
766 static const int kWidth = 10; | 767 static const int kWidth = 10; |
767 static const int kHeight = 10; | 768 static const int kHeight = 10; |
768 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); | 769 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); |
769 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight); | 770 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight); |
770 | 771 |
771 GrBackendObject textureObject = | 772 GrBackendObject textureObject = |
772 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(),
kWidth, kHeight, | 773 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(),
kWidth, kHeight, |
773 kRGBA_8888_Gr
PixelConfig); | 774 kRGBA_8888_Gr
PixelConfig); |
774 | 775 |
775 GrBackendTextureDesc desc; | 776 GrBackendTextureDesc desc; |
776 desc.fConfig = kRGBA_8888_GrPixelConfig; | 777 desc.fConfig = kRGBA_8888_GrPixelConfig; |
777 desc.fWidth = kWidth; | 778 desc.fWidth = kWidth; |
778 desc.fHeight = kHeight; | 779 desc.fHeight = kHeight; |
779 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 780 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
780 desc.fTextureHandle = textureObject; | 781 desc.fTextureHandle = textureObject; |
781 | 782 |
782 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul
lptr); | 783 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul
lptr); |
783 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); | 784 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); |
784 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 785 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
785 } | 786 } |
786 } | 787 } |
787 #endif | 788 #endif |
OLD | NEW |