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

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

Issue 516663003: Surfaceless OutputSurface implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
(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/buffer_queue.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 BufferQueueTest : 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(new BufferQueue(context_provider, GL_RGBA8_OES));
30 }
31
32 unsigned current_surface() { return output_surface_->current_surface_.image; }
33 const std::vector<BufferQueue::AllocatedSurface>& available_surfaces() {
34 return output_surface_->available_surfaces_;
35 }
36 const std::queue<BufferQueue::AllocatedSurface>& in_flight_surfaces() {
37 return output_surface_->in_flight_surfaces_;
38 }
39
40 int CountBuffers() {
41 int n = available_surfaces().size() + in_flight_surfaces().size();
42 if (current_surface())
43 n++;
44 return n;
45 }
46
47 // Check that each buffer is unique if present.
48 void CheckUnique() {
49 std::set<unsigned> buffers;
50 EXPECT_TRUE(InsertUnique(&buffers, current_surface()));
51 for (size_t i = 0; i < available_surfaces().size(); i++)
52 EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i].image));
53 std::queue<BufferQueue::AllocatedSurface> copy = in_flight_surfaces();
54 while (!copy.empty()) {
55 EXPECT_TRUE(InsertUnique(&buffers, copy.front().image));
56 copy.pop();
57 }
58 }
59
60 protected:
61 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
62 if (!value)
63 return true;
64 if (set->find(value) != set->end())
65 return false;
66 set->insert(value);
67 return true;
68 }
69
70 scoped_ptr<BufferQueue> output_surface_;
71 };
72
73 namespace {
74
75 class MockedContext : public cc::TestWebGraphicsContext3D {
76 public:
77 MOCK_METHOD2(bindFramebuffer, void(GLenum, GLuint));
78 MOCK_METHOD2(bindTexture, void(GLenum, GLuint));
79 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint));
80 MOCK_METHOD4(createImageCHROMIUM, GLuint(GLsizei, GLsizei, GLenum, GLenum));
81 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint));
82 MOCK_METHOD5(framebufferTexture2D,
83 void(GLenum, GLenum, GLenum, GLuint, GLint));
84 };
85
86 scoped_ptr<BufferQueue> CreateOutputSurfaceWithMock(MockedContext** context) {
87 *context = new MockedContext();
88 scoped_refptr<cc::TestContextProvider> context_provider =
89 cc::TestContextProvider::Create(
90 scoped_ptr<cc::TestWebGraphicsContext3D>(*context));
91 context_provider->BindToCurrentThread();
92 return scoped_ptr<BufferQueue>(
93 new BufferQueue(context_provider, GL_RGBA8_OES));
94 }
95
96 TEST(BufferQueueStandaloneTest, FboInitialization) {
97 MockedContext* context;
98 scoped_ptr<BufferQueue> output_surface =
99 CreateOutputSurfaceWithMock(&context);
100
101 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
102
103 output_surface->Reshape(gfx::Size(10, 20), 1.0f);
104 }
105
106 TEST(BufferQueueStandaloneTest, FboBinding) {
107 MockedContext* context;
108 scoped_ptr<BufferQueue> output_surface =
109 CreateOutputSurfaceWithMock(&context);
110 Expectation image =
111 EXPECT_CALL(
112 *context,
113 createImageCHROMIUM(0, 0, GL_RGBA8_OES, GL_IMAGE_SCANOUT_CHROMIUM))
114 .WillOnce(Return(1));
115 Expectation fb =
116 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
117 Expectation tex = EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, Ne(0U)));
118 Expectation bind_tex =
119 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1))
120 .After(tex, image);
121 EXPECT_CALL(
122 *context,
123 framebufferTexture2D(
124 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Ne(0U), _))
125 .After(fb, bind_tex);
126 EXPECT_CALL(*context, destroyImageCHROMIUM(1));
127
128 output_surface->BindFramebuffer();
129 }
130
131 TEST_F(BufferQueueTest, MultipleBindCalls) {
132 // Check that multiple bind calls do not create or change surfaces.
133 output_surface_->BindFramebuffer();
134 EXPECT_EQ(1, CountBuffers());
135 unsigned int fb = current_surface();
136 output_surface_->BindFramebuffer();
137 EXPECT_EQ(1, CountBuffers());
138 EXPECT_EQ(fb, current_surface());
139 }
140
141 TEST_F(BufferQueueTest, CheckDoubleBuffering) {
142 // Check buffer flow through double buffering path.
143 EXPECT_EQ(0, CountBuffers());
144 output_surface_->BindFramebuffer();
145 EXPECT_EQ(1, CountBuffers());
146 EXPECT_NE(0U, current_surface());
147 output_surface_->SwapBuffers();
148 EXPECT_EQ(1U, in_flight_surfaces().size());
149 output_surface_->PageFlipComplete();
150 EXPECT_EQ(1U, in_flight_surfaces().size());
151 output_surface_->BindFramebuffer();
152 EXPECT_EQ(2, CountBuffers());
153 CheckUnique();
154 EXPECT_NE(0U, current_surface());
155 EXPECT_EQ(1U, in_flight_surfaces().size());
156 output_surface_->SwapBuffers();
157 CheckUnique();
158 EXPECT_EQ(2U, in_flight_surfaces().size());
159 output_surface_->PageFlipComplete();
160 CheckUnique();
161 EXPECT_EQ(1U, in_flight_surfaces().size());
162 EXPECT_EQ(1U, available_surfaces().size());
163 output_surface_->BindFramebuffer();
164 EXPECT_EQ(2, CountBuffers());
165 CheckUnique();
166 EXPECT_TRUE(available_surfaces().empty());
167 }
168
169 TEST_F(BufferQueueTest, CheckTripleBuffering) {
170 // Check buffer flow through triple buffering path.
171
172 // This bit is the same sequence tested in the doublebuffering case.
173 output_surface_->BindFramebuffer();
174 output_surface_->SwapBuffers();
175 output_surface_->PageFlipComplete();
176 output_surface_->BindFramebuffer();
177 output_surface_->SwapBuffers();
178
179 EXPECT_EQ(2, CountBuffers());
180 CheckUnique();
181 EXPECT_EQ(2U, in_flight_surfaces().size());
182 output_surface_->BindFramebuffer();
183 EXPECT_EQ(3, CountBuffers());
184 CheckUnique();
185 EXPECT_NE(0U, current_surface());
186 EXPECT_EQ(2U, in_flight_surfaces().size());
187 output_surface_->PageFlipComplete();
188 EXPECT_EQ(3, CountBuffers());
189 CheckUnique();
190 EXPECT_NE(0U, current_surface());
191 EXPECT_EQ(1U, in_flight_surfaces().size());
192 EXPECT_EQ(1U, available_surfaces().size());
193 }
194
195 } // namespace
196 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698