2016-02-22 14:56:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tests/TestUtils.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2016-02-22 14:56:40 +00:00
|
|
|
|
2016-03-31 15:08:20 +00:00
|
|
|
using sk_gpu_test::GrContextFactory;
|
2016-02-22 14:56:40 +00:00
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct,
|
2019-05-13 14:40:06 +00:00
|
|
|
GrRenderable renderable) {
|
2016-02-22 14:56:40 +00:00
|
|
|
const int kWidth = 16;
|
|
|
|
const int kHeight = 16;
|
|
|
|
SkAutoTMalloc<GrColor> srcBuffer(kWidth*kHeight);
|
|
|
|
SkAutoTMalloc<GrColor> dstBuffer(kWidth*kHeight);
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
FillPixelData(kWidth, kHeight, srcBuffer.get());
|
2016-02-22 14:56:40 +00:00
|
|
|
|
2019-10-21 19:04:52 +00:00
|
|
|
auto grCT = SkColorTypeToGrColorType(ct);
|
|
|
|
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
|
|
|
|
context, renderable, kTopLeft_GrSurfaceOrigin,
|
|
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
2017-05-22 18:00:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
2017-04-17 11:43:27 +00:00
|
|
|
if (proxy) {
|
2019-12-19 21:41:40 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct),
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
bool result = sContext->readPixels(dstInfo, dstBuffer, 0, {0, 0});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
2019-10-25 00:07:39 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, kWidth, kHeight));
|
2016-02-22 14:56:40 +00:00
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType);
|
2019-07-01 17:05:28 +00:00
|
|
|
result = sContext->writePixels(dstInfo, srcBuffer, 0, {2, 10});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
2017-04-14 16:51:55 +00:00
|
|
|
|
2017-04-14 17:56:08 +00:00
|
|
|
memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
result = sContext->readPixels(dstInfo, dstBuffer, 0, {2, 10});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 10, 2));
|
2016-02-22 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 19:04:52 +00:00
|
|
|
proxy = sk_gpu_test::MakeTextureProxyFromData(
|
|
|
|
context, renderable, kBottomLeft_GrSurfaceOrigin,
|
|
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
2017-05-22 18:00:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
2017-04-17 11:43:27 +00:00
|
|
|
if (proxy) {
|
2019-12-19 21:41:40 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct),
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
bool result = sContext->readPixels(dstInfo, dstBuffer, 0, {0, 0});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
2019-10-25 00:07:39 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, kWidth, kHeight));
|
2016-02-22 14:56:40 +00:00
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType);
|
2019-07-01 17:05:28 +00:00
|
|
|
result = sContext->writePixels(dstInfo, srcBuffer, 0, {5, 4});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
2017-04-14 16:51:55 +00:00
|
|
|
|
2017-04-14 17:56:08 +00:00
|
|
|
memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
result = sContext->readPixels(dstInfo, dstBuffer, 0, {5, 4});
|
2017-04-17 11:43:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 4, 5));
|
2016-02-22 14:56:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:58:00 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrUploadPixelsTests, reporter, ctxInfo) {
|
2017-04-17 11:43:27 +00:00
|
|
|
// RGBA
|
2019-05-13 14:40:06 +00:00
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kNo);
|
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kYes);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
|
|
|
// BGRA
|
2019-05-13 14:40:06 +00:00
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kNo);
|
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kYes);
|
2016-02-22 14:56:40 +00:00
|
|
|
}
|