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

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 #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
13 class GLTest : public testing::Test { 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
44 class GLTextureMailboxTest : public testing::Test {
14 protected: 45 protected:
46 GLTextureMailboxTest() {
47 gles2::MailboxManager* mailbox_manager = new gles2::MailboxManager;
48 gfx::GLShareGroup* share_group = new gfx::GLShareGroup;
49 gl1_.reset(new GLManager(mailbox_manager, share_group));
50 gl2_.reset(new GLManager(mailbox_manager, share_group));
51 }
52
15 virtual void SetUp() { 53 virtual void SetUp() {
16 gl_.Initialize(gfx::Size(4, 4)); 54 gl1_->Initialize(gfx::Size(4, 4));
55 gl2_->Initialize(gfx::Size(4, 4));
17 } 56 }
18 57
19 virtual void TearDown() { 58 virtual void TearDown() {
20 gl_.Destroy(); 59 gl1_->Destroy();
60 gl2_->Destroy();
21 } 61 }
22 62
23 GLManager gl_; 63 scoped_ptr<GLManager> gl1_;
64 scoped_ptr<GLManager> gl2_;
24 }; 65 };
25 66
26 // Test that GL is at least minimally working. 67 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) {
27 TEST_F(GLTest, Basic) { 68 gl1_->MakeCurrent();
28 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); 69
29 glClear(GL_COLOR_BUFFER_BIT); 70 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM];
30 uint8 pixels[4] = { 0, }; 71 glGenMailboxCHROMIUM(mailbox1);
31 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 72
32 EXPECT_EQ(0u, pixels[0]); 73 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM];
33 EXPECT_EQ(255u, pixels[1]); 74 glGenMailboxCHROMIUM(mailbox2);
34 EXPECT_EQ(0u, pixels[2]); 75
35 EXPECT_EQ(255u, pixels[3]); 76 GLuint tex1;
77 glGenTextures(1, &tex1);
78
79 glBindTexture(GL_TEXTURE_2D, tex1);
80 uint32 source_pixel = 0xFF0000FF;
81 glTexImage2D(GL_TEXTURE_2D,
82 0,
83 GL_RGBA,
84 1, 1,
85 0,
86 GL_RGBA,
87 GL_UNSIGNED_BYTE,
88 &source_pixel);
89
90 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1);
91 glFlush();
92
93 gl2_->MakeCurrent();
94
95 GLuint tex2;
96 glGenTextures(1, &tex2);
97
98 glBindTexture(GL_TEXTURE_2D, tex2);
99 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1);
100 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0));
101 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2);
102 glFlush();
103
104 gl1_->MakeCurrent();
105
106 glBindTexture(GL_TEXTURE_2D, tex1);
107 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2);
108 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0));
109 }
110
111 TEST_F(GLTextureMailboxTest, ProduceTextureValidatesKey) {
112 GLuint tex;
113 glGenTextures(1, &tex);
114
115 glBindTexture(GL_TEXTURE_2D, tex);
116 glTexImage2D(GL_TEXTURE_2D,
117 0,
118 GL_RGBA,
119 1, 1,
120 0,
121 GL_RGBA,
122 GL_UNSIGNED_BYTE,
123 NULL);
124
125 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
126 glGenMailboxCHROMIUM(invalid_mailbox);
127 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
128
129 EXPECT_EQ(GL_NO_ERROR, glGetError());
130 glProduceTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
131 EXPECT_EQ(GL_INVALID_OPERATION, glGetError());
Ken Russell (switch to Gerrit) 2012/04/26 22:34:14 Ideally would also test whether the texture was de
apatrick_chromium 2012/04/27 22:31:58 Done.
132 }
133
134 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) {
135 GLuint tex;
136 glGenTextures(1, &tex);
137
138 glBindTexture(GL_TEXTURE_2D, tex);
139
140 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
141 glGenMailboxCHROMIUM(invalid_mailbox);
142 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
143
144 EXPECT_EQ(GL_NO_ERROR, glGetError());
145 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
146 EXPECT_EQ(GL_INVALID_OPERATION, glGetError());
36 } 147 }
37 148
38 } // namespace gpu 149 } // namespace gpu
39 150
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698