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.
|
|
|
|
*/
|
|
|
|
|
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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tests/TestUtils.h"
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, 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
|
|
|
|
2019-05-17 14:01:21 +00:00
|
|
|
const GrCaps* caps = context->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
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat backendFormat = context->defaultBackendFormat(ct, renderable);
|
|
|
|
if (!backendFormat.isValid()) {
|
2019-05-13 14:40:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
|
|
|
|
if (doDataUpload) {
|
|
|
|
SkASSERT(GrMipMapped::kNo == mipMapped);
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
|
2019-06-10 19:09:34 +00:00
|
|
|
|
2019-09-30 17:21:25 +00:00
|
|
|
backendTex = context->createBackendTexture(&expectedPixels, 1,
|
|
|
|
renderable, GrProtected::kNo);
|
2019-06-10 19:09:34 +00:00
|
|
|
} else {
|
|
|
|
backendTex = context->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
|
2019-07-01 19:04:06 +00:00
|
|
|
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) {
|
2019-06-14 15:49:03 +00:00
|
|
|
wrappedProxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
|
2019-07-16 11:47:56 +00:00
|
|
|
backendTex, kTopLeft_GrSurfaceOrigin, 1, grCT, kAdopt_GrWrapOwnership,
|
2019-06-14 15:49:03 +00:00
|
|
|
GrWrapCacheable::kNo);
|
2018-07-17 17:28:20 +00:00
|
|
|
} else {
|
2019-06-14 15:49:03 +00:00
|
|
|
wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
|
2019-07-23 14:27:09 +00:00
|
|
|
backendTex, grCT, kTopLeft_GrSurfaceOrigin, 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);
|
|
|
|
|
2019-06-24 19:50:07 +00:00
|
|
|
auto surfaceContext = context->priv().makeWrappedSurfaceContext(std::move(wrappedProxy), grCT,
|
2019-06-24 16:12:36 +00:00
|
|
|
kPremul_SkAlphaType);
|
2019-06-14 15:49:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, surfaceContext);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
bool result = surfaceContext->readPixels({grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight},
|
|
|
|
actualPixels.writable_addr(), actualPixels.rowBytes(),
|
|
|
|
{0, 0}, context);
|
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}) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|