summaryrefslogtreecommitdiffstats
path: root/cc/trees/remote_channel_unittest.cc
blob: e33f5802f5f99752153d6845d453263542eecf4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/test/begin_frame_args_test.h"
#include "cc/test/layer_tree_test.h"

namespace cc {

class RemoteChannelTest : public LayerTreeTest {
 protected:
  RemoteChannelTest() : calls_received_(0) {}

  ~RemoteChannelTest() override {}

  void BeginTest() override {
    DCHECK(IsRemoteTest());
    BeginChannelTest();
  }
  virtual void BeginChannelTest() {}

  int calls_received_;

 private:
  DISALLOW_COPY_AND_ASSIGN(RemoteChannelTest);
};

class RemoteChannelTestInitializationAndShutdown : public RemoteChannelTest {
  void SetVisibleOnImpl(bool visible) override { calls_received_++; }

  void RequestNewOutputSurface() override {
    LayerTreeTest::RequestNewOutputSurface();
    calls_received_++;
  }

  void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override {
    calls_received_++;
  }

  void DidInitializeOutputSurface() override {
    calls_received_++;
    EndTest();
  }

  void FinishGLOnImpl() override { calls_received_++; }

  // On initialization and shutdown, each of the above calls should happen only
  // once.
  void AfterTest() override { EXPECT_EQ(5, calls_received_); }
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestInitializationAndShutdown);

class RemoteChannelTestMainThreadStoppedFlinging : public RemoteChannelTest {
  void BeginChannelTest() override { proxy()->MainThreadHasStoppedFlinging(); }

  void MainThreadHasStoppedFlingingOnImpl() override {
    calls_received_++;
    EndTest();
  }

  void AfterTest() override { EXPECT_EQ(1, calls_received_); }
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestMainThreadStoppedFlinging);

class RemoteChannelTestDeferCommits : public RemoteChannelTest {
  void BeginChannelTest() override { DispatchSetDeferCommits(true); }

  void SetDeferCommitsOnImpl(bool defer_commits) override {
    EXPECT_TRUE(defer_commits);
    calls_received_++;
    EndTest();
  }

  void AfterTest() override { EXPECT_EQ(1, calls_received_); }
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestDeferCommits);

class RemoteChannelTestNeedsRedraw : public RemoteChannelTest {
 public:
  RemoteChannelTestNeedsRedraw()
      : damaged_rect_(4, 5), device_viewport_size_(0, 0) {}

  void BeginChannelTest() override {
    device_viewport_size_ =
        gfx::Rect(remote_client_layer_tree_host()->device_viewport_size());
    layer_tree_host()->SetNeedsRedrawRect(damaged_rect_);
  }

  void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override {
    calls_received_++;
    if (calls_received_ == 1) {
      EXPECT_EQ(damaged_rect_, damage_rect);
    } else {
      // The second call is received after the output surface is successfully
      // initialized.
      EXPECT_EQ(device_viewport_size_, damage_rect);
      EndTest();
    }
  }

  void AfterTest() override { EXPECT_EQ(2, calls_received_); }

  gfx::Rect damaged_rect_;
  gfx::Rect device_viewport_size_;
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestNeedsRedraw);

class RemoteChannelTestReleaseOutputSurface : public RemoteChannelTest {
  void DidInitializeOutputSurface() override {
    SetVisibleOnLayerTreeHost(false);
    ReleaseOutputSurfaceOnLayerTreeHost();
  }

  void ReleaseOutputSurfaceOnImpl() override {
    calls_received_++;
    EndTest();
  }

  void AfterTest() override { EXPECT_EQ(1, calls_received_); }
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestReleaseOutputSurface);

class RemoteChannelTestCommit : public RemoteChannelTest {
  void BeginChannelTest() override {
    layer_tree_host()->SetViewportSize(viewport_size_);
    PostSetNeedsCommitToMainThread();
  }

  void SetNeedsCommitOnImpl() override { EXPECT_EQ(0, calls_received_++); }

  void ReceivedBeginMainFrame() override { EXPECT_EQ(1, calls_received_++); }

  void StartCommitOnImpl() override { EXPECT_EQ(2, calls_received_++); }

  void DidCommitAndDrawFrame() override { EXPECT_EQ(3, calls_received_++); }

  void DidCompleteSwapBuffers() override {
    EXPECT_EQ(4, calls_received_++);
    EndTest();
  }

  void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
    // Ensure that we serialized and deserialized the LayerTreeHost for the
    // commit.
    EXPECT_EQ(viewport_size_, host_impl->device_viewport_size());
  }

  void ScheduledActionSendBeginMainFrame() override {
    last_args_sent_ = GetProxyImplForTest()->last_begin_frame_args();
  }

  void BeginMainFrame(const BeginFrameArgs& args) override {
    last_args_received_ = args;
  }

  void AfterTest() override {
    EXPECT_EQ(5, calls_received_);

    // Ensure that we serialized and deserialized the
    // BeginMainFrameAndCommitState. While the last_args_received_ will be set
    // on the impl thread, it is safe to read it here since the impl thread has
    // been destroyed now.
    EXPECT_EQ(last_args_sent_, last_args_received_);
  }

  const gfx::Size viewport_size_ = gfx::Size(5, 3);
  BeginFrameArgs last_args_sent_;
  BeginFrameArgs last_args_received_;
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestCommit);

class RemoteChannelTestBeginMainFrameAborted : public RemoteChannelTest {
  void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); }

  void ScheduledActionWillSendBeginMainFrame() override {
    PostSetDeferCommitsToMainThread(true);
  }

  void BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) override {
    EXPECT_EQ(reason, CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
    calls_received_++;
    EndTest();
  }

  void AfterTest() override { EXPECT_EQ(1, calls_received_); }
};

REMOTE_DIRECT_RENDERER_TEST_F(RemoteChannelTestBeginMainFrameAborted);

class RemoteChannelTestReleaseOutputSurfaceDuringCommit
    : public RemoteChannelTest {
 public:
  RemoteChannelTestReleaseOutputSurfaceDuringCommit()
      : output_surface_initialized_count_(0), commit_count_(0) {}
  void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); }

  void DidInitializeOutputSurface() override {
    ++output_surface_initialized_count_;

    // We should not have any commits at this point. This call runs either after
    // the first output surface is initialized so no commits should have been
    // started, or after the output surface was released by the main thread. In
    // which case, we should have queued the commit and it should only go
    // through after the new output surface is initialized.
    EXPECT_EQ(0, commit_count_);
  }

  void ReceivedBeginMainFrame() override {
    // Release the output surface before we respond to the BeginMainFrame.
    SetVisibleOnLayerTreeHost(false);
    ReleaseOutputSurfaceOnLayerTreeHost();
    SetVisibleOnLayerTreeHost(true);
  }

  void StartCommitOnImpl() override {
    // The commit should go through only when the second output surface is
    // initialized.
    EXPECT_EQ(2, output_surface_initialized_count_);
    EXPECT_EQ(0, commit_count_);
    ++commit_count_;
    EndTest();
  }

  void AfterTest() override {
    EXPECT_EQ(2, output_surface_initialized_count_);
    EXPECT_EQ(1, commit_count_);
  }

  int output_surface_initialized_count_;
  int commit_count_;
};

REMOTE_DIRECT_RENDERER_TEST_F(
    RemoteChannelTestReleaseOutputSurfaceDuringCommit);

}  // namespace cc