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

Side by Side Diff: ui/gl/test/gl_image_test_template.h

Issue 1415723006: ui: Add RGBX_8888 buffer format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gles but no conversion needed case Created 5 years, 2 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
« no previous file with comments | « ui/gl/test/gl_image_test_support.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This file defines tests that implementations of GLImage should pass in order 5 // This file defines tests that implementations of GLImage should pass in order
6 // to be conformant. 6 // to be conformant.
7 7
8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ 8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_
9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ 9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 TYPED_TEST_CASE_P(GLImageTest); 52 TYPED_TEST_CASE_P(GLImageTest);
53 53
54 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { 54 TYPED_TEST_P(GLImageTest, CreateAndDestroy) {
55 const Size small_image_size(4, 4); 55 const Size small_image_size(4, 4);
56 const Size large_image_size(512, 512); 56 const Size large_image_size(512, 512);
57 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; 57 const uint8_t image_color[] = {0, 0xff, 0, 0xff};
58 58
59 // Create a small solid color green image of preferred format. This must 59 // Create a small solid color green image of preferred format. This must
60 // succeed in order for a GLImage to be conformant. 60 // succeed in order for a GLImage to be conformant.
61 scoped_refptr<GLImage> small_image = this->delegate_.CreateSolidColorImage( 61 scoped_refptr<GLImage> small_image =
62 small_image_size, GLImageTestSupport::GetPreferredInternalFormat(), 62 this->delegate_.CreateSolidColorImage(small_image_size, image_color);
63 GLImageTestSupport::GetPreferredBufferFormat(), image_color);
64 ASSERT_TRUE(small_image); 63 ASSERT_TRUE(small_image);
65 64
66 // Create a large solid color green image of preferred format. This must 65 // Create a large solid color green image of preferred format. This must
67 // succeed in order for a GLImage to be conformant. 66 // succeed in order for a GLImage to be conformant.
68 scoped_refptr<GLImage> large_image = this->delegate_.CreateSolidColorImage( 67 scoped_refptr<GLImage> large_image =
69 large_image_size, GLImageTestSupport::GetPreferredInternalFormat(), 68 this->delegate_.CreateSolidColorImage(large_image_size, image_color);
70 GLImageTestSupport::GetPreferredBufferFormat(), image_color);
71 ASSERT_TRUE(large_image); 69 ASSERT_TRUE(large_image);
72 70
73 // Verify that image size is correct. 71 // Verify that image size is correct.
74 EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); 72 EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString());
75 EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); 73 EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString());
76 74
77 // Verify that internal format is correct.
78 EXPECT_EQ(small_image->GetInternalFormat(),
79 GLImageTestSupport::GetPreferredInternalFormat());
80 EXPECT_EQ(large_image->GetInternalFormat(),
81 GLImageTestSupport::GetPreferredInternalFormat());
82
83 // Verify that destruction of images work correctly both when we have a 75 // Verify that destruction of images work correctly both when we have a
84 // context and when we don't. 76 // context and when we don't.
85 small_image->Destroy(true /* have_context */); 77 small_image->Destroy(true /* have_context */);
86 large_image->Destroy(false /* have_context */); 78 large_image->Destroy(false /* have_context */);
87 } 79 }
88 80
89 // The GLImageTest test case verifies the behaviour that is expected from a 81 // The GLImageTest test case verifies the behaviour that is expected from a
90 // GLImage in order to be conformant. 82 // GLImage in order to be conformant.
91 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy); 83 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy);
92 84
93 template <typename GLImageTestDelegate> 85 template <typename GLImageTestDelegate>
94 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {}; 86 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {};
95 87
96 TYPED_TEST_CASE_P(GLImageCopyTest); 88 TYPED_TEST_CASE_P(GLImageCopyTest);
97 89
98 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { 90 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
99 const Size image_size(256, 256); 91 const Size image_size(256, 256);
100 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; 92 const uint8_t image_color[] = {0xff, 0xff, 0, 0xff};
101 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; 93 const uint8_t texture_color[] = {0, 0, 0xff, 0xff};
102 94
103 GLuint framebuffer = 95 GLuint framebuffer =
104 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); 96 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height());
105 ASSERT_TRUE(framebuffer); 97 ASSERT_TRUE(framebuffer);
106 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); 98 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer);
107 glViewport(0, 0, image_size.width(), image_size.height()); 99 glViewport(0, 0, image_size.width(), image_size.height());
108 100
109 // Create a solid color green image of preferred format. This must succeed 101 // Create a solid color green image of preferred format. This must succeed
110 // in order for a GLImage to be conformant. 102 // in order for a GLImage to be conformant.
111 scoped_refptr<GLImage> image = this->delegate_.CreateSolidColorImage( 103 scoped_refptr<GLImage> image =
112 image_size, GLImageTestSupport::GetPreferredInternalFormat(), 104 this->delegate_.CreateSolidColorImage(image_size, image_color);
113 GLImageTestSupport::GetPreferredBufferFormat(), image_color);
114 ASSERT_TRUE(image); 105 ASSERT_TRUE(image);
115 106
116 // Create a solid color blue texture of the same size as |image|. 107 // Create a solid color blue texture of the same size as |image|.
117 GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); 108 GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D);
118 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( 109 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat(
119 image_size, GLImageTestSupport::GetPreferredBufferFormat())]); 110 image_size, BufferFormat::RGBA_8888)]);
120 GLImageTestSupport::SetBufferDataToColor( 111 GLImageTestSupport::SetBufferDataToColor(
121 image_size.width(), image_size.height(), 112 image_size.width(), image_size.height(),
122 static_cast<int>(RowSizeForBufferFormat( 113 static_cast<int>(RowSizeForBufferFormat(image_size.width(),
123 image_size.width(), GLImageTestSupport::GetPreferredBufferFormat(), 114 BufferFormat::RGBA_8888, 0)),
124 0)), 115 BufferFormat::RGBA_8888, texture_color, pixels.get());
125 GLImageTestSupport::GetPreferredBufferFormat(), texture_color,
126 pixels.get());
127 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but 116 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but
128 // that might not be the case for some GLImage implementations. 117 // that might not be the case for some GLImage implementations.
129 glBindTexture(GL_TEXTURE_2D, texture); 118 glBindTexture(GL_TEXTURE_2D, texture);
130 glTexImage2D(GL_TEXTURE_2D, 0, 119 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_size.width(),
131 GLImageTestSupport::GetPreferredInternalFormat(), 120 image_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
132 image_size.width(), image_size.height(), 0,
133 GLImageTestSupport::GetPreferredInternalFormat(),
134 GL_UNSIGNED_BYTE, pixels.get());
135 121
136 // Copy |image| to |texture|. 122 // Copy |image| to |texture|.
137 bool rv = image->CopyTexImage(GL_TEXTURE_2D); 123 bool rv = image->CopyTexImage(GL_TEXTURE_2D);
138 EXPECT_TRUE(rv); 124 EXPECT_TRUE(rv);
139 125
140 // clang-format off 126 // clang-format off
141 const char kVertexShader[] = STRINGIZE( 127 const char kVertexShader[] = STRINGIZE(
142 attribute vec2 a_position; 128 attribute vec2 a_position;
143 attribute vec2 a_texCoord; 129 attribute vec2 a_texCoord;
144 varying vec2 v_texCoord; 130 varying vec2 v_texCoord;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 image->Destroy(true); 201 image->Destroy(true);
216 } 202 }
217 203
218 // The GLImageCopyTest test case verifies that the GLImage implementation 204 // The GLImageCopyTest test case verifies that the GLImage implementation
219 // handles CopyTexImage correctly. 205 // handles CopyTexImage correctly.
220 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); 206 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage);
221 207
222 } // namespace gfx 208 } // namespace gfx
223 209
224 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ 210 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « ui/gl/test/gl_image_test_support.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698