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

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: minor changes 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 SendFullFrame();
185 SendDamagedFrame(small_damage);
186 SendDamagedFrame(small_damage);
187 SendDamagedFrame(large_damage);
188 // Verify that the damage has propagated.
189 EXPECT_EQ(next_frame().damage, large_damage);
190 }
191
192 TEST_F(BufferQueueTest, PartialSwapFullFrame) {
193 output_surface_->Reshape(screen_size, 1.0f);
194 ASSERT_TRUE(doublebuffering_);
195 EXPECT_CALL(*output_surface_,
196 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1);
197 SendFullFrame();
198 SendDamagedFrame(small_damage);
199 SendFullFrame();
200 SendFullFrame();
201 EXPECT_EQ(next_frame().damage, screen_rect);
202 }
203
204 TEST_F(BufferQueueTest, PartialSwapOverlapping) {
205 output_surface_->Reshape(screen_size, 1.0f);
206 ASSERT_TRUE(doublebuffering_);
207 EXPECT_CALL(*output_surface_,
208 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1);
209 EXPECT_CALL(*output_surface_,
210 CopyBufferDamage(_, _, overlapping_damage, small_damage))
211 .Times(1);
212
213 SendFullFrame();
214 SendDamagedFrame(small_damage);
215 SendDamagedFrame(overlapping_damage);
216 EXPECT_EQ(next_frame().damage, overlapping_damage);
217 }
218
136 TEST_F(BufferQueueTest, MultipleBindCalls) { 219 TEST_F(BufferQueueTest, MultipleBindCalls) {
137 // Check that multiple bind calls do not create or change surfaces. 220 // Check that multiple bind calls do not create or change surfaces.
138 output_surface_->BindFramebuffer(); 221 output_surface_->BindFramebuffer();
139 EXPECT_EQ(1, CountBuffers()); 222 EXPECT_EQ(1, CountBuffers());
140 unsigned int fb = current_surface(); 223 unsigned int fb = current_surface();
141 output_surface_->BindFramebuffer(); 224 output_surface_->BindFramebuffer();
142 EXPECT_EQ(1, CountBuffers()); 225 EXPECT_EQ(1, CountBuffers());
143 EXPECT_EQ(fb, current_surface()); 226 EXPECT_EQ(fb, current_surface());
144 } 227 }
145 228
146 TEST_F(BufferQueueTest, CheckDoubleBuffering) { 229 TEST_F(BufferQueueTest, CheckDoubleBuffering) {
147 // Check buffer flow through double buffering path. 230 // Check buffer flow through double buffering path.
148 EXPECT_EQ(0, CountBuffers()); 231 EXPECT_EQ(0, CountBuffers());
149 output_surface_->BindFramebuffer(); 232 output_surface_->BindFramebuffer();
150 EXPECT_EQ(1, CountBuffers()); 233 EXPECT_EQ(1, CountBuffers());
151 EXPECT_NE(0U, current_surface()); 234 EXPECT_NE(0U, current_surface());
152 output_surface_->SwapBuffers(); 235 SwapBuffers();
153 EXPECT_EQ(1U, in_flight_surfaces().size()); 236 EXPECT_EQ(1U, in_flight_surfaces().size());
154 output_surface_->PageFlipComplete(); 237 output_surface_->PageFlipComplete();
155 EXPECT_EQ(1U, in_flight_surfaces().size()); 238 EXPECT_EQ(1U, in_flight_surfaces().size());
156 output_surface_->BindFramebuffer(); 239 output_surface_->BindFramebuffer();
157 EXPECT_EQ(2, CountBuffers()); 240 EXPECT_EQ(2, CountBuffers());
158 CheckUnique(); 241 CheckUnique();
159 EXPECT_NE(0U, current_surface()); 242 EXPECT_NE(0U, current_surface());
160 EXPECT_EQ(1U, in_flight_surfaces().size()); 243 EXPECT_EQ(1U, in_flight_surfaces().size());
161 output_surface_->SwapBuffers(); 244 SwapBuffers();
162 CheckUnique(); 245 CheckUnique();
163 EXPECT_EQ(2U, in_flight_surfaces().size()); 246 EXPECT_EQ(2U, in_flight_surfaces().size());
164 output_surface_->PageFlipComplete(); 247 output_surface_->PageFlipComplete();
165 CheckUnique(); 248 CheckUnique();
166 EXPECT_EQ(1U, in_flight_surfaces().size()); 249 EXPECT_EQ(1U, in_flight_surfaces().size());
167 EXPECT_EQ(1U, available_surfaces().size()); 250 EXPECT_EQ(1U, available_surfaces().size());
168 output_surface_->BindFramebuffer(); 251 output_surface_->BindFramebuffer();
169 EXPECT_EQ(2, CountBuffers()); 252 EXPECT_EQ(2, CountBuffers());
170 CheckUnique(); 253 CheckUnique();
171 EXPECT_TRUE(available_surfaces().empty()); 254 EXPECT_TRUE(available_surfaces().empty());
172 } 255 }
173 256
174 TEST_F(BufferQueueTest, CheckTripleBuffering) { 257 TEST_F(BufferQueueTest, CheckTripleBuffering) {
175 // Check buffer flow through triple buffering path. 258 // Check buffer flow through triple buffering path.
176 259
177 // This bit is the same sequence tested in the doublebuffering case. 260 // This bit is the same sequence tested in the doublebuffering case.
178 output_surface_->BindFramebuffer(); 261 output_surface_->BindFramebuffer();
179 output_surface_->SwapBuffers(); 262 SwapBuffers();
180 output_surface_->PageFlipComplete(); 263 output_surface_->PageFlipComplete();
181 output_surface_->BindFramebuffer(); 264 output_surface_->BindFramebuffer();
182 output_surface_->SwapBuffers(); 265 SwapBuffers();
183 266
184 EXPECT_EQ(2, CountBuffers()); 267 EXPECT_EQ(2, CountBuffers());
185 CheckUnique(); 268 CheckUnique();
186 EXPECT_EQ(2U, in_flight_surfaces().size()); 269 EXPECT_EQ(2U, in_flight_surfaces().size());
187 output_surface_->BindFramebuffer(); 270 output_surface_->BindFramebuffer();
188 EXPECT_EQ(3, CountBuffers()); 271 EXPECT_EQ(3, CountBuffers());
189 CheckUnique(); 272 CheckUnique();
190 EXPECT_NE(0U, current_surface()); 273 EXPECT_NE(0U, current_surface());
191 EXPECT_EQ(2U, in_flight_surfaces().size()); 274 EXPECT_EQ(2U, in_flight_surfaces().size());
192 output_surface_->PageFlipComplete(); 275 output_surface_->PageFlipComplete();
193 EXPECT_EQ(3, CountBuffers()); 276 EXPECT_EQ(3, CountBuffers());
194 CheckUnique(); 277 CheckUnique();
195 EXPECT_NE(0U, current_surface()); 278 EXPECT_NE(0U, current_surface());
196 EXPECT_EQ(1U, in_flight_surfaces().size()); 279 EXPECT_EQ(1U, in_flight_surfaces().size());
197 EXPECT_EQ(1U, available_surfaces().size()); 280 EXPECT_EQ(1U, available_surfaces().size());
198 } 281 }
199 282
200 } // namespace 283 } // namespace
201 } // namespace content 284 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698