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 "app/gfx/gl/gl_mock.h" | 6 #include "app/gfx/gl/gl_mock.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace gpu { | 9 namespace gpu { |
10 namespace gles2 { | 10 namespace gles2 { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 ASSERT_TRUE(info1 != NULL); | 68 ASSERT_TRUE(info1 != NULL); |
69 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id))) | 69 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id))) |
70 .Times(1) | 70 .Times(1) |
71 .RetiresOnSaturation(); | 71 .RetiresOnSaturation(); |
72 manager_.Destroy(true); | 72 manager_.Destroy(true); |
73 // Check the resources were released. | 73 // Check the resources were released. |
74 info1 = manager_.GetFramebufferInfo(kClient1Id); | 74 info1 = manager_.GetFramebufferInfo(kClient1Id); |
75 ASSERT_TRUE(info1 == NULL); | 75 ASSERT_TRUE(info1 == NULL); |
76 } | 76 } |
77 | 77 |
78 // TODO(gman): Write test for AttachRenderbuffer | 78 class FramebufferInfoTest : public testing::Test { |
| 79 public: |
| 80 static const GLuint kClient1Id = 1; |
| 81 static const GLuint kService1Id = 11; |
| 82 |
| 83 FramebufferInfoTest() |
| 84 : manager_() { |
| 85 } |
| 86 ~FramebufferInfoTest() { |
| 87 manager_.Destroy(false); |
| 88 } |
| 89 |
| 90 protected: |
| 91 virtual void SetUp() { |
| 92 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 93 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 94 manager_.CreateFramebufferInfo(kClient1Id, kService1Id); |
| 95 info_ = manager_.GetFramebufferInfo(kClient1Id); |
| 96 ASSERT_TRUE(info_ != NULL); |
| 97 } |
| 98 |
| 99 virtual void TearDown() { |
| 100 ::gfx::GLInterface::SetGLInterface(NULL); |
| 101 gl_.reset(); |
| 102 } |
| 103 |
| 104 // Use StrictMock to make 100% sure we know how GL will be called. |
| 105 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 106 FramebufferManager manager_; |
| 107 FramebufferManager::FramebufferInfo* info_; |
| 108 }; |
| 109 |
| 110 // GCC requires these declarations, but MSVC requires they not be present |
| 111 #ifndef COMPILER_MSVC |
| 112 const GLuint FramebufferInfoTest::kClient1Id; |
| 113 const GLuint FramebufferInfoTest::kService1Id; |
| 114 #endif |
| 115 |
| 116 TEST_F(FramebufferInfoTest, Basic) { |
| 117 EXPECT_EQ(kService1Id, info_->service_id()); |
| 118 EXPECT_FALSE(info_->IsDeleted()); |
| 119 } |
| 120 |
| 121 TEST_F(FramebufferInfoTest, AttachRenderbuffer) { |
| 122 const GLuint kRenderbufferClient1Id = 33; |
| 123 const GLuint kRenderbufferService1Id = 333; |
| 124 const GLuint kRenderbufferClient2Id = 34; |
| 125 const GLuint kRenderbufferService2Id = 334; |
| 126 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 127 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 128 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 129 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
| 130 |
| 131 RenderbufferManager rb_manager; |
| 132 rb_manager.CreateRenderbufferInfo( |
| 133 kRenderbufferClient1Id, kRenderbufferService1Id); |
| 134 RenderbufferManager::RenderbufferInfo* rb_info1 = |
| 135 rb_manager.GetRenderbufferInfo(kRenderbufferClient1Id); |
| 136 ASSERT_TRUE(rb_info1 != NULL); |
| 137 |
| 138 // check adding one attachment |
| 139 info_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, rb_info1); |
| 140 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 141 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 142 |
| 143 // check adding another |
| 144 info_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, rb_info1); |
| 145 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 146 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 147 |
| 148 // check marking them as cleared. |
| 149 info_->MarkAttachedRenderbuffersAsCleared(); |
| 150 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
| 151 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
| 152 |
| 153 // Check adding one that is already cleared. |
| 154 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info1); |
| 155 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 156 |
| 157 // Check marking the renderbuffer as unclared. |
| 158 rb_info1->set_internal_format(GL_RGBA); |
| 159 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 160 |
| 161 // Clear it. |
| 162 info_->MarkAttachedRenderbuffersAsCleared(); |
| 163 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 164 |
| 165 // Check replacing an attachment |
| 166 rb_manager.CreateRenderbufferInfo( |
| 167 kRenderbufferClient2Id, kRenderbufferService2Id); |
| 168 RenderbufferManager::RenderbufferInfo* rb_info2 = |
| 169 rb_manager.GetRenderbufferInfo(kRenderbufferClient2Id); |
| 170 ASSERT_TRUE(rb_info2 != NULL); |
| 171 |
| 172 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info2); |
| 173 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 174 |
| 175 // Check removing it. |
| 176 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL); |
| 177 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 178 |
| 179 rb_manager.Destroy(false); |
| 180 } |
79 | 181 |
80 } // namespace gles2 | 182 } // namespace gles2 |
81 } // namespace gpu | 183 } // namespace gpu |
82 | 184 |
83 | 185 |
OLD | NEW |