| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "gpu/command_buffer/service/framebuffer_manager.h" | 5 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 6 #include "gpu/command_buffer/service/feature_info.h" |
| 6 | 7 |
| 7 #include "gpu/command_buffer/common/gl_mock.h" | 8 #include "gpu/command_buffer/common/gl_mock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace gpu { | 11 namespace gpu { |
| 11 namespace gles2 { | 12 namespace gles2 { |
| 12 | 13 |
| 13 class FramebufferManagerTest : public testing::Test { | 14 class FramebufferManagerTest : public testing::Test { |
| 14 public: | 15 public: |
| 15 FramebufferManagerTest() { | 16 FramebufferManagerTest() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 // GCC requires these declarations, but MSVC requires they not be present | 112 // GCC requires these declarations, but MSVC requires they not be present |
| 112 #ifndef COMPILER_MSVC | 113 #ifndef COMPILER_MSVC |
| 113 const GLuint FramebufferInfoTest::kClient1Id; | 114 const GLuint FramebufferInfoTest::kClient1Id; |
| 114 const GLuint FramebufferInfoTest::kService1Id; | 115 const GLuint FramebufferInfoTest::kService1Id; |
| 115 #endif | 116 #endif |
| 116 | 117 |
| 117 TEST_F(FramebufferInfoTest, Basic) { | 118 TEST_F(FramebufferInfoTest, Basic) { |
| 118 EXPECT_EQ(kService1Id, info_->service_id()); | 119 EXPECT_EQ(kService1Id, info_->service_id()); |
| 119 EXPECT_FALSE(info_->IsDeleted()); | 120 EXPECT_FALSE(info_->IsDeleted()); |
| 121 EXPECT_TRUE(NULL == info_->GetAttachment(GL_COLOR_ATTACHMENT0)); |
| 122 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_ATTACHMENT)); |
| 123 EXPECT_TRUE(NULL == info_->GetAttachment(GL_STENCIL_ATTACHMENT)); |
| 124 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
| 120 } | 125 } |
| 121 | 126 |
| 122 TEST_F(FramebufferInfoTest, AttachRenderbuffer) { | 127 TEST_F(FramebufferInfoTest, AttachRenderbuffer) { |
| 123 const GLuint kRenderbufferClient1Id = 33; | 128 const GLuint kRenderbufferClient1Id = 33; |
| 124 const GLuint kRenderbufferService1Id = 333; | 129 const GLuint kRenderbufferService1Id = 333; |
| 125 const GLuint kRenderbufferClient2Id = 34; | 130 const GLuint kRenderbufferClient2Id = 34; |
| 126 const GLuint kRenderbufferService2Id = 334; | 131 const GLuint kRenderbufferService2Id = 334; |
| 127 const GLint kMaxRenderbufferSize = 128; | 132 const GLint kMaxRenderbufferSize = 128; |
| 133 const GLsizei kWidth1 = 16; |
| 134 const GLsizei kHeight1 = 32; |
| 135 const GLenum kFormat1 = GL_STENCIL_INDEX8; |
| 136 const GLsizei kSamples1 = 0; |
| 137 const GLsizei kWidth2 = 64; |
| 138 const GLsizei kHeight2 = 128; |
| 139 const GLenum kFormat2 = GL_STENCIL_INDEX; |
| 140 const GLsizei kSamples2 = 0; |
| 141 const GLsizei kWidth3 = 75; |
| 142 const GLsizei kHeight3 = 123; |
| 143 const GLenum kFormat3 = GL_STENCIL_INDEX8; |
| 144 const GLsizei kSamples3 = 0; |
| 145 |
| 128 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 146 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 129 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 147 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 130 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 148 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 131 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); | 149 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
| 132 | 150 |
| 133 RenderbufferManager rb_manager(kMaxRenderbufferSize); | 151 RenderbufferManager rb_manager(kMaxRenderbufferSize); |
| 134 rb_manager.CreateRenderbufferInfo( | 152 rb_manager.CreateRenderbufferInfo( |
| 135 kRenderbufferClient1Id, kRenderbufferService1Id); | 153 kRenderbufferClient1Id, kRenderbufferService1Id); |
| 136 RenderbufferManager::RenderbufferInfo* rb_info1 = | 154 RenderbufferManager::RenderbufferInfo* rb_info1 = |
| 137 rb_manager.GetRenderbufferInfo(kRenderbufferClient1Id); | 155 rb_manager.GetRenderbufferInfo(kRenderbufferClient1Id); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 // check marking them as cleared. | 168 // check marking them as cleared. |
| 151 info_->MarkAttachedRenderbuffersAsCleared(); | 169 info_->MarkAttachedRenderbuffersAsCleared(); |
| 152 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 170 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 153 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 171 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 154 | 172 |
| 155 // Check adding one that is already cleared. | 173 // Check adding one that is already cleared. |
| 156 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info1); | 174 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info1); |
| 157 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 175 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 158 | 176 |
| 159 // Check marking the renderbuffer as unclared. | 177 // Check marking the renderbuffer as unclared. |
| 160 rb_info1->set_internal_format(GL_RGBA); | 178 rb_info1->SetInfo(kSamples1, kFormat1, kWidth1, kHeight1); |
| 179 |
| 180 const FramebufferManager::FramebufferInfo::Attachment* attachment = |
| 181 info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 182 ASSERT_TRUE(attachment != NULL); |
| 183 EXPECT_EQ(kWidth1, attachment->width()); |
| 184 EXPECT_EQ(kHeight1, attachment->height()); |
| 185 EXPECT_EQ(kSamples1, attachment->samples()); |
| 186 EXPECT_EQ(kFormat1, attachment->internal_format()); |
| 187 EXPECT_FALSE(attachment->cleared()); |
| 188 |
| 161 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 189 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 162 | 190 |
| 163 // Clear it. | 191 // Clear it. |
| 164 info_->MarkAttachedRenderbuffersAsCleared(); | 192 info_->MarkAttachedRenderbuffersAsCleared(); |
| 165 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 193 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 166 | 194 |
| 167 // Check replacing an attachment | 195 // Check replacing an attachment |
| 168 rb_manager.CreateRenderbufferInfo( | 196 rb_manager.CreateRenderbufferInfo( |
| 169 kRenderbufferClient2Id, kRenderbufferService2Id); | 197 kRenderbufferClient2Id, kRenderbufferService2Id); |
| 170 RenderbufferManager::RenderbufferInfo* rb_info2 = | 198 RenderbufferManager::RenderbufferInfo* rb_info2 = |
| 171 rb_manager.GetRenderbufferInfo(kRenderbufferClient2Id); | 199 rb_manager.GetRenderbufferInfo(kRenderbufferClient2Id); |
| 172 ASSERT_TRUE(rb_info2 != NULL); | 200 ASSERT_TRUE(rb_info2 != NULL); |
| 201 rb_info2->SetInfo(kSamples2, kFormat2, kWidth2, kHeight2); |
| 173 | 202 |
| 174 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info2); | 203 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info2); |
| 175 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 204 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 176 | 205 |
| 206 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); |
| 207 ASSERT_TRUE(attachment != NULL); |
| 208 EXPECT_EQ(kWidth2, attachment->width()); |
| 209 EXPECT_EQ(kHeight2, attachment->height()); |
| 210 EXPECT_EQ(kSamples2, attachment->samples()); |
| 211 EXPECT_EQ(kFormat2, attachment->internal_format()); |
| 212 EXPECT_FALSE(attachment->cleared()); |
| 213 |
| 214 // Check changing an attachment. |
| 215 rb_info2->SetInfo(kSamples3, kFormat3, kWidth3, kHeight3); |
| 216 |
| 217 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); |
| 218 ASSERT_TRUE(attachment != NULL); |
| 219 EXPECT_EQ(kWidth3, attachment->width()); |
| 220 EXPECT_EQ(kHeight3, attachment->height()); |
| 221 EXPECT_EQ(kSamples3, attachment->samples()); |
| 222 EXPECT_EQ(kFormat3, attachment->internal_format()); |
| 223 EXPECT_FALSE(attachment->cleared()); |
| 224 |
| 177 // Check removing it. | 225 // Check removing it. |
| 178 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL); | 226 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL); |
| 179 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 227 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 180 | 228 |
| 181 rb_manager.Destroy(false); | 229 rb_manager.Destroy(false); |
| 182 } | 230 } |
| 183 | 231 |
| 232 TEST_F(FramebufferInfoTest, AttachTexture) { |
| 233 const GLuint kTextureClient1Id = 33; |
| 234 const GLuint kTextureService1Id = 333; |
| 235 const GLuint kTextureClient2Id = 34; |
| 236 const GLuint kTextureService2Id = 334; |
| 237 const GLint kMaxTextureSize = 128; |
| 238 const GLint kDepth = 1; |
| 239 const GLint kBorder = 0; |
| 240 const GLenum kType = GL_UNSIGNED_BYTE; |
| 241 const GLsizei kWidth1 = 16; |
| 242 const GLsizei kHeight1 = 32; |
| 243 const GLint kLevel1 = 0; |
| 244 const GLenum kFormat1 = GL_RGBA; |
| 245 const GLenum kTarget1 = GL_TEXTURE_2D; |
| 246 const GLsizei kSamples1 = 0; |
| 247 const GLsizei kWidth2 = 64; |
| 248 const GLsizei kHeight2 = 128; |
| 249 const GLint kLevel2 = 0; |
| 250 const GLenum kFormat2 = GL_RGB; |
| 251 const GLenum kTarget2 = GL_TEXTURE_2D; |
| 252 const GLsizei kSamples2 = 0; |
| 253 const GLsizei kWidth3 = 75; |
| 254 const GLsizei kHeight3 = 123; |
| 255 const GLint kLevel3 = 0; |
| 256 const GLenum kFormat3 = GL_RGB565; |
| 257 const GLsizei kSamples3 = 0; |
| 258 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 259 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 260 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 261 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
| 262 |
| 263 FeatureInfo feature_info; |
| 264 TextureManager tex_manager(kMaxTextureSize, kMaxTextureSize); |
| 265 tex_manager.CreateTextureInfo( |
| 266 &feature_info, kTextureClient1Id, kTextureService1Id); |
| 267 TextureManager::TextureInfo* tex_info1 = |
| 268 tex_manager.GetTextureInfo(kTextureClient1Id); |
| 269 ASSERT_TRUE(tex_info1 != NULL); |
| 270 tex_manager.SetInfoTarget(tex_info1, GL_TEXTURE_2D); |
| 271 tex_manager.SetLevelInfo( |
| 272 &feature_info, tex_info1, GL_TEXTURE_2D, kLevel1, |
| 273 kFormat1, kWidth1, kHeight1, kDepth, kBorder, kFormat1, kType); |
| 274 |
| 275 // check adding one attachment |
| 276 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info1, kTarget1, kLevel1); |
| 277 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 278 |
| 279 const FramebufferManager::FramebufferInfo::Attachment* attachment = |
| 280 info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 281 ASSERT_TRUE(attachment != NULL); |
| 282 EXPECT_EQ(kWidth1, attachment->width()); |
| 283 EXPECT_EQ(kHeight1, attachment->height()); |
| 284 EXPECT_EQ(kSamples1, attachment->samples()); |
| 285 EXPECT_EQ(kFormat1, attachment->internal_format()); |
| 286 EXPECT_TRUE(attachment->cleared()); |
| 287 |
| 288 // Check replacing an attachment |
| 289 tex_manager.CreateTextureInfo( |
| 290 &feature_info, kTextureClient2Id, kTextureService2Id); |
| 291 TextureManager::TextureInfo* tex_info2 = |
| 292 tex_manager.GetTextureInfo(kTextureClient2Id); |
| 293 ASSERT_TRUE(tex_info2 != NULL); |
| 294 tex_manager.SetInfoTarget(tex_info2, GL_TEXTURE_2D); |
| 295 tex_manager.SetLevelInfo( |
| 296 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel2, |
| 297 kFormat2, kWidth2, kHeight2, kDepth, kBorder, kFormat2, kType); |
| 298 |
| 299 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info2, kTarget2, kLevel2); |
| 300 |
| 301 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 302 ASSERT_TRUE(attachment != NULL); |
| 303 EXPECT_EQ(kWidth2, attachment->width()); |
| 304 EXPECT_EQ(kHeight2, attachment->height()); |
| 305 EXPECT_EQ(kSamples2, attachment->samples()); |
| 306 EXPECT_EQ(kFormat2, attachment->internal_format()); |
| 307 EXPECT_TRUE(attachment->cleared()); |
| 308 |
| 309 // Check changing attachment |
| 310 tex_manager.SetLevelInfo( |
| 311 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel3, |
| 312 kFormat3, kWidth3, kHeight3, kDepth, kBorder, kFormat3, kType); |
| 313 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 314 ASSERT_TRUE(attachment != NULL); |
| 315 EXPECT_EQ(kWidth3, attachment->width()); |
| 316 EXPECT_EQ(kHeight3, attachment->height()); |
| 317 EXPECT_EQ(kSamples3, attachment->samples()); |
| 318 EXPECT_EQ(kFormat3, attachment->internal_format()); |
| 319 EXPECT_TRUE(attachment->cleared()); |
| 320 |
| 321 // Check removing it. |
| 322 info_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0); |
| 323 EXPECT_TRUE(info_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL); |
| 324 |
| 325 tex_manager.Destroy(false); |
| 326 } |
| 327 |
| 184 } // namespace gles2 | 328 } // namespace gles2 |
| 185 } // namespace gpu | 329 } // namespace gpu |
| 186 | 330 |
| 187 | 331 |
| OLD | NEW |