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-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/core/SkConvertPixels.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.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;
|
|
|
|
SkAutoTMalloc<GrColor> srcBuffer;
|
|
|
|
if (doDataUpload) {
|
|
|
|
srcBuffer.reset(kWidth * kHeight);
|
|
|
|
fill_pixel_data(kWidth, kHeight, srcBuffer.get());
|
|
|
|
}
|
|
|
|
SkAutoTMalloc<GrColor> dstBuffer(kWidth * kHeight);
|
|
|
|
|
2019-05-17 14:01:21 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
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-05-17 14:01:21 +00:00
|
|
|
if (caps->supportedReadPixelsColorType(config, grCT) != grCT) {
|
2018-07-17 17:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
|
|
|
kWidth, kHeight, ct,
|
|
|
|
mipMapped, renderable, srcBuffer);
|
2018-09-25 13:31:10 +00:00
|
|
|
if (!backendTex.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:28:20 +00:00
|
|
|
sk_sp<GrTexture> wrappedTex;
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2019-01-24 21:03:07 +00:00
|
|
|
wrappedTex = gpu->wrapRenderableBackendTexture(
|
|
|
|
backendTex, 1, GrWrapOwnership::kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
|
2018-07-17 17:28:20 +00:00
|
|
|
} else {
|
2018-12-06 15:00:03 +00:00
|
|
|
wrappedTex = gpu->wrapBackendTexture(backendTex, GrWrapOwnership::kAdopt_GrWrapOwnership,
|
2019-01-24 21:03:07 +00:00
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-07-17 17:28:20 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, wrappedTex);
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
int rowBytes = GrColorTypeBytesPerPixel(grCT) * kWidth;
|
2018-07-17 17:28:20 +00:00
|
|
|
bool result = gpu->readPixels(wrappedTex.get(), 0, 0, kWidth,
|
2019-05-13 14:40:06 +00:00
|
|
|
kHeight, grCT, dstBuffer, rowBytes);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
|
|
|
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) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|