OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3141 } | 3141 } |
3142 | 3142 |
3143 void AfterTest() override {} | 3143 void AfterTest() override {} |
3144 | 3144 |
3145 protected: | 3145 protected: |
3146 int frame_; | 3146 int frame_; |
3147 }; | 3147 }; |
3148 | 3148 |
3149 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending); | 3149 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending); |
3150 | 3150 |
3151 class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { | |
3152 protected: | |
3153 void InitializeSettings(LayerTreeSettings* settings) override { | |
3154 settings->using_synchronous_renderer_compositor = true; | |
3155 } | |
3156 | |
3157 void SetupTree() override { | |
3158 root_layer_ = FakePictureLayer::Create(&client_); | |
3159 root_layer_->SetIsDrawable(true); | |
3160 root_layer_->SetBounds(gfx::Size(50, 50)); | |
3161 | |
3162 parent_layer_ = FakePictureLayer::Create(&client_); | |
3163 parent_layer_->SetIsDrawable(true); | |
3164 parent_layer_->SetBounds(gfx::Size(50, 50)); | |
3165 parent_layer_->SetForceRenderSurfaceForTesting(true); | |
3166 | |
3167 child_layer_ = FakePictureLayer::Create(&client_); | |
3168 child_layer_->SetIsDrawable(true); | |
3169 child_layer_->SetBounds(gfx::Size(50, 50)); | |
3170 | |
3171 root_layer_->AddChild(parent_layer_); | |
3172 parent_layer_->AddChild(child_layer_); | |
3173 layer_tree_host()->SetRootLayer(root_layer_); | |
3174 | |
3175 LayerTreeHostTest::SetupTree(); | |
3176 client_.set_bounds(root_layer_->bounds()); | |
3177 } | |
3178 | |
3179 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( | |
3180 scoped_refptr<ContextProvider> compositor_context_provider, | |
3181 scoped_refptr<ContextProvider> worker_context_provider) override { | |
3182 auto on_draw_callback = | |
3183 base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw, | |
3184 base::Unretained(this)); | |
3185 auto frame_sink = base::MakeUnique<OnDrawCompositorFrameSink>( | |
3186 compositor_context_provider, std::move(worker_context_provider), | |
3187 shared_bitmap_manager(), gpu_memory_buffer_manager(), | |
3188 layer_tree_host()->GetSettings().renderer_settings, | |
3189 ImplThreadTaskRunner(), false /* synchronous_composite */, | |
3190 false /* force_disable_reclaim_resources */, | |
3191 std::move(on_draw_callback)); | |
3192 compositor_frame_sink_ = frame_sink.get(); | |
3193 return std::move(frame_sink); | |
3194 } | |
3195 | |
3196 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
3197 | |
3198 void CallOnDraw() { | |
3199 if (!TestEnded()) { | |
3200 // Synchronous compositor does not draw unless told to do so by the output | |
3201 // surface. But it needs to be done on a new stack frame. | |
3202 bool resourceless_software_draw = true; | |
3203 ImplThreadTaskRunner()->PostTask( | |
3204 FROM_HERE, base::Bind(&OnDrawCompositorFrameSink::OnDraw, | |
3205 base::Unretained(compositor_frame_sink_), | |
3206 resourceless_software_draw)); | |
3207 } | |
3208 } | |
3209 | |
3210 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
3211 LayerTreeHostImpl::FrameData* frame_data, | |
3212 DrawResult draw_result) override { | |
3213 if (host_impl->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) { | |
3214 EXPECT_EQ(1u, frame_data->render_passes.size()); | |
3215 // Has at least 3 quads for each layer. | |
3216 RenderPass* render_pass = frame_data->render_passes[0].get(); | |
3217 EXPECT_GE(render_pass->quad_list.size(), 3u); | |
3218 } else { | |
3219 EXPECT_EQ(2u, frame_data->render_passes.size()); | |
3220 | |
3221 // At least root layer quad in root render pass. | |
3222 EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u); | |
3223 // At least parent and child layer quads in parent render pass. | |
3224 EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u); | |
3225 } | |
3226 return draw_result; | |
3227 } | |
3228 | |
3229 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
3230 draw_count_++; | |
3231 switch (draw_count_) { | |
3232 case 1: | |
3233 host_impl->SetNeedsRedraw(); | |
3234 break; | |
3235 case 2: | |
3236 EndTest(); | |
3237 break; | |
3238 default: | |
3239 NOTREACHED(); | |
3240 } | |
3241 } | |
3242 | |
3243 void AfterTest() override {} | |
3244 | |
3245 private: | |
3246 OnDrawCompositorFrameSink* compositor_frame_sink_ = nullptr; | |
3247 FakeContentLayerClient client_; | |
3248 scoped_refptr<Layer> root_layer_; | |
3249 scoped_refptr<Layer> parent_layer_; | |
3250 scoped_refptr<Layer> child_layer_; | |
3251 int draw_count_ = 0; | |
3252 }; | |
3253 | |
3254 // Resourceless is not used for SingleThreadProxy, so it is unimplemented. | |
3255 MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw); | |
3256 | |
3257 // Test for UI Resource management. | 3151 // Test for UI Resource management. |
3258 class LayerTreeHostTestUIResource : public LayerTreeHostTest { | 3152 class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
3259 public: | 3153 public: |
3260 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} | 3154 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} |
3261 | 3155 |
3262 void InitializeSettings(LayerTreeSettings* settings) override { | 3156 void InitializeSettings(LayerTreeSettings* settings) override { |
3263 settings->renderer_settings.texture_id_allocation_chunk_size = 1; | 3157 settings->renderer_settings.texture_id_allocation_chunk_size = 1; |
3264 } | 3158 } |
3265 | 3159 |
3266 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 3160 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
(...skipping 3850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7117 EndTest(); | 7011 EndTest(); |
7118 } | 7012 } |
7119 | 7013 |
7120 void AfterTest() override {} | 7014 void AfterTest() override {} |
7121 }; | 7015 }; |
7122 | 7016 |
7123 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSubmitFrameResources); | 7017 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSubmitFrameResources); |
7124 | 7018 |
7125 } // namespace | 7019 } // namespace |
7126 } // namespace cc | 7020 } // namespace cc |
OLD | NEW |