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 call_count() const { return call_count_; } |
| 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 scoped_ptr<content::BrowserCompositorOutputSurface> CreateSurface( |
| 67 scoped_ptr<cc::SoftwareOutputDevice> device); |
| 68 |
| 69 protected: |
| 70 scoped_ptr<content::BrowserCompositorOutputSurface> 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 DISALLOW_COPY_AND_ASSIGN(SoftwareBrowserCompositorOutputSurfaceTest); |
| 79 }; |
| 80 |
| 81 SoftwareBrowserCompositorOutputSurfaceTest:: |
| 82 SoftwareBrowserCompositorOutputSurfaceTest() { |
| 83 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); |
| 84 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
| 85 } |
| 86 |
| 87 SoftwareBrowserCompositorOutputSurfaceTest:: |
| 88 ~SoftwareBrowserCompositorOutputSurfaceTest() {} |
| 89 |
| 90 void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { |
| 91 ui::InitializeContextFactoryForTests(false); |
| 92 ui::Compositor::Initialize(); |
| 93 |
| 94 compositor_.reset(new ui::Compositor(true, gfx::kNullAcceleratedWidget)); |
| 95 surface_proxy_ = |
| 96 new content::BrowserCompositorOutputSurfaceProxy(&surface_map_); |
| 97 } |
| 98 |
| 99 void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() { |
| 100 output_surface_.reset(); |
| 101 compositor_.reset(); |
| 102 |
| 103 EXPECT_TRUE(surface_map_.IsEmpty()); |
| 104 |
| 105 surface_map_.Clear(); |
| 106 ui::TerminateContextFactoryForTests(); |
| 107 ui::Compositor::Terminate(); |
| 108 } |
| 109 |
| 110 scoped_ptr<content::BrowserCompositorOutputSurface> |
| 111 SoftwareBrowserCompositorOutputSurfaceTest::CreateSurface( |
| 112 scoped_ptr<cc::SoftwareOutputDevice> device) { |
| 113 return scoped_ptr<content::BrowserCompositorOutputSurface>( |
| 114 new content::SoftwareBrowserCompositorOutputSurface( |
| 115 surface_proxy_, |
| 116 device.Pass(), |
| 117 1, |
| 118 &surface_map_, |
| 119 compositor_->GetCompositorMessageLoop(), |
| 120 compositor_->AsWeakPtr())); |
| 121 } |
| 122 |
| 123 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, NoVSyncProvider) { |
| 124 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| 125 new cc::SoftwareOutputDevice()); |
| 126 output_surface_ = CreateSurface(software_device.Pass()); |
| 127 |
| 128 cc::CompositorFrame frame; |
| 129 output_surface_->SwapBuffers(&frame); |
| 130 |
| 131 EXPECT_EQ(NULL, output_surface_->software_device()->GetVSyncProvider()); |
| 132 } |
| 133 |
| 134 TEST_F(SoftwareBrowserCompositorOutputSurfaceTest, VSyncProviderUpdates) { |
| 135 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| 136 new FakeSoftwareOutputDevice()); |
| 137 output_surface_ = CreateSurface(software_device.Pass()); |
| 138 |
| 139 FakeVSyncProvider* vsync_provider = static_cast<FakeVSyncProvider*>( |
| 140 output_surface_->software_device()->GetVSyncProvider()); |
| 141 EXPECT_EQ(0, vsync_provider->call_count()); |
| 142 |
| 143 cc::CompositorFrame frame; |
| 144 output_surface_->SwapBuffers(&frame); |
| 145 |
| 146 EXPECT_EQ(1, vsync_provider->call_count()); |
| 147 } |
OLD | NEW |