| 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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 // Trigger copy on write, old backing should not be returned to scratch | 646 // Trigger copy on write, old backing should not be returned to scratch |
| 647 // pool because it is held by image2 | 647 // pool because it is held by image2 |
| 648 canvas1->clear(3); | 648 canvas1->clear(3); |
| 649 | 649 |
| 650 canvas2->clear(4); | 650 canvas2->clear(4); |
| 651 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); | 651 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); |
| 652 // Trigger copy on write on surface2. The new backing store should not | 652 // Trigger copy on write on surface2. The new backing store should not |
| 653 // be recycling a texture that is held by an existing image. | 653 // be recycling a texture that is held by an existing image. |
| 654 canvas2->clear(5); | 654 canvas2->clear(5); |
| 655 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); | 655 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); |
| 656 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getT
exture()); | 656 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); |
| 657 // The following assertion checks crbug.com/263329 | 657 // The following assertion checks crbug.com/263329 |
| 658 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getT
exture()); | 658 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 659 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getT
exture()); | 659 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 660 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getT
exture()); | 660 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 661 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getT
exture()); | 661 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 662 REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getT
exture()); | 662 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 663 } | 663 } |
| 664 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { | 664 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { |
| 665 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 665 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 666 SkAutoTUnref<SkSurface> surface1(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); | 666 SkAutoTUnref<SkSurface> surface1(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); |
| 667 SkAutoTUnref<SkSurface> surface2(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); | 667 SkAutoTUnref<SkSurface> surface2(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); |
| 668 test_crbug263329(reporter, surface1, surface2); | 668 test_crbug263329(reporter, surface1, surface2); |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 #endif | 671 #endif |
| 672 | 672 |
| 673 DEF_TEST(SurfaceGetTexture, reporter) { | 673 DEF_TEST(SurfaceGetTexture, reporter) { |
| 674 SkAutoTUnref<SkSurface> surface(create_surface()); | 674 SkAutoTUnref<SkSurface> surface(create_surface()); |
| 675 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 675 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 676 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == nullptr); | 676 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 677 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 677 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 678 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == nullptr); | 678 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 679 } | 679 } |
| 680 #if SK_SUPPORT_GPU | 680 #if SK_SUPPORT_GPU |
| 681 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceGetTexture_Gpu, reporter, context) { | 681 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { |
| 682 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 682 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 683 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); | 683 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); |
| 684 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 684 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 685 GrTexture* texture = as_IB(image)->getTexture(); | 685 GrTexture* texture = as_IB(image)->peekTexture(); |
| 686 REPORTER_ASSERT(reporter, texture); | 686 REPORTER_ASSERT(reporter, texture); |
| 687 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 687 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 688 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 688 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 689 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture); | 689 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); |
| 690 } | 690 } |
| 691 } | 691 } |
| 692 #endif | 692 #endif |
| 693 | 693 |
| 694 #if SK_SUPPORT_GPU | 694 #if SK_SUPPORT_GPU |
| 695 #include "GrGpuResourcePriv.h" | 695 #include "GrGpuResourcePriv.h" |
| 696 #include "SkGpuDevice.h" | 696 #include "SkGpuDevice.h" |
| 697 #include "SkImage_Gpu.h" | 697 #include "SkImage_Gpu.h" |
| 698 #include "SkSurface_Gpu.h" | 698 #include "SkSurface_Gpu.h" |
| 699 | 699 |
| 700 static SkBudgeted is_budgeted(SkSurface* surf) { | 700 static SkBudgeted is_budgeted(SkSurface* surf) { |
| 701 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr
iv().isBudgeted(); | 701 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr
iv().isBudgeted(); |
| 702 } | 702 } |
| 703 | 703 |
| 704 static SkBudgeted is_budgeted(SkImage* image) { | 704 static SkBudgeted is_budgeted(SkImage* image) { |
| 705 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted(); | 705 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); |
| 706 } | 706 } |
| 707 | 707 |
| 708 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { | 708 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { |
| 709 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); | 709 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); |
| 710 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 710 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 711 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 711 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 712 SkAutoTUnref<SkSurface> | 712 SkAutoTUnref<SkSurface> |
| 713 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0))
; | 713 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0))
; |
| 714 SkASSERT(surface); | 714 SkASSERT(surface); |
| 715 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 715 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 868 } |
| 869 | 869 |
| 870 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { | 870 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { |
| 871 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { | 871 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { |
| 872 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, | 872 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, |
| 873 [] (SkSurface* s){ | 873 [] (SkSurface* s){ |
| 874 SkBaseDevice* d = | 874 SkBaseDevice* d = |
| 875 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); | 875 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); |
| 876 return d->accessRenderTarget(); }, | 876 return d->accessRenderTarget(); }, |
| 877 [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); | 877 [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); |
| 878 return i->getTexture(); }, | |
| 879 [] (SkSurface* s){ SkAutoTUnref<SkImage> i(s->newImageSnapshot()); | |
| 880 return as_IB(i)->peekTexture(); }, | 878 return as_IB(i)->peekTexture(); }, |
| 881 }; | 879 }; |
| 882 for (auto grSurfaceGetter : grSurfaceGetters) { | 880 for (auto grSurfaceGetter : grSurfaceGetters) { |
| 883 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { | 881 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { |
| 884 SkSurface* surface = surface_func(context, kPremul_SkAlphaType, null
ptr); | 882 SkSurface* surface = surface_func(context, kPremul_SkAlphaType, null
ptr); |
| 885 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); | 883 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); |
| 886 } | 884 } |
| 887 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). | 885 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). |
| 888 static const int kWidth = 10; | 886 static const int kWidth = 10; |
| 889 static const int kHeight = 10; | 887 static const int kHeight = 10; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 900 desc.fHeight = kHeight; | 898 desc.fHeight = kHeight; |
| 901 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 899 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 902 desc.fTextureHandle = textureObject; | 900 desc.fTextureHandle = textureObject; |
| 903 | 901 |
| 904 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul
lptr); | 902 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul
lptr); |
| 905 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); | 903 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); |
| 906 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 904 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 907 } | 905 } |
| 908 } | 906 } |
| 909 #endif | 907 #endif |
| OLD | NEW |