| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_GL_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.fGrContext, 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, |
| 90 bool expectPeekSuccess) { | 90 bool expectPeekSuccess) { |
| 91 const SkColor color = SK_ColorRED; | 91 const SkColor color = SK_ColorRED; |
| 92 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 92 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 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_GL_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.fGrContext, kPremul_SkAlphaType, &requ
estInfo)); | 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 |
| 133 // exclusively using surface/image, and we can hide accessBitmap from device, we
can remove this | 133 // exclusively using surface/image, and we can hide accessBitmap from device, we
can remove this |
| 134 // test. | 134 // test. |
| 135 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su
rface) { | 135 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su
rface) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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_GL_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.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 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()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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_GL_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ct
xInfo) { |
| 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.fGrContext, 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 |
| 195 static GrBackendObject get_surface_backend_texture_handle( | 195 static GrBackendObject get_surface_backend_texture_handle( |
| 196 SkSurface* s, SkSurface::BackendHandleAccess a) { | 196 SkSurface* s, SkSurface::BackendHandleAccess a) { |
| 197 return s->getTextureHandle(a); | 197 return s->getTextureHandle(a); |
| 198 } | 198 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re
porter, ctxInfo) { | 236 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re
porter, ctxInfo) { |
| 237 const SkSurface::BackendHandleAccess accessModes[] = { | 237 const SkSurface::BackendHandleAccess accessModes[] = { |
| 238 SkSurface::kFlushRead_BackendHandleAccess, | 238 SkSurface::kFlushRead_BackendHandleAccess, |
| 239 SkSurface::kFlushWrite_BackendHandleAccess, | 239 SkSurface::kFlushWrite_BackendHandleAccess, |
| 240 SkSurface::kDiscardWrite_BackendHandleAccess, | 240 SkSurface::kDiscardWrite_BackendHandleAccess, |
| 241 }; | 241 }; |
| 242 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 242 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 243 for (auto& handle_access_func : | 243 for (auto& handle_access_func : |
| 244 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { | 244 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { |
| 245 for (auto& accessMode : accessModes) { | 245 for (auto& accessMode : accessModes) { |
| 246 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); | 246 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); |
| 247 test_backend_handle_access_copy_on_write(reporter, surface.get()
, accessMode, | 247 test_backend_handle_access_copy_on_write(reporter, surface.get()
, accessMode, |
| 248 handle_access_func); | 248 handle_access_func); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 #endif | 253 #endif |
| 254 | 254 |
| 255 static bool same_image(SkImage* a, SkImage* b, | 255 static bool same_image(SkImage* a, SkImage* b, |
| 256 std::function<intptr_t(SkImage*)> getImageBackingStore) { | 256 std::function<intptr_t(SkImage*)> getImageBackingStore) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 auto surface(create_surface()); | 325 auto surface(create_surface()); |
| 326 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, | 326 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, |
| 327 getSufaceBackingStore); | 327 getSufaceBackingStore); |
| 328 surface = create_direct_surface(); | 328 surface = create_direct_surface(); |
| 329 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, | 329 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, |
| 330 getSufaceBackingStore); | 330 getSufaceBackingStore); |
| 331 } | 331 } |
| 332 | 332 |
| 333 #if SK_SUPPORT_GPU | 333 #if SK_SUPPORT_GPU |
| 334 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) { | 334 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) { |
| 335 GrContext* context = ctxInfo.fGrContext; | 335 GrContext* context = ctxInfo.grContext(); |
| 336 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 336 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 337 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); | 337 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); |
| 338 | 338 |
| 339 auto imageBackingStore = [reporter](SkImage* image) { | 339 auto imageBackingStore = [reporter](SkImage* image) { |
| 340 GrTexture* texture = as_IB(image)->peekTexture(); | 340 GrTexture* texture = as_IB(image)->peekTexture(); |
| 341 if (!texture) { | 341 if (!texture) { |
| 342 ERRORF(reporter, "Not texture backed."); | 342 ERRORF(reporter, "Not texture backed."); |
| 343 return static_cast<intptr_t>(0); | 343 return static_cast<intptr_t>(0); |
| 344 } | 344 } |
| 345 return static_cast<intptr_t>(texture->getUniqueID()); | 345 return static_cast<intptr_t>(texture->getUniqueID()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // expect a new(er) image, since we claimed we would write | 432 // expect a new(er) image, since we claimed we would write |
| 433 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); | 433 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); |
| 434 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); | 434 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); |
| 435 } | 435 } |
| 436 // No CPU test. | 436 // No CPU test. |
| 437 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
ctxInfo) { | 437 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
ctxInfo) { |
| 438 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 438 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 439 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { | 439 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { |
| 440 for (auto& handle_access_func : | 440 for (auto& handle_access_func : |
| 441 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { | 441 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { |
| 442 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); | 442 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); |
| 443 test_func(reporter, surface.get(), handle_access_func); | 443 test_func(reporter, surface.get(), handle_access_func); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 #endif | 448 #endif |
| 449 | 449 |
| 450 // Verify that the right canvas commands trigger a copy on write. | 450 // Verify that the right canvas commands trigger a copy on write. |
| 451 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface)
{ | 451 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface)
{ |
| 452 SkCanvas* canvas = surface->getCanvas(); | 452 SkCanvas* canvas = surface->getCanvas(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_GL_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.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 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_GL_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu,
reporter, 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.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 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, |
| 562 SkSurface* surface2) { | 562 SkSurface* surface2) { |
| 563 // This is a regression test for crbug.com/263329 | 563 // This is a regression test for crbug.com/263329 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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_GL_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.fGrContext, kPremul_SkAlphaType, null
ptr)); | 594 auto surface1(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nul
lptr)); |
| 595 auto surface2(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null
ptr)); | 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_GL_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.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 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 } |
| 620 #endif | 620 #endif |
| 621 | 621 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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_GL_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.fGrContext, sbudget
ed, 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 |
| 652 // whether it is budgeted or not. | 652 // whether it is budgeted or not. |
| 653 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 653 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 654 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); | 654 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); |
| 655 | 655 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_GL_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.fGrContext, kPremul_SkAlphaTyp
e, 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 } |
| 714 } | 714 } |
| 715 #endif | 715 #endif |
| 716 | 716 |
| 717 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor
ter* reporter) { | 717 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor
ter* reporter) { |
| 718 SkPixmap surfacePM; | 718 SkPixmap surfacePM; |
| 719 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); | 719 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 ERRORF(reporter, | 831 ERRORF(reporter, |
| 832 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, | 832 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, |
| 833 expectedValue, x, y); | 833 expectedValue, x, y); |
| 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.fGrContext; | 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()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_GL_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo)
{ |
| 917 GrGpu* gpu = ctxInfo.fGrContext->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. |
| 927 // This works only for non-multisampled case. | 927 // This works only for non-multisampled case. |
| 928 GrBackendObject textureObject; | 928 GrBackendObject textureObject; |
| 929 auto surface = surfaceFunc(ctxInfo.fGrContext, 0, kOrigColor, &textureOb
ject); | 929 auto surface = surfaceFunc(ctxInfo.grContext(), 0, kOrigColor, &textureO
bject); |
| 930 if (surface) { | 930 if (surface) { |
| 931 test_surface_draw_partially(reporter, surface, kOrigColor); | 931 test_surface_draw_partially(reporter, surface, kOrigColor); |
| 932 surface.reset(); | 932 surface.reset(); |
| 933 gpu->deleteTestingOnlyBackendTexture(textureObject); | 933 gpu->deleteTestingOnlyBackendTexture(textureObject); |
| 934 } | 934 } |
| 935 } | 935 } |
| 936 } | 936 } |
| 937 | 937 |
| 938 | 938 |
| 939 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf
o) { | 939 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf
o) { |
| 940 GrGpu* gpu = ctxInfo.fGrContext->getGpu(); | 940 GrGpu* gpu = ctxInfo.grContext()->getGpu(); |
| 941 if (!gpu) { | 941 if (!gpu) { |
| 942 return; | 942 return; |
| 943 } | 943 } |
| 944 static const uint32_t kOrigColor = 0xFFAABBCC; | 944 static const uint32_t kOrigColor = 0xFFAABBCC; |
| 945 | 945 |
| 946 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, | 946 for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, |
| 947 &create_gpu_surface_backend_texture_as_render_targ
et}) { | 947 &create_gpu_surface_backend_texture_as_render_targ
et}) { |
| 948 for (int sampleCnt : {0, 4, 8}) { | 948 for (int sampleCnt : {0, 4, 8}) { |
| 949 GrBackendObject textureObject; | 949 GrBackendObject textureObject; |
| 950 auto surface = surfaceFunc(ctxInfo.fGrContext, sampleCnt, kOrigColor
, &textureObject); | 950 auto surface = surfaceFunc(ctxInfo.grContext(), sampleCnt, kOrigColo
r, &textureObject); |
| 951 | 951 |
| 952 if (!surface && sampleCnt > 0) { | 952 if (!surface && sampleCnt > 0) { |
| 953 // Certain platforms don't support MSAA, skip these. | 953 // Certain platforms don't support MSAA, skip these. |
| 954 continue; | 954 continue; |
| 955 } | 955 } |
| 956 | 956 |
| 957 // Validate that we can attach a stencil buffer to an SkSurface crea
ted by either of | 957 // Validate that we can attach a stencil buffer to an SkSurface crea
ted by either of |
| 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.fGrContext->resourceProvider()->attachStenci
lAttachment(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 |