| 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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
| 9 #include "cc/output/managed_memory_policy.h" | 9 #include "cc/output/managed_memory_policy.h" |
| 10 #include "cc/output/output_surface_client.h" | 10 #include "cc/output/output_surface_client.h" |
| 11 #include "cc/output/software_output_device.h" | 11 #include "cc/output/software_output_device.h" |
| 12 #include "cc/test/begin_frame_args_test.h" | 12 #include "cc/test/begin_frame_args_test.h" |
| 13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
| 14 #include "cc/test/fake_output_surface_client.h" | 14 #include "cc/test/fake_output_surface_client.h" |
| 15 #include "cc/test/test_context_provider.h" | 15 #include "cc/test/test_context_provider.h" |
| 16 #include "cc/test/test_web_graphics_context_3d.h" | 16 #include "cc/test/test_web_graphics_context_3d.h" |
| 17 #include "gpu/GLES2/gl2extchromium.h" | 17 #include "gpu/GLES2/gl2extchromium.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.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(std::move(context_provider), nullptr, nullptr) {} |
| 27 | 27 |
| 28 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 28 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 29 scoped_refptr<ContextProvider> worker_context_provider) | 29 scoped_refptr<ContextProvider> worker_context_provider) |
| 30 : OutputSurface(worker_context_provider) {} | 30 : OutputSurface(std::move(context_provider), |
| 31 std::move(worker_context_provider), |
| 32 nullptr) {} |
| 31 | 33 |
| 32 explicit TestOutputSurface( | 34 explicit TestOutputSurface( |
| 33 std::unique_ptr<SoftwareOutputDevice> software_device) | 35 std::unique_ptr<SoftwareOutputDevice> software_device) |
| 34 : OutputSurface(std::move(software_device)) {} | 36 : OutputSurface(nullptr, nullptr, std::move(software_device)) {} |
| 35 | 37 |
| 36 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 38 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 37 std::unique_ptr<SoftwareOutputDevice> software_device) | 39 std::unique_ptr<SoftwareOutputDevice> software_device) |
| 38 : OutputSurface(context_provider, std::move(software_device)) {} | 40 : OutputSurface(std::move(context_provider), |
| 41 nullptr, |
| 42 std::move(software_device)) {} |
| 39 | 43 |
| 40 void SwapBuffers(CompositorFrame* frame) override { | 44 void SwapBuffers(CompositorFrame* frame) override { |
| 41 client_->DidSwapBuffers(); | 45 client_->DidSwapBuffers(); |
| 42 client_->DidSwapBuffersComplete(); | 46 client_->DidSwapBuffersComplete(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); } | 49 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); } |
| 46 | 50 |
| 47 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } | 51 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } |
| 48 | 52 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 EXPECT_TRUE(output_surface.HasClient()); | 114 EXPECT_TRUE(output_surface.HasClient()); |
| 111 | 115 |
| 112 // Verify DidLoseOutputSurface callback is hooked up correctly. | 116 // Verify DidLoseOutputSurface callback is hooked up correctly. |
| 113 EXPECT_FALSE(client.did_lose_output_surface_called()); | 117 EXPECT_FALSE(client.did_lose_output_surface_called()); |
| 114 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( | 118 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( |
| 115 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 119 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 116 output_surface.context_provider()->ContextGL()->Flush(); | 120 output_surface.context_provider()->ContextGL()->Flush(); |
| 117 EXPECT_TRUE(client.did_lose_output_surface_called()); | 121 EXPECT_TRUE(client.did_lose_output_surface_called()); |
| 118 } | 122 } |
| 119 | 123 |
| 124 // TODO(danakj): Add a test for worker context failure as well when |
| 125 // OutputSurface creates/binds it. |
| 120 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { | 126 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { |
| 121 scoped_refptr<TestContextProvider> context_provider = | 127 scoped_refptr<TestContextProvider> context_provider = |
| 122 TestContextProvider::Create(); | 128 TestContextProvider::Create(); |
| 123 | 129 |
| 124 // Lose the context so BindToClient fails. | 130 // Lose the context so BindToClient fails. |
| 125 context_provider->UnboundTestContext3d()->set_context_lost(true); | 131 context_provider->UnboundTestContext3d()->set_context_lost(true); |
| 126 | 132 |
| 127 TestOutputSurface output_surface(context_provider); | 133 TestOutputSurface output_surface(context_provider); |
| 128 EXPECT_FALSE(output_surface.HasClient()); | 134 EXPECT_FALSE(output_surface.HasClient()); |
| 129 | 135 |
| 130 FakeOutputSurfaceClient client; | 136 FakeOutputSurfaceClient client; |
| 131 EXPECT_FALSE(output_surface.BindToClient(&client)); | 137 EXPECT_FALSE(output_surface.BindToClient(&client)); |
| 132 EXPECT_FALSE(output_surface.HasClient()); | 138 EXPECT_FALSE(output_surface.HasClient()); |
| 133 } | 139 } |
| 134 | 140 |
| 135 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientFailure) { | |
| 136 scoped_refptr<TestContextProvider> context_provider = | |
| 137 TestContextProvider::Create(); | |
| 138 scoped_refptr<TestContextProvider> worker_context_provider = | |
| 139 TestContextProvider::Create(); | |
| 140 | |
| 141 // Lose the context so BindToClient fails. | |
| 142 worker_context_provider->UnboundTestContext3d()->set_context_lost(true); | |
| 143 | |
| 144 TestOutputSurface output_surface(context_provider, worker_context_provider); | |
| 145 EXPECT_FALSE(output_surface.HasClient()); | |
| 146 | |
| 147 FakeOutputSurfaceClient client; | |
| 148 EXPECT_FALSE(output_surface.BindToClient(&client)); | |
| 149 EXPECT_FALSE(output_surface.HasClient()); | |
| 150 } | |
| 151 | |
| 152 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { | 141 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { |
| 153 TestSoftwareOutputDevice* software_output_device = | 142 TestSoftwareOutputDevice* software_output_device = |
| 154 new TestSoftwareOutputDevice(); | 143 new TestSoftwareOutputDevice(); |
| 155 | 144 |
| 156 // TestOutputSurface now owns software_output_device and has responsibility to | 145 // TestOutputSurface now owns software_output_device and has responsibility to |
| 157 // free it. | 146 // free it. |
| 158 TestOutputSurface output_surface(base::WrapUnique(software_output_device)); | 147 TestOutputSurface output_surface(base::WrapUnique(software_output_device)); |
| 159 | 148 |
| 160 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); | 149 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); |
| 161 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 150 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
| 162 | 151 |
| 163 output_surface.EnsureBackbuffer(); | 152 output_surface.EnsureBackbuffer(); |
| 164 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 153 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
| 165 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 154 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
| 166 output_surface.DiscardBackbuffer(); | 155 output_surface.DiscardBackbuffer(); |
| 167 | 156 |
| 168 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 157 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
| 169 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 158 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
| 170 } | 159 } |
| 171 | 160 |
| 172 } // namespace | 161 } // namespace |
| 173 } // namespace cc | 162 } // namespace cc |
| OLD | NEW |