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 #include "cc/output/output_surface_client.h" | 6 #include "cc/output/output_surface_client.h" |
| 7 #include "cc/output/software_output_device.h" |
7 #include "cc/test/test_web_graphics_context_3d.h" | 8 #include "cc/test/test_web_graphics_context_3d.h" |
| 9 #include "gpu/GLES2/gl2extchromium.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace cc { | 12 namespace cc { |
11 namespace { | 13 namespace { |
12 | 14 |
13 class TestOutputSurface : public OutputSurface { | 15 class TestOutputSurface : public OutputSurface { |
14 public: | 16 public: |
15 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 17 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
16 : OutputSurface(context3d.Pass()) {} | 18 : OutputSurface(context3d.Pass()) {} |
17 | 19 |
18 explicit TestOutputSurface( | 20 explicit TestOutputSurface( |
19 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 21 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
20 : OutputSurface(software_device.Pass()) {} | 22 : OutputSurface(software_device.Pass()) {} |
21 | 23 |
22 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 24 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
23 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 25 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
24 : OutputSurface(context3d.Pass(), software_device.Pass()) {} | 26 : OutputSurface(context3d.Pass(), software_device.Pass()) {} |
25 | 27 |
26 OutputSurfaceClient* client() { return client_; } | 28 OutputSurfaceClient* client() { return client_; } |
| 29 |
| 30 bool InitializeNewContext3D( |
| 31 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { |
| 32 return InitializeAndSetContext3D(new_context3d.Pass(), |
| 33 scoped_refptr<ContextProvider>()); |
| 34 } |
27 }; | 35 }; |
28 | 36 |
29 class FakeOutputSurfaceClient : public OutputSurfaceClient { | 37 class FakeOutputSurfaceClient : public OutputSurfaceClient { |
30 public: | 38 public: |
| 39 FakeOutputSurfaceClient() |
| 40 : deferred_initialize_result_(true), |
| 41 deferred_initialize_called_(false), |
| 42 did_lose_output_surface_called_(false) {} |
| 43 |
31 virtual bool DeferredInitialize( | 44 virtual bool DeferredInitialize( |
32 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { | 45 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { |
33 return true; | 46 deferred_initialize_called_ = true; |
| 47 return deferred_initialize_result_; |
34 } | 48 } |
35 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {} | 49 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {} |
36 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, | 50 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, |
37 base::TimeDelta interval) OVERRIDE {} | 51 base::TimeDelta interval) OVERRIDE {} |
38 virtual void BeginFrame(base::TimeTicks frame_time) OVERRIDE {} | 52 virtual void BeginFrame(base::TimeTicks frame_time) OVERRIDE {} |
39 virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck& ack) | 53 virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck& ack) |
40 OVERRIDE {} | 54 OVERRIDE {} |
41 virtual void OnSwapBuffersComplete() OVERRIDE {} | 55 virtual void OnSwapBuffersComplete() OVERRIDE {} |
42 virtual void DidLoseOutputSurface() OVERRIDE {} | 56 virtual void DidLoseOutputSurface() OVERRIDE { |
| 57 did_lose_output_surface_called_ = true; |
| 58 } |
43 virtual void SetExternalDrawConstraints(const gfx::Transform& transform, | 59 virtual void SetExternalDrawConstraints(const gfx::Transform& transform, |
44 gfx::Rect viewport) OVERRIDE {} | 60 gfx::Rect viewport) OVERRIDE {} |
| 61 |
| 62 void set_deferred_initialize_result(bool result) { |
| 63 deferred_initialize_result_ = result; |
| 64 } |
| 65 |
| 66 bool deferred_initialize_called() { |
| 67 return deferred_initialize_called_; |
| 68 } |
| 69 |
| 70 bool did_lose_output_surface_called() { |
| 71 return did_lose_output_surface_called_; |
| 72 } |
| 73 |
| 74 private: |
| 75 bool deferred_initialize_result_; |
| 76 bool deferred_initialize_called_; |
| 77 bool did_lose_output_surface_called_; |
45 }; | 78 }; |
46 | 79 |
47 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { | 80 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { |
48 scoped_ptr<TestWebGraphicsContext3D> context3d = | 81 scoped_ptr<TestWebGraphicsContext3D> context3d = |
49 TestWebGraphicsContext3D::Create(); | 82 TestWebGraphicsContext3D::Create(); |
50 | 83 |
51 TestOutputSurface output_surface( | 84 TestOutputSurface output_surface( |
52 context3d.PassAs<WebKit::WebGraphicsContext3D>()); | 85 context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
53 EXPECT_EQ(NULL, output_surface.client()); | 86 EXPECT_EQ(NULL, output_surface.client()); |
54 | 87 |
55 FakeOutputSurfaceClient client; | 88 FakeOutputSurfaceClient client; |
56 EXPECT_TRUE(output_surface.BindToClient(&client)); | 89 EXPECT_TRUE(output_surface.BindToClient(&client)); |
57 EXPECT_EQ(&client, output_surface.client()); | 90 EXPECT_EQ(&client, output_surface.client()); |
| 91 EXPECT_FALSE(client.deferred_initialize_called()); |
| 92 |
| 93 // Verify DidLoseOutputSurface callback is hooked up correctly. |
| 94 EXPECT_FALSE(client.did_lose_output_surface_called()); |
| 95 output_surface.context3d()->loseContextCHROMIUM( |
| 96 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 97 EXPECT_TRUE(client.did_lose_output_surface_called()); |
58 } | 98 } |
59 | 99 |
60 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { | 100 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { |
61 scoped_ptr<TestWebGraphicsContext3D> context3d = | 101 scoped_ptr<TestWebGraphicsContext3D> context3d = |
62 TestWebGraphicsContext3D::Create(); | 102 TestWebGraphicsContext3D::Create(); |
63 | 103 |
64 // Lose the context so BindToClient fails. | 104 // Lose the context so BindToClient fails. |
65 context3d->set_times_make_current_succeeds(0); | 105 context3d->set_times_make_current_succeeds(0); |
66 | 106 |
67 TestOutputSurface output_surface( | 107 TestOutputSurface output_surface( |
68 context3d.PassAs<WebKit::WebGraphicsContext3D>()); | 108 context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
69 EXPECT_EQ(NULL, output_surface.client()); | 109 EXPECT_EQ(NULL, output_surface.client()); |
70 | 110 |
71 FakeOutputSurfaceClient client; | 111 FakeOutputSurfaceClient client; |
72 EXPECT_FALSE(output_surface.BindToClient(&client)); | 112 EXPECT_FALSE(output_surface.BindToClient(&client)); |
73 EXPECT_EQ(NULL, output_surface.client()); | 113 EXPECT_EQ(NULL, output_surface.client()); |
74 } | 114 } |
75 | 115 |
| 116 class InitializeNewContext3D : public ::testing::Test { |
| 117 public: |
| 118 InitializeNewContext3D() |
| 119 : context3d_(TestWebGraphicsContext3D::Create()), |
| 120 output_surface_( |
| 121 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) {} |
| 122 |
| 123 protected: |
| 124 void BindOutputSurface() { |
| 125 EXPECT_TRUE(output_surface_.BindToClient(&client_)); |
| 126 EXPECT_EQ(&client_, output_surface_.client()); |
| 127 } |
| 128 |
| 129 void InitializeNewContextExpectFail() { |
| 130 EXPECT_FALSE(output_surface_.InitializeNewContext3D( |
| 131 context3d_.PassAs<WebKit::WebGraphicsContext3D>())); |
| 132 EXPECT_EQ(&client_, output_surface_.client()); |
| 133 |
| 134 EXPECT_FALSE(output_surface_.context3d()); |
| 135 EXPECT_TRUE(output_surface_.software_device()); |
| 136 } |
| 137 |
| 138 scoped_ptr<TestWebGraphicsContext3D> context3d_; |
| 139 TestOutputSurface output_surface_; |
| 140 FakeOutputSurfaceClient client_; |
| 141 }; |
| 142 |
| 143 TEST_F(InitializeNewContext3D, Success) { |
| 144 BindOutputSurface(); |
| 145 EXPECT_FALSE(client_.deferred_initialize_called()); |
| 146 |
| 147 EXPECT_TRUE(output_surface_.InitializeNewContext3D( |
| 148 context3d_.PassAs<WebKit::WebGraphicsContext3D>())); |
| 149 EXPECT_TRUE(client_.deferred_initialize_called()); |
| 150 |
| 151 EXPECT_FALSE(client_.did_lose_output_surface_called()); |
| 152 output_surface_.context3d()->loseContextCHROMIUM( |
| 153 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 154 EXPECT_TRUE(client_.did_lose_output_surface_called()); |
| 155 } |
| 156 |
| 157 TEST_F(InitializeNewContext3D, Context3dMakeCurrentFails) { |
| 158 BindOutputSurface(); |
| 159 context3d_->set_times_make_current_succeeds(0); |
| 160 InitializeNewContextExpectFail(); |
| 161 } |
| 162 |
| 163 TEST_F(InitializeNewContext3D, ClientDeferredInitializeFails) { |
| 164 BindOutputSurface(); |
| 165 client_.set_deferred_initialize_result(false); |
| 166 InitializeNewContextExpectFail(); |
| 167 } |
| 168 |
76 } // namespace | 169 } // namespace |
77 } // namespace cc | 170 } // namespace cc |
OLD | NEW |