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

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
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.cc ('k') | gpu/command_buffer/tests/gl_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8
9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h>
11
12 #include "gpu/command_buffer/service/mailbox_manager.h"
13 #include "gpu/command_buffer/tests/gl_manager.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/gl/gl_share_group.h"
17
18 namespace gpu {
19
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 {
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
56 virtual void SetUp() {
57 gl1_->Initialize(gfx::Size(4, 4));
58 gl2_->Initialize(gfx::Size(4, 4));
59 }
60
61 virtual void TearDown() {
62 gl1_->Destroy();
63 gl2_->Destroy();
64 }
65
66 scoped_ptr<GLManager> gl1_;
67 scoped_ptr<GLManager> gl2_;
68 };
69
70 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) {
71 gl1_->MakeCurrent();
72
73 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM];
74 glGenMailboxCHROMIUM(mailbox1);
75
76 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM];
77 glGenMailboxCHROMIUM(mailbox2);
78
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));
112 }
113
114 TEST_F(GLTextureMailboxTest, ProduceTextureValidatesKey) {
115 GLuint tex;
116 glGenTextures(1, &tex);
117
118 glBindTexture(GL_TEXTURE_2D, tex);
119 uint32 source_pixel = 0xFF0000FF;
120 glTexImage2D(GL_TEXTURE_2D,
121 0,
122 GL_RGBA,
123 1, 1,
124 0,
125 GL_RGBA,
126 GL_UNSIGNED_BYTE,
127 &source_pixel);
128
129 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
130 glGenMailboxCHROMIUM(invalid_mailbox);
131 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
132
133 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
134 glProduceTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
135 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
136
137 // Ensure level 0 is still intact after glProduceTextureCHROMIUM fails.
138 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
139 EXPECT_EQ(source_pixel, ReadTexel(tex, 0, 0));
140 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
141 }
142
143 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) {
144 GLuint tex;
145 glGenTextures(1, &tex);
146
147 glBindTexture(GL_TEXTURE_2D, tex);
148 uint32 source_pixel = 0xFF0000FF;
149 glTexImage2D(GL_TEXTURE_2D,
150 0,
151 GL_RGBA,
152 1, 1,
153 0,
154 GL_RGBA,
155 GL_UNSIGNED_BYTE,
156 &source_pixel);
157
158 GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM];
159 glGenMailboxCHROMIUM(invalid_mailbox);
160 ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1];
161
162 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
163 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox);
164 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
165
166 // Ensure level 0 is still intact after glConsumeTextureCHROMIUM fails.
167 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
168 EXPECT_EQ(source_pixel, ReadTexel(tex, 0, 0));
169 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
170 }
171 } // namespace gpu
172
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.cc ('k') | gpu/command_buffer/tests/gl_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698