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 "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
| 6 |
| 7 #include <set> |
| 8 |
| 9 #include "cc/test/test_context_provider.h" |
| 10 #include "cc/test/test_web_graphics_context_3d.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 //using ::testing::_; |
| 14 |
| 15 namespace content { |
| 16 class BufferedOutputSurfaceTest : public ::testing::Test { |
| 17 public: |
| 18 virtual void SetUp() OVERRIDE { |
| 19 scoped_refptr<cc::TestContextProvider> context_provider = |
| 20 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); |
| 21 context_provider->BindToCurrentThread(); |
| 22 output_surface_.reset(new BufferedOutputSurface(context_provider, 0)); |
| 23 } |
| 24 |
| 25 unsigned current_surface() { return output_surface_->current_surface_; } |
| 26 unsigned last_surface() { return output_surface_->last_surface_; } |
| 27 unsigned available_surface() { return output_surface_->available_surface_; } |
| 28 unsigned in_flight_surface() { return output_surface_->in_flight_surface_; } |
| 29 |
| 30 int CountBuffers() { |
| 31 int n = 0; |
| 32 if (in_flight_surface()) |
| 33 n++; |
| 34 if (available_surface()) |
| 35 n++; |
| 36 if (current_surface()) |
| 37 n++; |
| 38 if (last_surface()) |
| 39 n++; |
| 40 return n; |
| 41 } |
| 42 |
| 43 // Check that each buffer is unique if present. |
| 44 void CheckUnique() { |
| 45 std::set<unsigned> buffers; |
| 46 EXPECT_TRUE(InsertUnique(&buffers, current_surface())); |
| 47 EXPECT_TRUE(InsertUnique(&buffers, last_surface())); |
| 48 EXPECT_TRUE(InsertUnique(&buffers, available_surface())); |
| 49 EXPECT_TRUE(InsertUnique(&buffers, in_flight_surface())); |
| 50 } |
| 51 |
| 52 protected: |
| 53 bool InsertUnique(std::set<unsigned>* set, unsigned value) { |
| 54 if (!value) |
| 55 return true; |
| 56 if (set->find(value) != set->end()) |
| 57 return false; |
| 58 set->insert(value); |
| 59 return true; |
| 60 } |
| 61 |
| 62 scoped_ptr<BufferedOutputSurface> output_surface_; |
| 63 }; |
| 64 |
| 65 /*TEST(BufferedOutputSurfaceTest, FboBinding) { |
| 66 scoped_ptr<BufferedOutputSurface> output_surface; |
| 67 MockedContext *context = new MockedContext(); |
| 68 output_surface.reset(new |
| 69 BufferedOutputSurface(scoped_ptr<TestWebGraphicsContext3D>(context), 0)); |
| 70 EXPECT_CALL(context, bindFramebuffer(_)).Times(AnyNumber()); |
| 71 EXPECT_CALL(context, bindRenderbuffer(_)).Times(1); |
| 72 output_surface_->BindFramebuffer(); |
| 73 }*/ |
| 74 |
| 75 TEST_F(BufferedOutputSurfaceTest, MultipleBindCalls) { |
| 76 // Check that multiple bind calls do not create or change surfaces. |
| 77 output_surface_->BindFramebuffer(); |
| 78 EXPECT_EQ(1, CountBuffers()); |
| 79 unsigned int fb = current_surface(); |
| 80 output_surface_->BindFramebuffer(); |
| 81 EXPECT_EQ(1, CountBuffers()); |
| 82 EXPECT_EQ(fb, current_surface()); |
| 83 } |
| 84 |
| 85 TEST_F(BufferedOutputSurfaceTest, CheckDoubleBuffering) { |
| 86 // Check buffer flow through double buffering path. |
| 87 EXPECT_EQ(0, CountBuffers()); |
| 88 output_surface_->BindFramebuffer(); |
| 89 EXPECT_EQ(1, CountBuffers()); |
| 90 EXPECT_NE(0U, current_surface()); |
| 91 output_surface_->SwapBuffers(); |
| 92 EXPECT_EQ(1, CountBuffers()); |
| 93 EXPECT_EQ(0U, current_surface()); |
| 94 EXPECT_NE(0U, last_surface()); |
| 95 output_surface_->PageFlipComplete(); |
| 96 EXPECT_EQ(1, CountBuffers()); |
| 97 EXPECT_EQ(0U, current_surface()); |
| 98 EXPECT_NE(0U, last_surface()); |
| 99 output_surface_->BindFramebuffer(); |
| 100 EXPECT_EQ(2, CountBuffers()); |
| 101 CheckUnique(); |
| 102 EXPECT_NE(0U, current_surface()); |
| 103 EXPECT_NE(0U, last_surface()); |
| 104 output_surface_->SwapBuffers(); |
| 105 EXPECT_EQ(2, CountBuffers()); |
| 106 CheckUnique(); |
| 107 EXPECT_EQ(0U, current_surface()); |
| 108 EXPECT_NE(0U, last_surface()); |
| 109 EXPECT_NE(0U, in_flight_surface()); |
| 110 EXPECT_EQ(0U, available_surface()); |
| 111 output_surface_->PageFlipComplete(); |
| 112 EXPECT_EQ(2, CountBuffers()); |
| 113 CheckUnique(); |
| 114 EXPECT_EQ(0U, current_surface()); |
| 115 EXPECT_NE(0U, last_surface()); |
| 116 EXPECT_EQ(0U, in_flight_surface()); |
| 117 EXPECT_NE(0U, available_surface()); |
| 118 output_surface_->BindFramebuffer(); |
| 119 EXPECT_EQ(2, CountBuffers()); |
| 120 CheckUnique(); |
| 121 EXPECT_EQ(0U, available_surface()); |
| 122 } |
| 123 |
| 124 TEST_F(BufferedOutputSurfaceTest, CheckTripleBuffering) { |
| 125 // Check buffer flow through triple buffering path. |
| 126 |
| 127 // This bit is the same sequence tested in the doublebuffering case. |
| 128 output_surface_->BindFramebuffer(); |
| 129 output_surface_->SwapBuffers(); |
| 130 output_surface_->PageFlipComplete(); |
| 131 output_surface_->BindFramebuffer(); |
| 132 output_surface_->SwapBuffers(); |
| 133 |
| 134 EXPECT_EQ(2, CountBuffers()); |
| 135 CheckUnique(); |
| 136 EXPECT_EQ(0U, current_surface()); |
| 137 EXPECT_NE(0U, last_surface()); |
| 138 EXPECT_NE(0U, in_flight_surface()); |
| 139 EXPECT_EQ(0U, available_surface()); |
| 140 output_surface_->BindFramebuffer(); |
| 141 EXPECT_EQ(3, CountBuffers()); |
| 142 CheckUnique(); |
| 143 EXPECT_NE(0U, current_surface()); |
| 144 EXPECT_NE(0U, last_surface()); |
| 145 EXPECT_NE(0U, in_flight_surface()); |
| 146 EXPECT_EQ(0U, available_surface()); |
| 147 output_surface_->PageFlipComplete(); |
| 148 EXPECT_EQ(3, CountBuffers()); |
| 149 CheckUnique(); |
| 150 EXPECT_NE(0U, current_surface()); |
| 151 EXPECT_NE(0U, last_surface()); |
| 152 EXPECT_EQ(0U, in_flight_surface()); |
| 153 EXPECT_NE(0U, available_surface()); |
| 154 } |
| 155 |
| 156 TEST_F(BufferedOutputSurfaceTest, TripleBufferFreeExtra) { |
| 157 // Check that if we temporarily triple buffer, the extra one won't stick |
| 158 // around for too long once doublebuffering resumes. |
| 159 output_surface_->BindFramebuffer(); |
| 160 output_surface_->SwapBuffers(); |
| 161 output_surface_->PageFlipComplete(); |
| 162 |
| 163 output_surface_->BindFramebuffer(); |
| 164 output_surface_->SwapBuffers(); |
| 165 output_surface_->BindFramebuffer(); |
| 166 EXPECT_EQ(3, CountBuffers()); |
| 167 output_surface_->PageFlipComplete(); |
| 168 |
| 169 output_surface_->SwapBuffers(); |
| 170 output_surface_->PageFlipComplete(); |
| 171 |
| 172 output_surface_->BindFramebuffer(); |
| 173 output_surface_->SwapBuffers(); |
| 174 output_surface_->PageFlipComplete(); |
| 175 |
| 176 EXPECT_EQ(2, CountBuffers()); |
| 177 EXPECT_EQ(0U, current_surface()); |
| 178 EXPECT_NE(0U, last_surface()); |
| 179 EXPECT_EQ(0U, in_flight_surface()); |
| 180 EXPECT_NE(0U, available_surface()); |
| 181 } |
| 182 |
| 183 TEST_F(BufferedOutputSurfaceTest, NoPageFlipCalls) { |
| 184 // If PageFlipComplete is never called, it's expected that new buffers |
| 185 // will get created and cycle through current & last. This is inefficient, |
| 186 // but works. |
| 187 output_surface_->BindFramebuffer(); |
| 188 unsigned int fb1 = current_surface(); |
| 189 EXPECT_EQ(1, CountBuffers()); |
| 190 output_surface_->BindFramebuffer(); |
| 191 EXPECT_EQ(2, CountBuffers()); |
| 192 output_surface_->SwapBuffers(); |
| 193 output_surface_->BindFramebuffer(); |
| 194 unsigned int fb2 = current_surface(); |
| 195 EXPECT_EQ(3, CountBuffers()); |
| 196 output_surface_->SwapBuffers(); |
| 197 EXPECT_EQ(2, CountBuffers()); |
| 198 EXPECT_EQ(fb1, in_flight_surface()); |
| 199 EXPECT_EQ(fb2, last_surface()); |
| 200 EXPECT_EQ(0U, current_surface()); |
| 201 EXPECT_EQ(0U, available_surface()); |
| 202 } |
| 203 |
| 204 } // namespace content |
OLD | NEW |