| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 DEF_TEST(SurfaceEmpty, reporter) { | 70 DEF_TEST(SurfaceEmpty, reporter) { |
| 71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 72 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); | 72 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); |
| 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); | 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); |
| 74 | 74 |
| 75 } | 75 } |
| 76 #if SK_SUPPORT_GPU | 76 #if SK_SUPPORT_GPU |
| 77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { | 77 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { |
| 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 79 REPORTER_ASSERT(reporter, nullptr == | 79 REPORTER_ASSERT(reporter, nullptr == |
| 80 SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::
kNo, info, 0, | 80 SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::
kNo, info, 0, |
| 81 nullptr)); | 81 nullptr)); |
| 82 } | 82 } |
| 83 #endif | 83 #endif |
| 84 | 84 |
| 85 #if SK_SUPPORT_GPU | 85 #if SK_SUPPORT_GPU |
| 86 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, ctxInfo) { | 86 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, ctxInfo)
{ |
| 87 GrGpu* gpu = ctxInfo.fGrContext->getGpu(); | 87 GrGpu* gpu = ctxInfo.fGrContext->getGpu(); |
| 88 if (!gpu) { | 88 if (!gpu) { |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Test the wrapped factory for SkSurface by creating a backend texture and
then wrap it in | 92 // Test the wrapped factory for SkSurface by creating a backend texture and
then wrap it in |
| 93 // a SkSurface. | 93 // a SkSurface. |
| 94 static const int kW = 100; | 94 static const int kW = 100; |
| 95 static const int kH = 100; | 95 static const int kH = 100; |
| 96 static const uint32_t kOrigColor = 0xFFAABBCC; | 96 static const uint32_t kOrigColor = 0xFFAABBCC; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 DEF_TEST(SurfaceCanvasPeek, reporter) { | 181 DEF_TEST(SurfaceCanvasPeek, reporter) { |
| 182 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 182 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 183 SkImageInfo requestInfo; | 183 SkImageInfo requestInfo; |
| 184 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); | 184 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); |
| 185 test_canvas_peek(reporter, surface, requestInfo, true); | 185 test_canvas_peek(reporter, surface, requestInfo, true); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 #if SK_SUPPORT_GPU | 188 #if SK_SUPPORT_GPU |
| 189 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) { | 189 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo)
{ |
| 190 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 190 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 191 SkImageInfo requestInfo; | 191 SkImageInfo requestInfo; |
| 192 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, &requ
estInfo)); | 192 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, &requ
estInfo)); |
| 193 test_canvas_peek(reporter, surface, requestInfo, false); | 193 test_canvas_peek(reporter, surface, requestInfo, false); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 #endif | 196 #endif |
| 197 | 197 |
| 198 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump | 198 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump |
| 199 // the bitmap's genID when we draw to it, else they won't know it has new values
. When they are | 199 // 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... |
| 212 uint32_t genID1 = bm.getGenerationID(); | 212 uint32_t genID1 = bm.getGenerationID(); |
| 213 REPORTER_ASSERT(reporter, genID0 != genID1); | 213 REPORTER_ASSERT(reporter, genID0 != genID1); |
| 214 } | 214 } |
| 215 DEF_TEST(SurfaceAccessPixels, reporter) { | 215 DEF_TEST(SurfaceAccessPixels, reporter) { |
| 216 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 216 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 217 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); | 217 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); |
| 218 test_access_pixels(reporter, surface); | 218 test_access_pixels(reporter, surface); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 #if SK_SUPPORT_GPU | 221 #if SK_SUPPORT_GPU |
| 222 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo) { | 222 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo
) { |
| 223 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 223 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 224 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 224 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); |
| 225 test_access_pixels(reporter, surface); | 225 test_access_pixels(reporter, surface); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 #endif | 228 #endif |
| 229 | 229 |
| 230 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, | 230 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, |
| 231 bool expectOpaque) { | 231 bool expectOpaque) { |
| 232 REPORTER_ASSERT(reporter, surface); | 232 REPORTER_ASSERT(reporter, surface); |
| 233 if (surface) { | 233 if (surface) { |
| 234 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 234 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 235 REPORTER_ASSERT(reporter, image); | 235 REPORTER_ASSERT(reporter, image); |
| 236 if (image) { | 236 if (image) { |
| 237 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); | 237 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { | 241 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { |
| 242 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 242 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 243 for (auto& isOpaque : { true, false }) { | 243 for (auto& isOpaque : { true, false }) { |
| 244 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 244 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 245 auto surface(surface_func(alphaType, nullptr)); | 245 auto surface(surface_func(alphaType, nullptr)); |
| 246 test_snapshot_alphatype(reporter, surface, isOpaque); | 246 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 #if SK_SUPPORT_GPU | 250 #if SK_SUPPORT_GPU |
| 251 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxIn
fo) { | 251 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ct
xInfo) { |
| 252 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 252 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 253 for (auto& isOpaque : { true, false }) { | 253 for (auto& isOpaque : { true, false }) { |
| 254 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 254 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 255 auto surface(surface_func(ctxInfo.fGrContext, alphaType, nullptr)); | 255 auto surface(surface_func(ctxInfo.fGrContext, alphaType, nullptr)); |
| 256 test_snapshot_alphatype(reporter, surface, isOpaque); | 256 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 #endif | 260 #endif |
| 261 | 261 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 for (auto& handle_access_func : | 293 for (auto& handle_access_func : |
| 294 { &get_surface_backend_texture_handle, &get_surface_backend_render_t
arget_handle }) { | 294 { &get_surface_backend_texture_handle, &get_surface_backend_render_t
arget_handle }) { |
| 295 for (auto& accessMode : accessModes) { | 295 for (auto& accessMode : accessModes) { |
| 296 auto surface(create_surface()); | 296 auto surface(create_surface()); |
| 297 test_backend_handle_access_copy_on_write(reporter, surface.get(), ac
cessMode, | 297 test_backend_handle_access_copy_on_write(reporter, surface.get(), ac
cessMode, |
| 298 handle_access_func); | 298 handle_access_func); |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 #if SK_SUPPORT_GPU | 302 #if SK_SUPPORT_GPU |
| 303 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re
porter, ctxInfo) { | 303 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu,
reporter, ctxInfo) { |
| 304 const SkSurface::BackendHandleAccess accessModes[] = { | 304 const SkSurface::BackendHandleAccess accessModes[] = { |
| 305 SkSurface::kFlushRead_BackendHandleAccess, | 305 SkSurface::kFlushRead_BackendHandleAccess, |
| 306 SkSurface::kFlushWrite_BackendHandleAccess, | 306 SkSurface::kFlushWrite_BackendHandleAccess, |
| 307 SkSurface::kDiscardWrite_BackendHandleAccess, | 307 SkSurface::kDiscardWrite_BackendHandleAccess, |
| 308 }; | 308 }; |
| 309 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 309 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 310 for (auto& handle_access_func : | 310 for (auto& handle_access_func : |
| 311 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { | 311 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { |
| 312 for (auto& accessMode : accessModes) { | 312 for (auto& accessMode : accessModes) { |
| 313 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); | 313 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 391 |
| 392 auto surface(create_surface()); | 392 auto surface(create_surface()); |
| 393 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, | 393 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, |
| 394 getSufaceBackingStore); | 394 getSufaceBackingStore); |
| 395 surface = create_direct_surface(); | 395 surface = create_direct_surface(); |
| 396 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, | 396 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, |
| 397 getSufaceBackingStore); | 397 getSufaceBackingStore); |
| 398 } | 398 } |
| 399 | 399 |
| 400 #if SK_SUPPORT_GPU | 400 #if SK_SUPPORT_GPU |
| 401 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) { | 401 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo
) { |
| 402 GrContext* context = ctxInfo.fGrContext; | 402 GrContext* context = ctxInfo.fGrContext; |
| 403 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 403 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 404 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); | 404 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); |
| 405 | 405 |
| 406 auto imageBackingStore = [reporter](SkImage* image) { | 406 auto imageBackingStore = [reporter](SkImage* image) { |
| 407 GrTexture* texture = as_IB(image)->peekTexture(); | 407 GrTexture* texture = as_IB(image)->peekTexture(); |
| 408 if (!texture) { | 408 if (!texture) { |
| 409 ERRORF(reporter, "Not texture backed."); | 409 ERRORF(reporter, "Not texture backed."); |
| 410 return static_cast<intptr_t>(0); | 410 return static_cast<intptr_t>(0); |
| 411 } | 411 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); | 494 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); |
| 495 | 495 |
| 496 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); | 496 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); |
| 497 REPORTER_ASSERT(reporter, obj != 0); | 497 REPORTER_ASSERT(reporter, obj != 0); |
| 498 sk_sp<SkImage> image3(surface->makeImageSnapshot()); | 498 sk_sp<SkImage> image3(surface->makeImageSnapshot()); |
| 499 // expect a new(er) image, since we claimed we would write | 499 // expect a new(er) image, since we claimed we would write |
| 500 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); | 500 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); |
| 501 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); | 501 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); |
| 502 } | 502 } |
| 503 // No CPU test. | 503 // No CPU test. |
| 504 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
ctxInfo) { | 504 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporte
r, ctxInfo) { |
| 505 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 505 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 506 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { | 506 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { |
| 507 for (auto& handle_access_func : | 507 for (auto& handle_access_func : |
| 508 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { | 508 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { |
| 509 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); | 509 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); |
| 510 test_func(reporter, surface.get(), handle_access_func); | 510 test_func(reporter, surface.get(), handle_access_func); |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 } | 514 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) | 586 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) |
| 587 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ | 587 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ |
| 588 testPaint)) | 588 testPaint)) |
| 589 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ | 589 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ |
| 590 testPaint)) | 590 testPaint)) |
| 591 } | 591 } |
| 592 DEF_TEST(SurfaceCopyOnWrite, reporter) { | 592 DEF_TEST(SurfaceCopyOnWrite, reporter) { |
| 593 test_copy_on_write(reporter, create_surface().get()); | 593 test_copy_on_write(reporter, create_surface().get()); |
| 594 } | 594 } |
| 595 #if SK_SUPPORT_GPU | 595 #if SK_SUPPORT_GPU |
| 596 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) { | 596 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo)
{ |
| 597 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 597 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 598 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 598 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); |
| 599 test_copy_on_write(reporter, surface.get()); | 599 test_copy_on_write(reporter, surface.get()); |
| 600 } | 600 } |
| 601 } | 601 } |
| 602 #endif | 602 #endif |
| 603 | 603 |
| 604 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, | 604 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, |
| 605 SkSurface* surface) { | 605 SkSurface* surface) { |
| 606 // This test succeeds by not triggering an assertion. | 606 // This test succeeds by not triggering an assertion. |
| 607 // The test verifies that the surface remains writable (usable) after | 607 // The test verifies that the surface remains writable (usable) after |
| 608 // acquiring and releasing a snapshot without triggering a copy on write. | 608 // acquiring and releasing a snapshot without triggering a copy on write. |
| 609 SkCanvas* canvas = surface->getCanvas(); | 609 SkCanvas* canvas = surface->getCanvas(); |
| 610 canvas->clear(1); | 610 canvas->clear(1); |
| 611 surface->makeImageSnapshot(); // Create and destroy SkImage | 611 surface->makeImageSnapshot(); // Create and destroy SkImage |
| 612 canvas->clear(2); // Must not assert internally | 612 canvas->clear(2); // Must not assert internally |
| 613 } | 613 } |
| 614 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { | 614 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { |
| 615 test_writable_after_snapshot_release(reporter, create_surface().get()); | 615 test_writable_after_snapshot_release(reporter, create_surface().get()); |
| 616 } | 616 } |
| 617 #if SK_SUPPORT_GPU | 617 #if SK_SUPPORT_GPU |
| 618 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep
orter, ctxInfo) { | 618 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu,
reporter, ctxInfo) { |
| 619 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 619 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 620 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 620 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); |
| 621 test_writable_after_snapshot_release(reporter, surface.get()); | 621 test_writable_after_snapshot_release(reporter, surface.get()); |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 #endif | 624 #endif |
| 625 | 625 |
| 626 #if SK_SUPPORT_GPU | 626 #if SK_SUPPORT_GPU |
| 627 static void test_crbug263329(skiatest::Reporter* reporter, | 627 static void test_crbug263329(skiatest::Reporter* reporter, |
| 628 SkSurface* surface1, | 628 SkSurface* surface1, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 649 canvas2->clear(5); | 649 canvas2->clear(5); |
| 650 sk_sp<SkImage> image4(surface2->makeImageSnapshot()); | 650 sk_sp<SkImage> image4(surface2->makeImageSnapshot()); |
| 651 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); | 651 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); |
| 652 // The following assertion checks crbug.com/263329 | 652 // The following assertion checks crbug.com/263329 |
| 653 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); | 653 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 654 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); | 654 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 655 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); | 655 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 656 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); | 656 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 657 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); | 657 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 658 } | 658 } |
| 659 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) { | 659 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo)
{ |
| 660 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 660 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 661 auto surface1(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null
ptr)); | 661 auto surface1(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null
ptr)); |
| 662 auto surface2(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null
ptr)); | 662 auto surface2(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null
ptr)); |
| 663 test_crbug263329(reporter, surface1.get(), surface2.get()); | 663 test_crbug263329(reporter, surface1.get(), surface2.get()); |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 #endif | 666 #endif |
| 667 | 667 |
| 668 DEF_TEST(SurfaceGetTexture, reporter) { | 668 DEF_TEST(SurfaceGetTexture, reporter) { |
| 669 auto surface(create_surface()); | 669 auto surface(create_surface()); |
| 670 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 670 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 671 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 671 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 672 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 672 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 673 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 673 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 674 } | 674 } |
| 675 #if SK_SUPPORT_GPU | 675 #if SK_SUPPORT_GPU |
| 676 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) { | 676 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo)
{ |
| 677 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 677 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 678 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); | 678 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp
tr)); |
| 679 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 679 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 680 GrTexture* texture = as_IB(image)->peekTexture(); | 680 GrTexture* texture = as_IB(image)->peekTexture(); |
| 681 REPORTER_ASSERT(reporter, texture); | 681 REPORTER_ASSERT(reporter, texture); |
| 682 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 682 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 683 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 683 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 684 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); | 684 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); |
| 685 } | 685 } |
| 686 } | 686 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 698 } | 698 } |
| 699 | 699 |
| 700 static SkBudgeted is_budgeted(SkImage* image) { | 700 static SkBudgeted is_budgeted(SkImage* image) { |
| 701 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); | 701 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); |
| 702 } | 702 } |
| 703 | 703 |
| 704 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { | 704 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { |
| 705 return is_budgeted(image.get()); | 705 return is_budgeted(image.get()); |
| 706 } | 706 } |
| 707 | 707 |
| 708 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) { | 708 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) { |
| 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 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, sbudget
ed, info)); | 712 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, sbudget
ed, info)); |
| 713 SkASSERT(surface); | 713 SkASSERT(surface); |
| 714 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 714 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 715 | 715 |
| 716 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); | 716 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); |
| 717 | 717 |
| 718 // Initially the image shares a texture with the surface, and the su
rface decides | 718 // 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... |
| 760 DEF_TEST(SurfaceNoCanvas, reporter) { | 760 DEF_TEST(SurfaceNoCanvas, reporter) { |
| 761 SkSurface::ContentChangeMode modes[] = | 761 SkSurface::ContentChangeMode modes[] = |
| 762 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 762 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 763 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 763 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 764 for (auto& mode : modes) { | 764 for (auto& mode : modes) { |
| 765 test_func(reporter, create_surface().get(), mode); | 765 test_func(reporter, create_surface().get(), mode); |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 } | 768 } |
| 769 #if SK_SUPPORT_GPU | 769 #if SK_SUPPORT_GPU |
| 770 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) { | 770 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) { |
| 771 SkSurface::ContentChangeMode modes[] = | 771 SkSurface::ContentChangeMode modes[] = |
| 772 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 772 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 773 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 773 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 774 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 774 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 775 for (auto& mode : modes) { | 775 for (auto& mode : modes) { |
| 776 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); | 776 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp
e, nullptr)); |
| 777 test_func(reporter, surface.get(), mode); | 777 test_func(reporter, surface.get(), mode); |
| 778 } | 778 } |
| 779 } | 779 } |
| 780 } | 780 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 } | 851 } |
| 852 ERRORF(reporter, | 852 ERRORF(reporter, |
| 853 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, | 853 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_
str(), pixel, |
| 854 expectedValue, x, y); | 854 expectedValue, x, y); |
| 855 return; | 855 return; |
| 856 } | 856 } |
| 857 } | 857 } |
| 858 } | 858 } |
| 859 } | 859 } |
| 860 | 860 |
| 861 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { | 861 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { |
| 862 GrContext* context = ctxInfo.fGrContext; | 862 GrContext* context = ctxInfo.fGrContext; |
| 863 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { | 863 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { |
| 864 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, | 864 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, |
| 865 [] (SkSurface* s){ | 865 [] (SkSurface* s){ |
| 866 SkBaseDevice* d = | 866 SkBaseDevice* d = |
| 867 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); | 867 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); |
| 868 return d->accessRenderTarget(); }, | 868 return d->accessRenderTarget(); }, |
| 869 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); | 869 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); |
| 870 return as_IB(i)->peekTexture(); }, | 870 return as_IB(i)->peekTexture(); }, |
| 871 }; | 871 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 890 desc.fHeight = kHeight; | 890 desc.fHeight = kHeight; |
| 891 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 891 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 892 desc.fTextureHandle = textureObject; | 892 desc.fTextureHandle = textureObject; |
| 893 | 893 |
| 894 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr)
; | 894 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr)
; |
| 895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); | 895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); |
| 896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 897 } | 897 } |
| 898 } | 898 } |
| 899 #endif | 899 #endif |
| OLD | NEW |