| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 #if SK_SUPPORT_GPU | 121 #if SK_SUPPORT_GPU |
| 122 DEF_GPUTEST_FOR_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 | |
| 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 | |
| 134 // test. | |
| 135 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su
rface) { | |
| 136 SkCanvas* canvas = surface->getCanvas(); | |
| 137 canvas->clear(0); | |
| 138 | |
| 139 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_t
esting(); | |
| 140 SkBitmap bm = device->accessBitmap(false); | |
| 141 uint32_t genID0 = bm.getGenerationID(); | |
| 142 // Now we draw something, which needs to "dirty" the genID (sorta like copy-
on-write) | |
| 143 canvas->drawColor(SK_ColorBLUE); | |
| 144 // Now check that we get a different genID | |
| 145 uint32_t genID1 = bm.getGenerationID(); | |
| 146 REPORTER_ASSERT(reporter, genID0 != genID1); | |
| 147 } | |
| 148 DEF_TEST(SurfaceAccessPixels, reporter) { | |
| 149 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | |
| 150 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); | |
| 151 test_access_pixels(reporter, surface); | |
| 152 } | |
| 153 } | |
| 154 #if SK_SUPPORT_GPU | |
| 155 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo) { | |
| 156 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | |
| 157 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, null
ptr)); | |
| 158 test_access_pixels(reporter, surface); | |
| 159 } | |
| 160 } | |
| 161 #endif | |
| 162 | |
| 163 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, | 131 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, |
| 164 bool expectOpaque) { | 132 bool expectOpaque) { |
| 165 REPORTER_ASSERT(reporter, surface); | 133 REPORTER_ASSERT(reporter, surface); |
| 166 if (surface) { | 134 if (surface) { |
| 167 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 135 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 168 REPORTER_ASSERT(reporter, image); | 136 REPORTER_ASSERT(reporter, image); |
| 169 if (image) { | 137 if (image) { |
| 170 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); | 138 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); |
| 171 } | 139 } |
| 172 } | 140 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 test_unique_image_snap(reporter, surface.get(), true, imageBackingSt
ore, | 341 test_unique_image_snap(reporter, surface.get(), true, imageBackingSt
ore, |
| 374 surfaceBackingStore); | 342 surfaceBackingStore); |
| 375 } | 343 } |
| 376 texture->unref(); | 344 texture->unref(); |
| 377 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 345 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 378 } | 346 } |
| 379 } | 347 } |
| 380 #endif | 348 #endif |
| 381 | 349 |
| 382 #if SK_SUPPORT_GPU | 350 #if SK_SUPPORT_GPU |
| 383 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d
evice! | |
| 384 static uint32_t get_legacy_gen_id(SkSurface* surface) { | |
| 385 SkBaseDevice* device = | |
| 386 surface->getCanvas()->getDevice_just_for_deprecated_compatibility_te
sting(); | |
| 387 return device->accessBitmap(false).getGenerationID(); | |
| 388 } | |
| 389 /* | |
| 390 * Test legacy behavor of bumping the surface's device's bitmap's genID when we
access its | |
| 391 * texture handle for writing. | |
| 392 * | |
| 393 * Note: this needs to be tested separately from checking makeImageSnapshot, as
calling that | |
| 394 * can also incidentally bump the genID (when a new backing surface is created)
. | |
| 395 */ | |
| 396 static void test_backend_handle_gen_id( | |
| 397 skiatest::Reporter* reporter, SkSurface* surface, | |
| 398 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { | |
| 399 const uint32_t gen0 = get_legacy_gen_id(surface); | |
| 400 func(surface, SkSurface::kFlushRead_BackendHandleAccess); | |
| 401 const uint32_t gen1 = get_legacy_gen_id(surface); | |
| 402 REPORTER_ASSERT(reporter, gen0 == gen1); | |
| 403 | 351 |
| 404 func(surface, SkSurface::kFlushWrite_BackendHandleAccess); | |
| 405 const uint32_t gen2 = get_legacy_gen_id(surface); | |
| 406 REPORTER_ASSERT(reporter, gen0 != gen2); | |
| 407 | |
| 408 func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); | |
| 409 const uint32_t gen3 = get_legacy_gen_id(surface); | |
| 410 REPORTER_ASSERT(reporter, gen0 != gen3); | |
| 411 REPORTER_ASSERT(reporter, gen2 != gen3); | |
| 412 } | |
| 413 static void test_backend_handle_unique_id( | 352 static void test_backend_handle_unique_id( |
| 414 skiatest::Reporter* reporter, SkSurface* surface, | 353 skiatest::Reporter* reporter, SkSurface* surface, |
| 415 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { | 354 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { |
| 416 sk_sp<SkImage> image0(surface->makeImageSnapshot()); | 355 sk_sp<SkImage> image0(surface->makeImageSnapshot()); |
| 417 GrBackendObject obj = func(surface, SkSurface::kFlushRead_BackendHandleAcces
s); | 356 GrBackendObject obj = func(surface, SkSurface::kFlushRead_BackendHandleAcces
s); |
| 418 REPORTER_ASSERT(reporter, obj != 0); | 357 REPORTER_ASSERT(reporter, obj != 0); |
| 419 sk_sp<SkImage> image1(surface->makeImageSnapshot()); | 358 sk_sp<SkImage> image1(surface->makeImageSnapshot()); |
| 420 // just read access should not affect the snapshot | 359 // just read access should not affect the snapshot |
| 421 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID()); | 360 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID()); |
| 422 | 361 |
| 423 obj = func(surface, SkSurface::kFlushWrite_BackendHandleAccess); | 362 obj = func(surface, SkSurface::kFlushWrite_BackendHandleAccess); |
| 424 REPORTER_ASSERT(reporter, obj != 0); | 363 REPORTER_ASSERT(reporter, obj != 0); |
| 425 sk_sp<SkImage> image2(surface->makeImageSnapshot()); | 364 sk_sp<SkImage> image2(surface->makeImageSnapshot()); |
| 426 // expect a new image, since we claimed we would write | 365 // expect a new image, since we claimed we would write |
| 427 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); | 366 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); |
| 428 | 367 |
| 429 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); | 368 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); |
| 430 REPORTER_ASSERT(reporter, obj != 0); | 369 REPORTER_ASSERT(reporter, obj != 0); |
| 431 sk_sp<SkImage> image3(surface->makeImageSnapshot()); | 370 sk_sp<SkImage> image3(surface->makeImageSnapshot()); |
| 432 // expect a new(er) image, since we claimed we would write | 371 // expect a new(er) image, since we claimed we would write |
| 433 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); | 372 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); |
| 434 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); | 373 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); |
| 435 } | 374 } |
| 436 // No CPU test. | 375 // No CPU test. |
| 437 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
ctxInfo) { | 376 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
ctxInfo) { |
| 438 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 377 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 }) { | 378 for (auto& test_func : { &test_backend_handle_unique_id }) { |
| 440 for (auto& handle_access_func : | 379 for (auto& handle_access_func : |
| 441 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { | 380 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { |
| 442 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); | 381 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaTy
pe, nullptr)); |
| 443 test_func(reporter, surface.get(), handle_access_func); | 382 test_func(reporter, surface.get(), handle_access_func); |
| 444 } | 383 } |
| 445 } | 384 } |
| 446 } | 385 } |
| 447 } | 386 } |
| 448 #endif | 387 #endif |
| 449 | 388 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // our surface functions. | 905 // our surface functions. |
| 967 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() | 906 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() |
| 968 ->accessRenderTarget(); | 907 ->accessRenderTarget(); |
| 969 REPORTER_ASSERT(reporter, | 908 REPORTER_ASSERT(reporter, |
| 970 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); | 909 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); |
| 971 gpu->deleteTestingOnlyBackendTexture(textureObject); | 910 gpu->deleteTestingOnlyBackendTexture(textureObject); |
| 972 } | 911 } |
| 973 } | 912 } |
| 974 } | 913 } |
| 975 #endif | 914 #endif |
| OLD | NEW |