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"
|
|
|
|
|
2018-05-31 18:27:17 +00:00
|
|
|
#if defined(SK_VULKAN)
|
2016-02-22 14:56:40 +00:00
|
|
|
|
|
|
|
#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"
|
2016-02-22 14:56:40 +00:00
|
|
|
#include "GrTest.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"
|
|
|
|
#include "vk/GrVkGpu.h"
|
|
|
|
|
2016-03-31 15:08:20 +00:00
|
|
|
using sk_gpu_test::GrContextFactory;
|
2016-02-22 14:56:40 +00:00
|
|
|
|
|
|
|
void fill_pixel_data(int width, int height, GrColor* data) {
|
|
|
|
|
|
|
|
// build red-green gradient
|
|
|
|
for (int j = 0; j < height; ++j) {
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
unsigned int red = (unsigned int)(256.f*(i / (float)width));
|
|
|
|
unsigned int green = (unsigned int)(256.f*(j / (float)height));
|
|
|
|
data[i + j*width] = GrColorPackRGBA(red - (red>>8), green - (green>>8), 0xff, 0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool does_full_buffer_contain_correct_color(GrColor* srcBuffer,
|
|
|
|
GrColor* dstBuffer,
|
|
|
|
int width,
|
|
|
|
int height) {
|
|
|
|
GrColor* srcPtr = srcBuffer;
|
|
|
|
GrColor* dstPtr = dstBuffer;
|
|
|
|
for (int j = 0; j < height; ++j) {
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
if (srcPtr[i] != dstPtr[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srcPtr += width;
|
|
|
|
dstPtr += width;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 21:21:33 +00:00
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkUploadPixelsTests, 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
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|