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

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

Issue 2443003004: cc: Make OutputSurface::BindToClient pure virtual and not return bool (Closed)
Patch Set: bindtoclient-pure-virtual: rebase Created 4 years, 1 month 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_client.h ('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
(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/output_surface.h"
6
7 #include <utility>
8
9 #include "base/memory/ptr_util.h"
10 #include "cc/output/output_surface_frame.h"
11 #include "cc/output/software_output_device.h"
12 #include "cc/test/fake_output_surface_client.h"
13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_web_graphics_context_3d.h"
15 #include "gpu/GLES2/gl2extchromium.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace cc {
19 namespace {
20
21 class TestOutputSurface : public OutputSurface {
22 public:
23 explicit TestOutputSurface(
24 scoped_refptr<TestContextProvider> context_provider)
25 : OutputSurface(std::move(context_provider)) {}
26
27 explicit TestOutputSurface(
28 std::unique_ptr<SoftwareOutputDevice> software_device)
29 : OutputSurface(std::move(software_device)) {}
30
31 void EnsureBackbuffer() override {}
32 void DiscardBackbuffer() override {}
33 void BindFramebuffer() override {}
34 void Reshape(const gfx::Size& size,
35 float device_scale_factor,
36 const gfx::ColorSpace& color_space,
37 bool has_alpha) override {}
38 void SwapBuffers(OutputSurfaceFrame frame) override {
39 client_->DidReceiveSwapBuffersAck();
40 }
41 uint32_t GetFramebufferCopyTextureFormat() override {
42 // TestContextProvider has no real framebuffer, just use RGB.
43 return GL_RGB;
44 }
45 OverlayCandidateValidator* GetOverlayCandidateValidator() const override {
46 return nullptr;
47 }
48 bool IsDisplayedAsOverlayPlane() const override { return false; }
49 unsigned GetOverlayTextureId() const override { return 0; }
50 bool SurfaceIsSuspendForRecycle() const override { return false; }
51 bool HasExternalStencilTest() const override { return false; }
52 void ApplyExternalStencil() override {}
53
54 void OnSwapBuffersCompleteForTesting() {
55 client_->DidReceiveSwapBuffersAck();
56 }
57
58 protected:
59 };
60
61 class TestSoftwareOutputDevice : public SoftwareOutputDevice {
62 public:
63 TestSoftwareOutputDevice();
64 ~TestSoftwareOutputDevice() override;
65
66 // Overriden from cc:SoftwareOutputDevice
67 void DiscardBackbuffer() override;
68 void EnsureBackbuffer() override;
69
70 int discard_backbuffer_count() { return discard_backbuffer_count_; }
71 int ensure_backbuffer_count() { return ensure_backbuffer_count_; }
72
73 private:
74 int discard_backbuffer_count_;
75 int ensure_backbuffer_count_;
76 };
77
78 TestSoftwareOutputDevice::TestSoftwareOutputDevice()
79 : discard_backbuffer_count_(0), ensure_backbuffer_count_(0) {}
80
81 TestSoftwareOutputDevice::~TestSoftwareOutputDevice() {}
82
83 void TestSoftwareOutputDevice::DiscardBackbuffer() {
84 SoftwareOutputDevice::DiscardBackbuffer();
85 discard_backbuffer_count_++;
86 }
87
88 void TestSoftwareOutputDevice::EnsureBackbuffer() {
89 SoftwareOutputDevice::EnsureBackbuffer();
90 ensure_backbuffer_count_++;
91 }
92
93 TEST(OutputSurfaceTest, ContextLossInformsClient) {
94 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
95 TestOutputSurface output_surface(provider);
96
97 FakeOutputSurfaceClient client;
98 EXPECT_TRUE(output_surface.BindToClient(&client));
99
100 // Verify DidLoseOutputSurface callback is hooked up correctly.
101 EXPECT_FALSE(client.did_lose_output_surface_called());
102 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
103 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
104 output_surface.context_provider()->ContextGL()->Flush();
105 EXPECT_TRUE(client.did_lose_output_surface_called());
106 }
107
108 // TODO(danakj): Add a test for worker context failure as well when
109 // OutputSurface creates/binds it.
110 TEST(OutputSurfaceTest, ContextLossFailsBind) {
111 scoped_refptr<TestContextProvider> context_provider =
112 TestContextProvider::Create();
113
114 // Lose the context so BindToClient fails.
115 context_provider->UnboundTestContext3d()->set_context_lost(true);
116
117 TestOutputSurface output_surface(context_provider);
118
119 FakeOutputSurfaceClient client;
120 EXPECT_FALSE(output_surface.BindToClient(&client));
121 }
122
123 } // namespace
124 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface_client.h ('k') | cc/output/overlay_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698