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

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

Issue 2349743004: cc: Remove things from OutputSurface and CompositorFrameSink. (Closed)
Patch Set: delete-stuff-cfs: comment-and-rebase Created 4 years, 3 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
« no previous file with comments | « cc/output/output_surface.cc ('k') | cc/output/overlay_unittest.cc » ('j') | 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 6
7 #include <utility>
8
7 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
8 #include "base/test/test_simple_task_runner.h" 10 #include "cc/output/compositor_frame.h"
9 #include "cc/output/managed_memory_policy.h" 11 #include "cc/output/output_surface.h"
10 #include "cc/output/output_surface_client.h"
11 #include "cc/output/software_output_device.h" 12 #include "cc/output/software_output_device.h"
12 #include "cc/test/begin_frame_args_test.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h" 13 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/test_context_provider.h" 14 #include "cc/test/test_context_provider.h"
16 #include "cc/test/test_web_graphics_context_3d.h" 15 #include "cc/test/test_web_graphics_context_3d.h"
17 #include "gpu/GLES2/gl2extchromium.h" 16 #include "gpu/GLES2/gl2extchromium.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace cc { 19 namespace cc {
21 namespace { 20 namespace {
22 21
23 class TestOutputSurface : public OutputSurface { 22 class TestOutputSurface : public OutputSurface {
24 public: 23 public:
25 explicit TestOutputSurface( 24 explicit TestOutputSurface(
26 scoped_refptr<TestContextProvider> context_provider) 25 scoped_refptr<TestContextProvider> context_provider)
27 : OutputSurface(std::move(context_provider), nullptr, nullptr) {} 26 : OutputSurface(std::move(context_provider)) {}
28
29 TestOutputSurface(scoped_refptr<TestContextProvider> context_provider,
30 scoped_refptr<TestContextProvider> worker_context_provider)
31 : OutputSurface(std::move(context_provider),
32 std::move(worker_context_provider),
33 nullptr) {}
34 27
35 explicit TestOutputSurface( 28 explicit TestOutputSurface(
36 std::unique_ptr<SoftwareOutputDevice> software_device) 29 std::unique_ptr<SoftwareOutputDevice> software_device)
37 : OutputSurface(nullptr, nullptr, std::move(software_device)) {} 30 : OutputSurface(std::move(software_device)) {}
38
39 TestOutputSurface(scoped_refptr<TestContextProvider> context_provider,
40 std::unique_ptr<SoftwareOutputDevice> software_device)
41 : OutputSurface(std::move(context_provider),
42 nullptr,
43 std::move(software_device)) {}
44 31
45 void SwapBuffers(CompositorFrame frame) override { 32 void SwapBuffers(CompositorFrame frame) override {
46 client_->DidSwapBuffersComplete(); 33 client_->DidSwapBuffersComplete();
47 } 34 }
48 uint32_t GetFramebufferCopyTextureFormat() override { 35 uint32_t GetFramebufferCopyTextureFormat() override {
49 // TestContextProvider has no real framebuffer, just use RGB. 36 // TestContextProvider has no real framebuffer, just use RGB.
50 return GL_RGB; 37 return GL_RGB;
51 } 38 }
52 39
53 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } 40 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); }
(...skipping 26 matching lines...) Expand all
80 void TestSoftwareOutputDevice::DiscardBackbuffer() { 67 void TestSoftwareOutputDevice::DiscardBackbuffer() {
81 SoftwareOutputDevice::DiscardBackbuffer(); 68 SoftwareOutputDevice::DiscardBackbuffer();
82 discard_backbuffer_count_++; 69 discard_backbuffer_count_++;
83 } 70 }
84 71
85 void TestSoftwareOutputDevice::EnsureBackbuffer() { 72 void TestSoftwareOutputDevice::EnsureBackbuffer() {
86 SoftwareOutputDevice::EnsureBackbuffer(); 73 SoftwareOutputDevice::EnsureBackbuffer();
87 ensure_backbuffer_count_++; 74 ensure_backbuffer_count_++;
88 } 75 }
89 76
90 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { 77 TEST(OutputSurfaceTest, ContextLossInformsClient) {
91 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); 78 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
92 TestOutputSurface output_surface(provider); 79 TestOutputSurface output_surface(provider);
93 EXPECT_FALSE(output_surface.HasClient()); 80 EXPECT_FALSE(output_surface.HasClient());
94 81
95 FakeOutputSurfaceClient client; 82 FakeOutputSurfaceClient client;
96 EXPECT_TRUE(output_surface.BindToClient(&client)); 83 EXPECT_TRUE(output_surface.BindToClient(&client));
97 EXPECT_TRUE(output_surface.HasClient()); 84 EXPECT_TRUE(output_surface.HasClient());
98 85
99 // Verify DidLoseOutputSurface callback is hooked up correctly. 86 // Verify DidLoseOutputSurface callback is hooked up correctly.
100 EXPECT_FALSE(client.did_lose_output_surface_called()); 87 EXPECT_FALSE(client.did_lose_output_surface_called());
101 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( 88 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
102 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 89 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
103 output_surface.context_provider()->ContextGL()->Flush(); 90 output_surface.context_provider()->ContextGL()->Flush();
104 EXPECT_TRUE(client.did_lose_output_surface_called()); 91 EXPECT_TRUE(client.did_lose_output_surface_called());
105 } 92 }
106 93
107 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientSuccess) {
108 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
109 scoped_refptr<TestContextProvider> worker_provider =
110 TestContextProvider::Create();
111 TestOutputSurface output_surface(provider, worker_provider);
112 EXPECT_FALSE(output_surface.HasClient());
113
114 FakeOutputSurfaceClient client;
115 EXPECT_TRUE(output_surface.BindToClient(&client));
116 EXPECT_TRUE(output_surface.HasClient());
117
118 // Verify DidLoseOutputSurface callback is hooked up correctly.
119 EXPECT_FALSE(client.did_lose_output_surface_called());
120 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
121 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
122 output_surface.context_provider()->ContextGL()->Flush();
123 EXPECT_TRUE(client.did_lose_output_surface_called());
124 }
125
126 // TODO(danakj): Add a test for worker context failure as well when 94 // TODO(danakj): Add a test for worker context failure as well when
127 // OutputSurface creates/binds it. 95 // OutputSurface creates/binds it.
128 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { 96 TEST(OutputSurfaceTest, ContextLossFailsBind) {
129 scoped_refptr<TestContextProvider> context_provider = 97 scoped_refptr<TestContextProvider> context_provider =
130 TestContextProvider::Create(); 98 TestContextProvider::Create();
131 99
132 // Lose the context so BindToClient fails. 100 // Lose the context so BindToClient fails.
133 context_provider->UnboundTestContext3d()->set_context_lost(true); 101 context_provider->UnboundTestContext3d()->set_context_lost(true);
134 102
135 TestOutputSurface output_surface(context_provider); 103 TestOutputSurface output_surface(context_provider);
136 EXPECT_FALSE(output_surface.HasClient()); 104 EXPECT_FALSE(output_surface.HasClient());
137 105
138 FakeOutputSurfaceClient client; 106 FakeOutputSurfaceClient client;
139 EXPECT_FALSE(output_surface.BindToClient(&client)); 107 EXPECT_FALSE(output_surface.BindToClient(&client));
140 EXPECT_FALSE(output_surface.HasClient()); 108 EXPECT_FALSE(output_surface.HasClient());
141 } 109 }
142 110
143 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { 111 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) {
144 TestSoftwareOutputDevice* software_output_device = 112 auto device_owned = base::MakeUnique<TestSoftwareOutputDevice>();
145 new TestSoftwareOutputDevice(); 113 TestSoftwareOutputDevice* software_output_device = device_owned.get();
146 114
147 // TestOutputSurface now owns software_output_device and has responsibility to 115 // TestOutputSurface now owns software_output_device and has responsibility to
148 // free it. 116 // free it.
149 TestOutputSurface output_surface(base::WrapUnique(software_output_device)); 117 TestOutputSurface output_surface(std::move(device_owned));
150 118
151 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); 119 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count());
152 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); 120 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
153 121
154 output_surface.EnsureBackbuffer(); 122 output_surface.EnsureBackbuffer();
155 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 123 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
156 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); 124 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
157 output_surface.DiscardBackbuffer(); 125 output_surface.DiscardBackbuffer();
158 126
159 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 127 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
160 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); 128 EXPECT_EQ(1, software_output_device->discard_backbuffer_count());
161 } 129 }
162 130
163 } // namespace 131 } // namespace
164 } // namespace cc 132 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface.cc ('k') | cc/output/overlay_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698