Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 #include <set> | |
| 6 | |
| 7 #include "cc/test/test_context_provider.h" | |
| 8 #include "cc/test/test_web_graphics_context_3d.h" | |
| 9 #include "content/browser/compositor/buffered_output_surface.h" | |
| 10 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s urface.h" | |
| 11 #include "gpu/GLES2/gl2extchromium.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 #include "third_party/khronos/GLES2/gl2ext.h" | |
| 15 | |
| 16 using ::testing::_; | |
| 17 using ::testing::Expectation; | |
| 18 using ::testing::Ne; | |
| 19 using ::testing::Return; | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 class BufferedOutputSurfaceTest : public ::testing::Test { | |
| 24 public: | |
| 25 virtual void SetUp() OVERRIDE { | |
| 26 scoped_refptr<cc::TestContextProvider> context_provider = | |
| 27 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); | |
| 28 context_provider->BindToCurrentThread(); | |
| 29 output_surface_.reset( | |
| 30 new BufferedOutputSurface(context_provider, GL_RGBA8_OES)); | |
| 31 } | |
| 32 | |
| 33 unsigned current_surface() { return output_surface_->current_surface_.image; } | |
| 34 const std::vector<BufferedOutputSurface::AllocatedSurface>& | |
| 35 available_surfaces() { | |
| 36 return output_surface_->available_surfaces_; | |
| 37 } | |
| 38 const std::queue<BufferedOutputSurface::AllocatedSurface>& | |
| 39 in_flight_surfaces() { | |
| 40 return output_surface_->in_flight_surfaces_; | |
| 41 } | |
| 42 | |
| 43 int CountBuffers() { | |
| 44 int n = available_surfaces().size() + in_flight_surfaces().size(); | |
| 45 if (current_surface()) | |
| 46 n++; | |
| 47 return n; | |
| 48 } | |
| 49 | |
| 50 // Check that each buffer is unique if present. | |
| 51 void CheckUnique() { | |
| 52 std::set<unsigned> buffers; | |
| 53 EXPECT_TRUE(InsertUnique(&buffers, current_surface())); | |
| 54 for (size_t i = 0; i < available_surfaces().size(); i++) | |
| 55 EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i].image)); | |
| 56 std::queue<BufferedOutputSurface::AllocatedSurface> copy = | |
| 57 in_flight_surfaces(); | |
| 58 while (!copy.empty()) { | |
| 59 EXPECT_TRUE(InsertUnique(&buffers, copy.front().image)); | |
| 60 copy.pop(); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 protected: | |
| 65 bool InsertUnique(std::set<unsigned>* set, unsigned value) { | |
| 66 if (!value) | |
| 67 return true; | |
| 68 if (set->find(value) != set->end()) | |
|
piman
2014/09/12 21:58:30
nit: std::set::insert returns a (iterator, bool) p
| |
| 69 return false; | |
| 70 set->insert(value); | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 scoped_ptr<BufferedOutputSurface> output_surface_; | |
| 75 }; | |
| 76 | |
| 77 namespace { | |
| 78 | |
| 79 class MockedContext : public cc::TestWebGraphicsContext3D { | |
| 80 public: | |
| 81 MOCK_METHOD2(bindFramebuffer, void(GLenum, GLuint)); | |
| 82 MOCK_METHOD2(bindTexture, void(GLenum, GLuint)); | |
| 83 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint)); | |
| 84 MOCK_METHOD4(createImageCHROMIUM, GLuint(GLsizei, GLsizei, GLenum, GLenum)); | |
| 85 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint)); | |
| 86 MOCK_METHOD5(framebufferTexture2D, | |
| 87 void(GLenum, GLenum, GLenum, GLuint, GLint)); | |
| 88 }; | |
| 89 | |
| 90 scoped_ptr<BufferedOutputSurface> CreateOutputSurfaceWithMock( | |
| 91 MockedContext** context) { | |
| 92 *context = new MockedContext(); | |
| 93 scoped_refptr<cc::TestContextProvider> context_provider = | |
| 94 cc::TestContextProvider::Create( | |
| 95 scoped_ptr<cc::TestWebGraphicsContext3D>(*context)); | |
| 96 context_provider->BindToCurrentThread(); | |
| 97 return scoped_ptr<BufferedOutputSurface>( | |
| 98 new BufferedOutputSurface(context_provider, GL_RGBA8_OES)); | |
| 99 } | |
| 100 | |
| 101 TEST(BufferedOutputSurfaceStandaloneTest, FboInitialization) { | |
| 102 MockedContext* context; | |
| 103 scoped_ptr<BufferedOutputSurface> output_surface = | |
| 104 CreateOutputSurfaceWithMock(&context); | |
| 105 | |
| 106 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | |
| 107 | |
| 108 output_surface->Reshape(gfx::Size(10, 20), 1.0f); | |
| 109 } | |
| 110 | |
| 111 TEST(BufferedOutputSurfaceStandaloneTest, FboBinding) { | |
| 112 MockedContext* context; | |
| 113 scoped_ptr<BufferedOutputSurface> output_surface = | |
| 114 CreateOutputSurfaceWithMock(&context); | |
| 115 Expectation image = | |
| 116 EXPECT_CALL( | |
| 117 *context, | |
| 118 createImageCHROMIUM(0, 0, GL_RGBA8_OES, GL_IMAGE_SCANOUT_CHROMIUM)) | |
| 119 .WillOnce(Return(1)); | |
| 120 Expectation fb = | |
| 121 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | |
| 122 Expectation tex = EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, Ne(0U))); | |
| 123 Expectation bind_tex = | |
| 124 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1)) | |
| 125 .After(tex, image); | |
| 126 EXPECT_CALL( | |
| 127 *context, | |
| 128 framebufferTexture2D( | |
| 129 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Ne(0U), _)) | |
| 130 .After(fb, bind_tex); | |
| 131 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); | |
| 132 | |
| 133 output_surface->BindFramebuffer(); | |
| 134 } | |
| 135 | |
| 136 TEST_F(BufferedOutputSurfaceTest, MultipleBindCalls) { | |
| 137 // Check that multiple bind calls do not create or change surfaces. | |
| 138 output_surface_->BindFramebuffer(); | |
| 139 EXPECT_EQ(1, CountBuffers()); | |
| 140 unsigned int fb = current_surface(); | |
| 141 output_surface_->BindFramebuffer(); | |
| 142 EXPECT_EQ(1, CountBuffers()); | |
| 143 EXPECT_EQ(fb, current_surface()); | |
| 144 } | |
| 145 | |
| 146 TEST_F(BufferedOutputSurfaceTest, CheckDoubleBuffering) { | |
| 147 // Check buffer flow through double buffering path. | |
| 148 EXPECT_EQ(0, CountBuffers()); | |
| 149 output_surface_->BindFramebuffer(); | |
| 150 EXPECT_EQ(1, CountBuffers()); | |
| 151 EXPECT_NE(0U, current_surface()); | |
| 152 output_surface_->SwapBuffers(); | |
| 153 EXPECT_EQ(1U, in_flight_surfaces().size()); | |
| 154 output_surface_->PageFlipComplete(); | |
| 155 EXPECT_EQ(1U, in_flight_surfaces().size()); | |
| 156 output_surface_->BindFramebuffer(); | |
| 157 EXPECT_EQ(2, CountBuffers()); | |
| 158 CheckUnique(); | |
| 159 EXPECT_NE(0U, current_surface()); | |
| 160 EXPECT_EQ(1U, in_flight_surfaces().size()); | |
| 161 output_surface_->SwapBuffers(); | |
| 162 CheckUnique(); | |
| 163 EXPECT_EQ(2U, in_flight_surfaces().size()); | |
| 164 output_surface_->PageFlipComplete(); | |
| 165 CheckUnique(); | |
| 166 EXPECT_EQ(1U, in_flight_surfaces().size()); | |
| 167 EXPECT_EQ(1U, available_surfaces().size()); | |
| 168 output_surface_->BindFramebuffer(); | |
| 169 EXPECT_EQ(2, CountBuffers()); | |
| 170 CheckUnique(); | |
| 171 EXPECT_TRUE(available_surfaces().empty()); | |
| 172 } | |
| 173 | |
| 174 TEST_F(BufferedOutputSurfaceTest, CheckTripleBuffering) { | |
| 175 // Check buffer flow through triple buffering path. | |
| 176 | |
| 177 // This bit is the same sequence tested in the doublebuffering case. | |
| 178 output_surface_->BindFramebuffer(); | |
| 179 output_surface_->SwapBuffers(); | |
| 180 output_surface_->PageFlipComplete(); | |
| 181 output_surface_->BindFramebuffer(); | |
| 182 output_surface_->SwapBuffers(); | |
| 183 | |
| 184 EXPECT_EQ(2, CountBuffers()); | |
| 185 CheckUnique(); | |
| 186 EXPECT_EQ(2U, in_flight_surfaces().size()); | |
| 187 output_surface_->BindFramebuffer(); | |
| 188 EXPECT_EQ(3, CountBuffers()); | |
| 189 CheckUnique(); | |
| 190 EXPECT_NE(0U, current_surface()); | |
| 191 EXPECT_EQ(2U, in_flight_surfaces().size()); | |
| 192 output_surface_->PageFlipComplete(); | |
| 193 EXPECT_EQ(3, CountBuffers()); | |
| 194 CheckUnique(); | |
| 195 EXPECT_NE(0U, current_surface()); | |
| 196 EXPECT_EQ(1U, in_flight_surfaces().size()); | |
| 197 EXPECT_EQ(1U, available_surfaces().size()); | |
| 198 } | |
| 199 | |
| 200 } // namespace | |
| 201 } // namespace content | |
| OLD | NEW |