From 36848f6b30ddaca461c98e13b9976b2c449ca547 Mon Sep 17 00:00:00 2001 From: Timothy Liang Date: Fri, 13 Jul 2018 13:24:05 -0400 Subject: implemented metal gpu backend texture upload testing Bug: skia: Change-Id: Ia3af58a0710f7f9792b37682a3cc45dd14282b71 Reviewed-on: https://skia-review.googlesource.com/140248 Commit-Queue: Timothy Liang Reviewed-by: Greg Daniel --- tests/GrTestingBackendTextureUploadTest.cpp | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/GrTestingBackendTextureUploadTest.cpp (limited to 'tests/GrTestingBackendTextureUploadTest.cpp') diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp new file mode 100644 index 0000000000..1bdd455d67 --- /dev/null +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkTypes.h" + +#include "GrGpu.h" +#include "GrContextPriv.h" +#include "GrTexture.h" +#include "SkConvertPixels.h" +#include "Test.h" +#include "TestUtils.h" + +void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, GrColorType ct, + bool renderTarget, bool doDataUpload, GrMipMapped mipMapped) { + const int kWidth = 16; + const int kHeight = 16; + SkAutoTMalloc srcBuffer; + if (doDataUpload) { + srcBuffer.reset(kWidth * kHeight); + fill_pixel_data(kWidth, kHeight, srcBuffer.get()); + } + SkAutoTMalloc dstBuffer(kWidth * kHeight); + + GrGpu* gpu = context->contextPriv().getGpu(); + + GrPixelConfig config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo); + if (!gpu->caps()->isConfigTexturable(config)) { + return; + } + + GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(srcBuffer, + kWidth, + kHeight, + config, + renderTarget, + mipMapped); + sk_sp wrappedTex; + if (renderTarget) { + wrappedTex = gpu->wrapRenderableBackendTexture(backendTex, 1, + GrWrapOwnership::kAdopt_GrWrapOwnership); + } else { + wrappedTex = gpu->wrapBackendTexture(backendTex, + GrWrapOwnership::kAdopt_GrWrapOwnership); + } + REPORTER_ASSERT(reporter, wrappedTex); + + int rowBytes = GrColorTypeBytesPerPixel(ct) * kWidth; + bool result = gpu->readPixels(wrappedTex.get(), 0, 0, kWidth, + kHeight, ct, dstBuffer, rowBytes); + + if (!doDataUpload) { + // createTestingOnlyBackendTexture will fill the texture with 0's if no data is provided, so + // we set the expected result likewise. + srcBuffer.reset(kWidth * kHeight); + memset(srcBuffer, 0, kWidth * kHeight * sizeof(GrColor)); + } + REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, dstBuffer, + kWidth, kHeight)); +} + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) { + for (auto colorType: {GrColorType::kRGBA_8888, GrColorType::kBGRA_8888}) { + for (bool renderable: {true, false}) { + for (bool doDataUpload: {true, false}) { + testing_only_texture_test(reporter, ctxInfo.grContext(), colorType, + renderable, doDataUpload, GrMipMapped::kNo); + + if (!doDataUpload) { + testing_only_texture_test(reporter, ctxInfo.grContext(), colorType, + renderable, doDataUpload, GrMipMapped::kYes); + } + } + } + } +} + -- cgit v1.2.3