Commit 0abe2d40 authored by Prashant.Patil's avatar Prashant.Patil Committed by Commit bot

Add WebGLImageConversionTest

We add WebGLImageConversionTest in blink_platform_unittests.
This covers following conversion tests:
- ConvertRGBA4444toRGBA8
- ConvertRGBA5551toRGBA8
- ConvertRGBA8toRA8
- convertBGRA8toRGBA8
- ConvertRGBA8toR8
- ConvertRGBA8toRGBA8
- ConvertRGBA8ToUnsignedShort4444
- ConvertRGBA8ToRGBA5551
- ConvertRGBA8ToRGB565

R=kbr@chromium.org
BUG=642653

Review-Url: https://codereview.chromium.org/2333233002
Cr-Commit-Position: refs/heads/master@{#418486}
parent bea11049
......@@ -1671,6 +1671,7 @@ test("blink_platform_unittests") {
"graphics/filters/FilterOperationsTest.cpp",
"graphics/filters/ImageFilterBuilderTest.cpp",
"graphics/gpu/DrawingBufferTest.cpp",
"graphics/gpu/WebGLImageConversionTest.cpp",
"graphics/paint/DisplayItemClientTest.cpp",
"graphics/paint/DisplayItemListTest.cpp",
"graphics/paint/DisplayItemTest.cpp",
......
......@@ -2427,4 +2427,99 @@ bool WebGLImageConversion::packPixels(
return true;
}
void WebGLImageConversion::unpackPixels(const uint16_t* sourceData,
DataFormat sourceDataFormat,
unsigned pixelsPerRow,
uint8_t* destinationData )
{
switch (sourceDataFormat) {
case DataFormatRGBA4444:
{
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA4444>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
unpack<WebGLImageConversion::DataFormatRGBA4444>(srcRowStart, destinationData, pixelsPerRow);
}
break;
case DataFormatRGBA5551:
{
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA5551>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
unpack<WebGLImageConversion::DataFormatRGBA5551>(srcRowStart, destinationData, pixelsPerRow);
}
break;
case DataFormatBGRA8:
{
const uint8_t* psrc = (const uint8_t*)sourceData;
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatBGRA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(psrc);
unpack<WebGLImageConversion::DataFormatBGRA8>(srcRowStart, destinationData, pixelsPerRow);
}
break;
default:
break;
}
}
void WebGLImageConversion::packPixels(const uint8_t* sourceData,
DataFormat sourceDataFormat,
unsigned pixelsPerRow,
uint8_t* destinationData )
{
switch (sourceDataFormat) {
case DataFormatRA8:
{
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
pack<WebGLImageConversion::DataFormatRA8, WebGLImageConversion::AlphaDoUnmultiply>(srcRowStart, destinationData, pixelsPerRow);
}
break;
case DataFormatR8:
{
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
pack<WebGLImageConversion::DataFormatR8, WebGLImageConversion::AlphaDoUnmultiply>(srcRowStart, destinationData, pixelsPerRow);
}
break;
case DataFormatRGBA8:
{
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion::AlphaDoUnmultiply>(srcRowStart, destinationData, pixelsPerRow);
}
break;
case DataFormatRGBA4444:
{
uint16_t* pdst = (uint16_t*)destinationData;
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA4444>::Type DstType;
DstType* dstRowStart = static_cast<DstType*>(pdst);
pack<WebGLImageConversion::DataFormatRGBA4444, WebGLImageConversion::AlphaDoNothing>(srcRowStart, dstRowStart, pixelsPerRow);
}
break;
case DataFormatRGBA5551:
{
uint16_t* pdst = (uint16_t*)destinationData;
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA5551>::Type DstType;
DstType* dstRowStart = static_cast<DstType*>(pdst);
pack<WebGLImageConversion::DataFormatRGBA5551, WebGLImageConversion::AlphaDoNothing>(srcRowStart, dstRowStart, pixelsPerRow);
}
break;
case DataFormatRGB565:
{
uint16_t* pdst = (uint16_t*)destinationData;
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGBA8>::Type SrcType;
const SrcType* srcRowStart = static_cast<const SrcType*>(sourceData);
typedef typename DataTypeForFormat<WebGLImageConversion::DataFormatRGB565>::Type DstType;
DstType* dstRowStart = static_cast<DstType*>(pdst);
pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversion::AlphaDoNothing>(srcRowStart, dstRowStart, pixelsPerRow);
}
break;
default:
break;
}
}
} // namespace blink
......@@ -205,6 +205,7 @@ public:
// End GraphicsContext3DImagePacking.cpp functions
private:
friend class WebGLImageConversionTest;
// Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
// data into the specified OpenGL destination format and type.
// A sourceUnpackAlignment of zero indicates that the source
......@@ -212,6 +213,8 @@ private:
// Destination data will have no gaps between rows.
// Implemented in GraphicsContext3DImagePacking.cpp
static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
static void unpackPixels(const uint16_t* sourceData, DataFormat sourceDataFormat, unsigned pixelsPerRow, uint8_t* destinationData);
static void packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned pixelsPerRow, uint8_t* destinationData);
};
} // namespace blink
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "platform/graphics/gpu/WebGLImageConversion.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
class WebGLImageConversionTest : public testing::Test {
protected:
void unpackPixels(
const uint16_t* sourceData,
WebGLImageConversion::DataFormat sourceDataFormat,
unsigned pixelsPerRow,
uint8_t* destinationData)
{
WebGLImageConversion::unpackPixels(sourceData, sourceDataFormat, pixelsPerRow, destinationData);
}
void packPixels(
const uint8_t* sourceData,
WebGLImageConversion::DataFormat sourceDataFormat,
unsigned pixelsPerRow,
uint8_t* destinationData)
{
WebGLImageConversion::packPixels(sourceData, sourceDataFormat, pixelsPerRow, destinationData);
}
};
TEST_F(WebGLImageConversionTest, ConvertRGBA4444toRGBA8)
{
uint16_t sourceData[9] = { 0x1234, 0x3456, 0x1234, 0x3456, 0x1234, 0x3456, 0x1234, 0x3456, 0x1234 };
uint8_t expectedData[36] = { 0x11, 0x22, 0x33, 0x44, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22, 0x33, 0x44, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22, 0x33, 0x44, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22, 0x33, 0x44, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22, 0x33, 0x44 };
uint8_t destinationData[36];
unpackPixels(sourceData, WebGLImageConversion::DataFormatRGBA4444, 9, destinationData);
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA5551toRGBA8)
{
uint16_t sourceData[9] = { 0x1234, 0x3456, 0x1234, 0x3456, 0x1234, 0x3456, 0x1234, 0x3456, 0x1234 };
uint8_t expectedData[36] = { 0x12, 0x40, 0xd2, 0x0, 0x36, 0x89, 0x5b, 0x0, 0x12, 0x40, 0xd2, 0x0, 0x36, 0x89, 0x5b, 0x0, 0x12, 0x40, 0xd2, 0x0, 0x36, 0x89, 0x5b, 0x0, 0x12, 0x40, 0xd2, 0x0, 0x36, 0x89, 0x5b, 0x0, 0x12, 0x40, 0xd2, 0x0 };
uint8_t destinationData[36];
unpackPixels(sourceData, WebGLImageConversion::DataFormatRGBA5551, 9, destinationData);
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8toRA8)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint8_t expectedData[20] = { 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56, 0x9a, 0x56 };
uint8_t destinationData[20];
packPixels(sourceData, WebGLImageConversion::DataFormatRA8, 10, destinationData);
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, convertBGRA8toRGBA8)
{
uint32_t sourceData[9] = { 0x12345678, 0x34567888, 0x12345678, 0x34567888, 0x12345678, 0x34567888, 0x12345678, 0x34567888, 0x12345678 };
#if CPU(BIG_ENDIAN)
uint32_t expectedData[9] = { 0x56341278, 0x78563488, 0x56341278, 0x78563488, 0x56341278, 0x78563488, 0x56341278, 0x78563488, 0x56341278 };
#else
uint32_t expectedData[9] = { 0x12785634, 0x34887856, 0x12785634, 0x34887856, 0x12785634, 0x34887856, 0x12785634, 0x34887856, 0x12785634 };
#endif
uint32_t destinationData[9];
unpackPixels(reinterpret_cast<uint16_t*>(&sourceData[0]), WebGLImageConversion::DataFormatBGRA8, 9, reinterpret_cast<uint8_t*>(&destinationData[0]));
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8toR8)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint8_t expectedData[10] = { 0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9a, 0x9a };
uint8_t destinationData[10];
packPixels(sourceData, WebGLImageConversion::DataFormatR8, 10, destinationData);
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8toRGBA8)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint8_t expectedData[40] = { 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56, 0x9a, 0xff, 0x9a, 0x56 };
uint8_t destinationData[40];
packPixels(sourceData, WebGLImageConversion::DataFormatRGBA8, 10, destinationData);
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8ToUnsignedShort4444)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint16_t expectedData[10] = { 0x3535, 0x3535, 0x3535, 0x3535, 0x3535, 0x3535, 0x3535, 0x3535, 0x3535, 0x3535 };
uint16_t destinationData[10];
packPixels(sourceData, WebGLImageConversion::DataFormatRGBA4444, 10, reinterpret_cast<uint8_t*>(&destinationData[0]));
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8ToRGBA5551)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint16_t expectedData[10] = { 0x328c, 0x328c, 0x328c, 0x328c, 0x328c, 0x328c, 0x328c, 0x328c, 0x328c, 0x328c };
uint16_t destinationData[10];
packPixels(sourceData, WebGLImageConversion::DataFormatRGBA5551, 10, reinterpret_cast<uint8_t*>(&destinationData[0]));
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
TEST_F(WebGLImageConversionTest, ConvertRGBA8ToRGB565)
{
uint8_t sourceData[40] = { 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56, 0x34, 0x56 };
uint16_t expectedData[10] = { 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6, 0x32a6 };
uint16_t destinationData[10];
packPixels(sourceData, WebGLImageConversion::DataFormatRGB565, 10, reinterpret_cast<uint8_t*>(&destinationData[0]));
EXPECT_EQ(0, memcmp(expectedData, destinationData, sizeof(destinationData)));
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment