| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/output_surface.h" | 5 #include "cc/output/output_surface.h" |
| 6 | 6 |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "cc/output/managed_memory_policy.h" | 8 #include "cc/output/managed_memory_policy.h" |
| 9 #include "cc/output/output_surface_client.h" | 9 #include "cc/output/output_surface_client.h" |
| 10 #include "cc/output/software_output_device.h" | 10 #include "cc/output/software_output_device.h" |
| 11 #include "cc/test/begin_frame_args_test.h" | 11 #include "cc/test/begin_frame_args_test.h" |
| 12 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
| 13 #include "cc/test/fake_output_surface_client.h" | 13 #include "cc/test/fake_output_surface_client.h" |
| 14 #include "cc/test/test_context_provider.h" | 14 #include "cc/test/test_context_provider.h" |
| 15 #include "cc/test/test_web_graphics_context_3d.h" | 15 #include "cc/test/test_web_graphics_context_3d.h" |
| 16 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gfx/frame_time.h" | 18 #include "ui/gfx/frame_time.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class TestOutputSurface : public OutputSurface { | 23 class TestOutputSurface : public OutputSurface { |
| 24 public: | 24 public: |
| 25 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) | 25 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) |
| 26 : OutputSurface(context_provider) {} | 26 : OutputSurface(context_provider) {} |
| 27 | 27 |
| 28 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 29 scoped_refptr<ContextProvider> worker_context_provider) |
| 30 : OutputSurface(worker_context_provider) {} |
| 31 |
| 28 explicit TestOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) | 32 explicit TestOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) |
| 29 : OutputSurface(software_device.Pass()) {} | 33 : OutputSurface(software_device.Pass()) {} |
| 30 | 34 |
| 31 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 35 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 32 scoped_ptr<SoftwareOutputDevice> software_device) | 36 scoped_ptr<SoftwareOutputDevice> software_device) |
| 33 : OutputSurface(context_provider, software_device.Pass()) {} | 37 : OutputSurface(context_provider, software_device.Pass()) {} |
| 34 | 38 |
| 35 void SwapBuffers(CompositorFrame* frame) override { | 39 void SwapBuffers(CompositorFrame* frame) override { |
| 36 client_->DidSwapBuffers(); | 40 client_->DidSwapBuffers(); |
| 37 client_->DidSwapBuffersComplete(); | 41 client_->DidSwapBuffersComplete(); |
| 38 } | 42 } |
| 39 | 43 |
| 40 bool InitializeNewContext3d( | 44 bool InitializeNewContext3d(scoped_refptr<ContextProvider> context_provider) { |
| 41 scoped_refptr<ContextProvider> new_context_provider) { | 45 return InitializeAndSetContext3d(context_provider, nullptr); |
| 42 return InitializeAndSetContext3d(new_context_provider); | |
| 43 } | 46 } |
| 44 | 47 |
| 45 using OutputSurface::ReleaseGL; | 48 using OutputSurface::ReleaseGL; |
| 46 | 49 |
| 47 void CommitVSyncParametersForTesting(base::TimeTicks timebase, | 50 void CommitVSyncParametersForTesting(base::TimeTicks timebase, |
| 48 base::TimeDelta interval) { | 51 base::TimeDelta interval) { |
| 49 CommitVSyncParameters(timebase, interval); | 52 CommitVSyncParameters(timebase, interval); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); } | 55 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 EXPECT_FALSE(client.deferred_initialize_called()); | 102 EXPECT_FALSE(client.deferred_initialize_called()); |
| 100 | 103 |
| 101 // Verify DidLoseOutputSurface callback is hooked up correctly. | 104 // Verify DidLoseOutputSurface callback is hooked up correctly. |
| 102 EXPECT_FALSE(client.did_lose_output_surface_called()); | 105 EXPECT_FALSE(client.did_lose_output_surface_called()); |
| 103 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( | 106 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( |
| 104 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 107 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 105 output_surface.context_provider()->ContextGL()->Flush(); | 108 output_surface.context_provider()->ContextGL()->Flush(); |
| 106 EXPECT_TRUE(client.did_lose_output_surface_called()); | 109 EXPECT_TRUE(client.did_lose_output_surface_called()); |
| 107 } | 110 } |
| 108 | 111 |
| 112 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientSuccess) { |
| 113 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 114 scoped_refptr<TestContextProvider> worker_provider = |
| 115 TestContextProvider::Create(); |
| 116 TestOutputSurface output_surface(provider, worker_provider); |
| 117 EXPECT_FALSE(output_surface.HasClient()); |
| 118 |
| 119 FakeOutputSurfaceClient client; |
| 120 EXPECT_TRUE(output_surface.BindToClient(&client)); |
| 121 EXPECT_TRUE(output_surface.HasClient()); |
| 122 EXPECT_FALSE(client.deferred_initialize_called()); |
| 123 |
| 124 // Verify DidLoseOutputSurface callback is hooked up correctly. |
| 125 EXPECT_FALSE(client.did_lose_output_surface_called()); |
| 126 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( |
| 127 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 128 output_surface.context_provider()->ContextGL()->Flush(); |
| 129 EXPECT_TRUE(client.did_lose_output_surface_called()); |
| 130 } |
| 131 |
| 109 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { | 132 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { |
| 110 scoped_refptr<TestContextProvider> context_provider = | 133 scoped_refptr<TestContextProvider> context_provider = |
| 111 TestContextProvider::Create(); | 134 TestContextProvider::Create(); |
| 112 | 135 |
| 113 // Lose the context so BindToClient fails. | 136 // Lose the context so BindToClient fails. |
| 114 context_provider->UnboundTestContext3d()->set_context_lost(true); | 137 context_provider->UnboundTestContext3d()->set_context_lost(true); |
| 115 | 138 |
| 116 TestOutputSurface output_surface(context_provider); | 139 TestOutputSurface output_surface(context_provider); |
| 117 EXPECT_FALSE(output_surface.HasClient()); | 140 EXPECT_FALSE(output_surface.HasClient()); |
| 118 | 141 |
| 119 FakeOutputSurfaceClient client; | 142 FakeOutputSurfaceClient client; |
| 120 EXPECT_FALSE(output_surface.BindToClient(&client)); | 143 EXPECT_FALSE(output_surface.BindToClient(&client)); |
| 121 EXPECT_FALSE(output_surface.HasClient()); | 144 EXPECT_FALSE(output_surface.HasClient()); |
| 122 } | 145 } |
| 123 | 146 |
| 147 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientFailure) { |
| 148 scoped_refptr<TestContextProvider> context_provider = |
| 149 TestContextProvider::Create(); |
| 150 scoped_refptr<TestContextProvider> worker_context_provider = |
| 151 TestContextProvider::Create(); |
| 152 |
| 153 // Lose the context so BindToClient fails. |
| 154 worker_context_provider->UnboundTestContext3d()->set_context_lost(true); |
| 155 |
| 156 TestOutputSurface output_surface(context_provider, worker_context_provider); |
| 157 EXPECT_FALSE(output_surface.HasClient()); |
| 158 |
| 159 FakeOutputSurfaceClient client; |
| 160 EXPECT_FALSE(output_surface.BindToClient(&client)); |
| 161 EXPECT_FALSE(output_surface.HasClient()); |
| 162 } |
| 163 |
| 124 class OutputSurfaceTestInitializeNewContext3d : public ::testing::Test { | 164 class OutputSurfaceTestInitializeNewContext3d : public ::testing::Test { |
| 125 public: | 165 public: |
| 126 OutputSurfaceTestInitializeNewContext3d() | 166 OutputSurfaceTestInitializeNewContext3d() |
| 127 : context_provider_(TestContextProvider::Create()), | 167 : context_provider_(TestContextProvider::Create()), |
| 128 output_surface_( | 168 output_surface_( |
| 129 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)), | 169 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)), |
| 130 client_(&output_surface_) {} | 170 client_(&output_surface_) {} |
| 131 | 171 |
| 132 protected: | 172 protected: |
| 133 void BindOutputSurface() { | 173 void BindOutputSurface() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 259 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
| 220 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 260 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
| 221 output_surface.DiscardBackbuffer(); | 261 output_surface.DiscardBackbuffer(); |
| 222 | 262 |
| 223 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 263 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
| 224 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 264 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
| 225 } | 265 } |
| 226 | 266 |
| 227 } // namespace | 267 } // namespace |
| 228 } // namespace cc | 268 } // namespace cc |
| OLD | NEW |