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

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

Issue 2352963002: cc: Make most of cc::OutputSurface abstract. (Closed)
Patch Set: outputsurface-cleanup: rebase Created 4 years, 2 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> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
(...skipping 11 matching lines...) Expand all
22 class TestOutputSurface : public OutputSurface { 22 class TestOutputSurface : public OutputSurface {
23 public: 23 public:
24 explicit TestOutputSurface( 24 explicit TestOutputSurface(
25 scoped_refptr<TestContextProvider> context_provider) 25 scoped_refptr<TestContextProvider> context_provider)
26 : OutputSurface(std::move(context_provider)) {} 26 : OutputSurface(std::move(context_provider)) {}
27 27
28 explicit TestOutputSurface( 28 explicit TestOutputSurface(
29 std::unique_ptr<SoftwareOutputDevice> software_device) 29 std::unique_ptr<SoftwareOutputDevice> software_device)
30 : OutputSurface(std::move(software_device)) {} 30 : OutputSurface(std::move(software_device)) {}
31 31
32 void EnsureBackbuffer() override {}
33 void DiscardBackbuffer() override {}
34 void BindFramebuffer() override {}
32 void SwapBuffers(CompositorFrame frame) override { 35 void SwapBuffers(CompositorFrame frame) override {
33 client_->DidSwapBuffersComplete(); 36 client_->DidSwapBuffersComplete();
34 } 37 }
35 uint32_t GetFramebufferCopyTextureFormat() override { 38 uint32_t GetFramebufferCopyTextureFormat() override {
36 // TestContextProvider has no real framebuffer, just use RGB. 39 // TestContextProvider has no real framebuffer, just use RGB.
37 return GL_RGB; 40 return GL_RGB;
38 } 41 }
42 OverlayCandidateValidator* GetOverlayCandidateValidator() const override {
43 return nullptr;
44 }
45 bool IsDisplayedAsOverlayPlane() const override { return false; }
46 unsigned GetOverlayTextureId() const override { return 0; }
47 bool SurfaceIsSuspendForRecycle() const override { return false; }
48 bool HasExternalStencilTest() const override { return false; }
49 void ApplyExternalStencil() override {}
39 50
40 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } 51 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); }
41 52
42 protected: 53 protected:
43 }; 54 };
44 55
45 class TestSoftwareOutputDevice : public SoftwareOutputDevice { 56 class TestSoftwareOutputDevice : public SoftwareOutputDevice {
46 public: 57 public:
47 TestSoftwareOutputDevice(); 58 TestSoftwareOutputDevice();
48 ~TestSoftwareOutputDevice() override; 59 ~TestSoftwareOutputDevice() override;
(...skipping 21 matching lines...) Expand all
70 } 81 }
71 82
72 void TestSoftwareOutputDevice::EnsureBackbuffer() { 83 void TestSoftwareOutputDevice::EnsureBackbuffer() {
73 SoftwareOutputDevice::EnsureBackbuffer(); 84 SoftwareOutputDevice::EnsureBackbuffer();
74 ensure_backbuffer_count_++; 85 ensure_backbuffer_count_++;
75 } 86 }
76 87
77 TEST(OutputSurfaceTest, ContextLossInformsClient) { 88 TEST(OutputSurfaceTest, ContextLossInformsClient) {
78 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); 89 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
79 TestOutputSurface output_surface(provider); 90 TestOutputSurface output_surface(provider);
80 EXPECT_FALSE(output_surface.HasClient());
81 91
82 FakeOutputSurfaceClient client; 92 FakeOutputSurfaceClient client;
83 EXPECT_TRUE(output_surface.BindToClient(&client)); 93 EXPECT_TRUE(output_surface.BindToClient(&client));
84 EXPECT_TRUE(output_surface.HasClient());
85 94
86 // Verify DidLoseOutputSurface callback is hooked up correctly. 95 // Verify DidLoseOutputSurface callback is hooked up correctly.
87 EXPECT_FALSE(client.did_lose_output_surface_called()); 96 EXPECT_FALSE(client.did_lose_output_surface_called());
88 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( 97 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
89 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 98 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
90 output_surface.context_provider()->ContextGL()->Flush(); 99 output_surface.context_provider()->ContextGL()->Flush();
91 EXPECT_TRUE(client.did_lose_output_surface_called()); 100 EXPECT_TRUE(client.did_lose_output_surface_called());
92 } 101 }
93 102
94 // TODO(danakj): Add a test for worker context failure as well when 103 // TODO(danakj): Add a test for worker context failure as well when
95 // OutputSurface creates/binds it. 104 // OutputSurface creates/binds it.
96 TEST(OutputSurfaceTest, ContextLossFailsBind) { 105 TEST(OutputSurfaceTest, ContextLossFailsBind) {
97 scoped_refptr<TestContextProvider> context_provider = 106 scoped_refptr<TestContextProvider> context_provider =
98 TestContextProvider::Create(); 107 TestContextProvider::Create();
99 108
100 // Lose the context so BindToClient fails. 109 // Lose the context so BindToClient fails.
101 context_provider->UnboundTestContext3d()->set_context_lost(true); 110 context_provider->UnboundTestContext3d()->set_context_lost(true);
102 111
103 TestOutputSurface output_surface(context_provider); 112 TestOutputSurface output_surface(context_provider);
104 EXPECT_FALSE(output_surface.HasClient());
105 113
106 FakeOutputSurfaceClient client; 114 FakeOutputSurfaceClient client;
107 EXPECT_FALSE(output_surface.BindToClient(&client)); 115 EXPECT_FALSE(output_surface.BindToClient(&client));
108 EXPECT_FALSE(output_surface.HasClient());
109 }
110
111 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) {
112 auto device_owned = base::MakeUnique<TestSoftwareOutputDevice>();
113 TestSoftwareOutputDevice* software_output_device = device_owned.get();
114
115 // TestOutputSurface now owns software_output_device and has responsibility to
116 // free it.
117 TestOutputSurface output_surface(std::move(device_owned));
118
119 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count());
120 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
121
122 output_surface.EnsureBackbuffer();
123 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
124 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
125 output_surface.DiscardBackbuffer();
126
127 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
128 EXPECT_EQ(1, software_output_device->discard_backbuffer_count());
129 } 116 }
130 117
131 } // namespace 118 } // namespace
132 } // namespace cc 119 } // 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