| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 DEF_TEST(SurfaceEmpty, reporter) { | 72 DEF_TEST(SurfaceEmpty, reporter) { |
| 73 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 73 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 74 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); | 74 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); |
| 75 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); | 75 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); |
| 76 | 76 |
| 77 } | 77 } |
| 78 #if SK_SUPPORT_GPU | 78 #if SK_SUPPORT_GPU |
| 79 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { | 79 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { |
| 80 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 80 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 81 REPORTER_ASSERT(reporter, nullptr == | 81 REPORTER_ASSERT(reporter, nullptr == |
| 82 SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted:
:kNo, info, 0, | 82 SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted:
:kNo, info, 0, |
| 83 nullptr)); | 83 nullptr)); |
| 84 } | 84 } |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 static void test_canvas_peek(skiatest::Reporter* reporter, | 87 static void test_canvas_peek(skiatest::Reporter* reporter, |
| 88 sk_sp<SkSurface>& surface, | 88 sk_sp<SkSurface>& surface, |
| 89 const SkImageInfo& requestInfo, | 89 const SkImageInfo& requestInfo, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 DEF_TEST(SurfaceCanvasPeek, reporter) { | 114 DEF_TEST(SurfaceCanvasPeek, reporter) { |
| 115 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 115 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 116 SkImageInfo requestInfo; | 116 SkImageInfo requestInfo; |
| 117 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); | 117 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); |
| 118 test_canvas_peek(reporter, surface, requestInfo, true); | 118 test_canvas_peek(reporter, surface, requestInfo, true); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 #if SK_SUPPORT_GPU | 121 #if SK_SUPPORT_GPU |
| 122 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo)
{ | 122 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) { |
| 123 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 123 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 124 SkImageInfo requestInfo; | 124 SkImageInfo requestInfo; |
| 125 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, &req
uestInfo)); | 125 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, &req
uestInfo)); |
| 126 test_canvas_peek(reporter, surface, requestInfo, false); | 126 test_canvas_peek(reporter, surface, requestInfo, false); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 #endif | 129 #endif |
| 130 | 130 |
| 131 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump | 131 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump |
| 132 // the bitmap's genID when we draw to it, else they won't know it has new values
. When they are | 132 // the bitmap's genID when we draw to it, else they won't know it has new values
. When they are |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 uint32_t genID1 = bm.getGenerationID(); | 145 uint32_t genID1 = bm.getGenerationID(); |
| 146 REPORTER_ASSERT(reporter, genID0 != genID1); | 146 REPORTER_ASSERT(reporter, genID0 != genID1); |
| 147 } | 147 } |
| 148 DEF_TEST(SurfaceAccessPixels, reporter) { | 148 DEF_TEST(SurfaceAccessPixels, reporter) { |
| 149 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 149 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 150 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); | 150 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); |
| 151 test_access_pixels(reporter, surface); | 151 test_access_pixels(reporter, surface); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 #if SK_SUPPORT_GPU | 154 #if SK_SUPPORT_GPU |
| 155 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo
) { | 155 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo) { |
| 156 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 156 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 157 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); | 157 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); |
| 158 test_access_pixels(reporter, surface); | 158 test_access_pixels(reporter, surface); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 #endif | 161 #endif |
| 162 | 162 |
| 163 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, | 163 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, |
| 164 bool expectOpaque) { | 164 bool expectOpaque) { |
| 165 REPORTER_ASSERT(reporter, surface); | 165 REPORTER_ASSERT(reporter, surface); |
| 166 if (surface) { | 166 if (surface) { |
| 167 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 167 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 168 REPORTER_ASSERT(reporter, image); | 168 REPORTER_ASSERT(reporter, image); |
| 169 if (image) { | 169 if (image) { |
| 170 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); | 170 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { | 174 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { |
| 175 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 175 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 176 for (auto& isOpaque : { true, false }) { | 176 for (auto& isOpaque : { true, false }) { |
| 177 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 177 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 178 auto surface(surface_func(alphaType, nullptr)); | 178 auto surface(surface_func(alphaType, nullptr)); |
| 179 test_snapshot_alphatype(reporter, surface, isOpaque); | 179 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 #if SK_SUPPORT_GPU | 183 #if SK_SUPPORT_GPU |
| 184 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ct
xInfo) { | 184 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxIn
fo) { |
| 185 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 185 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 186 for (auto& isOpaque : { true, false }) { | 186 for (auto& isOpaque : { true, false }) { |
| 187 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 187 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 188 auto surface(surface_func(ctxInfo.grContext(), alphaType, nullptr)); | 188 auto surface(surface_func(ctxInfo.grContext(), alphaType, nullptr)); |
| 189 test_snapshot_alphatype(reporter, surface, isOpaque); | 189 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 #endif | 193 #endif |
| 194 | 194 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) | 519 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) |
| 520 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ | 520 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ |
| 521 testPaint)) | 521 testPaint)) |
| 522 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ | 522 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ |
| 523 testPaint)) | 523 testPaint)) |
| 524 } | 524 } |
| 525 DEF_TEST(SurfaceCopyOnWrite, reporter) { | 525 DEF_TEST(SurfaceCopyOnWrite, reporter) { |
| 526 test_copy_on_write(reporter, create_surface().get()); | 526 test_copy_on_write(reporter, create_surface().get()); |
| 527 } | 527 } |
| 528 #if SK_SUPPORT_GPU | 528 #if SK_SUPPORT_GPU |
| 529 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo)
{ | 529 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) { |
| 530 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 530 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 531 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); | 531 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); |
| 532 test_copy_on_write(reporter, surface.get()); | 532 test_copy_on_write(reporter, surface.get()); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 #endif | 535 #endif |
| 536 | 536 |
| 537 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, | 537 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, |
| 538 SkSurface* surface) { | 538 SkSurface* surface) { |
| 539 // This test succeeds by not triggering an assertion. | 539 // This test succeeds by not triggering an assertion. |
| 540 // The test verifies that the surface remains writable (usable) after | 540 // The test verifies that the surface remains writable (usable) after |
| 541 // acquiring and releasing a snapshot without triggering a copy on write. | 541 // acquiring and releasing a snapshot without triggering a copy on write. |
| 542 SkCanvas* canvas = surface->getCanvas(); | 542 SkCanvas* canvas = surface->getCanvas(); |
| 543 canvas->clear(1); | 543 canvas->clear(1); |
| 544 surface->makeImageSnapshot(); // Create and destroy SkImage | 544 surface->makeImageSnapshot(); // Create and destroy SkImage |
| 545 canvas->clear(2); // Must not assert internally | 545 canvas->clear(2); // Must not assert internally |
| 546 } | 546 } |
| 547 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { | 547 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { |
| 548 test_writable_after_snapshot_release(reporter, create_surface().get()); | 548 test_writable_after_snapshot_release(reporter, create_surface().get()); |
| 549 } | 549 } |
| 550 #if SK_SUPPORT_GPU | 550 #if SK_SUPPORT_GPU |
| 551 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu,
reporter, ctxInfo) { | 551 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep
orter, ctxInfo) { |
| 552 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 552 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 553 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); | 553 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); |
| 554 test_writable_after_snapshot_release(reporter, surface.get()); | 554 test_writable_after_snapshot_release(reporter, surface.get()); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 #endif | 557 #endif |
| 558 | 558 |
| 559 #if SK_SUPPORT_GPU | 559 #if SK_SUPPORT_GPU |
| 560 static void test_crbug263329(skiatest::Reporter* reporter, | 560 static void test_crbug263329(skiatest::Reporter* reporter, |
| 561 SkSurface* surface1, | 561 SkSurface* surface1, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 582 canvas2->clear(5); | 582 canvas2->clear(5); |
| 583 sk_sp<SkImage> image4(surface2->makeImageSnapshot()); | 583 sk_sp<SkImage> image4(surface2->makeImageSnapshot()); |
| 584 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); | 584 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); |
| 585 // The following assertion checks crbug.com/263329 | 585 // The following assertion checks crbug.com/263329 |
| 586 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); | 586 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 587 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); | 587 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 588 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); | 588 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 589 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); | 589 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 590 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); | 590 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 591 } | 591 } |
| 592 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo)
{ | 592 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) { |
| 593 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 593 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 594 auto surface1(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nul
lptr)); | 594 auto surface1(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nul
lptr)); |
| 595 auto surface2(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nul
lptr)); | 595 auto surface2(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nul
lptr)); |
| 596 test_crbug263329(reporter, surface1.get(), surface2.get()); | 596 test_crbug263329(reporter, surface1.get(), surface2.get()); |
| 597 } | 597 } |
| 598 } | 598 } |
| 599 #endif | 599 #endif |
| 600 | 600 |
| 601 DEF_TEST(SurfaceGetTexture, reporter) { | 601 DEF_TEST(SurfaceGetTexture, reporter) { |
| 602 auto surface(create_surface()); | 602 auto surface(create_surface()); |
| 603 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 603 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 604 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 604 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 605 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 605 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 606 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 606 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 607 } | 607 } |
| 608 #if SK_SUPPORT_GPU | 608 #if SK_SUPPORT_GPU |
| 609 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo)
{ | 609 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) { |
| 610 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 610 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 611 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); | 611 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); |
| 612 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 612 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 613 GrTexture* texture = as_IB(image)->peekTexture(); | 613 GrTexture* texture = as_IB(image)->peekTexture(); |
| 614 REPORTER_ASSERT(reporter, texture); | 614 REPORTER_ASSERT(reporter, texture); |
| 615 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 615 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 616 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 616 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 617 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); | 617 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); |
| 618 } | 618 } |
| 619 } | 619 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 631 } | 631 } |
| 632 | 632 |
| 633 static SkBudgeted is_budgeted(SkImage* image) { | 633 static SkBudgeted is_budgeted(SkImage* image) { |
| 634 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); | 634 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); |
| 635 } | 635 } |
| 636 | 636 |
| 637 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { | 637 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { |
| 638 return is_budgeted(image.get()); | 638 return is_budgeted(image.get()); |
| 639 } | 639 } |
| 640 | 640 |
| 641 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) { | 641 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) { |
| 642 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); | 642 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); |
| 643 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 643 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 644 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 644 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 645 auto surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), sbudge
ted, info)); | 645 auto surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), sbudge
ted, info)); |
| 646 SkASSERT(surface); | 646 SkASSERT(surface); |
| 647 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 647 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 648 | 648 |
| 649 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); | 649 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); |
| 650 | 650 |
| 651 // Initially the image shares a texture with the surface, and the su
rface decides | 651 // Initially the image shares a texture with the surface, and the su
rface decides |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 DEF_TEST(SurfaceNoCanvas, reporter) { | 693 DEF_TEST(SurfaceNoCanvas, reporter) { |
| 694 SkSurface::ContentChangeMode modes[] = | 694 SkSurface::ContentChangeMode modes[] = |
| 695 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 695 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 696 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 696 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 697 for (auto& mode : modes) { | 697 for (auto& mode : modes) { |
| 698 test_func(reporter, create_surface().get(), mode); | 698 test_func(reporter, create_surface().get(), mode); |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 } | 701 } |
| 702 #if SK_SUPPORT_GPU | 702 #if SK_SUPPORT_GPU |
| 703 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) { | 703 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) { |
| 704 SkSurface::ContentChangeMode modes[] = | 704 SkSurface::ContentChangeMode modes[] = |
| 705 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 705 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 706 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 706 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 707 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 707 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 708 for (auto& mode : modes) { | 708 for (auto& mode : modes) { |
| 709 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); | 709 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); |
| 710 test_func(reporter, surface.get(), mode); | 710 test_func(reporter, surface.get(), mode); |
| 711 } | 711 } |
| 712 } | 712 } |
| 713 } | 713 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return; | 834 return; |
| 835 } | 835 } |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 } | 838 } |
| 839 | 839 |
| 840 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { | 840 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { |
| 841 GrContext* context = ctxInfo.grContext(); | 841 GrContext* context = ctxInfo.grContext(); |
| 842 | 842 |
| 843 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { | 843 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { |
| 844 [] (SkSurface* s){ | 844 [] (SkSurface* s){ |
| 845 GrDrawContext* dc = s->getCanvas()->internal_private_accessTopLayerD
rawContext(); | 845 GrDrawContext* dc = s->getCanvas()->internal_private_accessTopLayerD
rawContext(); |
| 846 return dc->accessRenderTarget(); }, | 846 return dc->accessRenderTarget(); }, |
| 847 [] (SkSurface* s){ | 847 [] (SkSurface* s){ |
| 848 SkBaseDevice* d = | 848 SkBaseDevice* d = |
| 849 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); | 849 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); |
| 850 return d->accessRenderTarget(); }, | 850 return d->accessRenderTarget(); }, |
| 851 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); | 851 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); |
| 852 return as_IB(i)->peekTexture(); } | 852 return as_IB(i)->peekTexture(); } |
| 853 }; | 853 }; |
| 854 | 854 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 for (int y = kH/2; y < kH && !stop; ++y) { | 906 for (int y = kH/2; y < kH && !stop; ++y) { |
| 907 for (int x = 0; x < kW && !stop; ++x) { | 907 for (int x = 0; x < kW && !stop; ++x) { |
| 908 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]); | 908 REPORTER_ASSERT(reporter, origColorPM == pixels[x + y * kW]); |
| 909 if (origColorPM != pixels[x + y * kW]) { | 909 if (origColorPM != pixels[x + y * kW]) { |
| 910 stop = true; | 910 stop = true; |
| 911 } | 911 } |
| 912 } | 912 } |
| 913 } | 913 } |
| 914 } | 914 } |
| 915 | 915 |
| 916 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo)
{ | 916 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) { |
| 917 GrGpu* gpu = ctxInfo.grContext()->getGpu(); | 917 GrGpu* gpu = ctxInfo.grContext()->getGpu(); |
| 918 if (!gpu) { | 918 if (!gpu) { |
| 919 return; | 919 return; |
| 920 } | 920 } |
| 921 static const uint32_t kOrigColor = 0xFFAABBCC; | 921 static const uint32_t kOrigColor = 0xFFAABBCC; |
| 922 | 922 |
| 923 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, | 923 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, |
| 924 &create_gpu_surface_backend_texture_as_render_targ
et}) { | 924 &create_gpu_surface_backend_texture_as_render_targ
et}) { |
| 925 // Validate that we can draw to the canvas and that the original texture
color is | 925 // Validate that we can draw to the canvas and that the original texture
color is |
| 926 // preserved in pixels that aren't rendered to via the surface. | 926 // preserved in pixels that aren't rendered to via the surface. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 // our surface functions. | 958 // our surface functions. |
| 959 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() | 959 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() |
| 960 ->accessRenderTarget(); | 960 ->accessRenderTarget(); |
| 961 REPORTER_ASSERT(reporter, | 961 REPORTER_ASSERT(reporter, |
| 962 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); | 962 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); |
| 963 gpu->deleteTestingOnlyBackendTexture(textureObject); | 963 gpu->deleteTestingOnlyBackendTexture(textureObject); |
| 964 } | 964 } |
| 965 } | 965 } |
| 966 } | 966 } |
| 967 #endif | 967 #endif |
| OLD | NEW |