OLD | NEW |
---|---|
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 #define GL_GLEXT_PROTOTYPES | |
6 | |
5 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | |
6 | 9 |
10 #include "gpu/command_buffer/service/mailbox_manager.h" | |
7 #include "gpu/command_buffer/tests/gl_manager.h" | 11 #include "gpu/command_buffer/tests/gl_manager.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/gfx/gl/gl_share_group.h" | |
10 | 15 |
11 namespace gpu { | 16 namespace gpu { |
12 | 17 |
18 namespace { | |
19 uint32 ReadTexel(GLuint id, GLint x, GLint y) { | |
20 GLint old_fbo = 0; | |
21 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo); | |
22 | |
23 GLuint fbo; | |
24 glGenFramebuffers(1, &fbo); | |
25 glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
26 glFramebufferTexture2D(GL_FRAMEBUFFER, | |
27 GL_COLOR_ATTACHMENT0, | |
28 GL_TEXTURE_2D, | |
29 id, | |
30 0); | |
31 EXPECT_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
32 | |
33 uint32 texel; | |
34 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &texel); | |
35 | |
36 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); | |
37 | |
38 glDeleteFramebuffers(1, &fbo); | |
39 | |
40 return texel; | |
41 } | |
42 } | |
43 | |
13 class GLTest : public testing::Test { | 44 class GLTest : public testing::Test { |
14 protected: | 45 protected: |
46 GLTest() : gl_(new gles2::MailboxManager, new gfx::GLShareGroup) { | |
47 } | |
48 | |
15 virtual void SetUp() { | 49 virtual void SetUp() { |
16 gl_.Initialize(gfx::Size(4, 4)); | 50 gl_.Initialize(gfx::Size(4, 4)); |
17 } | 51 } |
18 | 52 |
19 virtual void TearDown() { | 53 virtual void TearDown() { |
20 gl_.Destroy(); | 54 gl_.Destroy(); |
21 } | 55 } |
22 | 56 |
23 GLManager gl_; | 57 GLManager gl_; |
24 }; | 58 }; |
25 | 59 |
26 // Test that GL is at least minimally working. | 60 // Test that GL is at least minimally working. |
27 TEST_F(GLTest, Basic) { | 61 TEST_F(GLTest, Basic) { |
28 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | 62 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
29 glClear(GL_COLOR_BUFFER_BIT); | 63 glClear(GL_COLOR_BUFFER_BIT); |
30 uint8 pixels[4] = { 0, }; | 64 uint8 pixels[4] = { 0, }; |
31 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 65 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
32 EXPECT_EQ(0u, pixels[0]); | 66 EXPECT_EQ(0u, pixels[0]); |
33 EXPECT_EQ(255u, pixels[1]); | 67 EXPECT_EQ(255u, pixels[1]); |
34 EXPECT_EQ(0u, pixels[2]); | 68 EXPECT_EQ(0u, pixels[2]); |
35 EXPECT_EQ(255u, pixels[3]); | 69 EXPECT_EQ(255u, pixels[3]); |
36 } | 70 } |
37 | 71 |
72 TEST_F(GLTest, ProduceAndConsumeTexture) { | |
Ken Russell (switch to Gerrit)
2012/04/26 01:10:53
Nice test!
| |
73 GLManager gl2(gl_.mailbox_manager(), gl_.share_group()); | |
74 gl2.Initialize(gfx::Size(1, 1)); | |
75 | |
76 char mailbox[32]; | |
Ken Russell (switch to Gerrit)
2012/04/26 01:10:53
Really wish the "32" could be part of the type.
| |
77 glGenMailboxCHROMIUM(mailbox); | |
78 | |
79 gl_.MakeCurrent(); | |
80 | |
81 GLuint tex1; | |
82 glGenTextures(1, &tex1); | |
83 | |
84 glBindTexture(GL_TEXTURE_2D, tex1); | |
85 uint32 source_pixel = 0xFF0000FF; | |
86 glTexImage2D(GL_TEXTURE_2D, | |
87 0, | |
88 GL_RGBA, | |
89 1, 1, | |
90 0, | |
91 GL_RGBA, | |
92 GL_UNSIGNED_BYTE, | |
93 &source_pixel); | |
94 | |
95 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | |
96 glFlush(); | |
97 | |
98 gl2.MakeCurrent(); | |
99 | |
100 GLuint tex2; | |
101 glGenTextures(1, &tex2); | |
102 | |
103 glBindTexture(GL_TEXTURE_2D, tex2); | |
104 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | |
105 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); | |
106 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | |
107 glFlush(); | |
108 | |
109 gl_.MakeCurrent(); | |
110 | |
111 glBindTexture(GL_TEXTURE_2D, tex1); | |
112 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | |
113 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); | |
114 | |
115 gl2.Destroy(); | |
116 } | |
117 | |
38 } // namespace gpu | 118 } // namespace gpu |
39 | 119 |
OLD | NEW |