2018-07-17 17:28:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-06-10 19:09:34 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrSurfaceContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tests/TestUtils.h"
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
static void testing_only_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
|
|
|
SkColorType ct, GrRenderable renderable, bool doDataUpload,
|
|
|
|
GrMipmapped mipMapped) {
|
2018-07-17 17:28:20 +00:00
|
|
|
const int kWidth = 16;
|
|
|
|
const int kHeight = 16;
|
2019-06-10 19:09:34 +00:00
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
SkAutoPixmapStorage expectedPixels, actualPixels;
|
|
|
|
expectedPixels.alloc(ii);
|
|
|
|
actualPixels.alloc(ii);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
const GrCaps* caps = dContext->priv().caps();
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(ct);
|
2019-07-18 18:28:01 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
GrBackendFormat backendFormat = dContext->defaultBackendFormat(ct, renderable);
|
2019-07-30 16:49:10 +00:00
|
|
|
if (!backendFormat.isValid()) {
|
2019-05-13 14:40:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
|
|
|
|
if (doDataUpload) {
|
2020-07-21 13:27:25 +00:00
|
|
|
SkASSERT(GrMipmapped::kNo == mipMapped);
|
2019-06-10 19:09:34 +00:00
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
|
2019-06-10 19:09:34 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
backendTex = dContext->createBackendTexture(&expectedPixels, 1,
|
|
|
|
renderable, GrProtected::kNo);
|
2019-06-10 19:09:34 +00:00
|
|
|
} else {
|
2020-07-22 13:35:49 +00:00
|
|
|
backendTex = dContext->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
|
|
|
|
mipMapped, renderable, GrProtected::kNo);
|
2019-06-10 19:09:34 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2018-09-25 13:31:10 +00:00
|
|
|
if (!backendTex.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-20 16:25:02 +00:00
|
|
|
// skbug.com/9165
|
|
|
|
auto supportedRead =
|
2019-07-18 18:28:01 +00:00
|
|
|
caps->supportedReadPixelsColorType(grCT, backendTex.getBackendFormat(), grCT);
|
2019-08-01 00:12:02 +00:00
|
|
|
if (supportedRead.fColorType != grCT) {
|
2019-06-20 16:25:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-25 13:31:10 +00:00
|
|
|
|
2019-06-14 15:49:03 +00:00
|
|
|
sk_sp<GrTextureProxy> wrappedProxy;
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2020-07-22 13:35:49 +00:00
|
|
|
wrappedProxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture(
|
2020-06-29 17:05:29 +00:00
|
|
|
backendTex, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
|
2018-07-17 17:28:20 +00:00
|
|
|
} else {
|
2020-07-22 13:35:49 +00:00
|
|
|
wrappedProxy = dContext->priv().proxyProvider()->wrapBackendTexture(
|
2020-03-27 14:42:15 +00:00
|
|
|
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, GrIOType::kRW_GrIOType);
|
2018-07-17 17:28:20 +00:00
|
|
|
}
|
2019-06-14 15:49:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, wrappedProxy);
|
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(),
|
|
|
|
grCT);
|
2020-01-14 14:56:04 +00:00
|
|
|
GrSurfaceProxyView view(std::move(wrappedProxy), kTopLeft_GrSurfaceOrigin, swizzle);
|
2020-07-22 13:35:49 +00:00
|
|
|
auto surfaceContext = GrSurfaceContext::Make(dContext, std::move(view), grCT,
|
2019-12-19 21:41:40 +00:00
|
|
|
kPremul_SkAlphaType, nullptr);
|
2019-06-14 15:49:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, surfaceContext);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
bool result = surfaceContext->readPixels(dContext,
|
|
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight},
|
2019-07-01 17:05:28 +00:00
|
|
|
actualPixels.writable_addr(), actualPixels.rowBytes(),
|
2020-08-11 16:02:22 +00:00
|
|
|
{0, 0});
|
2018-07-17 17:28:20 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
2019-10-25 00:07:39 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
DoesFullBufferContainCorrectColor(expectedPixels.addr32(),
|
|
|
|
actualPixels.addr32(), kWidth, kHeight));
|
2018-07-17 17:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) {
|
2019-05-13 14:40:06 +00:00
|
|
|
for (auto colorType: { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType }) {
|
|
|
|
for (auto renderable: { GrRenderable::kYes, GrRenderable::kNo }) {
|
2018-07-17 17:28:20 +00:00
|
|
|
for (bool doDataUpload: {true, false}) {
|
2020-07-06 14:56:46 +00:00
|
|
|
testing_only_texture_test(reporter, ctxInfo.directContext(), colorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
renderable, doDataUpload, GrMipmapped::kNo);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
|
|
|
if (!doDataUpload) {
|
2020-07-06 14:56:46 +00:00
|
|
|
testing_only_texture_test(reporter, ctxInfo.directContext(), colorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
renderable, doDataUpload, GrMipmapped::kYes);
|
2018-07-17 17:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|