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

Side by Side Diff: content/browser/aura/software_browser_compositor_output_surface_unittest.cc

Issue 57883007: Adding support for VSyncProvider to the software drawing path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unittests Created 7 years, 1 month 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
(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/software_browser_compositor_output_surface.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/compositor/test/context_factories_for_test.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/vsync_provider.h"
12
13 namespace {
14
15 class FakeVSyncProvider : public gfx::VSyncProvider {
16 public:
17 FakeVSyncProvider() : call_count_(0) {}
18 virtual ~FakeVSyncProvider() {}
19
20 virtual void GetVSyncParameters(
21 const UpdateVSyncCallback& callback) OVERRIDE {
22 callback.Run(timebase_, interval_);
23 call_count_++;
24 }
25
26 int get_call_count() const { return call_count_; }
27
28 void set_timebase(base::TimeTicks timebase) { timebase_ = timebase; }
29 void set_interval(base::TimeDelta interval) { interval_ = interval; }
30
31 private:
32 base::TimeTicks timebase_;
33 base::TimeDelta interval_;
34
35 int call_count_;
36
37 DISALLOW_COPY_AND_ASSIGN(FakeVSyncProvider);
38 };
39
40 class FakeSoftwareOutputDevice : public cc::SoftwareOutputDevice {
41 public:
42 FakeSoftwareOutputDevice() : vsync_provider_(new FakeVSyncProvider()) {}
43 virtual ~FakeSoftwareOutputDevice() {}
44
45 virtual gfx::VSyncProvider* GetVSyncProvider() OVERRIDE {
46 return vsync_provider_.get();
47 }
48 private:
49 scoped_ptr<gfx::VSyncProvider> vsync_provider_;
50
51 DISALLOW_COPY_AND_ASSIGN(FakeSoftwareOutputDevice);
52 };
53
54 } // namespace
55
56 class SoftwareBrowserCompositorOutputSurfaceTest : public testing::Test {
57 public:
58 SoftwareBrowserCompositorOutputSurfaceTest();
59 virtual ~SoftwareBrowserCompositorOutputSurfaceTest();
60
61 virtual void SetUp() OVERRIDE;
62 virtual void TearDown() OVERRIDE;
63
64 protected:
65 scoped_ptr<content::SoftwareBrowserCompositorOutputSurface> output_surface_;
66
67 scoped_ptr<base::MessageLoop> message_loop_;
68 scoped_ptr<ui::Compositor> compositor_;
69 };
70
71 SoftwareBrowserCompositorOutputSurfaceTest::
72 SoftwareBrowserCompositorOutputSurfaceTest() {
73 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
74 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
75 }
76
77 SoftwareBrowserCompositorOutputSurfaceTest::
78 ~SoftwareBrowserCompositorOutputSurfaceTest() {
79 }
80
81 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
82 ui::InitializeContextFactoryForTests(false);
83 ui::Compositor::Initialize();
84
85 compositor_.reset(new ui::Compositor(true, 1));
86 }
87
88 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() {
89 output_surface_.reset();
90 compositor_.reset();
91
92 ui::TerminateContextFactoryForTests();
93 ui::Compositor::Terminate();
94 }
95
96 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) {
97 scoped_ptr<cc::SoftwareOutputDevice> software_device(
98 new cc::SoftwareOutputDevice());
99 output_surface_ = content::SoftwareBrowserCompositorOutputSurface::Create(
100 software_device.Pass(),
101 compositor_->GetCompositorMessageLoop(),
102 compositor_->AsWeakPtr());
103
104 cc::CompositorFrame frame;
105 static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame);
106
107 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider());
108 }
109
110 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) {
111 scoped_ptr<cc::SoftwareOutputDevice> software_device(
112 new FakeSoftwareOutputDevice());
113 output_surface_ = content::SoftwareBrowserCompositorOutputSurface::Create(
114 software_device.Pass(),
115 compositor_->GetCompositorMessageLoop(),
116 compositor_->AsWeakPtr());
117
118 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>(
119 output_surface_->software_device()->GetVSyncProvider());
120 EXPECT_EQ(0, vsync_provider->get_call_count());
121
122 cc::CompositorFrame frame;
123 static_cast<cc::OutputSurface*>(output_surface_.get())->SwapBuffers(&frame);
124
125 EXPECT_EQ(1, vsync_provider->get_call_count());
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698