OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 "base/message_loop/message_loop.h" | |
6 #include "cc/output/compositor_frame.h" | |
7 #include "content/browser/aura/browser_compositor_output_surface_proxy.h" | |
8 #include "content/browser/aura/software_browser_compositor_output_surface.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ui/compositor/test/context_factories_for_test.h" | |
11 #include "ui/gl/gl_implementation.h" | |
12 #include "ui/gl/vsync_provider.h" | |
13 | |
14 namespace { | |
15 | |
16 class FakeVSyncProvider : public gfx::VSyncProvider { | |
17 public: | |
18 FakeVSyncProvider() : call_count_(0) {} | |
19 virtual ~FakeVSyncProvider() {} | |
20 | |
21 virtual void GetVSyncParameters(const UpdateVSyncCallback& callback) | |
22 OVERRIDE { | |
23 callback.Run(timebase_, interval_); | |
24 call_count_++; | |
25 } | |
26 | |
27 int get_call_count() const { return call_count_; } | |
piman
2013/11/07 00:45:12
nit: call_count()
dnicoara
2013/11/07 15:17:41
Done.
| |
28 | |
29 void set_timebase(base::TimeTicks timebase) { timebase_ = timebase; } | |
30 void set_interval(base::TimeDelta interval) { interval_ = interval; } | |
31 | |
32 private: | |
33 base::TimeTicks timebase_; | |
34 base::TimeDelta interval_; | |
35 | |
36 int call_count_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(FakeVSyncProvider); | |
39 }; | |
40 | |
41 class FakeSoftwareOutputDevice : public cc::SoftwareOutputDevice { | |
42 public: | |
43 FakeSoftwareOutputDevice() : vsync_provider_(new FakeVSyncProvider()) {} | |
44 virtual ~FakeSoftwareOutputDevice() {} | |
45 | |
46 virtual gfx::VSyncProvider* GetVSyncProvider() OVERRIDE { | |
47 return vsync_provider_.get(); | |
48 } | |
49 | |
50 private: | |
51 scoped_ptr<gfx::VSyncProvider> vsync_provider_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice); | |
54 }; | |
55 | |
56 } // namespace | |
57 | |
58 class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test { | |
59 public: | |
60 SoftwareBrowserCompositorOutputSurfaceTest(); | |
61 virtual ~SoftwareBrowserCompositorOutputSurfaceTest(); | |
62 | |
63 virtual void SetUp() OVERRIDE; | |
64 virtual void TearDown() OVERRIDE; | |
65 | |
66 content::SoftwareBrowserCompositorOutputSurface* CreateSurface( | |
67 scoped_ptr<cc::SoftwareOutputDevice> device); | |
68 | |
69 protected: | |
70 scoped_ptr<content::SoftwareBrowserCompositorOutputSurface> output_surface_; | |
71 | |
72 scoped_ptr<base::MessageLoop> message_loop_; | |
73 scoped_ptr<ui::Compositor> compositor_; | |
74 | |
75 IDMap<content::BrowserCompositorOutputSurface> surface_map_; | |
76 scoped_refptr<content::BrowserCompositorOutputSurfaceProxy> surface_proxy_; | |
77 }; | |
78 | |
79 SoftwareBrowserCompositorOutputSurfaceTest:: | |
80 SoftwareBrowserCompositorOutputSurfaceTest() { | |
81 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); | |
82 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | |
83 } | |
84 | |
85 SoftwareBrowserCompositorOutputSurfaceTest:: | |
86 ~SoftwareBrowserCompositorOutputSurfaceTest() {} | |
87 | |
88 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { | |
89 ui::InitializeContextFactoryForTests(false); | |
90 ui::Compositor::Initialize(); | |
91 | |
92 compositor_.reset(new ui::Compositor(1)); | |
93 surface_proxy_ = | |
94 new content::BrowserCompositorOutputSurfaceProxy(&surface_map_); | |
95 } | |
96 | |
97 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() { | |
98 output_surface_.reset(); | |
99 compositor_.reset(); | |
100 | |
101 EXPECT_TRUE(surface_map_.IsEmpty()); | |
102 | |
103 surface_map_.Clear(); | |
104 ui::TerminateContextFactoryForTests(); | |
105 ui::Compositor::Terminate(); | |
106 } | |
107 | |
108 content::SoftwareBrowserCompositorOutputSurface* | |
piman
2013/11/07 00:45:12
nit: return a scoped_ptr<SoftwareBrowserCompositor
dnicoara
2013/11/07 15:17:41
Done.
| |
109 SoftwareBrowserCompositorOutputSurfaceTest::CreateSurface( | |
110 scoped_ptr<cc::SoftwareOutputDevice> device) { | |
111 return new content::SoftwareBrowserCompositorOutputSurface( | |
112 surface_proxy_, | |
113 device.Pass(), | |
114 1, | |
115 &surface_map_, | |
116 compositor_->GetCompositorMessageLoop(), | |
117 compositor_->AsWeakPtr()); | |
118 } | |
119 | |
120 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { | |
121 scoped_ptr<cc::SoftwareOutputDevice> software_device( | |
122 new cc::SoftwareOutputDevice()); | |
123 output_surface_.reset(CreateSurface(software_device.Pass())); | |
124 | |
125 cc::CompositorFrame frame; | |
126 static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame); | |
piman
2013/11/07 00:45:12
nit: you shouldn't need the static cast.
dnicoara
2013/11/07 15:17:41
Done.
| |
127 | |
128 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider()); | |
129 } | |
130 | |
131 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) { | |
132 scoped_ptr<cc::SoftwareOutputDevice> software_device( | |
133 new FakeSoftwareOutputDevice()); | |
134 output_surface_.reset(CreateSurface(software_device.Pass())); | |
135 | |
136 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( | |
137 output_surface_->software_device()->GetVSyncProvider()); | |
138 EXPECT_EQ(0, vsync_provider->get_call_count()); | |
139 | |
140 cc::CompositorFrame frame; | |
141 static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame); | |
piman
2013/11/07 00:45:12
nit: Shouldn't need the static_cast either
dnicoara
2013/11/07 15:17:41
Done.
| |
142 | |
143 EXPECT_EQ(1, vsync_provider->get_call_count()); | |
144 } | |
OLD | NEW |