2016-08-15 17:59:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 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 straightforward test of using packed pixel configs (4444, 565).
|
|
|
|
* This test will make sure that these RGBA_4444 and RGB_565 are always supported
|
|
|
|
* as valid texturing configs.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2016-08-15 17:59:17 +00:00
|
|
|
|
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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.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/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2016-08-15 17:59:17 +00:00
|
|
|
|
|
|
|
static const int DEV_W = 10, DEV_H = 10;
|
|
|
|
static const uint8_t TOL = 0x4;
|
|
|
|
|
|
|
|
static void check_component(skiatest::Reporter* reporter, uint8_t control, uint8_t test) {
|
|
|
|
uint8_t diff = 0;
|
|
|
|
if (control >= test) {
|
|
|
|
diff = control - test;
|
|
|
|
} else {
|
|
|
|
diff = test - control;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, diff < TOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t expand_value(uint8_t original, int sigBits) {
|
|
|
|
SkASSERT(sigBits >= 4);
|
|
|
|
uint8_t inSigBitShift = 8 - sigBits;
|
|
|
|
uint8_t duplBitShift = sigBits - inSigBitShift;
|
|
|
|
return (original << inSigBitShift) + (original >> duplBitShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_4444(skiatest::Reporter* reporter,
|
|
|
|
const SkTDArray<uint16_t>& controlData,
|
|
|
|
const SkTDArray<uint32_t>& readBuffer) {
|
|
|
|
for (int j = 0; j < DEV_H; ++j) {
|
|
|
|
for (int i = 0; i < DEV_W; ++i) {
|
|
|
|
uint16_t control = controlData[i + j * DEV_H];
|
|
|
|
uint32_t test = readBuffer[i + j * DEV_H];
|
|
|
|
|
|
|
|
// Test alpha component
|
|
|
|
uint8_t ctrlComp = expand_value(control & 0xF, 4);
|
|
|
|
uint8_t testComp = GrColorUnpackA(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
|
|
|
|
// Test blue component
|
|
|
|
ctrlComp = expand_value((control >> 4) & 0xF, 4);
|
|
|
|
testComp = GrColorUnpackB(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
|
|
|
|
// Test green component
|
|
|
|
ctrlComp = expand_value((control >> 8) & 0xF, 4);
|
|
|
|
testComp = GrColorUnpackG(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
|
|
|
|
// Test red component
|
|
|
|
ctrlComp = expand_value((control >> 12) & 0xF, 4);
|
|
|
|
testComp = GrColorUnpackR(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_565(skiatest::Reporter* reporter,
|
|
|
|
const SkTDArray<uint16_t>& controlData,
|
|
|
|
const SkTDArray<GrColor>& readBuffer) {
|
|
|
|
for (int j = 0; j < DEV_H; ++j) {
|
|
|
|
for (int i = 0; i < DEV_W; ++i) {
|
|
|
|
uint16_t control = controlData[i + j * DEV_H];
|
|
|
|
GrColor test = readBuffer[i + j * DEV_H];
|
|
|
|
// Test blue component (5 bit control)
|
|
|
|
uint8_t ctrlComp = expand_value(control & 0x1F, 5);
|
|
|
|
uint8_t testComp = GrColorUnpackB(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
|
|
|
|
// Test green component (6 bit control)
|
|
|
|
ctrlComp = expand_value((control >> 5) & 0x3F, 6);
|
|
|
|
testComp = GrColorUnpackG(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
|
|
|
|
// Test red component (5 bit control)
|
|
|
|
ctrlComp = expand_value((control >> 11) & 0x1F, 5);
|
|
|
|
testComp = GrColorUnpackR(test);
|
|
|
|
check_component(reporter, ctrlComp, testComp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
static void run_test(skiatest::Reporter* reporter, GrDirectContext* dContext, int arraySize,
|
2018-03-19 20:06:44 +00:00
|
|
|
SkColorType colorType) {
|
2017-04-17 11:43:27 +00:00
|
|
|
SkTDArray<uint16_t> controlPixelData;
|
2017-03-29 16:08:49 +00:00
|
|
|
// We will read back into an 8888 buffer since 565/4444 read backs aren't supported
|
2016-08-15 17:59:17 +00:00
|
|
|
SkTDArray<GrColor> readBuffer;
|
|
|
|
controlPixelData.setCount(arraySize);
|
|
|
|
readBuffer.setCount(arraySize);
|
|
|
|
|
|
|
|
for (int i = 0; i < arraySize; i += 2) {
|
2018-07-12 13:35:37 +00:00
|
|
|
controlPixelData[i] = 0xF00F;
|
|
|
|
controlPixelData[i + 1] = 0xA62F;
|
2016-08-15 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 14:01:16 +00:00
|
|
|
const SkImageInfo dstInfo =
|
|
|
|
SkImageInfo::Make(DEV_W, DEV_H, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
|
|
|
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
|
2019-10-21 19:04:52 +00:00
|
|
|
auto grColorType = SkColorTypeToGrColorType(colorType);
|
2020-08-12 18:06:50 +00:00
|
|
|
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext, GrRenderable::kNo, origin,
|
2020-08-12 18:06:50 +00:00
|
|
|
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
|
|
|
|
0);
|
|
|
|
SkASSERT(view);
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
GrSurfaceContext sContext(dContext, std::move(view), grColorType, kPremul_SkAlphaType,
|
2020-01-14 14:56:04 +00:00
|
|
|
nullptr);
|
2019-12-19 21:41:40 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
if (!sContext.readPixels(dContext, dstInfo, readBuffer.begin(), 0, {0, 0})) {
|
2018-03-19 20:06:44 +00:00
|
|
|
// We only require this to succeed if the format is renderable.
|
2020-08-11 16:02:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, !dContext->colorTypeSupportedAsSurface(colorType));
|
2018-03-19 20:06:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-04-17 11:43:27 +00:00
|
|
|
|
2018-03-19 20:06:44 +00:00
|
|
|
if (kARGB_4444_SkColorType == colorType) {
|
2016-08-15 17:59:17 +00:00
|
|
|
check_4444(reporter, controlPixelData, readBuffer);
|
|
|
|
} else {
|
2018-03-19 20:06:44 +00:00
|
|
|
SkASSERT(kRGB_565_SkColorType == colorType);
|
2016-08-15 17:59:17 +00:00
|
|
|
check_565(reporter, controlPixelData, readBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int CONTROL_ARRAY_SIZE = DEV_W * DEV_H;
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGBA4444TextureTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
|
|
|
|
if (direct->colorTypeSupportedAsImage(kARGB_4444_SkColorType)) {
|
|
|
|
run_test(reporter, direct, CONTROL_ARRAY_SIZE, kARGB_4444_SkColorType);
|
2019-03-15 19:22:39 +00:00
|
|
|
}
|
2016-08-15 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGB565TextureTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
|
|
|
|
if (direct->colorTypeSupportedAsImage(kRGB_565_SkColorType)) {
|
|
|
|
run_test(reporter, direct, CONTROL_ARRAY_SIZE, kRGB_565_SkColorType);
|
2019-03-15 19:22:39 +00:00
|
|
|
}
|
2016-08-15 17:59:17 +00:00
|
|
|
}
|