2828#include " src/gpu/mtl/GrMtlCppUtil.h"
2929#endif
3030
31- static void delete_backend_texture (GrContext* context, const GrBackendTexture& backendTexture,
32- bool * finishedCreate) {
31+ static void wait_on_backend_work_to_finish (GrContext* context, bool * finishedCreate) {
3332 while (finishedCreate && !(*finishedCreate)) {
3433 context->checkAsyncWorkCompletion ();
3534 }
@@ -39,9 +38,18 @@ static void delete_backend_texture(GrContext* context, const GrBackendTexture& b
3938 // Reset it here so that it can be use to signal a future backend texture's creation
4039 *finishedCreate = false ;
4140 }
41+ }
42+
43+ static void delete_backend_texture (GrContext* context, const GrBackendTexture& backendTexture,
44+ bool * finishedCreate) {
45+ wait_on_backend_work_to_finish (context, finishedCreate);
4246 context->deleteBackendTexture (backendTexture);
4347}
4448
49+ static void mark_signaled (void * context) {
50+ *(bool *)context = true ;
51+ }
52+
4553// Test wrapping of GrBackendObjects in SkSurfaces and SkImages (non-static since used in Mtl test)
4654void test_wrapping (GrContext* context, skiatest::Reporter* reporter,
4755 std::function<GrBackendTexture (GrContext*,
@@ -313,16 +321,35 @@ void test_color_init(GrContext* context, skiatest::Reporter* reporter,
313321 return ;
314322 }
315323
316- if (mipMapped == GrMipMapped::kYes ) {
317- SkColor4f expectedColor = get_expected_color (color, skColorType);
318- SkColor4f expectedColors[6 ] = { expectedColor, expectedColor, expectedColor,
319- expectedColor, expectedColor, expectedColor };
320- check_mipmaps (context, backendTex, skColorType, expectedColors, reporter, " colorinit" );
321- }
324+ auto checkBackendTexture = [&](const SkColor4f& testColor) {
325+ if (mipMapped == GrMipMapped::kYes ) {
326+ SkColor4f expectedColor = get_expected_color (testColor, skColorType);
327+ SkColor4f expectedColors[6 ] = {expectedColor, expectedColor, expectedColor,
328+ expectedColor, expectedColor, expectedColor};
329+ check_mipmaps (context, backendTex, skColorType, expectedColors, reporter, " colorinit" );
330+ }
331+
332+ // The last step in this test will dirty the mipmaps so do it last
333+ check_base_readbacks (context, backendTex, skColorType, renderable, testColor, reporter,
334+ " colorinit" );
335+ };
336+
337+ checkBackendTexture (color);
338+
339+ // Make sure the initial create work has finished so we can test the update independently.
340+ wait_on_backend_work_to_finish (context, finishedBECreate);
341+
342+ SkColor4f newColor = {color.fB , color.fR , color.fG , color.fA };
343+
344+ // Reupload the new data and make sure everything still works. We test with an SkColorType so
345+ // we may actually swizzle the input during the create path. The update does not do any swizzle
346+ // of the passed in color. So we manually do it here so we get the same expected results.
347+ SkColor4f swizzledColor = context->priv ().caps ()->getWriteSwizzle (
348+ backendTex.getBackendFormat (), grColorType).applyTo (newColor);
349+ context->updateBackendTexture (backendTex, swizzledColor, mark_signaled, finishedBECreate);
350+
351+ checkBackendTexture (newColor);
322352
323- // The last step in this test will dirty the mipmaps so do it last
324- check_base_readbacks (context, backendTex, skColorType, renderable, color,
325- reporter, " colorinit" );
326353 delete_backend_texture (context, backendTex, finishedBECreate);
327354}
328355
@@ -461,22 +488,49 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
461488 return ;
462489 }
463490
464- if (mipMapped == GrMipMapped::kYes ) {
465- SkColor4f expectedColors[6 ] = {
466- get_expected_color (colors[0 ], skColorType),
467- get_expected_color (colors[1 ], skColorType),
468- get_expected_color (colors[2 ], skColorType),
469- get_expected_color (colors[3 ], skColorType),
470- get_expected_color (colors[4 ], skColorType),
471- get_expected_color (colors[5 ], skColorType),
472- };
473-
474- check_mipmaps (context, backendTex, skColorType, expectedColors, reporter, " pixmap" );
491+ auto checkBackendTexture = [&](SkColor4f colors[6 ]) {
492+ if (mipMapped == GrMipMapped::kYes ) {
493+ SkColor4f expectedColors[6 ] = {
494+ get_expected_color (colors[0 ], skColorType),
495+ get_expected_color (colors[1 ], skColorType),
496+ get_expected_color (colors[2 ], skColorType),
497+ get_expected_color (colors[3 ], skColorType),
498+ get_expected_color (colors[4 ], skColorType),
499+ get_expected_color (colors[5 ], skColorType),
500+ };
501+
502+ check_mipmaps (context, backendTex, skColorType, expectedColors, reporter, " pixmap" );
503+ }
504+
505+ // The last step in this test will dirty the mipmaps so do it last
506+ check_base_readbacks (context, backendTex, skColorType, renderable, colors[0 ], reporter,
507+ " pixmap" );
508+ };
509+
510+ checkBackendTexture (colors);
511+
512+ // Make sure the initial create work has finished so we can test the update independently.
513+ wait_on_backend_work_to_finish (context, finishedBECreate);
514+
515+ SkColor4f colorsNew[6 ] = {
516+ {1 .0f , 1 .0f , 0 .0f , 0 .2f }, // Y
517+ {1 .0f , 0 .0f , 0 .0f , 1 .0f }, // R
518+ {0 .0f , 1 .0f , 0 .0f , 0 .9f }, // G
519+ {0 .0f , 0 .0f , 1 .0f , 0 .7f }, // B
520+ {0 .0f , 1 .0f , 1 .0f , 0 .5f }, // C
521+ {1 .0f , 0 .0f , 1 .0f , 0 .3f }, // M
522+ };
523+ make_pixmaps (skColorType, mipMapped, colorsNew, pixmapMem);
524+ for (int i = 0 ; i < numMipLevels; ++i) {
525+ pixmaps[i].reset (pixmapMem[i].info (), pixmapMem[i].addr (), pixmapMem[i].rowBytes ());
475526 }
476527
477- // The last step in this test will dirty the mipmaps so do it last
478- check_base_readbacks (context, backendTex, skColorType, renderable, colors[0 ],
479- reporter, " pixmap" );
528+ // Upload new data and make sure everything still works
529+ context->updateBackendTexture (backendTex, pixmaps, numMipLevels, mark_signaled,
530+ finishedBECreate);
531+
532+ checkBackendTexture (colorsNew);
533+
480534 delete_backend_texture (context, backendTex, finishedBECreate);
481535}
482536
@@ -509,10 +563,6 @@ void check_vk_layout(const GrBackendTexture& backendTex, VkLayout layout) {
509563#endif
510564}
511565
512- static void mark_signaled (void * context) {
513- *(bool *)context = true ;
514- }
515-
516566// /////////////////////////////////////////////////////////////////////////////
517567// This test is a bit different from the others in this file. It is mainly checking that, for any
518568// SkSurface we can create in Ganesh, we can also create a backend texture that is compatible with
0 commit comments