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

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

Issue 1484473003: gl, ozone: enable GLImageBindTest unittests Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add new GLImageBindTest unittests. add R_8 test. give up dynamic way Created 4 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
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 protected: 139 protected:
140 scoped_refptr<gfx::GLSurface> surface_; 140 scoped_refptr<gfx::GLSurface> surface_;
141 scoped_refptr<gfx::GLContext> context_; 141 scoped_refptr<gfx::GLContext> context_;
142 GLImageTestDelegate delegate_; 142 GLImageTestDelegate delegate_;
143 }; 143 };
144 144
145 TYPED_TEST_CASE_P(GLImageTest); 145 TYPED_TEST_CASE_P(GLImageTest);
146 146
147 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { 147 TYPED_TEST_P(GLImageTest, CreateAndDestroy) {
148 if (!this->delegate_.IsSupported())
149 return;
150
148 const gfx::Size small_image_size(4, 4); 151 const gfx::Size small_image_size(4, 4);
149 const gfx::Size large_image_size(512, 512); 152 const gfx::Size large_image_size(512, 512);
150 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; 153 const uint8_t image_color[] = {0, 0xff, 0, 0xff};
151 154
152 // Create a small solid color green image of preferred format. This must 155 // Create a small solid color green image of preferred format. This must
153 // succeed in order for a GLImage to be conformant. 156 // succeed in order for a GLImage to be conformant.
154 scoped_refptr<gl::GLImage> small_image = 157 scoped_refptr<gl::GLImage> small_image =
155 this->delegate_.CreateSolidColorImage(small_image_size, image_color); 158 this->delegate_.CreateSolidColorImage(small_image_size, image_color);
156 ASSERT_TRUE(small_image); 159 ASSERT_TRUE(small_image);
157 160
(...skipping 18 matching lines...) Expand all
176 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy); 179 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy);
177 180
178 template <typename GLImageTestDelegate> 181 template <typename GLImageTestDelegate>
179 class GLImageZeroInitializeTest : public GLImageTest<GLImageTestDelegate> {}; 182 class GLImageZeroInitializeTest : public GLImageTest<GLImageTestDelegate> {};
180 183
181 // This test verifies that if an uninitialized image is bound to a texture, the 184 // This test verifies that if an uninitialized image is bound to a texture, the
182 // result is zero-initialized. 185 // result is zero-initialized.
183 TYPED_TEST_CASE_P(GLImageZeroInitializeTest); 186 TYPED_TEST_CASE_P(GLImageZeroInitializeTest);
184 187
185 TYPED_TEST_P(GLImageZeroInitializeTest, ZeroInitialize) { 188 TYPED_TEST_P(GLImageZeroInitializeTest, ZeroInitialize) {
189 // Ozone platform knows the supported format in runtime.
190 if (!this->delegate_.IsSupported())
dshwang 2016/04/08 13:16:31 reveman suggested to keep static way, while ozone
191 return;
186 #if defined(OS_MACOSX) 192 #if defined(OS_MACOSX)
187 // This functionality is disabled on Mavericks because it breaks PDF 193 // This functionality is disabled on Mavericks because it breaks PDF
188 // rendering. https://crbug.com/594343. 194 // rendering. https://crbug.com/594343.
189 if (base::mac::IsOSMavericks()) 195 if (base::mac::IsOSMavericks())
190 return; 196 return;
191 #endif 197 #endif
192 198
193 const gfx::Size image_size(256, 256); 199 const gfx::Size image_size(256, 256);
194 200
195 GLuint framebuffer = 201 GLuint framebuffer =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 234 }
229 235
230 REGISTER_TYPED_TEST_CASE_P(GLImageZeroInitializeTest, ZeroInitialize); 236 REGISTER_TYPED_TEST_CASE_P(GLImageZeroInitializeTest, ZeroInitialize);
231 237
232 template <typename GLImageTestDelegate> 238 template <typename GLImageTestDelegate>
233 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {}; 239 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {};
234 240
235 TYPED_TEST_CASE_P(GLImageCopyTest); 241 TYPED_TEST_CASE_P(GLImageCopyTest);
236 242
237 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { 243 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
244 if (!this->delegate_.IsSupported())
245 return;
246
238 const gfx::Size image_size(256, 256); 247 const gfx::Size image_size(256, 256);
239 // These values are picked so that RGB -> YUV on the CPU converted 248 // These values are picked so that RGB -> YUV on the CPU converted
240 // back to RGB on the GPU produces the original RGB values without 249 // back to RGB on the GPU produces the original RGB values without
241 // any error. 250 // any error.
242 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; 251 uint8_t image_color[] = {0x10, 0x20, 0x00, 0xff};
252 // glReadPixels(.., GL_RGBA, ..) for RED texture returns (R, 0x00, 0x00, 0xff)
253 if (gfx::BufferFormat::R_8 == this->delegate_.GetBufferFormat())
254 image_color[1] = 0x00;
243 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; 255 const uint8_t texture_color[] = {0, 0, 0xff, 0xff};
244 256
245 GLuint framebuffer = 257 GLuint framebuffer =
246 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); 258 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height());
247 ASSERT_TRUE(framebuffer); 259 ASSERT_TRUE(framebuffer);
248 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); 260 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer);
249 glViewport(0, 0, image_size.width(), image_size.height()); 261 glViewport(0, 0, image_size.width(), image_size.height());
250 262
251 // Create a solid color green image of preferred format. This must succeed 263 // Create a solid color green image of preferred format. This must succeed
252 // in order for a GLImage to be conformant. 264 // in order for a GLImage to be conformant.
253 scoped_refptr<gl::GLImage> image = 265 scoped_refptr<gl::GLImage> image =
254 this->delegate_.CreateSolidColorImage(image_size, image_color); 266 this->delegate_.CreateSolidColorImage(image_size, image_color);
255 ASSERT_TRUE(image); 267 ASSERT_TRUE(image);
256 268
257 // Create a solid color blue texture of the same size as |image|. 269 // Create a solid color blue texture of the same size as |image|.
258 unsigned target = this->delegate_.GetTextureTarget(); 270 unsigned target = this->delegate_.GetTextureTarget();
259 GLuint texture = GLTestHelper::CreateTexture(target); 271 GLuint texture = GLTestHelper::CreateTexture(target);
260 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( 272 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat(
261 image_size, gfx::BufferFormat::RGBA_8888)]); 273 image_size, gfx::BufferFormat::RGBA_8888)]);
262 GLImageTestSupport::SetBufferDataToColor( 274 GLImageTestSupport::SetBufferDataToColor(
263 image_size.width(), image_size.height(), 275 image_size.width(), image_size.height(),
264 static_cast<int>(RowSizeForBufferFormat(image_size.width(), 276 static_cast<int>(RowSizeForBufferFormat(image_size.width(),
265 gfx::BufferFormat::RGBA_8888, 0)), 277 gfx::BufferFormat::RGBA_8888, 0)),
266 0, gfx::BufferFormat::RGBA_8888, texture_color, pixels.get()); 278 0, gfx::BufferFormat::RGBA_8888, texture_color, pixels.get());
267 glBindTexture(target, texture); 279 glBindTexture(target, texture);
268 glTexImage2D(target, 0, GL_RGBA, image_size.width(), image_size.height(), 0, 280 glTexImage2D(target, 0, GL_RGBA, image_size.width(), image_size.height(), 0,
269 GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); 281 GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
270 282
271 // Copy |image| to |texture|. 283 // Copy |image| to |texture|.
272 bool rv = image->CopyTexImage(target); 284 bool rv = image->CopyTexImage(target);
dshwang 2016/04/08 13:16:31 ozone fails this line. copy test is not relevant t
273 EXPECT_TRUE(rv); 285 EXPECT_TRUE(rv);
274 286
275 // Draw |texture| to viewport. 287 // Draw |texture| to viewport.
276 DrawTextureQuad(target, image_size); 288 DrawTextureQuad(target, image_size);
277 289
278 // Read back pixels to check expectations. 290 // Read back pixels to check expectations.
279 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), 291 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(),
280 image_color); 292 image_color);
281 293
282 // Clean up. 294 // Clean up.
283 glDeleteTextures(1, &texture); 295 glDeleteTextures(1, &texture);
284 glDeleteFramebuffersEXT(1, &framebuffer); 296 glDeleteFramebuffersEXT(1, &framebuffer);
285 image->Destroy(true /* have_context */); 297 image->Destroy(true /* have_context */);
286 } 298 }
287 299
288 // The GLImageCopyTest test case verifies that the GLImage implementation 300 // The GLImageCopyTest test case verifies that the GLImage implementation
289 // handles CopyTexImage correctly. 301 // handles CopyTexImage correctly.
290 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); 302 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage);
291 303
304 template <typename GLImageTestDelegate>
305 class GLImageBindTest : public GLImageTest<GLImageTestDelegate> {};
306
307 TYPED_TEST_CASE_P(GLImageBindTest);
308
309 TYPED_TEST_P(GLImageBindTest, BindTexImage) {
dshwang 2016/04/08 13:16:31 android can reuse this test also.
310 if (!this->delegate_.IsSupported())
311 return;
312
313 const gfx::Size image_size(256, 256);
314 // These values are picked so that RGB -> YUV on the CPU converted
315 // back to RGB on the GPU produces the original RGB values without
316 // any error.
317 uint8_t image_color[] = {0x10, 0x20, 0x00, 0xff};
318 // glReadPixels(.., GL_RGBA, ..) for RED texture returns (R, 0x00, 0x00, 0xff)
319 if (gfx::BufferFormat::R_8 == this->delegate_.GetBufferFormat())
320 image_color[1] = 0x00;
321
322 GLuint framebuffer =
323 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height());
324 ASSERT_TRUE(framebuffer);
325 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer);
326 glViewport(0, 0, image_size.width(), image_size.height());
327
328 // Create a solid color green image of preferred format. This must succeed
329 // in order for a GLImage to be conformant.
330 scoped_refptr<gl::GLImage> image =
331 this->delegate_.CreateSolidColorImage(image_size, image_color);
332 ASSERT_TRUE(image);
333
334 // Bind |image| to |texture|.
335 unsigned target = this->delegate_.GetTextureTarget();
336 GLuint texture = GLTestHelper::CreateTexture(target);
337 bool rv = image->BindTexImage(target);
338 EXPECT_TRUE(rv);
339
340 // Draw |texture| to viewport.
341 DrawTextureQuad(target, image_size);
342
343 // Read back pixels to check expectations.
344 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(),
345 image_color);
346
347 // Clean up.
348 glDeleteTextures(1, &texture);
349 glDeleteFramebuffersEXT(1, &framebuffer);
350 image->Destroy(true /* have_context */);
351 }
352
353 // The GLImageBindTest test case verifies that the GLImage implementation
354 // handles BindTexImage correctly.
355 REGISTER_TYPED_TEST_CASE_P(GLImageBindTest, BindTexImage);
356
292 } // namespace gl 357 } // namespace gl
293 358
294 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ 359 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698