From a8046af0b0501e53726c01fa5ec2ec6590c79a82 Mon Sep 17 00:00:00 2001 From: Timothy Liang Date: Thu, 19 Jul 2018 09:58:00 -0400 Subject: implemented onWritePixels and related tests for metal gpu backend Bug: skia: Change-Id: Iab8bc8611a9de8afcf0eaeb58a8ef46fdc38d4f1 Reviewed-on: https://skia-review.googlesource.com/140571 Commit-Queue: Timothy Liang Reviewed-by: Greg Daniel --- tests/GrUploadPixelsTests.cpp | 102 ++++++++++++++++++++++++++++++++++++++++ tests/VkUploadPixelsTests.cpp | 107 ------------------------------------------ 2 files changed, 102 insertions(+), 107 deletions(-) create mode 100644 tests/GrUploadPixelsTests.cpp delete mode 100644 tests/VkUploadPixelsTests.cpp (limited to 'tests') diff --git a/tests/GrUploadPixelsTests.cpp b/tests/GrUploadPixelsTests.cpp new file mode 100644 index 0000000000..88a6bc14b6 --- /dev/null +++ b/tests/GrUploadPixelsTests.cpp @@ -0,0 +1,102 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +// This is a GPU-backend specific test. It relies on static intializers to work + +#include "SkTypes.h" + +#include "GrContextFactory.h" +#include "GrContextPriv.h" +#include "GrSurfaceProxy.h" +#include "GrTest.h" +#include "ProxyUtils.h" +#include "SkGr.h" +#include "Test.h" +#include "TestUtils.h" + +using sk_gpu_test::GrContextFactory; + +void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct, + bool renderTarget) { + const int kWidth = 16; + const int kHeight = 16; + SkAutoTMalloc srcBuffer(kWidth*kHeight); + SkAutoTMalloc dstBuffer(kWidth*kHeight); + + fill_pixel_data(kWidth, kHeight, srcBuffer.get()); + + auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct, + kTopLeft_GrSurfaceOrigin, srcBuffer, 0); + REPORTER_ASSERT(reporter, proxy); + if (proxy) { + sk_sp sContext = context->contextPriv().makeWrappedSurfaceContext(proxy); + + SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); + + bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); + REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, + dstBuffer, + kWidth, + kHeight)); + + dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType); + result = sContext->writePixels(dstInfo, srcBuffer, 0, 2, 10); + REPORTER_ASSERT(reporter, result); + + memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); + + result = sContext->readPixels(dstInfo, dstBuffer, 0, 2, 10); + REPORTER_ASSERT(reporter, result); + + REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, + dstBuffer, + 10, + 2)); + } + + proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct, + kBottomLeft_GrSurfaceOrigin, srcBuffer, 0); + REPORTER_ASSERT(reporter, proxy); + if (proxy) { + sk_sp sContext = context->contextPriv().makeWrappedSurfaceContext(proxy); + + SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); + + bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); + REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, + dstBuffer, + kWidth, + kHeight)); + + dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType); + result = sContext->writePixels(dstInfo, srcBuffer, 0, 5, 4); + REPORTER_ASSERT(reporter, result); + + memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); + + result = sContext->readPixels(dstInfo, dstBuffer, 0, 5, 4); + REPORTER_ASSERT(reporter, result); + + REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, + dstBuffer, + 4, + 5)); + + } +} + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrUploadPixelsTests, reporter, ctxInfo) { + // RGBA + basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, false); + basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, true); + + // BGRA + basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, false); + basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, true); +} diff --git a/tests/VkUploadPixelsTests.cpp b/tests/VkUploadPixelsTests.cpp deleted file mode 100644 index b13de41571..0000000000 --- a/tests/VkUploadPixelsTests.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -// This is a GPU-backend specific test. It relies on static intializers to work - -#include "SkTypes.h" - -#if defined(SK_VULKAN) - -#include "GrContextFactory.h" -#include "GrContextPriv.h" -#include "GrSurfaceProxy.h" -#include "GrTest.h" -#include "ProxyUtils.h" -#include "SkGr.h" -#include "Test.h" -#include "TestUtils.h" -#include "vk/GrVkGpu.h" - -using sk_gpu_test::GrContextFactory; - -void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct, - bool renderTarget) { - const int kWidth = 16; - const int kHeight = 16; - SkAutoTMalloc srcBuffer(kWidth*kHeight); - SkAutoTMalloc dstBuffer(kWidth*kHeight); - - fill_pixel_data(kWidth, kHeight, srcBuffer.get()); - - auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct, - kTopLeft_GrSurfaceOrigin, srcBuffer, 0); - REPORTER_ASSERT(reporter, proxy); - if (proxy) { - sk_sp sContext = context->contextPriv().makeWrappedSurfaceContext(proxy); - - SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); - - bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); - REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, - dstBuffer, - kWidth, - kHeight)); - - dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType); - result = sContext->writePixels(dstInfo, srcBuffer, 0, 2, 10); - REPORTER_ASSERT(reporter, result); - - memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); - - result = sContext->readPixels(dstInfo, dstBuffer, 0, 2, 10); - REPORTER_ASSERT(reporter, result); - - REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, - dstBuffer, - 10, - 2)); - } - - proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct, - kBottomLeft_GrSurfaceOrigin, srcBuffer, 0); - REPORTER_ASSERT(reporter, proxy); - if (proxy) { - sk_sp sContext = context->contextPriv().makeWrappedSurfaceContext(proxy); - - SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); - - bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); - REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, - dstBuffer, - kWidth, - kHeight)); - - dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType); - result = sContext->writePixels(dstInfo, srcBuffer, 0, 5, 4); - REPORTER_ASSERT(reporter, result); - - memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); - - result = sContext->readPixels(dstInfo, dstBuffer, 0, 5, 4); - REPORTER_ASSERT(reporter, result); - - REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, - dstBuffer, - 4, - 5)); - - } -} - -DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkUploadPixelsTests, reporter, ctxInfo) { - // RGBA - basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, false); - basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, true); - - // BGRA - basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, false); - basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, true); -} - -#endif -- cgit v1.2.3