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

Side by Side Diff: content/browser/compositor/buffer_queue_unittest.cc

Issue 571623003: Partial swap implementation for surfaceless (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplify some of the swap logic. verified works Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 <set> 5 #include <set>
6 6
7 #include "cc/test/test_context_provider.h" 7 #include "cc/test/test_context_provider.h"
8 #include "cc/test/test_web_graphics_context_3d.h" 8 #include "cc/test/test_web_graphics_context_3d.h"
9 #include "content/browser/compositor/buffer_queue.h" 9 #include "content/browser/compositor/buffer_queue.h"
10 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s urface.h" 10 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s urface.h"
11 #include "gpu/GLES2/gl2extchromium.h" 11 #include "gpu/GLES2/gl2extchromium.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/khronos/GLES2/gl2ext.h" 14 #include "third_party/khronos/GLES2/gl2ext.h"
15 15
16 using ::testing::_; 16 using ::testing::_;
17 using ::testing::Expectation; 17 using ::testing::Expectation;
18 using ::testing::Ne; 18 using ::testing::Ne;
19 using ::testing::Return; 19 using ::testing::Return;
20 20
21 namespace content { 21 namespace content {
22 class MockBufferQueue : public BufferQueue {
23 public:
24 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
25 unsigned int internalformat)
26 : BufferQueue(context_provider, internalformat) {}
27 MOCK_METHOD4(CopyBufferDamage,
28 void(int, int, const gfx::Rect&, const gfx::Rect&));
29 };
22 30
23 class BufferQueueTest : public ::testing::Test { 31 class BufferQueueTest : public ::testing::Test {
24 public: 32 public:
33 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {}
34
25 virtual void SetUp() OVERRIDE { 35 virtual void SetUp() OVERRIDE {
26 scoped_refptr<cc::TestContextProvider> context_provider = 36 scoped_refptr<cc::TestContextProvider> context_provider =
27 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); 37 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create());
28 context_provider->BindToCurrentThread(); 38 context_provider->BindToCurrentThread();
29 output_surface_.reset(new BufferQueue(context_provider, GL_RGBA8_OES)); 39 output_surface_.reset(new MockBufferQueue(context_provider, GL_RGBA8_OES));
40 output_surface_->Initialize();
30 } 41 }
31 42
32 unsigned current_surface() { return output_surface_->current_surface_.image; } 43 unsigned current_surface() { return output_surface_->current_surface_.image; }
33 const std::vector<BufferQueue::AllocatedSurface>& available_surfaces() { 44 const std::vector<BufferQueue::AllocatedSurface>& available_surfaces() {
34 return output_surface_->available_surfaces_; 45 return output_surface_->available_surfaces_;
35 } 46 }
36 const std::queue<BufferQueue::AllocatedSurface>& in_flight_surfaces() { 47 const std::deque<BufferQueue::AllocatedSurface>& in_flight_surfaces() {
37 return output_surface_->in_flight_surfaces_; 48 return output_surface_->in_flight_surfaces_;
38 } 49 }
39 50
51 const BufferQueue::AllocatedSurface& last_frame() {
52 return output_surface_->in_flight_surfaces_.back();
53 }
54 const BufferQueue::AllocatedSurface& next_frame() {
55 return output_surface_->available_surfaces_.back();
56 }
57 const gfx::Size size() { return output_surface_->size_; }
58
40 int CountBuffers() { 59 int CountBuffers() {
41 int n = available_surfaces().size() + in_flight_surfaces().size(); 60 int n = available_surfaces().size() + in_flight_surfaces().size();
42 if (current_surface()) 61 if (current_surface())
43 n++; 62 n++;
44 return n; 63 return n;
45 } 64 }
46 65
47 // Check that each buffer is unique if present. 66 // Check that each buffer is unique if present.
48 void CheckUnique() { 67 void CheckUnique() {
49 std::set<unsigned> buffers; 68 std::set<unsigned> buffers;
50 EXPECT_TRUE(InsertUnique(&buffers, current_surface())); 69 EXPECT_TRUE(InsertUnique(&buffers, current_surface()));
51 for (size_t i = 0; i < available_surfaces().size(); i++) 70 for (size_t i = 0; i < available_surfaces().size(); i++)
52 EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i].image)); 71 EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i].image));
53 std::queue<BufferQueue::AllocatedSurface> copy = in_flight_surfaces(); 72 for (std::deque<BufferQueue::AllocatedSurface>::const_iterator it =
54 while (!copy.empty()) { 73 in_flight_surfaces().begin();
55 EXPECT_TRUE(InsertUnique(&buffers, copy.front().image)); 74 it != in_flight_surfaces().end();
56 copy.pop(); 75 ++it)
57 } 76 EXPECT_TRUE(InsertUnique(&buffers, it->image));
58 } 77 }
59 78
79 void SwapBuffers() {
80 output_surface_->SwapBuffers(gfx::Rect(output_surface_->size_));
81 }
82
83 void SendDamagedFrame(const gfx::Rect& damage) {
84 // We don't care about the GL-level implementation here, just how it uses
85 // damage rects.
86 output_surface_->BindFramebuffer();
87 output_surface_->SwapBuffers(damage);
88 if (doublebuffering_ || !first_frame_)
89 output_surface_->PageFlipComplete();
90 first_frame_ = false;
91 }
92
93 void SendFullFrame() { SendDamagedFrame(gfx::Rect(output_surface_->size_)); }
94
60 protected: 95 protected:
61 bool InsertUnique(std::set<unsigned>* set, unsigned value) { 96 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
62 if (!value) 97 if (!value)
63 return true; 98 return true;
64 if (set->find(value) != set->end()) 99 if (set->find(value) != set->end())
65 return false; 100 return false;
66 set->insert(value); 101 set->insert(value);
67 return true; 102 return true;
68 } 103 }
69 104
70 scoped_ptr<BufferQueue> output_surface_; 105 scoped_ptr<MockBufferQueue> output_surface_;
106 bool doublebuffering_;
107 bool first_frame_;
71 }; 108 };
72 109
73 namespace { 110 namespace {
111 const gfx::Size screen_size = gfx::Size(30, 30);
112 const gfx::Rect screen_rect = gfx::Rect(screen_size);
113 const gfx::Rect small_damage = gfx::Rect(gfx::Size(10, 10));
114 const gfx::Rect large_damage = gfx::Rect(gfx::Size(20, 20));
115 const gfx::Rect overlapping_damage = gfx::Rect(gfx::Size(5, 20));
74 116
75 class MockedContext : public cc::TestWebGraphicsContext3D { 117 class MockedContext : public cc::TestWebGraphicsContext3D {
76 public: 118 public:
77 MOCK_METHOD2(bindFramebuffer, void(GLenum, GLuint)); 119 MOCK_METHOD2(bindFramebuffer, void(GLenum, GLuint));
78 MOCK_METHOD2(bindTexture, void(GLenum, GLuint)); 120 MOCK_METHOD2(bindTexture, void(GLenum, GLuint));
79 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint)); 121 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint));
80 MOCK_METHOD4(createImageCHROMIUM, GLuint(GLsizei, GLsizei, GLenum, GLenum)); 122 MOCK_METHOD4(createImageCHROMIUM, GLuint(GLsizei, GLsizei, GLenum, GLenum));
81 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint)); 123 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint));
82 MOCK_METHOD5(framebufferTexture2D, 124 MOCK_METHOD5(framebufferTexture2D,
83 void(GLenum, GLenum, GLenum, GLuint, GLint)); 125 void(GLenum, GLenum, GLenum, GLuint, GLint));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 .After(tex, image); 168 .After(tex, image);
127 EXPECT_CALL( 169 EXPECT_CALL(
128 *context, 170 *context,
129 framebufferTexture2D( 171 framebufferTexture2D(
130 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Ne(0U), _)) 172 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Ne(0U), _))
131 .After(fb, bind_tex); 173 .After(fb, bind_tex);
132 174
133 output_surface->BindFramebuffer(); 175 output_surface->BindFramebuffer();
134 } 176 }
135 177
178 TEST_F(BufferQueueTest, PartialSwapReuse) {
179 // Check that
180 output_surface_->Reshape(screen_size, 1.0f);
181 ASSERT_TRUE(doublebuffering_);
182 EXPECT_CALL(*output_surface_,
183 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1);
184 EXPECT_CALL(*output_surface_,
185 CopyBufferDamage(_, _, small_damage, small_damage)).Times(1);
186 EXPECT_CALL(*output_surface_,
187 CopyBufferDamage(_, _, large_damage, small_damage)).Times(1);
188 SendFullFrame();
189 SendDamagedFrame(small_damage);
190 SendDamagedFrame(small_damage);
191 SendDamagedFrame(large_damage);
192 // Verify that the damage has propagated.
193 EXPECT_EQ(next_frame().damage, large_damage);
194 }
195
196 TEST_F(BufferQueueTest, PartialSwapFullFrame) {
197 output_surface_->Reshape(screen_size, 1.0f);
198 ASSERT_TRUE(doublebuffering_);
199 EXPECT_CALL(*output_surface_,
200 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1);
201 SendFullFrame();
202 SendDamagedFrame(small_damage);
203 SendFullFrame();
204 SendFullFrame();
205 EXPECT_EQ(next_frame().damage, screen_rect);
206 }
207
208 TEST_F(BufferQueueTest, PartialSwapOverlapping) {
209 output_surface_->Reshape(screen_size, 1.0f);
210 ASSERT_TRUE(doublebuffering_);
211 EXPECT_CALL(*output_surface_,
212 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1);
213 EXPECT_CALL(*output_surface_,
214 CopyBufferDamage(_, _, overlapping_damage, small_damage))
215 .Times(1);
216
217 SendFullFrame();
218 SendDamagedFrame(small_damage);
219 SendDamagedFrame(overlapping_damage);
220 EXPECT_EQ(next_frame().damage, overlapping_damage);
221 }
222
136 TEST_F(BufferQueueTest, MultipleBindCalls) { 223 TEST_F(BufferQueueTest, MultipleBindCalls) {
137 // Check that multiple bind calls do not create or change surfaces. 224 // Check that multiple bind calls do not create or change surfaces.
138 output_surface_->BindFramebuffer(); 225 output_surface_->BindFramebuffer();
139 EXPECT_EQ(1, CountBuffers()); 226 EXPECT_EQ(1, CountBuffers());
140 unsigned int fb = current_surface(); 227 unsigned int fb = current_surface();
141 output_surface_->BindFramebuffer(); 228 output_surface_->BindFramebuffer();
142 EXPECT_EQ(1, CountBuffers()); 229 EXPECT_EQ(1, CountBuffers());
143 EXPECT_EQ(fb, current_surface()); 230 EXPECT_EQ(fb, current_surface());
144 } 231 }
145 232
146 TEST_F(BufferQueueTest, CheckDoubleBuffering) { 233 TEST_F(BufferQueueTest, CheckDoubleBuffering) {
147 // Check buffer flow through double buffering path. 234 // Check buffer flow through double buffering path.
148 EXPECT_EQ(0, CountBuffers()); 235 EXPECT_EQ(0, CountBuffers());
149 output_surface_->BindFramebuffer(); 236 output_surface_->BindFramebuffer();
150 EXPECT_EQ(1, CountBuffers()); 237 EXPECT_EQ(1, CountBuffers());
151 EXPECT_NE(0U, current_surface()); 238 EXPECT_NE(0U, current_surface());
152 output_surface_->SwapBuffers(); 239 SwapBuffers();
153 EXPECT_EQ(1U, in_flight_surfaces().size()); 240 EXPECT_EQ(1U, in_flight_surfaces().size());
154 output_surface_->PageFlipComplete(); 241 output_surface_->PageFlipComplete();
155 EXPECT_EQ(1U, in_flight_surfaces().size()); 242 EXPECT_EQ(1U, in_flight_surfaces().size());
156 output_surface_->BindFramebuffer(); 243 output_surface_->BindFramebuffer();
157 EXPECT_EQ(2, CountBuffers()); 244 EXPECT_EQ(2, CountBuffers());
158 CheckUnique(); 245 CheckUnique();
159 EXPECT_NE(0U, current_surface()); 246 EXPECT_NE(0U, current_surface());
160 EXPECT_EQ(1U, in_flight_surfaces().size()); 247 EXPECT_EQ(1U, in_flight_surfaces().size());
161 output_surface_->SwapBuffers(); 248 SwapBuffers();
162 CheckUnique(); 249 CheckUnique();
163 EXPECT_EQ(2U, in_flight_surfaces().size()); 250 EXPECT_EQ(2U, in_flight_surfaces().size());
164 output_surface_->PageFlipComplete(); 251 output_surface_->PageFlipComplete();
165 CheckUnique(); 252 CheckUnique();
166 EXPECT_EQ(1U, in_flight_surfaces().size()); 253 EXPECT_EQ(1U, in_flight_surfaces().size());
167 EXPECT_EQ(1U, available_surfaces().size()); 254 EXPECT_EQ(1U, available_surfaces().size());
168 output_surface_->BindFramebuffer(); 255 output_surface_->BindFramebuffer();
169 EXPECT_EQ(2, CountBuffers()); 256 EXPECT_EQ(2, CountBuffers());
170 CheckUnique(); 257 CheckUnique();
171 EXPECT_TRUE(available_surfaces().empty()); 258 EXPECT_TRUE(available_surfaces().empty());
172 } 259 }
173 260
174 TEST_F(BufferQueueTest, CheckTripleBuffering) { 261 TEST_F(BufferQueueTest, CheckTripleBuffering) {
175 // Check buffer flow through triple buffering path. 262 // Check buffer flow through triple buffering path.
176 263
177 // This bit is the same sequence tested in the doublebuffering case. 264 // This bit is the same sequence tested in the doublebuffering case.
178 output_surface_->BindFramebuffer(); 265 output_surface_->BindFramebuffer();
179 output_surface_->SwapBuffers(); 266 SwapBuffers();
180 output_surface_->PageFlipComplete(); 267 output_surface_->PageFlipComplete();
181 output_surface_->BindFramebuffer(); 268 output_surface_->BindFramebuffer();
182 output_surface_->SwapBuffers(); 269 SwapBuffers();
183 270
184 EXPECT_EQ(2, CountBuffers()); 271 EXPECT_EQ(2, CountBuffers());
185 CheckUnique(); 272 CheckUnique();
186 EXPECT_EQ(2U, in_flight_surfaces().size()); 273 EXPECT_EQ(2U, in_flight_surfaces().size());
187 output_surface_->BindFramebuffer(); 274 output_surface_->BindFramebuffer();
188 EXPECT_EQ(3, CountBuffers()); 275 EXPECT_EQ(3, CountBuffers());
189 CheckUnique(); 276 CheckUnique();
190 EXPECT_NE(0U, current_surface()); 277 EXPECT_NE(0U, current_surface());
191 EXPECT_EQ(2U, in_flight_surfaces().size()); 278 EXPECT_EQ(2U, in_flight_surfaces().size());
192 output_surface_->PageFlipComplete(); 279 output_surface_->PageFlipComplete();
193 EXPECT_EQ(3, CountBuffers()); 280 EXPECT_EQ(3, CountBuffers());
194 CheckUnique(); 281 CheckUnique();
195 EXPECT_NE(0U, current_surface()); 282 EXPECT_NE(0U, current_surface());
196 EXPECT_EQ(1U, in_flight_surfaces().size()); 283 EXPECT_EQ(1U, in_flight_surfaces().size());
197 EXPECT_EQ(1U, available_surfaces().size()); 284 EXPECT_EQ(1U, available_surfaces().size());
198 } 285 }
199 286
200 } // namespace 287 } // namespace
201 } // namespace content 288 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698