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"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-06-14 15:49:03 +00:00
|
|
|
#include "src/gpu/GrSurfaceContext.h"
|
2019-05-13 14:40:06 +00:00
|
|
|
#include "src/gpu/SkGr.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
|
|
|
GrPixelConfig config = SkColorType2GrPixelConfig(ct);
|
2019-05-17 14:01:21 +00:00
|
|
|
if (!caps->isConfigTexturable(config)) {
|
2018-07-17 17:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-13 14:40:06 +00:00
|
|
|
|
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(ct);
|
|
|
|
if (GrColorType::kUnknown == grCT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
|
|
|
|
if (doDataUpload) {
|
|
|
|
SkASSERT(GrMipMapped::kNo == mipMapped);
|
|
|
|
|
|
|
|
fill_pixel_data(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
|
|
|
|
|
2019-07-01 19:04:06 +00:00
|
|
|
backendTex = context->priv().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 =
|
|
|
|
caps->supportedReadPixelsColorType(config, backendTex.getBackendFormat(), grCT);
|
|
|
|
if (supportedRead.fColorType != grCT || supportedRead.fSwizzle != GrSwizzle("rgba")) {
|
|
|
|
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(
|
|
|
|
backendTex, kTopLeft_GrSurfaceOrigin, 1, kAdopt_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2018-07-17 17:28:20 +00:00
|
|
|
} else {
|
2019-06-14 15:49:03 +00:00
|
|
|
wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
|
|
|
|
backendTex, 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-06-10 19:09:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(expectedPixels.addr32(),
|
|
|
|
actualPixels.addr32(),
|
2018-07-17 17:28:20 +00:00
|
|
|
kWidth, kHeight));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|