2017-01-27 15:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestUtils.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
#include "GrSurfaceContext.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
#include "GrSurfaceContextPriv.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
#include "GrSurfaceProxy.h"
|
2017-03-09 03:21:00 +00:00
|
|
|
#include "GrTextureProxy.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
#include "ProxyUtils.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
void test_read_pixels(skiatest::Reporter* reporter,
|
2017-01-27 15:11:42 +00:00
|
|
|
GrSurfaceContext* srcContext, uint32_t expectedPixelValues[],
|
|
|
|
const char* testName) {
|
|
|
|
int pixelCnt = srcContext->width() * srcContext->height();
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
|
|
|
|
memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(srcContext->width(), srcContext->height(),
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
bool read = srcContext->readPixels(ii, pixels.get(), 0, 0, 0);
|
|
|
|
if (!read) {
|
|
|
|
ERRORF(reporter, "%s: Error reading from texture.", testName);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < pixelCnt; ++i) {
|
|
|
|
if (pixels.get()[i] != expectedPixelValues[i]) {
|
|
|
|
ERRORF(reporter, "%s: Error, pixel value %d should be 0x%08x, got 0x%08x.",
|
|
|
|
testName, i, expectedPixelValues[i], pixels.get()[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
void test_write_pixels(skiatest::Reporter* reporter,
|
2017-01-27 15:11:42 +00:00
|
|
|
GrSurfaceContext* dstContext, bool expectedToWork,
|
|
|
|
const char* testName) {
|
|
|
|
int pixelCnt = dstContext->width() * dstContext->height();
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
|
|
|
|
for (int y = 0; y < dstContext->width(); ++y) {
|
|
|
|
for (int x = 0; x < dstContext->height(); ++x) {
|
|
|
|
pixels.get()[y * dstContext->width() + x] =
|
|
|
|
GrPremulColor(GrColorPackRGBA(x, y, x + y, 2*y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(dstContext->width(), dstContext->height(),
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
bool write = dstContext->writePixels(ii, pixels.get(), 0, 0, 0);
|
|
|
|
if (!write) {
|
|
|
|
if (expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: Error writing to texture.", testName);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write && !expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: writePixels succeeded when it wasn't supposed to.", testName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, dstContext, pixels.get(), testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_copy_from_surface(skiatest::Reporter* reporter, GrContext* context,
|
|
|
|
GrSurfaceProxy* proxy, uint32_t expectedPixelValues[],
|
|
|
|
bool onlyTestRTConfig, const char* testName) {
|
|
|
|
GrSurfaceDesc copyDstDesc;
|
|
|
|
copyDstDesc.fWidth = proxy->width();
|
|
|
|
copyDstDesc.fHeight = proxy->height();
|
2017-07-27 20:16:25 +00:00
|
|
|
copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
2017-01-27 15:11:42 +00:00
|
|
|
|
|
|
|
for (auto flags : { kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag }) {
|
|
|
|
if (kNone_GrSurfaceFlags == flags && onlyTestRTConfig) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
copyDstDesc.fFlags = flags;
|
2018-03-04 03:43:43 +00:00
|
|
|
auto origin = (kNone_GrSurfaceFlags == flags) ? kTopLeft_GrSurfaceOrigin
|
|
|
|
: kBottomLeft_GrSurfaceOrigin;
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrSurfaceContext> dstContext(
|
|
|
|
GrSurfaceProxy::TestCopy(context, copyDstDesc, origin, proxy));
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, dstContext.get(), expectedPixelValues, testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
void test_copy_to_surface(skiatest::Reporter* reporter, GrProxyProvider* proxyProvider,
|
2017-01-27 15:11:42 +00:00
|
|
|
GrSurfaceContext* dstContext, const char* testName) {
|
|
|
|
|
|
|
|
int pixelCnt = dstContext->width() * dstContext->height();
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
|
|
|
|
for (int y = 0; y < dstContext->width(); ++y) {
|
|
|
|
for (int x = 0; x < dstContext->height(); ++x) {
|
|
|
|
pixels.get()[y * dstContext->width() + x] =
|
|
|
|
GrPremulColor(GrColorPackRGBA(y, x, x * y, 2*y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
for (auto isRT : {false, true}) {
|
|
|
|
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
|
|
|
|
auto src = sk_gpu_test::MakeTextureProxyFromData(
|
|
|
|
dstContext->surfPriv().getContext(), isRT, dstContext->width(),
|
|
|
|
dstContext->height(), GrColorType::kRGBA_8888, origin, pixels.get(), 0);
|
|
|
|
dstContext->copy(src.get());
|
|
|
|
test_read_pixels(reporter, dstContext, pixels.get(), testName);
|
|
|
|
}
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|