Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: cc/output/output_surface_unittest.cc

Issue 15647021: Factor out cc::OutputSurface::InitializeAndSetContext3D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor clean up Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« cc/output/output_surface.cc ('K') | « cc/output/output_surface.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/test_web_graphics_context_3d.h" 7 #include "cc/test/test_web_graphics_context_3d.h"
8 #include "gpu/GLES2/gl2extchromium.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace cc { 11 namespace cc {
11 namespace { 12 namespace {
12 13
13 class TestOutputSurface : public OutputSurface { 14 class TestOutputSurface : public OutputSurface {
14 public: 15 public:
15 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 16 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
16 : OutputSurface(context3d.Pass()) {} 17 : OutputSurface(context3d.Pass()) {}
17 18
18 explicit TestOutputSurface( 19 explicit TestOutputSurface(
19 scoped_ptr<cc::SoftwareOutputDevice> software_device) 20 scoped_ptr<cc::SoftwareOutputDevice> software_device)
20 : OutputSurface(software_device.Pass()) {} 21 : OutputSurface(software_device.Pass()) {}
21 22
22 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 23 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
23 scoped_ptr<cc::SoftwareOutputDevice> software_device) 24 scoped_ptr<cc::SoftwareOutputDevice> software_device)
24 : OutputSurface(context3d.Pass(), software_device.Pass()) {} 25 : OutputSurface(context3d.Pass(), software_device.Pass()) {}
25 26
26 OutputSurfaceClient* client() { return client_; } 27 OutputSurfaceClient* client() { return client_; }
28
29 bool InitializeNewContext3D(
30 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) {
31 return InitializeAndSetContext3D(new_context3d.Pass());
32 }
27 }; 33 };
28 34
29 class FakeOutputSurfaceClient : public OutputSurfaceClient { 35 class FakeOutputSurfaceClient : public OutputSurfaceClient {
30 public: 36 public:
37 FakeOutputSurfaceClient() : did_lose_output_surface_called_(false) {}
38
31 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {} 39 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {}
32 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, 40 virtual void OnVSyncParametersChanged(base::TimeTicks timebase,
33 base::TimeDelta interval) OVERRIDE {} 41 base::TimeDelta interval) OVERRIDE {}
34 virtual void BeginFrame(base::TimeTicks frame_time) OVERRIDE {} 42 virtual void BeginFrame(base::TimeTicks frame_time) OVERRIDE {}
35 virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck& ack) 43 virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck& ack)
36 OVERRIDE {} 44 OVERRIDE {}
37 virtual void OnSwapBuffersComplete() OVERRIDE {} 45 virtual void OnSwapBuffersComplete() OVERRIDE {}
38 virtual void DidLoseOutputSurface() OVERRIDE {} 46 virtual void DidLoseOutputSurface() OVERRIDE {
47 did_lose_output_surface_called_ = true;
48 }
49
50 bool did_lose_output_surface_called() {
51 return did_lose_output_surface_called_;
52 }
53
54 private:
55 bool did_lose_output_surface_called_;
39 }; 56 };
40 57
41 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { 58 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
42 scoped_ptr<TestWebGraphicsContext3D> context3d = 59 scoped_ptr<TestWebGraphicsContext3D> context3d =
43 TestWebGraphicsContext3D::Create(); 60 TestWebGraphicsContext3D::Create();
44 61
45 TestOutputSurface output_surface( 62 TestOutputSurface output_surface(
46 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 63 context3d.PassAs<WebKit::WebGraphicsContext3D>());
47 EXPECT_EQ(NULL, output_surface.client()); 64 EXPECT_EQ(NULL, output_surface.client());
48 65
49 FakeOutputSurfaceClient client; 66 FakeOutputSurfaceClient client;
50 EXPECT_TRUE(output_surface.BindToClient(&client)); 67 EXPECT_TRUE(output_surface.BindToClient(&client));
51 EXPECT_EQ(&client, output_surface.client()); 68 EXPECT_EQ(&client, output_surface.client());
69
70 // Verify DidLoseOutputSurface callback is hooked up correctly.
71 ASSERT_FALSE(client.did_lose_output_surface_called());
danakj 2013/06/05 18:50:22 nit: EXPECT instead of ASSERT throughout, this doe
boliu 2013/06/05 19:06:31 All except ASSERT_TRUE(output_surface.context3d())
72 output_surface.context3d()->loseContextCHROMIUM(
73 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
74 ASSERT_TRUE(client.did_lose_output_surface_called());
52 } 75 }
53 76
54 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { 77 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) {
55 scoped_ptr<TestWebGraphicsContext3D> context3d = 78 scoped_ptr<TestWebGraphicsContext3D> context3d =
56 TestWebGraphicsContext3D::Create(); 79 TestWebGraphicsContext3D::Create();
57 80
58 // Lose the context so BindToClient fails. 81 // Lose the context so BindToClient fails.
59 context3d->set_times_make_current_succeeds(0); 82 context3d->set_times_make_current_succeeds(0);
60 83
61 TestOutputSurface output_surface( 84 TestOutputSurface output_surface(
62 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 85 context3d.PassAs<WebKit::WebGraphicsContext3D>());
63 EXPECT_EQ(NULL, output_surface.client()); 86 EXPECT_EQ(NULL, output_surface.client());
64 87
65 FakeOutputSurfaceClient client; 88 FakeOutputSurfaceClient client;
66 EXPECT_FALSE(output_surface.BindToClient(&client)); 89 EXPECT_FALSE(output_surface.BindToClient(&client));
67 EXPECT_EQ(NULL, output_surface.client()); 90 EXPECT_EQ(NULL, output_surface.client());
68 } 91 }
69 92
93 TEST(OutputSurfaceTest, InitializeNewContext3DSuccess) {
94 scoped_ptr<TestWebGraphicsContext3D> first_context3d =
95 TestWebGraphicsContext3D::Create();
96 TestOutputSurface output_surface(
97 first_context3d.PassAs<WebKit::WebGraphicsContext3D>());
98
99 FakeOutputSurfaceClient client;
100 EXPECT_TRUE(output_surface.BindToClient(&client));
101 EXPECT_EQ(&client, output_surface.client());
102
103 scoped_ptr<TestWebGraphicsContext3D> second_context3d =
104 TestWebGraphicsContext3D::Create();
105 EXPECT_TRUE(output_surface.InitializeNewContext3D(
106 second_context3d.PassAs<WebKit::WebGraphicsContext3D>()));
107 ASSERT_FALSE(client.did_lose_output_surface_called());
108 output_surface.context3d()->loseContextCHROMIUM(
109 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
110 ASSERT_TRUE(client.did_lose_output_surface_called());
111 }
112
113 TEST(OutputSurfaceTest, InitializeNewContext3DFails) {
114 scoped_ptr<TestWebGraphicsContext3D> first_context3d =
115 TestWebGraphicsContext3D::Create();
116 TestWebGraphicsContext3D* first_context3d_ptr = first_context3d.get();
117 TestOutputSurface output_surface(
118 first_context3d.PassAs<WebKit::WebGraphicsContext3D>());
119
120 FakeOutputSurfaceClient client;
121 EXPECT_TRUE(output_surface.BindToClient(&client));
122 EXPECT_EQ(&client, output_surface.client());
123
124 scoped_ptr<TestWebGraphicsContext3D> second_context3d =
125 TestWebGraphicsContext3D::Create();
126 second_context3d->set_times_make_current_succeeds(0);
127
128 EXPECT_FALSE(output_surface.InitializeNewContext3D(
129 second_context3d.PassAs<WebKit::WebGraphicsContext3D>()));
130 EXPECT_EQ(&client, output_surface.client());
131
132 // First context3d still in place.
133 ASSERT_TRUE(output_surface.context3d());
134 EXPECT_EQ(first_context3d_ptr, output_surface.context3d());
135 ASSERT_FALSE(client.did_lose_output_surface_called());
136 output_surface.context3d()->loseContextCHROMIUM(
137 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
138 ASSERT_TRUE(client.did_lose_output_surface_called());
139 }
140
70 } // namespace 141 } // namespace
71 } // namespace cc 142 } // namespace cc
OLDNEW
« cc/output/output_surface.cc ('K') | « cc/output/output_surface.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698