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"
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.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/GrSurfaceContext.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
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext, 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);
|
2020-08-12 18:06:50 +00:00
|
|
|
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext, renderable, kTopLeft_GrSurfaceOrigin,
|
2019-10-21 19:04:52 +00:00
|
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
2020-08-12 18:06:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, view);
|
|
|
|
if (view) {
|
2020-08-11 16:02:22 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
|
2020-01-14 14:56:04 +00:00
|
|
|
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
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
bool result = sContext->readPixels(dContext, 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);
|
2020-08-11 16:02:22 +00:00
|
|
|
result = sContext->writePixels(dContext, 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
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
result = sContext->readPixels(dContext, 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
|
|
|
}
|
|
|
|
|
2020-08-12 18:06:50 +00:00
|
|
|
view = sk_gpu_test::MakeTextureProxyViewFromData(
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext, renderable, kBottomLeft_GrSurfaceOrigin,
|
2019-10-21 19:04:52 +00:00
|
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
2020-08-12 18:06:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, view);
|
|
|
|
if (view) {
|
2020-08-11 16:02:22 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
|
2020-01-14 14:56:04 +00:00
|
|
|
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
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
bool result = sContext->readPixels(dContext, 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);
|
2020-08-11 16:02:22 +00:00
|
|
|
result = sContext->writePixels(dContext, 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
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
result = sContext->readPixels(dContext, 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) {
|
2020-07-01 20:09:43 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
|
2017-04-17 11:43:27 +00:00
|
|
|
// RGBA
|
2020-07-01 20:09:43 +00:00
|
|
|
basic_texture_test(reporter, direct, kRGBA_8888_SkColorType, GrRenderable::kNo);
|
|
|
|
basic_texture_test(reporter, direct, kRGBA_8888_SkColorType, GrRenderable::kYes);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
|
|
|
// BGRA
|
2020-07-01 20:09:43 +00:00
|
|
|
basic_texture_test(reporter, direct, kBGRA_8888_SkColorType, GrRenderable::kNo);
|
|
|
|
basic_texture_test(reporter, direct, kBGRA_8888_SkColorType, GrRenderable::kYes);
|
2016-02-22 14:56:40 +00:00
|
|
|
}
|