1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_GL_TEST_GL_IMAGE_BIND_TEST_TEMPLATE_H_
6 #define UI_GL_TEST_GL_IMAGE_BIND_TEST_TEMPLATE_H_
7
8 #include "ui/gl/test/gl_image_test_template.h"
9
10 namespace gl {
11
12 template <typename GLImageTestDelegate>
13 class GLImageBindTest : public GLImageTest<GLImageTestDelegate> {};
14
15 TYPED_TEST_SUITE_P(GLImageBindTest);
16
TYPED_TEST_P(GLImageBindTest,BindTexImage)17 TYPED_TEST_P(GLImageBindTest, BindTexImage) {
18 if (this->delegate_.SkipTest())
19 return;
20
21 const gfx::Size image_size(256, 256);
22 const uint8_t* image_color = this->delegate_.GetImageColor();
23
24 GLuint framebuffer =
25 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height());
26 ASSERT_TRUE(framebuffer);
27 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer);
28 glViewport(0, 0, image_size.width(), image_size.height());
29
30 // Create a solid color green image of preferred format. This must succeed
31 // in order for a GLImage to be conformant.
32 scoped_refptr<GLImage> image =
33 this->delegate_.CreateSolidColorImage(image_size, image_color);
34 ASSERT_TRUE(image);
35
36 // Initialize a blue texture of the same size as |image|.
37 unsigned target = this->delegate_.GetTextureTarget();
38 GLuint texture = GLTestHelper::CreateTexture(target);
39 glBindTexture(target, texture);
40
41 // Bind |image| to |texture|.
42 bool rv = image->BindTexImage(target);
43 EXPECT_TRUE(rv);
44
45 glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
46 glClear(GL_COLOR_BUFFER_BIT);
47 // Draw |texture| to viewport.
48 internal::DrawTextureQuad(target, image_size);
49
50 // Read back pixels to check expectations.
51 GLTestHelper::CheckPixelsWithError(
52 0, 0, image_size.width(), image_size.height(),
53 this->delegate_.GetAdmissibleError(), image_color);
54
55 // Clean up.
56 glDeleteTextures(1, &texture);
57 glDeleteFramebuffersEXT(1, &framebuffer);
58 }
59
60 REGISTER_TYPED_TEST_SUITE_P(GLImageBindTest, BindTexImage);
61
62 } // namespace gl
63
64 #endif // UI_GL_TEST_GL_IMAGE_BIND_TEST_TEMPLATE_H_
65