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

Side by Side Diff: cc/output/gl_renderer_unittest.cc

Issue 15688002: Part 1/3 (compositor) of adding with device scale factor to transport surfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix return value Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/output/compositor_frame_metadata.h" 10 #include "cc/output/compositor_frame_metadata.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 }; 144 };
145 145
146 class FakeRendererClient : public RendererClient { 146 class FakeRendererClient : public RendererClient {
147 public: 147 public:
148 FakeRendererClient() 148 FakeRendererClient()
149 : host_impl_(&proxy_), 149 : host_impl_(&proxy_),
150 set_full_root_layer_damage_count_(0), 150 set_full_root_layer_damage_count_(0),
151 last_call_was_set_visibility_(0), 151 last_call_was_set_visibility_(0),
152 root_layer_(LayerImpl::Create(host_impl_.active_tree(), 1)), 152 root_layer_(LayerImpl::Create(host_impl_.active_tree(), 1)),
153 memory_allocation_limit_bytes_( 153 memory_allocation_limit_bytes_(
154 PrioritizedResourceManager::DefaultMemoryAllocationLimit()) { 154 PrioritizedResourceManager::DefaultMemoryAllocationLimit()),
155 viewport_size_(gfx::Size(1, 1)),
156 scale_factor_(1.f),
157 is_viewport_changed_(true) {
155 root_layer_->CreateRenderSurface(); 158 root_layer_->CreateRenderSurface();
156 RenderPass::Id render_pass_id = 159 RenderPass::Id render_pass_id =
157 root_layer_->render_surface()->RenderPassId(); 160 root_layer_->render_surface()->RenderPassId();
158 scoped_ptr<RenderPass> root_render_pass = RenderPass::Create(); 161 scoped_ptr<RenderPass> root_render_pass = RenderPass::Create();
159 root_render_pass->SetNew( 162 root_render_pass->SetNew(
160 render_pass_id, gfx::Rect(), gfx::Rect(), gfx::Transform()); 163 render_pass_id, gfx::Rect(), gfx::Rect(), gfx::Transform());
161 render_passes_in_draw_order_.push_back(root_render_pass.Pass()); 164 render_passes_in_draw_order_.push_back(root_render_pass.Pass());
162 } 165 }
163 166
164 // RendererClient methods. 167 // RendererClient methods.
165 virtual gfx::Size DeviceViewportSize() const OVERRIDE { 168 virtual gfx::Size DeviceViewportSize() const OVERRIDE {
166 static gfx::Size fake_size(1, 1); 169 static gfx::Size fake_size(1, 1);
167 return fake_size; 170 return fake_size;
168 } 171 }
172 virtual float DeviceScaleFactor() const OVERRIDE {
173 return scale_factor_;
174 }
169 virtual const LayerTreeSettings& Settings() const OVERRIDE { 175 virtual const LayerTreeSettings& Settings() const OVERRIDE {
170 static LayerTreeSettings fake_settings; 176 static LayerTreeSettings fake_settings;
171 return fake_settings; 177 return fake_settings;
172 } 178 }
173 virtual void SetFullRootLayerDamage() OVERRIDE { 179 virtual void SetFullRootLayerDamage() OVERRIDE {
174 set_full_root_layer_damage_count_++; 180 set_full_root_layer_damage_count_++;
175 } 181 }
176 virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy) 182 virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy)
177 OVERRIDE { 183 OVERRIDE {
178 memory_allocation_limit_bytes_ = policy.bytes_limit_when_visible; 184 memory_allocation_limit_bytes_ = policy.bytes_limit_when_visible;
(...skipping 13 matching lines...) Expand all
192 } 198 }
193 199
194 // Methods added for test. 200 // Methods added for test.
195 int set_full_root_layer_damage_count() const { 201 int set_full_root_layer_damage_count() const {
196 return set_full_root_layer_damage_count_; 202 return set_full_root_layer_damage_count_;
197 } 203 }
198 void set_last_call_was_set_visibility_pointer( 204 void set_last_call_was_set_visibility_pointer(
199 bool* last_call_was_set_visibility) { 205 bool* last_call_was_set_visibility) {
200 last_call_was_set_visibility_ = last_call_was_set_visibility; 206 last_call_was_set_visibility_ = last_call_was_set_visibility;
201 } 207 }
208 void set_viewport_and_scale(
209 gfx::Size viewport_size, float scale_factor) {
210 viewport_size_ = viewport_size;
211 scale_factor_ = scale_factor;
212 is_viewport_changed_ = true;
213 }
214 bool is_viewport_changed() const { return is_viewport_changed_; }
215 void clear_viewport_changed() { is_viewport_changed_ = false; }
202 216
203 RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); } 217 RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); }
204 RenderPassList* render_passes_in_draw_order() { 218 RenderPassList* render_passes_in_draw_order() {
205 return &render_passes_in_draw_order_; 219 return &render_passes_in_draw_order_;
206 } 220 }
207 221
208 size_t memory_allocation_limit_bytes() const { 222 size_t memory_allocation_limit_bytes() const {
209 return memory_allocation_limit_bytes_; 223 return memory_allocation_limit_bytes_;
210 } 224 }
211 225
212 private: 226 private:
213 FakeImplProxy proxy_; 227 FakeImplProxy proxy_;
214 FakeLayerTreeHostImpl host_impl_; 228 FakeLayerTreeHostImpl host_impl_;
215 int set_full_root_layer_damage_count_; 229 int set_full_root_layer_damage_count_;
216 bool* last_call_was_set_visibility_; 230 bool* last_call_was_set_visibility_;
217 scoped_ptr<LayerImpl> root_layer_; 231 scoped_ptr<LayerImpl> root_layer_;
218 RenderPassList render_passes_in_draw_order_; 232 RenderPassList render_passes_in_draw_order_;
219 size_t memory_allocation_limit_bytes_; 233 size_t memory_allocation_limit_bytes_;
234 gfx::Size viewport_size_;
235 float scale_factor_;
236 bool is_viewport_changed_;
220 }; 237 };
221 238
222 class FakeRendererGL : public GLRenderer { 239 class FakeRendererGL : public GLRenderer {
223 public: 240 public:
224 FakeRendererGL(RendererClient* client, 241 FakeRendererGL(RendererClient* client,
225 OutputSurface* output_surface, 242 OutputSurface* output_surface,
226 ResourceProvider* resource_provider) 243 ResourceProvider* resource_provider)
227 : GLRenderer(client, output_surface, resource_provider, 0) {} 244 : GLRenderer(client, output_surface, resource_provider, 0) {}
228 245
229 // GLRenderer methods. 246 // GLRenderer methods.
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 class OutputSurfaceMockContext : public TestWebGraphicsContext3D { 1447 class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
1431 public: 1448 public:
1432 // Specifically override methods even if they are unused (used in conjunction 1449 // Specifically override methods even if they are unused (used in conjunction
1433 // with StrictMock). We need to make sure that GLRenderer does not issue 1450 // with StrictMock). We need to make sure that GLRenderer does not issue
1434 // framebuffer-related GL calls directly. Instead these are supposed to go 1451 // framebuffer-related GL calls directly. Instead these are supposed to go
1435 // through the OutputSurface abstraction. 1452 // through the OutputSurface abstraction.
1436 MOCK_METHOD0(ensureBackbufferCHROMIUM, void()); 1453 MOCK_METHOD0(ensureBackbufferCHROMIUM, void());
1437 MOCK_METHOD0(discardBackbufferCHROMIUM, void()); 1454 MOCK_METHOD0(discardBackbufferCHROMIUM, void());
1438 MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer)); 1455 MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer));
1439 MOCK_METHOD0(prepareTexture, void()); 1456 MOCK_METHOD0(prepareTexture, void());
1440 MOCK_METHOD2(reshape, void(int width, int height)); 1457 MOCK_METHOD3(reshapeWithScaleFactor,
1458 void(int width, int height, float scale_factor));
1441 MOCK_METHOD4(drawElements, 1459 MOCK_METHOD4(drawElements,
1442 void(WGC3Denum mode, 1460 void(WGC3Denum mode,
1443 WGC3Dsizei count, 1461 WGC3Dsizei count,
1444 WGC3Denum type, 1462 WGC3Denum type,
1445 WGC3Dintptr offset)); 1463 WGC3Dintptr offset));
1446 1464
1447 virtual WebString getString(WebKit::WGC3Denum name) { 1465 virtual WebString getString(WebKit::WGC3Denum name) {
1448 if (name == GL_EXTENSIONS) 1466 if (name == GL_EXTENSIONS)
1449 return WebString( 1467 return WebString(
1450 "GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_backbuffer"); 1468 "GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_backbuffer");
1451 return WebString(); 1469 return WebString();
1452 } 1470 }
1453 }; 1471 };
1454 1472
1455 class MockOutputSurface : public OutputSurface { 1473 class MockOutputSurface : public OutputSurface {
1456 public: 1474 public:
1457 MockOutputSurface() 1475 MockOutputSurface()
1458 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>( 1476 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(
1459 new StrictMock<OutputSurfaceMockContext>)) {} 1477 new StrictMock<OutputSurfaceMockContext>)) {}
1460 virtual ~MockOutputSurface() {} 1478 virtual ~MockOutputSurface() {}
1461 1479
1462 MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame)); 1480 MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame));
1463 MOCK_METHOD0(EnsureBackbuffer, void()); 1481 MOCK_METHOD0(EnsureBackbuffer, void());
1464 MOCK_METHOD0(DiscardBackbuffer, void()); 1482 MOCK_METHOD0(DiscardBackbuffer, void());
1465 MOCK_METHOD1(Reshape, void(gfx::Size size)); 1483 MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor));
1466 MOCK_METHOD0(BindFramebuffer, void()); 1484 MOCK_METHOD0(BindFramebuffer, void());
1467 MOCK_METHOD2(PostSubBuffer, void(gfx::Rect rect, const LatencyInfo&)); 1485 MOCK_METHOD2(PostSubBuffer, void(gfx::Rect rect, const LatencyInfo&));
1468 MOCK_METHOD1(SwapBuffers, void(const LatencyInfo&)); 1486 MOCK_METHOD1(SwapBuffers, void(const LatencyInfo&));
1469 }; 1487 };
1470 1488
1471 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient { 1489 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
1472 protected: 1490 protected:
1473 MockOutputSurfaceTest() 1491 MockOutputSurfaceTest()
1474 : resource_provider_(ResourceProvider::Create(&output_surface_, 0)), 1492 : resource_provider_(ResourceProvider::Create(&output_surface_, 0)),
1475 renderer_(this, &output_surface_, resource_provider_.get()) {} 1493 renderer_(this, &output_surface_, resource_provider_.get()) {}
1476 1494
1477 virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); } 1495 virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); }
1478 1496
1479 void SwapBuffers() { renderer_.SwapBuffers(LatencyInfo()); } 1497 void SwapBuffers() { renderer_.SwapBuffers(LatencyInfo()); }
1480 1498
1481 void DrawFrame() { 1499 void DrawFrame() {
1482 gfx::Rect viewport_rect(DeviceViewportSize()); 1500 gfx::Rect viewport_rect(DeviceViewportSize());
1483 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order(); 1501 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order();
1484 render_passes->clear(); 1502 render_passes->clear();
1485 1503
1486 RenderPass::Id render_pass_id(1, 0); 1504 RenderPass::Id render_pass_id(1, 0);
1487 TestRenderPass* render_pass = AddRenderPass( 1505 TestRenderPass* render_pass = AddRenderPass(
1488 render_passes, render_pass_id, viewport_rect, gfx::Transform()); 1506 render_passes, render_pass_id, viewport_rect, gfx::Transform());
1489 AddQuad(render_pass, viewport_rect, SK_ColorGREEN); 1507 AddQuad(render_pass, viewport_rect, SK_ColorGREEN);
1490 1508
1491 EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return()); 1509 EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return());
1492 1510
1493 EXPECT_CALL(output_surface_, Reshape(_)).Times(1); 1511 if (is_viewport_changed()) {
1512 EXPECT_CALL(output_surface_,
1513 Reshape(DeviceViewportSize(), DeviceScaleFactor())).Times(1);
1514 clear_viewport_changed();
danakj 2013/05/22 18:39:16 nit: 4space indent
ccameron 2013/05/22 19:24:43 Done.
1515 }
1494 1516
1495 EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1); 1517 EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1);
1496 1518
1497 EXPECT_CALL(*Context(), drawElements(_, _, _, _)).Times(1); 1519 EXPECT_CALL(*Context(), drawElements(_, _, _, _)).Times(1);
1498 1520
1499 renderer_.DecideRenderPassAllocationsForFrame( 1521 renderer_.DecideRenderPassAllocationsForFrame(
1500 *render_passes_in_draw_order()); 1522 *render_passes_in_draw_order());
1501 renderer_.DrawFrame(render_passes_in_draw_order()); 1523 renderer_.DrawFrame(render_passes_in_draw_order());
1502 } 1524 }
1503 1525
1504 OutputSurfaceMockContext* Context() { 1526 OutputSurfaceMockContext* Context() {
1505 return static_cast<OutputSurfaceMockContext*>(output_surface_.context3d()); 1527 return static_cast<OutputSurfaceMockContext*>(output_surface_.context3d());
1506 } 1528 }
1507 1529
1508 StrictMock<MockOutputSurface> output_surface_; 1530 StrictMock<MockOutputSurface> output_surface_;
1509 scoped_ptr<ResourceProvider> resource_provider_; 1531 scoped_ptr<ResourceProvider> resource_provider_;
1510 FakeRendererGL renderer_; 1532 FakeRendererGL renderer_;
1511 }; 1533 };
1512 1534
1513 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) { 1535 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) {
1514 DrawFrame(); 1536 DrawFrame();
1515 1537
1516 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1538 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1517 renderer_.SwapBuffers(LatencyInfo()); 1539 renderer_.SwapBuffers(LatencyInfo());
1518 } 1540 }
1519 1541
1542 TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) {
1543 DrawFrame();
1544 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1545 renderer_.SwapBuffers(LatencyInfo());
1546
1547 set_viewport_and_scale(gfx::Size(2, 2), 2.f);
1548 renderer_.ViewportChanged();
Ken Russell (switch to Gerrit) 2013/05/22 18:50:54 Is there any way to check that these result in a p
ccameron 2013/05/22 19:24:43 ViewportChanged() indicates that the RendererClien
1549
1550 DrawFrame();
1551 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1552 renderer_.SwapBuffers(LatencyInfo());
1553
1554 DrawFrame();
1555 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1556 renderer_.SwapBuffers(LatencyInfo());
1557
1558 set_viewport_and_scale(gfx::Size(1, 1), 1.f);
1559 renderer_.ViewportChanged();
1560
1561 DrawFrame();
1562 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1563 renderer_.SwapBuffers(LatencyInfo());
1564 }
1565
1520 class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest { 1566 class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest {
1521 public: 1567 public:
1522 virtual const LayerTreeSettings& Settings() const OVERRIDE { 1568 virtual const LayerTreeSettings& Settings() const OVERRIDE {
1523 static LayerTreeSettings fake_settings; 1569 static LayerTreeSettings fake_settings;
1524 fake_settings.partial_swap_enabled = true; 1570 fake_settings.partial_swap_enabled = true;
1525 return fake_settings; 1571 return fake_settings;
1526 } 1572 }
1527 }; 1573 };
1528 1574
1529 TEST_F(MockOutputSurfaceTestWithPartialSwap, DrawFrameAndSwap) { 1575 TEST_F(MockOutputSurfaceTestWithPartialSwap, DrawFrameAndSwap) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 base::MessageLoop::current()->Run(); 1659 base::MessageLoop::current()->Run();
1614 1660
1615 // The sync point should have happened. 1661 // The sync point should have happened.
1616 EXPECT_EQ(1, sync_point_callback_count); 1662 EXPECT_EQ(1, sync_point_callback_count);
1617 EXPECT_EQ(1, other_callback_count); 1663 EXPECT_EQ(1, other_callback_count);
1618 } 1664 }
1619 #endif // OS_ANDROID 1665 #endif // OS_ANDROID
1620 1666
1621 } // namespace 1667 } // namespace
1622 } // namespace cc 1668 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698