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 "cc/output/compositor_frame_sink.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/test/fake_compositor_frame_sink_client.h" |
| 10 #include "cc/test/test_context_provider.h" |
| 11 #include "cc/test/test_web_graphics_context_3d.h" |
| 12 #include "gpu/GLES2/gl2extchromium.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace cc { |
| 16 namespace { |
| 17 |
| 18 class TestCompositorFrameSink : public CompositorFrameSink { |
| 19 public: |
| 20 explicit TestCompositorFrameSink( |
| 21 scoped_refptr<TestContextProvider> context_provider, |
| 22 scoped_refptr<TestContextProvider> worker_context_provider) |
| 23 : CompositorFrameSink(std::move(context_provider), |
| 24 std::move(worker_context_provider)) {} |
| 25 |
| 26 void SwapBuffers(CompositorFrame frame) override { |
| 27 client_->DidSwapBuffersComplete(); |
| 28 } |
| 29 |
| 30 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } |
| 31 |
| 32 protected: |
| 33 }; |
| 34 |
| 35 TEST(CompositorFrameSinkTest, ContextLossInformsClient) { |
| 36 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| 37 scoped_refptr<TestContextProvider> worker_provider = |
| 38 TestContextProvider::CreateWorker(); |
| 39 TestCompositorFrameSink compositor_frame_sink(provider, worker_provider); |
| 40 EXPECT_FALSE(compositor_frame_sink.HasClient()); |
| 41 |
| 42 FakeCompositorFrameSinkClient client; |
| 43 EXPECT_TRUE(compositor_frame_sink.BindToClient(&client)); |
| 44 EXPECT_TRUE(compositor_frame_sink.HasClient()); |
| 45 |
| 46 // Verify DidLoseCompositorFrameSink callback is hooked up correctly. |
| 47 EXPECT_FALSE(client.did_lose_compositor_frame_sink_called()); |
| 48 compositor_frame_sink.context_provider()->ContextGL()->LoseContextCHROMIUM( |
| 49 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 50 compositor_frame_sink.context_provider()->ContextGL()->Flush(); |
| 51 EXPECT_TRUE(client.did_lose_compositor_frame_sink_called()); |
| 52 } |
| 53 |
| 54 // TODO(danakj): Add a test for worker context failure as well when |
| 55 // CompositorFrameSink creates/binds it. |
| 56 TEST(CompositorFrameSinkTest, ContextLossFailsBind) { |
| 57 scoped_refptr<TestContextProvider> context_provider = |
| 58 TestContextProvider::Create(); |
| 59 scoped_refptr<TestContextProvider> worker_provider = |
| 60 TestContextProvider::CreateWorker(); |
| 61 |
| 62 // Lose the context so BindToClient fails. |
| 63 context_provider->UnboundTestContext3d()->set_context_lost(true); |
| 64 |
| 65 TestCompositorFrameSink compositor_frame_sink(context_provider, |
| 66 worker_provider); |
| 67 EXPECT_FALSE(compositor_frame_sink.HasClient()); |
| 68 |
| 69 FakeCompositorFrameSinkClient client; |
| 70 EXPECT_FALSE(compositor_frame_sink.BindToClient(&client)); |
| 71 EXPECT_FALSE(compositor_frame_sink.HasClient()); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 } // namespace cc |
OLD | NEW |