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

Side by Side Diff: cc/trees/layer_tree_host_unittest_no_message_loop.cc

Issue 292493006: cc: BlockingTaskRunner without MessageLoopProxy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delegated layer test Created 6 years, 7 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
« no previous file with comments | « cc/trees/blocking_task_runner.cc ('k') | cc/trees/proxy.h » ('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 2014 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 "base/message_loop/message_loop_proxy.h"
6 #include "base/threading/simple_thread.h"
7 #include "cc/layers/delegated_frame_provider.h"
8 #include "cc/layers/delegated_frame_resource_collection.h"
9 #include "cc/layers/delegated_renderer_layer.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/solid_color_layer.h"
12 #include "cc/output/delegated_frame_data.h"
13 #include "cc/output/output_surface.h"
14 #include "cc/output/output_surface_client.h"
15 #include "cc/resources/resource_provider.h"
16 #include "cc/test/fake_delegated_renderer_layer.h"
17 #include "cc/test/test_context_provider.h"
18 #include "cc/trees/layer_tree_host.h"
19 #include "cc/trees/layer_tree_host_client.h"
20 #include "cc/trees/layer_tree_host_single_thread_client.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/skia/include/core/SkColor.h"
23 #include "ui/gfx/frame_time.h"
24
25 namespace cc {
26 namespace {
27
28 class NoMessageLoopOutputSurface : public OutputSurface {
29 public:
30 NoMessageLoopOutputSurface() : OutputSurface(TestContextProvider::Create()) {}
31 virtual ~NoMessageLoopOutputSurface() {}
32
33 // OutputSurface overrides.
34 virtual void SwapBuffers(CompositorFrame* frame) OVERRIDE {
35 DCHECK(client_);
36 client_->DidSwapBuffers();
37 client_->DidSwapBuffersComplete();
38 }
39 };
40
41 class LayerTreeHostNoMessageLoopTest
42 : public testing::Test,
43 public base::DelegateSimpleThread::Delegate,
44 public LayerTreeHostClient,
45 public LayerTreeHostSingleThreadClient {
46 public:
47 LayerTreeHostNoMessageLoopTest()
48 : did_initialize_output_surface_(false),
49 did_commit_(false),
50 did_commit_and_draw_frame_(false),
51 size_(100, 100),
52 no_loop_thread_(this, "LayerTreeHostNoMessageLoopTest") {}
53 virtual ~LayerTreeHostNoMessageLoopTest() {}
54
55 // LayerTreeHostClient overrides.
56 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {}
57 virtual void DidBeginMainFrame() OVERRIDE {}
58 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {}
59 virtual void Layout() OVERRIDE {}
60 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
61 float page_scale) OVERRIDE {}
62 virtual scoped_ptr<OutputSurface> CreateOutputSurface(
63 bool fallback) OVERRIDE {
64 return make_scoped_ptr<OutputSurface>(new NoMessageLoopOutputSurface);
65 }
66 virtual void DidInitializeOutputSurface() OVERRIDE {
67 did_initialize_output_surface_ = true;
68 }
69 virtual void WillCommit() OVERRIDE {}
70 virtual void DidCommit() OVERRIDE { did_commit_ = true; }
71 virtual void DidCommitAndDrawFrame() OVERRIDE {
72 did_commit_and_draw_frame_ = true;
73 }
74 virtual void DidCompleteSwapBuffers() OVERRIDE {}
75
76 // LayerTreeHostSingleThreadClient overrides.
77 virtual void ScheduleComposite() OVERRIDE {}
78 virtual void ScheduleAnimation() OVERRIDE {}
79 virtual void DidPostSwapBuffers() OVERRIDE {}
80 virtual void DidAbortSwapBuffers() OVERRIDE {}
81
82 void RunTest() {
83 no_loop_thread_.Start();
84 no_loop_thread_.Join();
85 }
86
87 // base::DelegateSimpleThread::Delegate override.
88 virtual void Run() OVERRIDE {
89 ASSERT_FALSE(base::MessageLoopProxy::current());
90 RunTestWithoutMessageLoop();
91 EXPECT_FALSE(base::MessageLoopProxy::current());
92 }
93
94 protected:
95 virtual void RunTestWithoutMessageLoop() = 0;
96
97 void SetupLayerTreeHost() {
98 LayerTreeSettings settings;
99 layer_tree_host_ =
100 LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
101 layer_tree_host_->SetViewportSize(size_);
102 layer_tree_host_->SetRootLayer(root_layer_);
103 }
104
105 void Composite() {
106 did_commit_ = false;
107 did_commit_and_draw_frame_ = false;
108 layer_tree_host_->Composite(gfx::FrameTime::Now());
109 EXPECT_TRUE(did_initialize_output_surface_);
110 EXPECT_TRUE(did_commit_);
111 EXPECT_TRUE(did_commit_and_draw_frame_);
112 }
113
114 void TearDownLayerTreeHost() {
115 // Explicit teardown to make failures easier to debug.
116 layer_tree_host_.reset();
117 root_layer_ = NULL;
118 }
119
120 // All protected member variables are accessed only on |no_loop_thread_|.
121 scoped_ptr<LayerTreeHost> layer_tree_host_;
122 scoped_refptr<Layer> root_layer_;
123
124 bool did_initialize_output_surface_;
125 bool did_commit_;
126 bool did_commit_and_draw_frame_;
127 gfx::Size size_;
128
129 private:
130 base::DelegateSimpleThread no_loop_thread_;
131 };
132
133 class LayerTreeHostNoMessageLoopSmokeTest
134 : public LayerTreeHostNoMessageLoopTest {
135 protected:
136 virtual void RunTestWithoutMessageLoop() OVERRIDE {
137 gfx::Size size(100, 100);
138
139 // Set up root layer.
140 {
141 scoped_refptr<SolidColorLayer> solid_color_layer =
142 SolidColorLayer::Create();
143 solid_color_layer->SetBackgroundColor(SK_ColorRED);
144 solid_color_layer->SetBounds(size_);
145 solid_color_layer->SetIsDrawable(true);
146 root_layer_ = solid_color_layer;
147 }
148
149 SetupLayerTreeHost();
150 Composite();
151 TearDownLayerTreeHost();
152 }
153 };
154
155 TEST_F(LayerTreeHostNoMessageLoopSmokeTest, SmokeTest) {
156 RunTest();
157 }
158
159 class LayerTreeHostNoMessageLoopDelegatedLayer
160 : public LayerTreeHostNoMessageLoopTest,
161 public DelegatedFrameResourceCollectionClient {
162 protected:
163 virtual void RunTestWithoutMessageLoop() OVERRIDE {
164 resource_collection_ = new DelegatedFrameResourceCollection;
165 frame_provider_ = new DelegatedFrameProvider(
166 resource_collection_.get(), CreateFrameDataWithResource(998));
167
168 root_layer_ = Layer::Create();
169 delegated_layer_ = FakeDelegatedRendererLayer::Create(frame_provider_);
170 delegated_layer_->SetBounds(size_);
171 delegated_layer_->SetIsDrawable(true);
172 root_layer_->AddChild(delegated_layer_);
173
174 SetupLayerTreeHost();
175
176 // Draw first frame.
177 Composite();
178
179 // Prepare and draw second frame.
180 frame_provider_->SetFrameData(CreateFrameDataWithResource(999));
181 Composite();
182
183 // Resource from first frame should be returned.
184 CheckReturnedResource(1u);
185
186 TearDownLayerTreeHost();
187 delegated_layer_ = NULL;
188 frame_provider_ = NULL;
189
190 // Resource from second frame should be returned.
191 CheckReturnedResource(1u);
192 resource_collection_ = NULL;
193 }
194
195 // DelegatedFrameResourceCollectionClient overrides.
196 virtual void UnusedResourcesAreAvailable() OVERRIDE {}
197
198 private:
199 scoped_ptr<DelegatedFrameData> CreateFrameDataWithResource(
200 ResourceProvider::ResourceId resource_id) {
201 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData);
202 gfx::Rect frame_rect(size_);
203
204 scoped_ptr<RenderPass> root_pass(RenderPass::Create());
205 root_pass->SetNew(
206 RenderPass::Id(1, 1), frame_rect, frame_rect, gfx::Transform());
207 frame->render_pass_list.push_back(root_pass.Pass());
208
209 TransferableResource resource;
210 resource.id = resource_id;
211 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
212 GLbyte arbitrary_mailbox[GL_MAILBOX_SIZE_CHROMIUM] = {
213 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
214 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
215 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
216 resource.mailbox_holder.mailbox.SetName(arbitrary_mailbox);
piman 2014/05/22 23:36:23 nit: you can also use gpu::Mailbox::Generate().
boliu 2014/05/22 23:48:31 Done.
217 frame->resource_list.push_back(resource);
218
219 return frame.Pass();
220 }
221
222 void CheckReturnedResource(size_t expected_num) {
223 ReturnedResourceArray returned_resources;
224 resource_collection_->TakeUnusedResourcesForChildCompositor(
225 &returned_resources);
226 EXPECT_EQ(expected_num, returned_resources.size());
227 }
228
229 scoped_refptr<DelegatedFrameResourceCollection> resource_collection_;
230 scoped_refptr<DelegatedFrameProvider> frame_provider_;
231 scoped_refptr<DelegatedRendererLayer> delegated_layer_;
232 };
233
234 TEST_F(LayerTreeHostNoMessageLoopDelegatedLayer, SingleDelegatedLayer) {
235 RunTest();
236 }
237
238 } // namespace
239 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/blocking_task_runner.cc ('k') | cc/trees/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698