skia2/tests/GrTestingBackendTextureUploadTest.cpp

105 lines
4.0 KiB
C++
Raw Normal View History

/*
* 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 "src/core/SkAutoPixmapStorage.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct,
GrRenderable renderable, bool doDataUpload, GrMipMapped mipMapped) {
const int kWidth = 16;
const int kHeight = 16;
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
SkAutoPixmapStorage expectedPixels, actualPixels;
expectedPixels.alloc(ii);
actualPixels.alloc(ii);
const GrCaps* caps = context->priv().caps();
GrColorType grCT = SkColorTypeToGrColorType(ct);
GrBackendFormat backendFormat = context->defaultBackendFormat(ct, renderable);
if (!backendFormat.isValid()) {
return;
}
GrBackendTexture backendTex;
if (doDataUpload) {
SkASSERT(GrMipMapped::kNo == mipMapped);
FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
backendTex = context->createBackendTexture(&expectedPixels, 1,
renderable, GrProtected::kNo);
} else {
backendTex = context->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
mipMapped, renderable, GrProtected::kNo);
size_t allocSize = SkAutoPixmapStorage::AllocSize(ii, nullptr);
// createBackendTexture will fill the texture with 0's if no data is provided, so
// we set the expected result likewise.
memset(expectedPixels.writable_addr32(0, 0), 0, allocSize);
}
if (!backendTex.isValid()) {
return;
}
// skbug.com/9165
auto supportedRead =
caps->supportedReadPixelsColorType(grCT, backendTex.getBackendFormat(), grCT);
Reland "Remove GrCaps::SupportedRead::fSwizzle and supporting code" This reverts commit a0f864d6acda0d526d3901d0d26e9393aee04115. Reason for revert: updated valgrind suppression EXTRA_TRYBOTS=Test-Ubuntu18-GCC-Golo-GPU-QuadroP400-x86_64-Release-All-Valgrind_SK_CPU_LIMIT_SSE41 Original change's description: > Revert "Remove GrCaps::SupportedRead::fSwizzle and supporting code" > > This reverts commit 1cec69ae5cdc2c183f6a2115d60ebdf796a89a92. > > Reason for revert: Causing Valgrind failures > > Original change's description: > > Remove GrCaps::SupportedRead::fSwizzle and supporting code > > > > Add weird color types that handle the swizzling. > > > > Change-Id: Ie37a00eb877fe5e519f7498bf749e02a2f1dc204 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230135 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com > > Change-Id: I710e1952f2cef1a1e6e7ccf408b8a71ce721c002 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231262 > Reviewed-by: Ben Wagner aka dogben <benjaminwagner@google.com> > Commit-Queue: Ben Wagner aka dogben <benjaminwagner@google.com> TBR=egdaniel@google.com,bsalomon@google.com,benjaminwagner@google.com Change-Id: I367f62ba7349b112d0a2eb5340a37be938ad5ef5 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231178 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
2019-08-01 00:12:02 +00:00
if (supportedRead.fColorType != grCT) {
return;
}
sk_sp<GrTextureProxy> wrappedProxy;
if (GrRenderable::kYes == renderable) {
wrappedProxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
backendTex, kTopLeft_GrSurfaceOrigin, 1, grCT, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo);
} else {
wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
backendTex, grCT, kTopLeft_GrSurfaceOrigin, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo, GrIOType::kRW_GrIOType);
}
REPORTER_ASSERT(reporter, wrappedProxy);
auto surfaceContext = GrSurfaceContext::Make(context, std::move(wrappedProxy), grCT,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, surfaceContext);
bool result = surfaceContext->readPixels({grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight},
actualPixels.writable_addr(), actualPixels.rowBytes(),
{0, 0}, context);
REPORTER_ASSERT(reporter, result);
REPORTER_ASSERT(reporter,
DoesFullBufferContainCorrectColor(expectedPixels.addr32(),
actualPixels.addr32(), kWidth, kHeight));
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) {
for (auto colorType: { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType }) {
for (auto renderable: { GrRenderable::kYes, GrRenderable::kNo }) {
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);
}
}
}
}
}