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

Side by Side Diff: gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc

Issue 10106015: Allow textures to be moved from one GL context group to another. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8
5 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h>
6 11
12 #include "gpu/command_buffer/service/mailbox_manager.h"
7 #include "gpu/command_buffer/tests/gl_manager.h" 13 #include "gpu/command_buffer/tests/gl_manager.h"
8 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/gl/gl_share_group.h"
10 17
11 namespace gpu { 18 namespace gpu {
12 19
13 class GLTest : public testing::Test { 20 namespace {
21 uint32 ReadTexel(GLuint id, GLint x, GLint y) {
22 GLint old_fbo = 0;
23 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);
24
25 GLuint fbo;
26 glGenFramebuffers(1, &fbo);
27 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
28 glFramebufferTexture2D(GL_FRAMEBUFFER,
29 GL_COLOR_ATTACHMENT0,
30 GL_TEXTURE_2D,
31 id,
32 0);
33 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
34 glCheckFramebufferStatus(GL_FRAMEBUFFER));
35
36 uint32 texel;
37 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &texel);
38
39 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
40
41 glDeleteFramebuffers(1, &fbo);
42
43 return texel;
44 }
45 }
46
47 class GLTextureMailboxTest : public testing::Test {
14 protected: 48 protected:
49 GLTextureMailboxTest() {
50 gles2::MailboxManager* mailbox_manager = new gles2::MailboxManager;
51 gfx::GLShareGroup* share_group = new gfx::GLShareGroup;
52 gl1_.reset(new GLManager(mailbox_manager, share_group));
53 gl2_.reset(new GLManager(mailbox_manager, share_group));
54 }
55
15 virtual void SetUp() { 56 virtual void SetUp() {
16 gl_.Initialize(gfx::Size(4, 4)); 57 gl1_->Initialize(gfx::Size(4, 4));
58 gl2_->Initialize(gfx::Size(4, 4));
17 } 59 }
18 60
19 virtual void TearDown() { 61 virtual void TearDown() {
20 gl_.Destroy(); 62 gl1_->Destroy();
63 gl2_->Destroy();
21 } 64 }
22 65
23 GLManager gl_; 66 scoped_ptr<GLManager> gl1_;
67 scoped_ptr<GLManager> gl2_;
24 }; 68 };
25 69
26 // Test that GL is at least minimally working. 70 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) {
27 TEST_F(GLTest, Basic) { 71 gl1_->MakeCurrent();
28 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); 72
29 glClear(GL_COLOR_BUFFER_BIT); 73 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM];
30 uint8 pixels[4] = { 0, }; 74 glGenMailboxCHROMIUM(mailbox1);
31 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 75
32 EXPECT_EQ(0u, pixels[0]); 76 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM];
33 EXPECT_EQ(255u, pixels[1]); 77 glGenMailboxCHROMIUM(mailbox2);
34 EXPECT_EQ(0u, pixels[2]); 78
35 EXPECT_EQ(255u, pixels[3]); 79 GLuint tex1;
80 glGenTextures(1, &tex1);
81
82 glBindTexture(GL_TEXTURE_2D, tex1);
83 uint32 source_pixel = 0xFF0000FF;
84 glTexImage2D(GL_TEXTURE_2D,
85 0,
86 GL_RGBA,
87 1, 1,
88 0,
89 GL_RGBA,
90 GL_UNSIGNED_BYTE,
91 &source_pixel);
92
93 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1);
94 glFlush();
95
96 gl2_->MakeCurrent();
97
98 GLuint tex2;
99 glGenTextures(1, &tex2);
100
101 glBindTexture(GL_TEXTURE_2D, tex2);
102 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1);
103 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0));
104 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2);
105 glFlush();
106
107 gl1_->MakeCurrent();
108
109 glBindTexture(GL_TEXTURE_2D, tex1);
110 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2);
111 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0));
36 } 112 }
37 113
114 TEST_F(GLTextureMailboxTest, ProduceTextureValidatesKey) {
115 GLuint tex;
116 glGenTextures(1, &tex);
117
118 glBindTexture(GL_TEXTURE_2D, tex);
119 glTexImage2D(GL_TEXTURE_2D,
120 0,
121 GL_RGBA,
122 1, 1,
123 0,
124 GL_RGBA,
125 GL_UNSIGNED_BYTE,
126 NULL);
127
128 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
129 glGenMailboxCHROMIUM(invalid_mailbox);
130 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
131
132 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
133 glProduceTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
134 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
135
136 // Ensure level 0 is still intact after glProduceTextureCHROMIUM fails.
137 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
138 EXPECT_EQ(0x00000000U, ReadTexel(tex, 0, 0));
Ken Russell (switch to Gerrit) 2012/04/28 00:27:40 Consider filling the texture with a color first to
139 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
140 }
141
142 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) {
143 GLuint tex;
144 glGenTextures(1, &tex);
145
146 glBindTexture(GL_TEXTURE_2D, tex);
147 glTexImage2D(GL_TEXTURE_2D,
148 0,
149 GL_RGBA,
150 1, 1,
151 0,
152 GL_RGBA,
153 GL_UNSIGNED_BYTE,
154 NULL);
155
156 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
157 glGenMailboxCHROMIUM(invalid_mailbox);
158 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
159
160 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
161 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
162 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
163
164 // Ensure level 0 is still intact after glConsumeTextureCHROMIUM fails.
165 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
166 EXPECT_EQ(0x00000000U, ReadTexel(tex, 0, 0));
167 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
168 }
38 } // namespace gpu 169 } // namespace gpu
39 170
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698