Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: gpu/command_buffer/client/gles2_implementation_unittest.cc

Issue 10012057: Add GL_EXT_unpack_subimage support to command buffer client code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests for GLES2Implementation. 5 // Tests for GLES2Implementation.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include "gpu/command_buffer/client/client_test_helper.h" 10 #include "gpu/command_buffer/client/client_test_helper.h"
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 1777
1778 ExpectedMemoryInfo result1 = 1778 ExpectedMemoryInfo result1 =
1779 GetExpectedResultMemory(sizeof(GetError::Result)); 1779 GetExpectedResultMemory(sizeof(GetError::Result));
1780 1780
1781 EXPECT_CALL(*command_buffer(), OnFlush()) 1781 EXPECT_CALL(*command_buffer(), OnFlush())
1782 .WillOnce(SetMemory(result1.ptr, GLuint(GL_NO_ERROR))) 1782 .WillOnce(SetMemory(result1.ptr, GLuint(GL_NO_ERROR)))
1783 .RetiresOnSaturation(); 1783 .RetiresOnSaturation();
1784 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError()); 1784 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError());
1785 } 1785 }
1786 1786
1787 static bool ComputeImageDataSizes(
1788 int width, int height, int format, int type, int unpack_alignment,
1789 uint32* size, uint32* unpadded_row_size, uint32* padded_row_size) {
1790 uint32 temp_size;
1791 if (!GLES2Util::ComputeImageDataSize(
1792 width, 1, format, type, unpack_alignment, &temp_size)) {
1793 return false;
1794 }
1795 *unpadded_row_size = temp_size;
1796 if (!GLES2Util::ComputeImageDataSize(
1797 width, 2, format, type, unpack_alignment, &temp_size)) {
1798 return false;
1799 }
1800 *padded_row_size = temp_size - *unpadded_row_size;
1801 return GLES2Util::ComputeImageDataSize(
1802 width, height, format, type, unpack_alignment, size);
1803 }
1804
1805 static bool CheckRect( 1787 static bool CheckRect(
1806 int width, int height, GLenum format, GLenum type, int alignment, 1788 int width, int height, GLenum format, GLenum type, int alignment,
1807 bool flip_y, const uint8* r1, const uint8* r2) { 1789 bool flip_y, const uint8* r1, const uint8* r2) {
1808 uint32 size = 0; 1790 uint32 size = 0;
1809 uint32 unpadded_row_size = 0; 1791 uint32 unpadded_row_size = 0;
1810 uint32 padded_row_size = 0; 1792 uint32 padded_row_size = 0;
1811 if (!ComputeImageDataSizes( 1793 if (!GLES2Util::ComputeImageDataSizes(
1812 width, height, format, type, alignment, &size, &unpadded_row_size, 1794 width, height, format, type, alignment, &size, &unpadded_row_size,
1813 &padded_row_size)) { 1795 &padded_row_size)) {
1814 return false; 1796 return false;
1815 } 1797 }
1816 1798
1817 int r2_stride = flip_y ? 1799 int r2_stride = flip_y ?
1818 -static_cast<int>(padded_row_size) : 1800 -static_cast<int>(padded_row_size) :
1819 static_cast<int>(padded_row_size); 1801 static_cast<int>(padded_row_size);
1820 r2 = flip_y ? (r2 + (height - 1) * padded_row_size) : r2; 1802 r2 = flip_y ? (r2 + (height - 1) * padded_row_size) : r2;
1821 1803
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 const GLint kLevel = 0; 1888 const GLint kLevel = 0;
1907 const GLenum kFormat = GL_RGB; 1889 const GLenum kFormat = GL_RGB;
1908 const GLint kBorder = 0; 1890 const GLint kBorder = 0;
1909 const GLenum kType = GL_UNSIGNED_BYTE; 1891 const GLenum kType = GL_UNSIGNED_BYTE;
1910 const GLint kPixelStoreUnpackAlignment = 4; 1892 const GLint kPixelStoreUnpackAlignment = 4;
1911 const GLsizei kWidth = 3; 1893 const GLsizei kWidth = 3;
1912 1894
1913 uint32 size = 0; 1895 uint32 size = 0;
1914 uint32 unpadded_row_size = 0; 1896 uint32 unpadded_row_size = 0;
1915 uint32 padded_row_size = 0; 1897 uint32 padded_row_size = 0;
1916 ASSERT_TRUE(ComputeImageDataSizes( 1898 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
1917 kWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, 1899 kWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment,
1918 &size, &unpadded_row_size, &padded_row_size)); 1900 &size, &unpadded_row_size, &padded_row_size));
1919 const GLsizei kHeight = (MaxTransferBufferSize() / padded_row_size) * 2; 1901 const GLsizei kHeight = (MaxTransferBufferSize() / padded_row_size) * 2;
1920 ASSERT_TRUE(GLES2Util::ComputeImageDataSize( 1902 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
1921 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, 1903 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment,
1922 &size)); 1904 &size, NULL, NULL));
1923 uint32 half_size = 0; 1905 uint32 half_size = 0;
1924 ASSERT_TRUE(GLES2Util::ComputeImageDataSize( 1906 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
1925 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment, 1907 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment,
1926 &half_size)); 1908 &half_size, NULL, NULL));
1927 1909
1928 scoped_array<uint8> pixels(new uint8[size]); 1910 scoped_array<uint8> pixels(new uint8[size]);
1929 for (uint32 ii = 0; ii < size; ++ii) { 1911 for (uint32 ii = 0; ii < size; ++ii) {
1930 pixels[ii] = static_cast<uint8>(ii); 1912 pixels[ii] = static_cast<uint8>(ii);
1931 } 1913 }
1932 1914
1933 ExpectedMemoryInfo mem1 = GetExpectedMemory(half_size); 1915 ExpectedMemoryInfo mem1 = GetExpectedMemory(half_size);
1934 ExpectedMemoryInfo mem2 = GetExpectedMemory(half_size); 1916 ExpectedMemoryInfo mem2 = GetExpectedMemory(half_size);
1935 1917
1936 Cmds expected; 1918 Cmds expected;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 struct Cmds { 1996 struct Cmds {
2015 PixelStorei pixel_store_i1; 1997 PixelStorei pixel_store_i1;
2016 TexImage2D tex_image_2d; 1998 TexImage2D tex_image_2d;
2017 TexSubImage2D tex_sub_image_2d1; 1999 TexSubImage2D tex_sub_image_2d1;
2018 cmd::SetToken set_token1; 2000 cmd::SetToken set_token1;
2019 TexSubImage2D tex_sub_image_2d2; 2001 TexSubImage2D tex_sub_image_2d2;
2020 cmd::SetToken set_token2; 2002 cmd::SetToken set_token2;
2021 }; 2003 };
2022 2004
2023 uint32 sub_2_high_size = 0; 2005 uint32 sub_2_high_size = 0;
2024 ASSERT_TRUE(GLES2Util::ComputeImageDataSize( 2006 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2025 kSubImageWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, 2007 kSubImageWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment,
2026 &sub_2_high_size)); 2008 &sub_2_high_size, NULL, NULL));
2027 2009
2028 ExpectedMemoryInfo mem1 = GetExpectedMemory(sub_2_high_size); 2010 ExpectedMemoryInfo mem1 = GetExpectedMemory(sub_2_high_size);
2029 ExpectedMemoryInfo mem2 = GetExpectedMemory(sub_2_high_size); 2011 ExpectedMemoryInfo mem2 = GetExpectedMemory(sub_2_high_size);
2030 2012
2031 Cmds expected; 2013 Cmds expected;
2032 expected.pixel_store_i1.Init(GL_UNPACK_ALIGNMENT, kPixelStoreUnpackAlignment); 2014 expected.pixel_store_i1.Init(GL_UNPACK_ALIGNMENT, kPixelStoreUnpackAlignment);
2033 expected.tex_image_2d.Init( 2015 expected.tex_image_2d.Init(
2034 kTarget, kLevel, kFormat, kTextureWidth, kTextureHeight, kBorder, kFormat, 2016 kTarget, kLevel, kFormat, kTextureWidth, kTextureHeight, kBorder, kFormat,
2035 kType, 0, 0); 2017 kType, 0, 0);
2036 expected.tex_sub_image_2d1.Init(kTarget, kLevel, kSubImageXOffset, 2018 expected.tex_sub_image_2d1.Init(kTarget, kLevel, kSubImageXOffset,
(...skipping 21 matching lines...) Expand all
2058 GL_TEXTURE_2D, 0, kSubImageXOffset, kSubImageYOffset, kSubImageWidth, 2040 GL_TEXTURE_2D, 0, kSubImageXOffset, kSubImageYOffset, kSubImageWidth,
2059 kSubImageHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); 2041 kSubImageHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
2060 2042
2061 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 2043 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2062 EXPECT_TRUE(CheckRect( 2044 EXPECT_TRUE(CheckRect(
2063 kSubImageWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, true, 2045 kSubImageWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment, true,
2064 reinterpret_cast<uint8*>(pixels.get() + 2 * kSubImageWidth), 2046 reinterpret_cast<uint8*>(pixels.get() + 2 * kSubImageWidth),
2065 mem2.ptr)); 2047 mem2.ptr));
2066 } 2048 }
2067 2049
2050 TEST_F(GLES2ImplementationTest, SubImageUnpack) {
2051 static const GLint unpack_alignments[] = { 1, 2, 4, 8 };
2052
2053 static const GLenum kFormat = GL_RGB;
2054 static const GLenum kType = GL_UNSIGNED_BYTE;
2055 static const GLint kLevel = 0;
2056 static const GLint kBorder = 0;
2057 // We're testing using the unpack params to pull a subimage out of a larger
2058 // source of pixels. Here we specify the subimage by its border rows /
2059 // columns.
2060 static const GLint kSrcWidth = 33;
2061 static const GLint kSrcSubImageX0 = 11;
2062 static const GLint kSrcSubImageX1 = 20;
2063 static const GLint kSrcSubImageY0 = 18;
2064 static const GLint kSrcSubImageY1 = 23;
2065 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0;
2066 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0;
2067
2068 // these are only used in the texsubimage tests
2069 static const GLint kTexWidth = 1023;
2070 static const GLint kTexHeight = 511;
2071 static const GLint kTexSubXOffset = 419;
2072 static const GLint kTexSubYOffset = 103;
2073
2074 struct {
2075 PixelStorei pixel_store_i;
2076 TexImage2D tex_image_2d;
2077 } texImageExpected;
2078
2079 struct {
2080 PixelStorei pixel_store_i;
2081 TexImage2D tex_image_2d;
2082 TexSubImage2D tex_sub_image_2d;
2083 } texSubImageExpected;
2084
2085 uint32 src_size;
2086 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2087 kSrcWidth, kSrcSubImageY1, kFormat, kType, 8, &src_size, NULL, NULL));
2088 scoped_array<uint8> src_pixels;
2089 src_pixels.reset(new uint8[src_size]);
2090 for (size_t i = 0; i < src_size; ++i) {
2091 src_pixels[i] = static_cast<int8>(i);
2092 }
2093
2094 for (int sub = 0; sub < 2; ++sub) {
2095 for (int flip_y = 0; flip_y < 2; ++flip_y) {
2096 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) {
2097 GLint alignment = unpack_alignments[a];
2098 uint32 size;
2099 uint32 unpadded_row_size;
2100 uint32 padded_row_size;
2101 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2102 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, alignment,
2103 &size, &unpadded_row_size, &padded_row_size));
2104 ASSERT_TRUE(size <= MaxTransferBufferSize());
2105 ExpectedMemoryInfo mem = GetExpectedMemory(size);
2106
2107 const void* commands = GetPut();
2108 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment);
2109 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth);
2110 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0);
2111 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0);
2112 gl_->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
2113 if (sub) {
2114 gl_->TexImage2D(
2115 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder,
2116 kFormat, kType, NULL);
2117 gl_->TexSubImage2D(
2118 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
2119 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType,
2120 src_pixels.get());
2121 texSubImageExpected.pixel_store_i.Init(
2122 GL_UNPACK_ALIGNMENT, alignment);
2123 texSubImageExpected.tex_image_2d.Init(
2124 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder,
2125 kFormat, kType, 0, 0);
2126 texSubImageExpected.tex_sub_image_2d.Init(
2127 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
2128 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id,
2129 mem.offset, GL_FALSE);
2130 EXPECT_EQ(0, memcmp(
2131 &texSubImageExpected, commands, sizeof(texSubImageExpected)));
2132 } else {
2133 gl_->TexImage2D(
2134 GL_TEXTURE_2D, kLevel, kFormat,
2135 kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType,
2136 src_pixels.get());
2137 texImageExpected.pixel_store_i.Init(GL_UNPACK_ALIGNMENT, alignment);
2138 texImageExpected.tex_image_2d.Init(
2139 GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth,
2140 kSrcSubImageHeight, kBorder, kFormat, kType, mem.id, mem.offset);
2141 EXPECT_EQ(0, memcmp(
2142 &texImageExpected, commands, sizeof(texImageExpected)));
2143 }
2144 uint32 src_padded_row_size;
2145 ASSERT_TRUE(GLES2Util::ComputeImagePaddedRowSize(
2146 kSrcWidth, kFormat, kType, alignment, &src_padded_row_size));
2147 uint32 bytes_per_group = GLES2Util::ComputeImageGroupSize(
2148 kFormat, kType);
2149 for (int y = 0; y < kSrcSubImageHeight; ++y) {
2150 GLint src_sub_y = flip_y ? kSrcSubImageHeight - y - 1 : y;
2151 const uint8* src_row = src_pixels.get() +
2152 (kSrcSubImageY0 + src_sub_y) * src_padded_row_size +
2153 bytes_per_group * kSrcSubImageX0;
2154 const uint8* dst_row = mem.ptr + y * padded_row_size;
2155 EXPECT_EQ(0, memcmp(src_row, dst_row, unpadded_row_size));
2156 }
2157 ClearCommands();
2158 }
2159 }
2160 }
2161 }
2162
2068 // Binds can not be cached with bind_generates_resource = false because 2163 // Binds can not be cached with bind_generates_resource = false because
2069 // our id might not be valid. More specifically if you bind on contextA then 2164 // our id might not be valid. More specifically if you bind on contextA then
2070 // delete on contextB the resource is still bound on contextA but GetInterger 2165 // delete on contextB the resource is still bound on contextA but GetInterger
2071 // won't return an id. 2166 // won't return an id.
2072 TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) { 2167 TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
2073 struct PNameValue { 2168 struct PNameValue {
2074 GLenum pname; 2169 GLenum pname;
2075 GLint expected; 2170 GLint expected;
2076 }; 2171 };
2077 const PNameValue pairs[] = { 2172 const PNameValue pairs[] = {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 2217 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2123 EXPECT_EQ(handle, kResult); 2218 EXPECT_EQ(handle, kResult);
2124 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError()); 2219 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError());
2125 } 2220 }
2126 2221
2127 TEST_F(GLES2ImplementationTest, GetString) { 2222 TEST_F(GLES2ImplementationTest, GetString) {
2128 const uint32 kBucketId = GLES2Implementation::kResultBucketId; 2223 const uint32 kBucketId = GLES2Implementation::kResultBucketId;
2129 const Str7 kString = {"foobar"}; 2224 const Str7 kString = {"foobar"};
2130 // GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into 2225 // GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into
2131 // GLES2Implementation. 2226 // GLES2Implementation.
2132 const char* expected_str = "foobar GL_CHROMIUM_map_sub GL_CHROMIUM_flipy"; 2227 const char* expected_str =
2228 "foobar GL_CHROMIUM_map_sub GL_CHROMIUM_flipy GL_EXT_unpack_subimage";
2133 const char kBad = 0x12; 2229 const char kBad = 0x12;
2134 struct Cmds { 2230 struct Cmds {
2135 cmd::SetBucketSize set_bucket_size1; 2231 cmd::SetBucketSize set_bucket_size1;
2136 GetString get_string; 2232 GetString get_string;
2137 cmd::GetBucketSize get_bucket_size; 2233 cmd::GetBucketSize get_bucket_size;
2138 cmd::GetBucketData get_bucket_data; 2234 cmd::GetBucketData get_bucket_data;
2139 cmd::SetToken set_token1; 2235 cmd::SetToken set_token1;
2140 cmd::SetBucketSize set_bucket_size2; 2236 cmd::SetBucketSize set_bucket_size2;
2141 }; 2237 };
2142 ExpectedMemoryInfo result1 = 2238 ExpectedMemoryInfo result1 =
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 EXPECT_TRUE(NoCommandsWritten()); 2454 EXPECT_TRUE(NoCommandsWritten());
2359 EXPECT_EQ(0u, available); 2455 EXPECT_EQ(0u, available);
2360 } 2456 }
2361 2457
2362 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 2458 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
2363 2459
2364 } // namespace gles2 2460 } // namespace gles2
2365 } // namespace gpu 2461 } // namespace gpu
2366 2462
2367 2463
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698