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
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include "GrContextFactory.h"
|
2017-04-06 11:59:41 +00:00
|
|
|
#include "GrContextPriv.h"
|
2017-04-17 11:43:27 +00:00
|
|
|
#include "GrSurfaceProxy.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
#include "ProxyUtils.h"
|
2017-04-17 11:43:27 +00:00
|
|
|
#include "SkGr.h"
|
2016-02-22 14:56:40 +00:00
|
|
|
#include "Test.h"
|
2018-07-17 17:28:20 +00:00
|
|
|
#include "TestUtils.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,
|
2017-05-22 18:00:07 +00:00
|
|
|
bool renderTarget) {
|
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);
|
|
|
|
|
|
|
|
fill_pixel_data(kWidth, kHeight, srcBuffer.get());
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct,
|
|
|
|
kTopLeft_GrSurfaceOrigin, srcBuffer, 0);
|
2017-05-22 18:00:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
2017-04-17 11:43:27 +00:00
|
|
|
if (proxy) {
|
2018-01-31 14:29:48 +00:00
|
|
|
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(proxy);
|
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
|
|
|
|
|
|
|
bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
2016-02-22 14:56:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
|
|
|
|
dstBuffer,
|
|
|
|
kWidth,
|
|
|
|
kHeight));
|
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType);
|
2017-04-17 11:43:27 +00:00
|
|
|
result = sContext->writePixels(dstInfo, srcBuffer, 0, 2, 10);
|
|
|
|
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
|
|
|
|
|
|
|
result = sContext->readPixels(dstInfo, dstBuffer, 0, 2, 10);
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2016-02-22 14:56:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
|
|
|
|
dstBuffer,
|
|
|
|
10,
|
|
|
|
2));
|
|
|
|
}
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderTarget, kWidth, kHeight, ct,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, srcBuffer, 0);
|
2017-05-22 18:00:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
2017-04-17 11:43:27 +00:00
|
|
|
if (proxy) {
|
2018-01-31 14:29:48 +00:00
|
|
|
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(proxy);
|
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
|
|
|
|
|
|
|
bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
2016-02-22 14:56:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
|
|
|
|
dstBuffer,
|
|
|
|
kWidth,
|
|
|
|
kHeight));
|
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType);
|
2017-04-17 11:43:27 +00:00
|
|
|
result = sContext->writePixels(dstInfo, srcBuffer, 0, 5, 4);
|
|
|
|
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
|
|
|
|
|
|
|
result = sContext->readPixels(dstInfo, dstBuffer, 0, 5, 4);
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2016-02-22 14:56:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
|
|
|
|
dstBuffer,
|
|
|
|
4,
|
|
|
|
5));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2018-03-07 18:01:25 +00:00
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, false);
|
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, true);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
|
|
|
// BGRA
|
2018-03-07 18:01:25 +00:00
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, false);
|
|
|
|
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, true);
|
2016-02-22 14:56:40 +00:00
|
|
|
}
|