| OLD | NEW |
| 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "cc/layers/delegated_frame_provider.h" |
| 15 #include "cc/layers/delegated_frame_resource_collection.h" |
| 14 #include "cc/layers/delegated_renderer_layer.h" | 16 #include "cc/layers/delegated_renderer_layer.h" |
| 15 #include "cc/layers/delegated_renderer_layer_client.h" | 17 #include "cc/layers/delegated_renderer_layer_client.h" |
| 16 #include "cc/layers/delegated_renderer_layer_impl.h" | 18 #include "cc/layers/delegated_renderer_layer_impl.h" |
| 17 #include "cc/output/compositor_frame.h" | 19 #include "cc/output/compositor_frame.h" |
| 18 #include "cc/output/compositor_frame_ack.h" | 20 #include "cc/output/compositor_frame_ack.h" |
| 19 #include "cc/output/delegated_frame_data.h" | 21 #include "cc/output/delegated_frame_data.h" |
| 20 #include "cc/quads/render_pass_draw_quad.h" | 22 #include "cc/quads/render_pass_draw_quad.h" |
| 21 #include "cc/quads/shared_quad_state.h" | 23 #include "cc/quads/shared_quad_state.h" |
| 22 #include "cc/quads/texture_draw_quad.h" | 24 #include "cc/quads/texture_draw_quad.h" |
| 23 #include "cc/resources/returned_resource.h" | 25 #include "cc/resources/returned_resource.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 false, // is_replica | 183 false, // is_replica |
| 182 0, // mask_resource_id | 184 0, // mask_resource_id |
| 183 damage_rect, | 185 damage_rect, |
| 184 gfx::Rect(0, 0, 1, 1), // mask_uv_rect | 186 gfx::Rect(0, 0, 1, 1), // mask_uv_rect |
| 185 filters, | 187 filters, |
| 186 background_filters); | 188 background_filters); |
| 187 frame->render_pass_list[0]->shared_quad_state_list.push_back(sqs.Pass()); | 189 frame->render_pass_list[0]->shared_quad_state_list.push_back(sqs.Pass()); |
| 188 frame->render_pass_list[0]->quad_list.push_back(quad.PassAs<DrawQuad>()); | 190 frame->render_pass_list[0]->quad_list.push_back(quad.PassAs<DrawQuad>()); |
| 189 } | 191 } |
| 190 | 192 |
| 191 scoped_ptr<DelegatedFrameData> CreateEmptyFrameData() { | |
| 192 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); | |
| 193 return frame.Pass(); | |
| 194 } | |
| 195 | |
| 196 | |
| 197 static ResourceProvider::ResourceId AppendResourceId( | 193 static ResourceProvider::ResourceId AppendResourceId( |
| 198 std::vector<ResourceProvider::ResourceId>* resources_in_last_sent_frame, | 194 std::vector<ResourceProvider::ResourceId>* resources_in_last_sent_frame, |
| 199 ResourceProvider::ResourceId resource_id) { | 195 ResourceProvider::ResourceId resource_id) { |
| 200 resources_in_last_sent_frame->push_back(resource_id); | 196 resources_in_last_sent_frame->push_back(resource_id); |
| 201 return resource_id; | 197 return resource_id; |
| 202 } | 198 } |
| 203 | 199 |
| 204 void ReturnUnusedResourcesFromParent(LayerTreeHostImpl* host_impl) { | 200 void ReturnUnusedResourcesFromParent(LayerTreeHostImpl* host_impl) { |
| 205 DelegatedFrameData* delegated_frame_data = | 201 DelegatedFrameData* delegated_frame_data = |
| 206 output_surface()->last_sent_frame().delegated_frame_data.get(); | 202 output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 207 if (!delegated_frame_data) | 203 if (!delegated_frame_data) |
| 208 return; | 204 return; |
| 209 | 205 |
| 210 std::vector<ResourceProvider::ResourceId> resources_in_last_sent_frame; | 206 std::vector<ResourceProvider::ResourceId> resources_in_last_sent_frame; |
| 211 for (size_t i = 0; i < delegated_frame_data->render_pass_list.size(); ++i) { | 207 for (size_t i = 0; i < delegated_frame_data->resource_list.size(); ++i) { |
| 212 RenderPass* pass = delegated_frame_data->render_pass_list.at(i); | 208 resources_in_last_sent_frame.push_back( |
| 213 for (size_t j = 0; j < pass->quad_list.size(); ++j) { | 209 delegated_frame_data->resource_list[i].id); |
| 214 DrawQuad* quad = pass->quad_list[j]; | |
| 215 quad->IterateResources(base::Bind(&AppendResourceId, | |
| 216 &resources_in_last_sent_frame)); | |
| 217 } | |
| 218 } | 210 } |
| 219 | 211 |
| 220 std::vector<ResourceProvider::ResourceId> resources_to_return; | 212 std::vector<ResourceProvider::ResourceId> resources_to_return; |
| 221 | 213 |
| 222 const TransferableResourceArray& resources_held_by_parent = | 214 const TransferableResourceArray& resources_held_by_parent = |
| 223 output_surface()->resources_held_by_parent(); | 215 output_surface()->resources_held_by_parent(); |
| 224 for (size_t i = 0; i < resources_held_by_parent.size(); ++i) { | 216 for (size_t i = 0; i < resources_held_by_parent.size(); ++i) { |
| 225 ResourceProvider::ResourceId resource_in_parent = | 217 ResourceProvider::ResourceId resource_in_parent = |
| 226 resources_held_by_parent[i].id; | 218 resources_held_by_parent[i].id; |
| 227 bool resource_in_parent_is_not_part_of_frame = | 219 bool resource_in_parent_is_not_part_of_frame = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 238 CompositorFrameAck ack; | 230 CompositorFrameAck ack; |
| 239 for (size_t i = 0; i < resources_to_return.size(); ++i) | 231 for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 240 output_surface()->ReturnResource(resources_to_return[i], &ack); | 232 output_surface()->ReturnResource(resources_to_return[i], &ack); |
| 241 host_impl->ReclaimResources(&ack); | 233 host_impl->ReclaimResources(&ack); |
| 242 host_impl->OnSwapBuffersComplete(); | 234 host_impl->OnSwapBuffersComplete(); |
| 243 } | 235 } |
| 244 }; | 236 }; |
| 245 | 237 |
| 246 class LayerTreeHostDelegatedTestCaseSingleDelegatedLayer | 238 class LayerTreeHostDelegatedTestCaseSingleDelegatedLayer |
| 247 : public LayerTreeHostDelegatedTest, | 239 : public LayerTreeHostDelegatedTest, |
| 248 public DelegatedRendererLayerClient { | 240 public DelegatedRendererLayerClient, |
| 241 public DelegatedFrameResourceCollectionClient { |
| 249 public: | 242 public: |
| 250 LayerTreeHostDelegatedTestCaseSingleDelegatedLayer() : available_(false) {} | 243 LayerTreeHostDelegatedTestCaseSingleDelegatedLayer() |
| 244 : resource_collection_(new DelegatedFrameResourceCollection), |
| 245 available_(false) { |
| 246 resource_collection_->SetClient(this); |
| 247 } |
| 251 | 248 |
| 252 virtual void SetupTree() OVERRIDE { | 249 virtual void SetupTree() OVERRIDE { |
| 253 root_ = Layer::Create(); | 250 root_ = Layer::Create(); |
| 254 root_->SetAnchorPoint(gfx::PointF()); | 251 root_->SetAnchorPoint(gfx::PointF()); |
| 255 root_->SetBounds(gfx::Size(10, 10)); | 252 root_->SetBounds(gfx::Size(10, 10)); |
| 256 | 253 |
| 257 delegated_ = FakeDelegatedRendererLayer::Create(this); | |
| 258 delegated_->SetAnchorPoint(gfx::PointF()); | |
| 259 delegated_->SetBounds(gfx::Size(10, 10)); | |
| 260 delegated_->SetIsDrawable(true); | |
| 261 | |
| 262 root_->AddChild(delegated_); | |
| 263 layer_tree_host()->SetRootLayer(root_); | 254 layer_tree_host()->SetRootLayer(root_); |
| 264 LayerTreeHostDelegatedTest::SetupTree(); | 255 LayerTreeHostDelegatedTest::SetupTree(); |
| 265 } | 256 } |
| 266 | 257 |
| 267 virtual void BeginTest() OVERRIDE { | 258 virtual void BeginTest() OVERRIDE { |
| 259 resource_collection_->SetClient(this); |
| 268 PostSetNeedsCommitToMainThread(); | 260 PostSetNeedsCommitToMainThread(); |
| 269 } | 261 } |
| 270 | 262 |
| 271 virtual void AfterTest() OVERRIDE {} | 263 void SetFrameData(scoped_ptr<DelegatedFrameData> frame_data) { |
| 264 RenderPass* root_pass = frame_data->render_pass_list.back(); |
| 265 gfx::Size frame_size = root_pass->output_rect.size(); |
| 266 |
| 267 if (frame_provider_.get() && frame_size == frame_provider_->frame_size()) { |
| 268 frame_provider_->SetFrameData(frame_data.Pass()); |
| 269 return; |
| 270 } |
| 271 |
| 272 if (delegated_.get()) { |
| 273 delegated_->RemoveFromParent(); |
| 274 delegated_ = NULL; |
| 275 frame_provider_ = NULL; |
| 276 } |
| 277 |
| 278 frame_provider_ = new DelegatedFrameProvider(resource_collection_.get(), |
| 279 frame_data.Pass()); |
| 280 |
| 281 delegated_ = CreateDelegatedLayer(frame_provider_.get()); |
| 282 } |
| 283 |
| 284 scoped_refptr<DelegatedRendererLayer> CreateDelegatedLayer( |
| 285 DelegatedFrameProvider* frame_provider) { |
| 286 scoped_refptr<DelegatedRendererLayer> delegated = |
| 287 FakeDelegatedRendererLayer::Create(this, frame_provider); |
| 288 delegated->SetAnchorPoint(gfx::PointF()); |
| 289 delegated->SetBounds(gfx::Size(10, 10)); |
| 290 delegated->SetIsDrawable(true); |
| 291 |
| 292 root_->AddChild(delegated); |
| 293 return delegated; |
| 294 } |
| 295 |
| 296 virtual void AfterTest() OVERRIDE { resource_collection_->SetClient(NULL); } |
| 272 | 297 |
| 273 // DelegatedRendererLayerClient implementation. | 298 // DelegatedRendererLayerClient implementation. |
| 274 virtual void DidCommitFrameData() OVERRIDE {} | 299 virtual void DidCommitFrameData() OVERRIDE {} |
| 300 |
| 301 // DelegatedFrameProviderClient implementation. |
| 275 virtual void UnusedResourcesAreAvailable() OVERRIDE { available_ = true; } | 302 virtual void UnusedResourcesAreAvailable() OVERRIDE { available_ = true; } |
| 276 | 303 |
| 277 bool TestAndResetAvailable() { | 304 bool TestAndResetAvailable() { |
| 278 bool available = available_; | 305 bool available = available_; |
| 279 available_ = false; | 306 available_ = false; |
| 280 return available; | 307 return available; |
| 281 } | 308 } |
| 282 | 309 |
| 283 protected: | 310 protected: |
| 311 scoped_refptr<DelegatedFrameResourceCollection> resource_collection_; |
| 312 scoped_refptr<DelegatedFrameProvider> frame_provider_; |
| 284 scoped_refptr<Layer> root_; | 313 scoped_refptr<Layer> root_; |
| 285 scoped_refptr<DelegatedRendererLayer> delegated_; | 314 scoped_refptr<DelegatedRendererLayer> delegated_; |
| 286 bool available_; | 315 bool available_; |
| 287 }; | 316 }; |
| 288 | 317 |
| 289 class LayerTreeHostDelegatedTestClientDidCommitCallback | 318 class LayerTreeHostDelegatedTestClientDidCommitCallback |
| 290 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 319 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 291 public: | 320 public: |
| 292 LayerTreeHostDelegatedTestClientDidCommitCallback() | 321 LayerTreeHostDelegatedTestClientDidCommitCallback() |
| 293 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), | 322 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), |
| 294 num_did_commit_frame_data_(0) {} | 323 num_did_commit_frame_data_(0) {} |
| 295 | 324 |
| 296 virtual void DidCommit() OVERRIDE { | 325 virtual void DidCommit() OVERRIDE { |
| 297 if (TestEnded()) | 326 if (TestEnded()) |
| 298 return; | 327 return; |
| 299 | 328 |
| 300 EXPECT_EQ(1, num_did_commit_frame_data_); | 329 EXPECT_EQ(1, num_did_commit_frame_data_); |
| 301 EndTest(); | 330 EndTest(); |
| 302 } | 331 } |
| 303 | 332 |
| 304 virtual void BeginTest() OVERRIDE { | 333 virtual void BeginTest() OVERRIDE { |
| 305 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), | 334 SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1))); |
| 306 gfx::Rect(0, 0, 1, 1))); | |
| 307 PostSetNeedsCommitToMainThread(); | 335 PostSetNeedsCommitToMainThread(); |
| 308 } | 336 } |
| 309 | 337 |
| 310 virtual void DidCommitFrameData() OVERRIDE { | 338 virtual void DidCommitFrameData() OVERRIDE { |
| 311 num_did_commit_frame_data_++; | 339 num_did_commit_frame_data_++; |
| 312 } | 340 } |
| 313 | 341 |
| 314 protected: | 342 protected: |
| 315 int num_did_commit_frame_data_; | 343 int num_did_commit_frame_data_; |
| 316 }; | 344 }; |
| 317 | 345 |
| 318 SINGLE_AND_MULTI_THREAD_TEST_F( | 346 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 319 LayerTreeHostDelegatedTestClientDidCommitCallback); | 347 LayerTreeHostDelegatedTestClientDidCommitCallback); |
| 320 | 348 |
| 321 class LayerTreeHostDelegatedTestCreateChildId | 349 class LayerTreeHostDelegatedTestCreateChildId |
| 322 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 350 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 323 public: | 351 public: |
| 324 LayerTreeHostDelegatedTestCreateChildId() | 352 LayerTreeHostDelegatedTestCreateChildId() |
| 325 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), | 353 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), |
| 326 num_activates_(0), | 354 num_activates_(0), |
| 327 did_reset_child_id_(false) {} | 355 did_reset_child_id_(false) {} |
| 328 | 356 |
| 329 virtual void DidCommit() OVERRIDE { | 357 virtual void DidCommit() OVERRIDE { |
| 330 if (TestEnded()) | 358 if (TestEnded()) |
| 331 return; | 359 return; |
| 332 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), | 360 SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1))); |
| 333 gfx::Rect(0, 0, 1, 1))); | |
| 334 } | 361 } |
| 335 | 362 |
| 336 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 363 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 364 if (host_impl->active_tree()->source_frame_number() < 1) |
| 365 return; |
| 366 |
| 337 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 367 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 338 FakeDelegatedRendererLayerImpl* delegated_impl = | 368 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 339 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 369 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 340 | 370 |
| 341 ContextProvider* context_provider = | 371 ContextProvider* context_provider = |
| 342 host_impl->output_surface()->context_provider(); | 372 host_impl->output_surface()->context_provider(); |
| 343 | 373 |
| 344 ++num_activates_; | 374 ++num_activates_; |
| 345 switch (num_activates_) { | 375 switch (num_activates_) { |
| 346 case 2: | 376 case 2: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 368 | 398 |
| 369 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 399 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 370 FakeDelegatedRendererLayerImpl* delegated_impl = | 400 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 371 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 401 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 372 | 402 |
| 373 EXPECT_EQ(2, num_activates_); | 403 EXPECT_EQ(2, num_activates_); |
| 374 EXPECT_FALSE(delegated_impl->ChildId()); | 404 EXPECT_FALSE(delegated_impl->ChildId()); |
| 375 did_reset_child_id_ = true; | 405 did_reset_child_id_ = true; |
| 376 } | 406 } |
| 377 | 407 |
| 378 virtual void AfterTest() OVERRIDE {} | |
| 379 | |
| 380 protected: | 408 protected: |
| 381 int num_activates_; | 409 int num_activates_; |
| 382 bool did_reset_child_id_; | 410 bool did_reset_child_id_; |
| 383 }; | 411 }; |
| 384 | 412 |
| 385 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCreateChildId); | 413 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCreateChildId); |
| 386 | 414 |
| 387 class LayerTreeHostDelegatedTestOffscreenContext_NoFilters | 415 class LayerTreeHostDelegatedTestOffscreenContext_NoFilters |
| 388 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 416 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 389 protected: | 417 protected: |
| 390 virtual void BeginTest() OVERRIDE { | 418 virtual void BeginTest() OVERRIDE { |
| 391 scoped_ptr<DelegatedFrameData> frame = | 419 scoped_ptr<DelegatedFrameData> frame = |
| 392 CreateFrameData(gfx::Rect(0, 0, 1, 1), | 420 CreateFrameData(gfx::Rect(0, 0, 1, 1), |
| 393 gfx::Rect(0, 0, 1, 1)); | 421 gfx::Rect(0, 0, 1, 1)); |
| 394 delegated_->SetFrameData(frame.Pass()); | 422 SetFrameData(frame.Pass()); |
| 395 | 423 |
| 396 PostSetNeedsCommitToMainThread(); | 424 PostSetNeedsCommitToMainThread(); |
| 397 } | 425 } |
| 398 | 426 |
| 399 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 427 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 400 EXPECT_FALSE(host_impl->offscreen_context_provider()); | 428 EXPECT_FALSE(host_impl->offscreen_context_provider()); |
| 401 EndTest(); | 429 EndTest(); |
| 402 } | 430 } |
| 403 | |
| 404 virtual void AfterTest() OVERRIDE {} | |
| 405 }; | 431 }; |
| 406 | 432 |
| 407 SINGLE_AND_MULTI_THREAD_TEST_F( | 433 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 408 LayerTreeHostDelegatedTestOffscreenContext_NoFilters); | 434 LayerTreeHostDelegatedTestOffscreenContext_NoFilters); |
| 409 | 435 |
| 410 class LayerTreeHostDelegatedTestOffscreenContext_Filters | 436 class LayerTreeHostDelegatedTestOffscreenContext_Filters |
| 411 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 437 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 412 protected: | 438 protected: |
| 413 virtual void BeginTest() OVERRIDE { | 439 virtual void BeginTest() OVERRIDE { |
| 414 scoped_ptr<DelegatedFrameData> frame = | 440 scoped_ptr<DelegatedFrameData> frame = |
| 415 CreateFrameData(gfx::Rect(0, 0, 1, 1), | 441 CreateFrameData(gfx::Rect(0, 0, 1, 1), |
| 416 gfx::Rect(0, 0, 1, 1)); | 442 gfx::Rect(0, 0, 1, 1)); |
| 417 | 443 |
| 418 FilterOperations filters; | 444 FilterOperations filters; |
| 419 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); | 445 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
| 420 AddRenderPass(frame.get(), | 446 AddRenderPass(frame.get(), |
| 421 RenderPass::Id(2, 1), | 447 RenderPass::Id(2, 1), |
| 422 gfx::Rect(0, 0, 1, 1), | 448 gfx::Rect(0, 0, 1, 1), |
| 423 gfx::Rect(0, 0, 1, 1), | 449 gfx::Rect(0, 0, 1, 1), |
| 424 filters, | 450 filters, |
| 425 FilterOperations()); | 451 FilterOperations()); |
| 426 delegated_->SetFrameData(frame.Pass()); | 452 SetFrameData(frame.Pass()); |
| 427 | 453 |
| 428 PostSetNeedsCommitToMainThread(); | 454 PostSetNeedsCommitToMainThread(); |
| 429 } | 455 } |
| 430 | 456 |
| 431 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 457 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 432 bool expect_context = !delegating_renderer(); | 458 bool expect_context = !delegating_renderer(); |
| 433 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); | 459 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); |
| 434 EndTest(); | 460 EndTest(); |
| 435 } | 461 } |
| 436 | |
| 437 virtual void AfterTest() OVERRIDE {} | |
| 438 }; | 462 }; |
| 439 | 463 |
| 440 SINGLE_AND_MULTI_THREAD_TEST_F( | 464 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 441 LayerTreeHostDelegatedTestOffscreenContext_Filters); | 465 LayerTreeHostDelegatedTestOffscreenContext_Filters); |
| 442 | 466 |
| 443 class LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters | 467 class LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters |
| 444 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 468 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 445 protected: | 469 protected: |
| 446 virtual void BeginTest() OVERRIDE { | 470 virtual void BeginTest() OVERRIDE { |
| 447 scoped_ptr<DelegatedFrameData> frame = | 471 scoped_ptr<DelegatedFrameData> frame = |
| 448 CreateFrameData(gfx::Rect(0, 0, 1, 1), | 472 CreateFrameData(gfx::Rect(0, 0, 1, 1), |
| 449 gfx::Rect(0, 0, 1, 1)); | 473 gfx::Rect(0, 0, 1, 1)); |
| 450 | 474 |
| 451 FilterOperations filters; | 475 FilterOperations filters; |
| 452 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); | 476 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
| 453 AddRenderPass(frame.get(), | 477 AddRenderPass(frame.get(), |
| 454 RenderPass::Id(2, 1), | 478 RenderPass::Id(2, 1), |
| 455 gfx::Rect(0, 0, 1, 1), | 479 gfx::Rect(0, 0, 1, 1), |
| 456 gfx::Rect(0, 0, 1, 1), | 480 gfx::Rect(0, 0, 1, 1), |
| 457 FilterOperations(), | 481 FilterOperations(), |
| 458 filters); | 482 filters); |
| 459 delegated_->SetFrameData(frame.Pass()); | 483 SetFrameData(frame.Pass()); |
| 460 | 484 |
| 461 PostSetNeedsCommitToMainThread(); | 485 PostSetNeedsCommitToMainThread(); |
| 462 } | 486 } |
| 463 | 487 |
| 464 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 488 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 465 bool expect_context = !delegating_renderer(); | 489 bool expect_context = !delegating_renderer(); |
| 466 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); | 490 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); |
| 467 EndTest(); | 491 EndTest(); |
| 468 } | 492 } |
| 469 | |
| 470 virtual void AfterTest() OVERRIDE {} | |
| 471 }; | 493 }; |
| 472 | 494 |
| 473 SINGLE_AND_MULTI_THREAD_TEST_F( | 495 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 474 LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters); | 496 LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters); |
| 475 | 497 |
| 476 class LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree | 498 class LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree |
| 477 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 499 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 478 protected: | 500 protected: |
| 479 virtual void BeginTest() OVERRIDE { | 501 virtual void BeginTest() OVERRIDE { |
| 480 scoped_ptr<DelegatedFrameData> frame = | 502 scoped_ptr<DelegatedFrameData> frame_no_filters = |
| 481 CreateFrameData(gfx::Rect(0, 0, 1, 1), | 503 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 482 gfx::Rect(0, 0, 1, 1)); | 504 |
| 505 scoped_ptr<DelegatedFrameData> frame_with_filters = |
| 506 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 483 | 507 |
| 484 FilterOperations filters; | 508 FilterOperations filters; |
| 485 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); | 509 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
| 486 AddRenderPass(frame.get(), | 510 AddRenderPass(frame_with_filters.get(), |
| 487 RenderPass::Id(2, 1), | 511 RenderPass::Id(2, 1), |
| 488 gfx::Rect(0, 0, 1, 1), | 512 gfx::Rect(0, 0, 1, 1), |
| 489 gfx::Rect(0, 0, 1, 1), | 513 gfx::Rect(0, 0, 1, 1), |
| 490 filters, | 514 filters, |
| 491 FilterOperations()); | 515 FilterOperations()); |
| 492 | 516 |
| 517 SetFrameData(frame_no_filters.Pass()); |
| 493 delegated_->RemoveFromParent(); | 518 delegated_->RemoveFromParent(); |
| 494 delegated_->SetFrameData(frame.Pass()); | 519 SetFrameData(frame_with_filters.Pass()); |
| 495 layer_tree_host()->root_layer()->AddChild(delegated_); | 520 layer_tree_host()->root_layer()->AddChild(delegated_); |
| 496 | 521 |
| 497 PostSetNeedsCommitToMainThread(); | 522 PostSetNeedsCommitToMainThread(); |
| 498 } | 523 } |
| 499 | 524 |
| 500 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 525 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 501 bool expect_context = !delegating_renderer(); | 526 bool expect_context = !delegating_renderer(); |
| 502 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); | 527 EXPECT_EQ(expect_context, !!host_impl->offscreen_context_provider()); |
| 503 EndTest(); | 528 EndTest(); |
| 504 } | 529 } |
| 505 | |
| 506 virtual void AfterTest() OVERRIDE {} | |
| 507 }; | 530 }; |
| 508 | 531 |
| 509 SINGLE_AND_MULTI_THREAD_TEST_F( | 532 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 510 LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree); | 533 LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree); |
| 511 | 534 |
| 512 class LayerTreeHostDelegatedTestLayerUsesFrameDamage | 535 class LayerTreeHostDelegatedTestLayerUsesFrameDamage |
| 513 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 536 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 514 public: | 537 public: |
| 515 LayerTreeHostDelegatedTestLayerUsesFrameDamage() | 538 LayerTreeHostDelegatedTestLayerUsesFrameDamage() |
| 516 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), | 539 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(), |
| 517 first_draw_for_source_frame_(true) {} | 540 first_draw_for_source_frame_(true) {} |
| 518 | 541 |
| 519 virtual void DidCommit() OVERRIDE { | 542 virtual void DidCommit() OVERRIDE { |
| 520 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 543 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 521 switch (next_source_frame_number) { | 544 switch (next_source_frame_number) { |
| 522 case 1: | 545 case 1: |
| 523 // The first time the layer gets a frame the whole layer should be | 546 // The first time the layer gets a frame the whole layer should be |
| 524 // damaged. | 547 // damaged. |
| 525 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), | 548 SetFrameData( |
| 526 gfx::Rect(0, 0, 1, 1))); | 549 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1))); |
| 527 break; | 550 break; |
| 528 case 2: | 551 case 2: |
| 552 // A different frame size will damage the whole layer. |
| 553 SetFrameData( |
| 554 CreateFrameData(gfx::Rect(0, 0, 20, 20), gfx::Rect(0, 0, 0, 0))); |
| 555 break; |
| 556 case 3: |
| 529 // Should create a total amount of gfx::Rect(2, 2, 10, 6) damage. | 557 // Should create a total amount of gfx::Rect(2, 2, 10, 6) damage. |
| 530 // The frame size is 20x20 while the layer is 10x10, so this should | 558 // The frame size is 20x20 while the layer is 10x10, so this should |
| 531 // produce a gfx::Rect(1, 1, 5, 3) damage rect. | 559 // produce a gfx::Rect(1, 1, 5, 3) damage rect. |
| 532 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 20, 20), | 560 SetFrameData( |
| 533 gfx::Rect(2, 2, 5, 5))); | 561 CreateFrameData(gfx::Rect(0, 0, 20, 20), gfx::Rect(2, 2, 5, 5))); |
| 534 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 20, 20), | 562 SetFrameData( |
| 535 gfx::Rect(7, 2, 5, 6))); | 563 CreateFrameData(gfx::Rect(0, 0, 20, 20), gfx::Rect(7, 2, 5, 6))); |
| 536 break; | 564 break; |
| 537 case 3: | 565 case 4: |
| 538 // Should create zero damage. | 566 // Should create zero damage. |
| 539 layer_tree_host()->SetNeedsCommit(); | 567 layer_tree_host()->SetNeedsCommit(); |
| 540 break; | 568 break; |
| 541 case 4: | 569 case 5: |
| 542 // Should damage the full viewport. | 570 // Should damage the full viewport. |
| 543 delegated_->SetBounds(gfx::Size(2, 2)); | 571 delegated_->SetBounds(gfx::Size(2, 2)); |
| 544 break; | 572 break; |
| 545 case 5: | 573 case 6: |
| 546 // Should create zero damage. | 574 // Should create zero damage. |
| 547 layer_tree_host()->SetNeedsCommit(); | 575 layer_tree_host()->SetNeedsCommit(); |
| 548 break; | 576 break; |
| 549 case 6: | 577 case 7: |
| 550 // Should damage the full layer. | 578 // Should damage the full layer, tho the frame size is not changing. |
| 551 delegated_->SetBounds(gfx::Size(6, 6)); | 579 delegated_->SetBounds(gfx::Size(6, 6)); |
| 552 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5), | 580 SetFrameData( |
| 553 gfx::Rect(1, 1, 2, 2))); | 581 CreateFrameData(gfx::Rect(0, 0, 20, 20), gfx::Rect(1, 1, 2, 2))); |
| 554 break; | 582 break; |
| 555 case 7: | 583 case 8: |
| 556 // Should create zero damage. | 584 // Should create zero damage. |
| 557 layer_tree_host()->SetNeedsCommit(); | 585 layer_tree_host()->SetNeedsCommit(); |
| 558 break; | 586 break; |
| 559 case 8: | 587 case 9: |
| 560 // Should damage the full layer. | 588 // Should damage the full layer. |
| 561 delegated_->SetDisplaySize(gfx::Size(10, 10)); | 589 delegated_->SetDisplaySize(gfx::Size(10, 10)); |
| 562 break; | 590 break; |
| 563 case 9: | 591 case 10: |
| 564 // Should create zero damage. | 592 // Should create zero damage. |
| 565 layer_tree_host()->SetNeedsCommit(); | 593 layer_tree_host()->SetNeedsCommit(); |
| 566 break; | 594 break; |
| 567 case 10: | |
| 568 // Setting an empty frame should damage the whole layer the | |
| 569 // first time. | |
| 570 delegated_->SetFrameData(CreateEmptyFrameData()); | |
| 571 break; | |
| 572 case 11: | 595 case 11: |
| 573 // Setting an empty frame shouldn't damage anything after the | 596 // Changing the frame size damages the full layer. |
| 574 // first time. | 597 SetFrameData( |
| 575 delegated_->SetFrameData(CreateEmptyFrameData()); | 598 CreateFrameData(gfx::Rect(0, 0, 5, 5), gfx::Rect(4, 4, 1, 1))); |
| 576 break; | 599 break; |
| 577 case 12: | 600 case 12: |
| 578 // Having valid content to display agains should damage the whole layer. | 601 // An invalid frame isn't used, so it should not cause damage. |
| 579 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10), | 602 SetFrameData(CreateInvalidFrameData(gfx::Rect(0, 0, 5, 5), |
| 580 gfx::Rect(5, 5, 1, 1))); | 603 gfx::Rect(4, 4, 1, 1))); |
| 581 break; | 604 break; |
| 582 case 13: | 605 case 13: |
| 583 // An invalid frame isn't used, so it should not cause damage. | |
| 584 delegated_->SetFrameData(CreateInvalidFrameData(gfx::Rect(0, 0, 10, 10), | |
| 585 gfx::Rect(5, 5, 1, 1))); | |
| 586 break; | |
| 587 case 14: | |
| 588 // Should create gfx::Rect(1, 1, 2, 2) of damage. The frame size is | 606 // Should create gfx::Rect(1, 1, 2, 2) of damage. The frame size is |
| 589 // 5x5 and the display size is now set to 10x10, so this should result | 607 // 5x5 and the display size is now set to 10x10, so this should result |
| 590 // in a gfx::Rect(2, 2, 4, 4) damage rect. | 608 // in a gfx::Rect(2, 2, 4, 4) damage rect. |
| 591 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5), | 609 SetFrameData( |
| 592 gfx::Rect(1, 1, 2, 2))); | 610 CreateFrameData(gfx::Rect(0, 0, 5, 5), gfx::Rect(1, 1, 2, 2))); |
| 593 break; | 611 break; |
| 594 case 15: | 612 case 14: |
| 595 // Should create zero damage. | 613 // Should create zero damage. |
| 596 layer_tree_host()->SetNeedsCommit(); | 614 layer_tree_host()->SetNeedsCommit(); |
| 597 break; | 615 break; |
| 598 case 16: | 616 case 15: |
| 599 // Moving the layer out of the tree and back in will damage the whole | 617 // Moving the layer out of the tree and back in will damage the whole |
| 600 // impl layer. | 618 // impl layer. |
| 601 delegated_->RemoveFromParent(); | 619 delegated_->RemoveFromParent(); |
| 602 layer_tree_host()->root_layer()->AddChild(delegated_); | 620 layer_tree_host()->root_layer()->AddChild(delegated_); |
| 603 break; | 621 break; |
| 604 case 17: | 622 case 16: |
| 605 // Make a larger frame with lots of damage. Then a frame smaller than | 623 // Make a larger frame with lots of damage. Then a frame smaller than |
| 606 // the first frame's damage. The entire layer should be damaged, but | 624 // the first frame's damage. The entire layer should be damaged, but |
| 607 // nothing more. | 625 // nothing more. |
| 608 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10), | 626 SetFrameData( |
| 609 gfx::Rect(0, 0, 10, 10))); | 627 CreateFrameData(gfx::Rect(0, 0, 10, 10), gfx::Rect(0, 0, 10, 10))); |
| 610 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5), | 628 SetFrameData( |
| 611 gfx::Rect(1, 1, 2, 2))); | 629 CreateFrameData(gfx::Rect(0, 0, 5, 5), gfx::Rect(1, 1, 2, 2))); |
| 612 break; | 630 break; |
| 613 case 18: | 631 case 17: |
| 614 // Make a frame with lots of damage. Then replace it with an empty | 632 // Make a frame with lots of damage. Then replace it with a frame with |
| 615 // frame. The entire layer should be damaged, but nothing more. | 633 // no damage. The entire layer should be damaged, but nothing more. |
| 616 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10), | 634 SetFrameData( |
| 617 gfx::Rect(0, 0, 10, 10))); | 635 CreateFrameData(gfx::Rect(0, 0, 10, 10), gfx::Rect(0, 0, 10, 10))); |
| 618 delegated_->SetFrameData(CreateEmptyFrameData()); | 636 SetFrameData( |
| 637 CreateFrameData(gfx::Rect(0, 0, 10, 10), gfx::Rect(0, 0, 0, 0))); |
| 619 break; | 638 break; |
| 620 } | 639 } |
| 621 first_draw_for_source_frame_ = true; | 640 first_draw_for_source_frame_ = true; |
| 622 } | 641 } |
| 623 | 642 |
| 624 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 643 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 625 LayerTreeHostImpl::FrameData* frame, | 644 LayerTreeHostImpl::FrameData* frame, |
| 626 bool result) OVERRIDE { | 645 bool result) OVERRIDE { |
| 627 EXPECT_TRUE(result); | 646 EXPECT_TRUE(result); |
| 628 | 647 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 641 case 0: | 660 case 0: |
| 642 // First frame is damaged because of viewport resize. | 661 // First frame is damaged because of viewport resize. |
| 643 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), | 662 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 644 damage_rect.ToString()); | 663 damage_rect.ToString()); |
| 645 break; | 664 break; |
| 646 case 1: | 665 case 1: |
| 647 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), | 666 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 648 damage_rect.ToString()); | 667 damage_rect.ToString()); |
| 649 break; | 668 break; |
| 650 case 2: | 669 case 2: |
| 670 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 671 damage_rect.ToString()); |
| 672 break; |
| 673 case 3: |
| 651 EXPECT_EQ(gfx::RectF(1.f, 1.f, 5.f, 3.f).ToString(), | 674 EXPECT_EQ(gfx::RectF(1.f, 1.f, 5.f, 3.f).ToString(), |
| 652 damage_rect.ToString()); | 675 damage_rect.ToString()); |
| 653 break; | 676 break; |
| 654 case 3: | 677 case 4: |
| 655 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 678 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 656 damage_rect.ToString()); | 679 damage_rect.ToString()); |
| 657 break; | 680 break; |
| 658 case 4: | 681 case 5: |
| 659 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), | 682 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 660 damage_rect.ToString()); | 683 damage_rect.ToString()); |
| 661 break; | 684 break; |
| 662 case 5: | 685 case 6: |
| 663 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 686 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 664 damage_rect.ToString()); | 687 damage_rect.ToString()); |
| 665 break; | 688 break; |
| 666 case 6: | 689 case 7: |
| 667 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 690 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), |
| 668 damage_rect.ToString()); | 691 damage_rect.ToString()); |
| 669 break; | 692 break; |
| 670 case 7: | 693 case 8: |
| 671 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 694 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 672 damage_rect.ToString()); | 695 damage_rect.ToString()); |
| 673 break; | 696 break; |
| 674 case 8: | 697 case 9: |
| 675 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 698 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), |
| 676 damage_rect.ToString()); | 699 damage_rect.ToString()); |
| 677 break; | 700 break; |
| 678 case 9: | 701 case 10: |
| 679 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 702 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 680 damage_rect.ToString()); | 703 damage_rect.ToString()); |
| 681 break; | 704 break; |
| 682 case 10: | 705 case 11: |
| 683 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 706 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 684 damage_rect.ToString()); | 707 damage_rect.ToString()); |
| 685 break; | 708 break; |
| 686 case 11: | 709 case 12: |
| 687 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 710 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 688 damage_rect.ToString()); | 711 damage_rect.ToString()); |
| 689 break; | 712 break; |
| 690 case 12: | 713 case 13: |
| 691 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 714 EXPECT_EQ(gfx::RectF(2.f, 2.f, 4.f, 4.f).ToString(), |
| 692 damage_rect.ToString()); | 715 damage_rect.ToString()); |
| 693 break; | 716 break; |
| 694 case 13: | 717 case 14: |
| 695 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 718 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), |
| 696 damage_rect.ToString()); | 719 damage_rect.ToString()); |
| 697 break; | 720 break; |
| 698 case 14: | |
| 699 EXPECT_EQ(gfx::RectF(2.f, 2.f, 4.f, 4.f).ToString(), | |
| 700 damage_rect.ToString()); | |
| 701 break; | |
| 702 case 15: | 721 case 15: |
| 703 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.f, 0.f).ToString(), | 722 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 704 damage_rect.ToString()); | 723 damage_rect.ToString()); |
| 705 break; | 724 break; |
| 706 case 16: | 725 case 16: |
| 707 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 726 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 708 damage_rect.ToString()); | 727 damage_rect.ToString()); |
| 709 break; | 728 break; |
| 710 case 17: | 729 case 17: |
| 711 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | 730 EXPECT_EQ(gfx::RectF(0.f, 0.f, 10.f, 10.f).ToString(), |
| 712 damage_rect.ToString()); | |
| 713 break; | |
| 714 case 18: | |
| 715 EXPECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 6.f).ToString(), | |
| 716 damage_rect.ToString()); | 731 damage_rect.ToString()); |
| 717 EndTest(); | 732 EndTest(); |
| 718 break; | 733 break; |
| 719 } | 734 } |
| 720 | 735 |
| 721 return result; | 736 return result; |
| 722 } | 737 } |
| 723 | 738 |
| 724 protected: | 739 protected: |
| 725 bool first_draw_for_source_frame_; | 740 bool first_draw_for_source_frame_; |
| 726 }; | 741 }; |
| 727 | 742 |
| 728 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestLayerUsesFrameDamage); | 743 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestLayerUsesFrameDamage); |
| 729 | 744 |
| 730 class LayerTreeHostDelegatedTestMergeResources | 745 class LayerTreeHostDelegatedTestMergeResources |
| 731 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 746 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 732 public: | 747 public: |
| 733 virtual void BeginTest() OVERRIDE { | 748 virtual void BeginTest() OVERRIDE { |
| 734 // Push two frames to the delegated renderer layer with no commit between. | 749 // Push two frames to the delegated renderer layer with no commit between. |
| 735 | 750 |
| 736 // The first frame has resource 999. | 751 // The first frame has resource 999. |
| 737 scoped_ptr<DelegatedFrameData> frame1 = | 752 scoped_ptr<DelegatedFrameData> frame1 = |
| 738 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 753 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 739 AddTextureQuad(frame1.get(), 999); | 754 AddTextureQuad(frame1.get(), 999); |
| 740 AddTransferableResource(frame1.get(), 999); | 755 AddTransferableResource(frame1.get(), 999); |
| 741 delegated_->SetFrameData(frame1.Pass()); | 756 SetFrameData(frame1.Pass()); |
| 742 | 757 |
| 743 // The second frame uses resource 999 still, but also adds 555. | 758 // The second frame uses resource 999 still, but also adds 555. |
| 744 scoped_ptr<DelegatedFrameData> frame2 = | 759 scoped_ptr<DelegatedFrameData> frame2 = |
| 745 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 760 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 746 AddTextureQuad(frame2.get(), 999); | 761 AddTextureQuad(frame2.get(), 999); |
| 747 AddTransferableResource(frame2.get(), 999); | 762 AddTransferableResource(frame2.get(), 999); |
| 748 AddTextureQuad(frame2.get(), 555); | 763 AddTextureQuad(frame2.get(), 555); |
| 749 AddTransferableResource(frame2.get(), 555); | 764 AddTransferableResource(frame2.get(), 555); |
| 750 delegated_->SetFrameData(frame2.Pass()); | 765 SetFrameData(frame2.Pass()); |
| 751 | 766 |
| 752 // The resource 999 from frame1 is returned since it is still on the main | 767 // The resource 999 from frame1 is returned since it is still on the main |
| 753 // thread. | 768 // thread. |
| 754 ReturnedResourceArray returned_resources; | 769 ReturnedResourceArray returned_resources; |
| 755 delegated_->TakeUnusedResourcesForChildCompositor(&returned_resources); | 770 resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 771 &returned_resources); |
| 756 { | 772 { |
| 757 unsigned expected[] = {999}; | 773 unsigned expected[] = {999}; |
| 758 EXPECT_RESOURCES(expected, returned_resources); | 774 EXPECT_RESOURCES(expected, returned_resources); |
| 759 EXPECT_TRUE(TestAndResetAvailable()); | 775 EXPECT_TRUE(TestAndResetAvailable()); |
| 760 } | 776 } |
| 761 | 777 |
| 762 PostSetNeedsCommitToMainThread(); | 778 PostSetNeedsCommitToMainThread(); |
| 763 } | 779 } |
| 764 | 780 |
| 765 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 781 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 766 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 782 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 767 FakeDelegatedRendererLayerImpl* delegated_impl = | 783 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 768 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 784 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 769 | 785 |
| 770 const ResourceProvider::ResourceIdMap& map = | 786 const ResourceProvider::ResourceIdMap& map = |
| 771 host_impl->resource_provider()->GetChildToParentMap( | 787 host_impl->resource_provider()->GetChildToParentMap( |
| 772 delegated_impl->ChildId()); | 788 delegated_impl->ChildId()); |
| 773 | 789 |
| 774 // Both frames' resources should be in the parent's resource provider. | 790 // Both frames' resources should be in the parent's resource provider. |
| 775 EXPECT_EQ(2u, map.size()); | 791 EXPECT_EQ(2u, map.size()); |
| 776 EXPECT_EQ(1u, map.count(999)); | 792 EXPECT_EQ(1u, map.count(999)); |
| 777 EXPECT_EQ(1u, map.count(555)); | 793 EXPECT_EQ(1u, map.count(555)); |
| 778 | 794 |
| 779 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 795 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
| 780 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); | 796 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
| 781 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); | 797 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
| 782 | 798 |
| 783 EndTest(); | 799 EndTest(); |
| 784 } | 800 } |
| 785 | |
| 786 virtual void AfterTest() OVERRIDE {} | |
| 787 }; | 801 }; |
| 788 | 802 |
| 789 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources); | 803 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources); |
| 790 | 804 |
| 791 class LayerTreeHostDelegatedTestRemapResourcesInQuads | 805 class LayerTreeHostDelegatedTestRemapResourcesInQuads |
| 792 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 806 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 793 public: | 807 public: |
| 794 virtual void BeginTest() OVERRIDE { | 808 virtual void BeginTest() OVERRIDE { |
| 795 // Generate a frame with two resources in it. | 809 // Generate a frame with two resources in it. |
| 796 scoped_ptr<DelegatedFrameData> frame = | 810 scoped_ptr<DelegatedFrameData> frame = |
| 797 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 811 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 798 AddTextureQuad(frame.get(), 999); | 812 AddTextureQuad(frame.get(), 999); |
| 799 AddTransferableResource(frame.get(), 999); | 813 AddTransferableResource(frame.get(), 999); |
| 800 AddTextureQuad(frame.get(), 555); | 814 AddTextureQuad(frame.get(), 555); |
| 801 AddTransferableResource(frame.get(), 555); | 815 AddTransferableResource(frame.get(), 555); |
| 802 delegated_->SetFrameData(frame.Pass()); | 816 SetFrameData(frame.Pass()); |
| 803 | 817 |
| 804 PostSetNeedsCommitToMainThread(); | 818 PostSetNeedsCommitToMainThread(); |
| 805 } | 819 } |
| 806 | 820 |
| 807 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 821 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 808 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 822 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 809 FakeDelegatedRendererLayerImpl* delegated_impl = | 823 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 810 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 824 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 811 | 825 |
| 812 const ResourceProvider::ResourceIdMap& map = | 826 const ResourceProvider::ResourceIdMap& map = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 826 // The resources in the quads should be remapped to the parent's namespace. | 840 // The resources in the quads should be remapped to the parent's namespace. |
| 827 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 841 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 828 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[0]); | 842 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[0]); |
| 829 EXPECT_EQ(parent_resource_id1, quad1->resource_id); | 843 EXPECT_EQ(parent_resource_id1, quad1->resource_id); |
| 830 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 844 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
| 831 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[1]); | 845 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[1]); |
| 832 EXPECT_EQ(parent_resource_id2, quad2->resource_id); | 846 EXPECT_EQ(parent_resource_id2, quad2->resource_id); |
| 833 | 847 |
| 834 EndTest(); | 848 EndTest(); |
| 835 } | 849 } |
| 836 | |
| 837 virtual void AfterTest() OVERRIDE {} | |
| 838 }; | 850 }; |
| 839 | 851 |
| 840 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestRemapResourcesInQuads); | 852 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestRemapResourcesInQuads); |
| 841 | 853 |
| 842 class LayerTreeHostDelegatedTestReturnUnusedResources | 854 class LayerTreeHostDelegatedTestReturnUnusedResources |
| 843 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 855 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 844 public: | 856 public: |
| 845 virtual void BeginTest() OVERRIDE { | 857 virtual void BeginTest() OVERRIDE { |
| 846 PostSetNeedsCommitToMainThread(); | 858 PostSetNeedsCommitToMainThread(); |
| 847 } | 859 } |
| 848 | 860 |
| 849 virtual void DidCommitAndDrawFrame() OVERRIDE { | 861 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 850 scoped_ptr<DelegatedFrameData> frame; | 862 scoped_ptr<DelegatedFrameData> frame; |
| 851 ReturnedResourceArray resources; | 863 ReturnedResourceArray resources; |
| 852 | 864 |
| 853 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 865 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 854 switch (next_source_frame_number) { | 866 switch (next_source_frame_number) { |
| 855 case 1: | 867 case 1: |
| 856 // Generate a frame with two resources in it. | 868 // Generate a frame with two resources in it. |
| 857 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 869 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 858 AddTextureQuad(frame.get(), 999); | 870 AddTextureQuad(frame.get(), 999); |
| 859 AddTransferableResource(frame.get(), 999); | 871 AddTransferableResource(frame.get(), 999); |
| 860 AddTextureQuad(frame.get(), 555); | 872 AddTextureQuad(frame.get(), 555); |
| 861 AddTransferableResource(frame.get(), 555); | 873 AddTransferableResource(frame.get(), 555); |
| 862 delegated_->SetFrameData(frame.Pass()); | 874 SetFrameData(frame.Pass()); |
| 863 break; | 875 break; |
| 864 case 2: | 876 case 2: |
| 865 // All of the resources are in use. | 877 // All of the resources are in use. |
| 866 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 878 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 867 EXPECT_EQ(0u, resources.size()); | 879 EXPECT_EQ(0u, resources.size()); |
| 868 EXPECT_FALSE(TestAndResetAvailable()); | 880 EXPECT_FALSE(TestAndResetAvailable()); |
| 869 | 881 |
| 870 // Keep using 999 but stop using 555. | 882 // Keep using 999 but stop using 555. |
| 871 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 883 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 872 AddTextureQuad(frame.get(), 999); | 884 AddTextureQuad(frame.get(), 999); |
| 873 AddTransferableResource(frame.get(), 999); | 885 AddTransferableResource(frame.get(), 999); |
| 874 AddTextureQuad(frame.get(), 444); | 886 AddTextureQuad(frame.get(), 444); |
| 875 AddTransferableResource(frame.get(), 444); | 887 AddTransferableResource(frame.get(), 444); |
| 876 delegated_->SetFrameData(frame.Pass()); | 888 SetFrameData(frame.Pass()); |
| 877 break; | 889 break; |
| 878 case 3: | 890 case 3: |
| 879 // 555 is no longer in use. | 891 // 555 is no longer in use. |
| 880 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 892 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 881 { | 893 { |
| 882 unsigned expected[] = {555}; | 894 unsigned expected[] = {555}; |
| 883 EXPECT_RESOURCES(expected, resources); | 895 EXPECT_RESOURCES(expected, resources); |
| 884 EXPECT_TRUE(TestAndResetAvailable()); | 896 EXPECT_TRUE(TestAndResetAvailable()); |
| 885 } | 897 } |
| 886 | 898 |
| 887 // Stop using any resources. | 899 // Stop using any resources. |
| 888 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 900 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 889 delegated_->SetFrameData(frame.Pass()); | 901 SetFrameData(frame.Pass()); |
| 890 break; | 902 break; |
| 891 case 4: | 903 case 4: |
| 892 // Postpone collecting resources for a frame. They should still be there | 904 // Postpone collecting resources for a frame. They should still be there |
| 893 // the next frame. | 905 // the next frame. |
| 894 layer_tree_host()->SetNeedsCommit(); | 906 layer_tree_host()->SetNeedsCommit(); |
| 895 return; | 907 return; |
| 896 case 5: | 908 case 5: |
| 897 // 444 and 999 are no longer in use. We sent two refs to 999, so we | 909 // 444 and 999 are no longer in use. We sent two refs to 999, so we |
| 898 // should get two back. | 910 // should get two back. |
| 899 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 911 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 900 { | 912 { |
| 901 unsigned expected[] = {444, 999, 999}; | 913 unsigned expected[] = {444, 999, 999}; |
| 902 EXPECT_RESOURCES(expected, resources); | 914 EXPECT_RESOURCES(expected, resources); |
| 903 EXPECT_TRUE(TestAndResetAvailable()); | 915 EXPECT_TRUE(TestAndResetAvailable()); |
| 904 } | 916 } |
| 905 EndTest(); | 917 EndTest(); |
| 906 break; | 918 break; |
| 907 } | 919 } |
| 908 | 920 |
| 909 // Resources are never immediately released. | 921 // Resources are never immediately released. |
| 910 ReturnedResourceArray empty_resources; | 922 ReturnedResourceArray empty_resources; |
| 911 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources); | 923 resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 924 &empty_resources); |
| 912 EXPECT_EQ(0u, empty_resources.size()); | 925 EXPECT_EQ(0u, empty_resources.size()); |
| 913 EXPECT_FALSE(TestAndResetAvailable()); | 926 EXPECT_FALSE(TestAndResetAvailable()); |
| 914 } | 927 } |
| 915 | 928 |
| 916 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 929 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 917 bool result) OVERRIDE { | 930 bool result) OVERRIDE { |
| 918 ReturnUnusedResourcesFromParent(host_impl); | 931 ReturnUnusedResourcesFromParent(host_impl); |
| 919 } | 932 } |
| 920 | |
| 921 virtual void AfterTest() OVERRIDE {} | |
| 922 }; | 933 }; |
| 923 | 934 |
| 924 SINGLE_AND_MULTI_THREAD_TEST_F( | 935 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 925 LayerTreeHostDelegatedTestReturnUnusedResources); | 936 LayerTreeHostDelegatedTestReturnUnusedResources); |
| 926 | 937 |
| 927 class LayerTreeHostDelegatedTestReusedResources | 938 class LayerTreeHostDelegatedTestReusedResources |
| 928 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 939 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 929 public: | 940 public: |
| 930 virtual void BeginTest() OVERRIDE { | 941 virtual void BeginTest() OVERRIDE { |
| 931 PostSetNeedsCommitToMainThread(); | 942 PostSetNeedsCommitToMainThread(); |
| 932 } | 943 } |
| 933 | 944 |
| 934 virtual void DidCommitAndDrawFrame() OVERRIDE { | 945 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 935 scoped_ptr<DelegatedFrameData> frame; | 946 scoped_ptr<DelegatedFrameData> frame; |
| 936 ReturnedResourceArray resources; | 947 ReturnedResourceArray resources; |
| 937 | 948 |
| 938 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 949 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 939 switch (next_source_frame_number) { | 950 switch (next_source_frame_number) { |
| 940 case 1: | 951 case 1: |
| 941 // Generate a frame with some resources in it. | 952 // Generate a frame with some resources in it. |
| 942 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 953 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 943 AddTextureQuad(frame.get(), 999); | 954 AddTextureQuad(frame.get(), 999); |
| 944 AddTransferableResource(frame.get(), 999); | 955 AddTransferableResource(frame.get(), 999); |
| 945 AddTextureQuad(frame.get(), 555); | 956 AddTextureQuad(frame.get(), 555); |
| 946 AddTransferableResource(frame.get(), 555); | 957 AddTransferableResource(frame.get(), 555); |
| 947 AddTextureQuad(frame.get(), 444); | 958 AddTextureQuad(frame.get(), 444); |
| 948 AddTransferableResource(frame.get(), 444); | 959 AddTransferableResource(frame.get(), 444); |
| 949 delegated_->SetFrameData(frame.Pass()); | 960 SetFrameData(frame.Pass()); |
| 950 break; | 961 break; |
| 951 case 2: | 962 case 2: |
| 952 // All of the resources are in use. | 963 // All of the resources are in use. |
| 953 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 964 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 954 EXPECT_EQ(0u, resources.size()); | 965 EXPECT_EQ(0u, resources.size()); |
| 955 EXPECT_FALSE(TestAndResetAvailable()); | 966 EXPECT_FALSE(TestAndResetAvailable()); |
| 956 | 967 |
| 957 // Keep using 999 but stop using 555 and 444. | 968 // Keep using 999 but stop using 555 and 444. |
| 958 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 969 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 959 AddTextureQuad(frame.get(), 999); | 970 AddTextureQuad(frame.get(), 999); |
| 960 AddTransferableResource(frame.get(), 999); | 971 AddTransferableResource(frame.get(), 999); |
| 961 delegated_->SetFrameData(frame.Pass()); | 972 SetFrameData(frame.Pass()); |
| 962 | 973 |
| 963 // Resource are not immediately released. | 974 // Resource are not immediately released. |
| 964 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 975 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 965 EXPECT_EQ(0u, resources.size()); | 976 EXPECT_EQ(0u, resources.size()); |
| 966 EXPECT_FALSE(TestAndResetAvailable()); | 977 EXPECT_FALSE(TestAndResetAvailable()); |
| 967 | 978 |
| 968 // Now using 555 and 444 again, but not 999. | 979 // Now using 555 and 444 again, but not 999. |
| 969 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 980 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 970 AddTextureQuad(frame.get(), 555); | 981 AddTextureQuad(frame.get(), 555); |
| 971 AddTransferableResource(frame.get(), 555); | 982 AddTransferableResource(frame.get(), 555); |
| 972 AddTextureQuad(frame.get(), 444); | 983 AddTextureQuad(frame.get(), 444); |
| 973 AddTransferableResource(frame.get(), 444); | 984 AddTransferableResource(frame.get(), 444); |
| 974 delegated_->SetFrameData(frame.Pass()); | 985 SetFrameData(frame.Pass()); |
| 975 break; | 986 break; |
| 976 case 3: | 987 case 3: |
| 977 // The 999 resource is the only unused one. Two references were sent, so | 988 // The 999 resource is the only unused one. Two references were sent, so |
| 978 // two should be returned. | 989 // two should be returned. |
| 979 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 990 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 980 { | 991 { |
| 981 unsigned expected[] = {999, 999}; | 992 unsigned expected[] = {999, 999}; |
| 982 EXPECT_RESOURCES(expected, resources); | 993 EXPECT_RESOURCES(expected, resources); |
| 983 EXPECT_TRUE(TestAndResetAvailable()); | 994 EXPECT_TRUE(TestAndResetAvailable()); |
| 984 } | 995 } |
| 985 EndTest(); | 996 EndTest(); |
| 986 break; | 997 break; |
| 987 } | 998 } |
| 988 } | 999 } |
| 989 | 1000 |
| 990 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1001 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 991 bool result) OVERRIDE { | 1002 bool result) OVERRIDE { |
| 992 ReturnUnusedResourcesFromParent(host_impl); | 1003 ReturnUnusedResourcesFromParent(host_impl); |
| 993 } | 1004 } |
| 994 | |
| 995 virtual void AfterTest() OVERRIDE {} | |
| 996 }; | 1005 }; |
| 997 | 1006 |
| 998 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestReusedResources); | 1007 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestReusedResources); |
| 999 | 1008 |
| 1000 class LayerTreeHostDelegatedTestFrameBeforeAck | 1009 class LayerTreeHostDelegatedTestFrameBeforeAck |
| 1001 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1010 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1002 public: | 1011 public: |
| 1003 virtual void BeginTest() OVERRIDE { | 1012 virtual void BeginTest() OVERRIDE { |
| 1004 PostSetNeedsCommitToMainThread(); | 1013 PostSetNeedsCommitToMainThread(); |
| 1005 } | 1014 } |
| 1006 | 1015 |
| 1007 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1016 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1008 scoped_ptr<DelegatedFrameData> frame; | 1017 scoped_ptr<DelegatedFrameData> frame; |
| 1009 ReturnedResourceArray resources; | 1018 ReturnedResourceArray resources; |
| 1010 | 1019 |
| 1011 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1020 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1012 switch (next_source_frame_number) { | 1021 switch (next_source_frame_number) { |
| 1013 case 1: | 1022 case 1: |
| 1014 // Generate a frame with some resources in it. | 1023 // Generate a frame with some resources in it. |
| 1015 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1024 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1016 AddTextureQuad(frame.get(), 999); | 1025 AddTextureQuad(frame.get(), 999); |
| 1017 AddTransferableResource(frame.get(), 999); | 1026 AddTransferableResource(frame.get(), 999); |
| 1018 AddTextureQuad(frame.get(), 555); | 1027 AddTextureQuad(frame.get(), 555); |
| 1019 AddTransferableResource(frame.get(), 555); | 1028 AddTransferableResource(frame.get(), 555); |
| 1020 AddTextureQuad(frame.get(), 444); | 1029 AddTextureQuad(frame.get(), 444); |
| 1021 AddTransferableResource(frame.get(), 444); | 1030 AddTransferableResource(frame.get(), 444); |
| 1022 delegated_->SetFrameData(frame.Pass()); | 1031 SetFrameData(frame.Pass()); |
| 1023 break; | 1032 break; |
| 1024 case 2: | 1033 case 2: |
| 1025 // All of the resources are in use. | 1034 // All of the resources are in use. |
| 1026 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1035 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1027 EXPECT_EQ(0u, resources.size()); | 1036 EXPECT_EQ(0u, resources.size()); |
| 1028 EXPECT_FALSE(TestAndResetAvailable()); | 1037 EXPECT_FALSE(TestAndResetAvailable()); |
| 1029 | 1038 |
| 1030 // Keep using 999 but stop using 555 and 444. | 1039 // Keep using 999 but stop using 555 and 444. |
| 1031 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1040 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1032 AddTextureQuad(frame.get(), 999); | 1041 AddTextureQuad(frame.get(), 999); |
| 1033 AddTransferableResource(frame.get(), 999); | 1042 AddTransferableResource(frame.get(), 999); |
| 1034 delegated_->SetFrameData(frame.Pass()); | 1043 SetFrameData(frame.Pass()); |
| 1035 | 1044 |
| 1036 // Resource are not immediately released. | 1045 // Resource are not immediately released. |
| 1037 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1046 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1038 EXPECT_EQ(0u, resources.size()); | 1047 EXPECT_EQ(0u, resources.size()); |
| 1039 EXPECT_FALSE(TestAndResetAvailable()); | 1048 EXPECT_FALSE(TestAndResetAvailable()); |
| 1040 | 1049 |
| 1041 // The parent compositor (this one) does a commit. | 1050 // The parent compositor (this one) does a commit. |
| 1042 break; | 1051 break; |
| 1043 case 3: | 1052 case 3: |
| 1044 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1053 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1045 { | 1054 { |
| 1046 unsigned expected[] = {444, 555}; | 1055 unsigned expected[] = {444, 555}; |
| 1047 EXPECT_RESOURCES(expected, resources); | 1056 EXPECT_RESOURCES(expected, resources); |
| 1048 EXPECT_TRUE(TestAndResetAvailable()); | 1057 EXPECT_TRUE(TestAndResetAvailable()); |
| 1049 } | 1058 } |
| 1050 | 1059 |
| 1051 // The child compositor sends a frame referring to resources not in the | 1060 // The child compositor sends a frame referring to resources not in the |
| 1052 // frame. | 1061 // frame. |
| 1053 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1062 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1054 AddTextureQuad(frame.get(), 999); | 1063 AddTextureQuad(frame.get(), 999); |
| 1055 AddTextureQuad(frame.get(), 555); | 1064 AddTextureQuad(frame.get(), 555); |
| 1056 AddTextureQuad(frame.get(), 444); | 1065 AddTextureQuad(frame.get(), 444); |
| 1057 delegated_->SetFrameData(frame.Pass()); | 1066 SetFrameData(frame.Pass()); |
| 1058 break; | 1067 break; |
| 1059 } | 1068 } |
| 1060 } | 1069 } |
| 1061 | 1070 |
| 1062 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1071 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1063 if (host_impl->active_tree()->source_frame_number() != 3) | 1072 if (host_impl->active_tree()->source_frame_number() != 3) |
| 1064 return; | 1073 return; |
| 1065 | 1074 |
| 1066 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 1075 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 1067 FakeDelegatedRendererLayerImpl* delegated_impl = | 1076 FakeDelegatedRendererLayerImpl* delegated_impl = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1086 pass->quad_list[0]); | 1095 pass->quad_list[0]); |
| 1087 EXPECT_EQ(map.find(999)->second, quad->resource_id); | 1096 EXPECT_EQ(map.find(999)->second, quad->resource_id); |
| 1088 | 1097 |
| 1089 EndTest(); | 1098 EndTest(); |
| 1090 } | 1099 } |
| 1091 | 1100 |
| 1092 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1101 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1093 bool result) OVERRIDE { | 1102 bool result) OVERRIDE { |
| 1094 ReturnUnusedResourcesFromParent(host_impl); | 1103 ReturnUnusedResourcesFromParent(host_impl); |
| 1095 } | 1104 } |
| 1096 | |
| 1097 virtual void AfterTest() OVERRIDE {} | |
| 1098 }; | 1105 }; |
| 1099 | 1106 |
| 1100 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestFrameBeforeAck); | 1107 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestFrameBeforeAck); |
| 1101 | 1108 |
| 1102 class LayerTreeHostDelegatedTestFrameBeforeTakeResources | 1109 class LayerTreeHostDelegatedTestFrameBeforeTakeResources |
| 1103 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1110 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1104 public: | 1111 public: |
| 1105 virtual void BeginTest() OVERRIDE { | 1112 virtual void BeginTest() OVERRIDE { |
| 1106 PostSetNeedsCommitToMainThread(); | 1113 PostSetNeedsCommitToMainThread(); |
| 1107 } | 1114 } |
| 1108 | 1115 |
| 1109 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1116 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1110 scoped_ptr<DelegatedFrameData> frame; | 1117 scoped_ptr<DelegatedFrameData> frame; |
| 1111 ReturnedResourceArray resources; | 1118 ReturnedResourceArray resources; |
| 1112 | 1119 |
| 1113 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1120 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1114 switch (next_source_frame_number) { | 1121 switch (next_source_frame_number) { |
| 1115 case 1: | 1122 case 1: |
| 1116 // Generate a frame with some resources in it. | 1123 // Generate a frame with some resources in it. |
| 1117 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1124 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1118 AddTextureQuad(frame.get(), 999); | 1125 AddTextureQuad(frame.get(), 999); |
| 1119 AddTransferableResource(frame.get(), 999); | 1126 AddTransferableResource(frame.get(), 999); |
| 1120 AddTextureQuad(frame.get(), 555); | 1127 AddTextureQuad(frame.get(), 555); |
| 1121 AddTransferableResource(frame.get(), 555); | 1128 AddTransferableResource(frame.get(), 555); |
| 1122 AddTextureQuad(frame.get(), 444); | 1129 AddTextureQuad(frame.get(), 444); |
| 1123 AddTransferableResource(frame.get(), 444); | 1130 AddTransferableResource(frame.get(), 444); |
| 1124 delegated_->SetFrameData(frame.Pass()); | 1131 SetFrameData(frame.Pass()); |
| 1125 break; | 1132 break; |
| 1126 case 2: | 1133 case 2: |
| 1127 // All of the resources are in use. | 1134 // All of the resources are in use. |
| 1128 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1135 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1129 EXPECT_EQ(0u, resources.size()); | 1136 EXPECT_EQ(0u, resources.size()); |
| 1130 EXPECT_FALSE(TestAndResetAvailable()); | 1137 EXPECT_FALSE(TestAndResetAvailable()); |
| 1131 | 1138 |
| 1132 // Keep using 999 but stop using 555 and 444. | 1139 // Keep using 999 but stop using 555 and 444. |
| 1133 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1140 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1134 AddTextureQuad(frame.get(), 999); | 1141 AddTextureQuad(frame.get(), 999); |
| 1135 AddTransferableResource(frame.get(), 999); | 1142 AddTransferableResource(frame.get(), 999); |
| 1136 delegated_->SetFrameData(frame.Pass()); | 1143 SetFrameData(frame.Pass()); |
| 1137 | 1144 |
| 1138 // Resource are not immediately released. | 1145 // Resource are not immediately released. |
| 1139 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1146 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1140 EXPECT_EQ(0u, resources.size()); | 1147 EXPECT_EQ(0u, resources.size()); |
| 1141 EXPECT_FALSE(TestAndResetAvailable()); | 1148 EXPECT_FALSE(TestAndResetAvailable()); |
| 1142 | 1149 |
| 1143 // The parent compositor (this one) does a commit. | 1150 // The parent compositor (this one) does a commit. |
| 1144 break; | 1151 break; |
| 1145 case 3: | 1152 case 3: |
| 1146 // The child compositor sends a frame before taking resources back | 1153 // The child compositor sends a frame before taking resources back |
| 1147 // from the previous commit. This frame makes use of the resources 555 | 1154 // from the previous commit. This frame makes use of the resources 555 |
| 1148 // and 444, which were just released during commit. | 1155 // and 444, which were just released during commit. |
| 1149 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1156 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1150 AddTextureQuad(frame.get(), 999); | 1157 AddTextureQuad(frame.get(), 999); |
| 1151 AddTransferableResource(frame.get(), 999); | 1158 AddTransferableResource(frame.get(), 999); |
| 1152 AddTextureQuad(frame.get(), 555); | 1159 AddTextureQuad(frame.get(), 555); |
| 1153 AddTransferableResource(frame.get(), 555); | 1160 AddTransferableResource(frame.get(), 555); |
| 1154 AddTextureQuad(frame.get(), 444); | 1161 AddTextureQuad(frame.get(), 444); |
| 1155 AddTransferableResource(frame.get(), 444); | 1162 AddTransferableResource(frame.get(), 444); |
| 1156 delegated_->SetFrameData(frame.Pass()); | 1163 SetFrameData(frame.Pass()); |
| 1157 | 1164 |
| 1158 // The resources are used by the new frame but are returned anyway since | 1165 // The resources are used by the new frame but are returned anyway since |
| 1159 // we passed them again. | 1166 // we passed them again. |
| 1160 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1167 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1161 { | 1168 { |
| 1162 unsigned expected[] = {444, 555}; | 1169 unsigned expected[] = {444, 555}; |
| 1163 EXPECT_RESOURCES(expected, resources); | 1170 EXPECT_RESOURCES(expected, resources); |
| 1164 EXPECT_TRUE(TestAndResetAvailable()); | 1171 EXPECT_TRUE(TestAndResetAvailable()); |
| 1165 } | 1172 } |
| 1166 break; | 1173 break; |
| 1167 case 4: | 1174 case 4: |
| 1168 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1175 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1169 EXPECT_EQ(0u, resources.size()); | 1176 EXPECT_EQ(0u, resources.size()); |
| 1170 EXPECT_FALSE(TestAndResetAvailable()); | 1177 EXPECT_FALSE(TestAndResetAvailable()); |
| 1171 EndTest(); | 1178 EndTest(); |
| 1172 break; | 1179 break; |
| 1173 } | 1180 } |
| 1174 } | 1181 } |
| 1175 | 1182 |
| 1176 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1183 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1177 if (host_impl->active_tree()->source_frame_number() != 3) | 1184 if (host_impl->active_tree()->source_frame_number() != 3) |
| 1178 return; | 1185 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1207 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 1214 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
| 1208 const TextureDrawQuad* quad3 = TextureDrawQuad::MaterialCast( | 1215 const TextureDrawQuad* quad3 = TextureDrawQuad::MaterialCast( |
| 1209 pass->quad_list[2]); | 1216 pass->quad_list[2]); |
| 1210 EXPECT_EQ(map.find(444)->second, quad3->resource_id); | 1217 EXPECT_EQ(map.find(444)->second, quad3->resource_id); |
| 1211 } | 1218 } |
| 1212 | 1219 |
| 1213 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1220 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1214 bool result) OVERRIDE { | 1221 bool result) OVERRIDE { |
| 1215 ReturnUnusedResourcesFromParent(host_impl); | 1222 ReturnUnusedResourcesFromParent(host_impl); |
| 1216 } | 1223 } |
| 1217 | |
| 1218 virtual void AfterTest() OVERRIDE {} | |
| 1219 }; | 1224 }; |
| 1220 | 1225 |
| 1221 SINGLE_AND_MULTI_THREAD_TEST_F( | 1226 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1222 LayerTreeHostDelegatedTestFrameBeforeTakeResources); | 1227 LayerTreeHostDelegatedTestFrameBeforeTakeResources); |
| 1223 | 1228 |
| 1224 class LayerTreeHostDelegatedTestBadFrame | 1229 class LayerTreeHostDelegatedTestBadFrame |
| 1225 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1230 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1226 public: | 1231 public: |
| 1227 virtual void BeginTest() OVERRIDE { | 1232 virtual void BeginTest() OVERRIDE { |
| 1228 PostSetNeedsCommitToMainThread(); | 1233 PostSetNeedsCommitToMainThread(); |
| 1229 } | 1234 } |
| 1230 | 1235 |
| 1231 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1236 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1232 scoped_ptr<DelegatedFrameData> frame; | 1237 scoped_ptr<DelegatedFrameData> frame; |
| 1233 ReturnedResourceArray resources; | 1238 ReturnedResourceArray resources; |
| 1234 | 1239 |
| 1235 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1240 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1236 switch (next_source_frame_number) { | 1241 switch (next_source_frame_number) { |
| 1237 case 1: | 1242 case 1: |
| 1238 // Generate a frame with some resources in it. | 1243 // Generate a frame with some resources in it. |
| 1239 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1244 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1240 AddTextureQuad(frame.get(), 999); | 1245 AddTextureQuad(frame.get(), 999); |
| 1241 AddTransferableResource(frame.get(), 999); | 1246 AddTransferableResource(frame.get(), 999); |
| 1242 AddTextureQuad(frame.get(), 555); | 1247 AddTextureQuad(frame.get(), 555); |
| 1243 AddTransferableResource(frame.get(), 555); | 1248 AddTransferableResource(frame.get(), 555); |
| 1244 delegated_->SetFrameData(frame.Pass()); | 1249 SetFrameData(frame.Pass()); |
| 1245 break; | 1250 break; |
| 1246 case 2: | 1251 case 2: |
| 1247 // All of the resources are in use. | 1252 // All of the resources are in use. |
| 1248 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1253 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1249 EXPECT_EQ(0u, resources.size()); | 1254 EXPECT_EQ(0u, resources.size()); |
| 1250 EXPECT_FALSE(TestAndResetAvailable()); | 1255 EXPECT_FALSE(TestAndResetAvailable()); |
| 1251 | 1256 |
| 1252 // Generate a bad frame with a resource the layer doesn't have. The | 1257 // Generate a bad frame with a resource the layer doesn't have. The |
| 1253 // 885 and 775 resources are unknown, while ownership of the legit 444 | 1258 // 885 and 775 resources are unknown, while ownership of the legit 444 |
| 1254 // resource is passed in here. The bad frame does not use any of the | 1259 // resource is passed in here. The bad frame does not use any of the |
| 1255 // previous resources, 999 or 555. | 1260 // previous resources, 999 or 555. |
| 1256 // A bad quad is present both before and after the good quad. | 1261 // A bad quad is present both before and after the good quad. |
| 1257 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1262 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1258 AddTextureQuad(frame.get(), 885); | 1263 AddTextureQuad(frame.get(), 885); |
| 1259 AddTextureQuad(frame.get(), 444); | 1264 AddTextureQuad(frame.get(), 444); |
| 1260 AddTransferableResource(frame.get(), 444); | 1265 AddTransferableResource(frame.get(), 444); |
| 1261 AddTextureQuad(frame.get(), 775); | 1266 AddTextureQuad(frame.get(), 775); |
| 1262 delegated_->SetFrameData(frame.Pass()); | 1267 SetFrameData(frame.Pass()); |
| 1263 | 1268 |
| 1264 // The parent compositor (this one) does a commit. | 1269 // The parent compositor (this one) does a commit. |
| 1265 break; | 1270 break; |
| 1266 case 3: | 1271 case 3: |
| 1267 // The bad frame's resource is given back to the child compositor. | 1272 // The bad frame's resource is given back to the child compositor. |
| 1268 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1273 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1269 { | 1274 { |
| 1270 unsigned expected[] = {444}; | 1275 unsigned expected[] = {444}; |
| 1271 EXPECT_RESOURCES(expected, resources); | 1276 EXPECT_RESOURCES(expected, resources); |
| 1272 EXPECT_TRUE(TestAndResetAvailable()); | 1277 EXPECT_TRUE(TestAndResetAvailable()); |
| 1273 } | 1278 } |
| 1274 | 1279 |
| 1275 // Now send a good frame with 999 again. | 1280 // Now send a good frame with 999 again. |
| 1276 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1281 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1277 AddTextureQuad(frame.get(), 999); | 1282 AddTextureQuad(frame.get(), 999); |
| 1278 delegated_->SetFrameData(frame.Pass()); | 1283 SetFrameData(frame.Pass()); |
| 1279 break; | 1284 break; |
| 1280 case 4: | 1285 case 4: |
| 1281 // The unused 555 from the last good frame is now released. | 1286 // The unused 555 from the last good frame is now released. |
| 1282 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1287 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1283 { | 1288 { |
| 1284 unsigned expected[] = {555}; | 1289 unsigned expected[] = {555}; |
| 1285 EXPECT_RESOURCES(expected, resources); | 1290 EXPECT_RESOURCES(expected, resources); |
| 1286 EXPECT_TRUE(TestAndResetAvailable()); | 1291 EXPECT_TRUE(TestAndResetAvailable()); |
| 1287 } | 1292 } |
| 1288 | 1293 |
| 1289 EndTest(); | 1294 EndTest(); |
| 1290 break; | 1295 break; |
| 1291 } | 1296 } |
| 1292 } | 1297 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 | 1365 |
| 1361 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1366 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 1362 EXPECT_EQ(1u, pass->quad_list.size()); | 1367 EXPECT_EQ(1u, pass->quad_list.size()); |
| 1363 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 1368 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 1364 pass->quad_list[0]); | 1369 pass->quad_list[0]); |
| 1365 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 1370 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
| 1366 break; | 1371 break; |
| 1367 } | 1372 } |
| 1368 } | 1373 } |
| 1369 } | 1374 } |
| 1370 | |
| 1371 virtual void AfterTest() OVERRIDE {} | |
| 1372 }; | 1375 }; |
| 1373 | 1376 |
| 1374 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame); | 1377 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame); |
| 1375 | 1378 |
| 1376 class LayerTreeHostDelegatedTestUnnamedResource | 1379 class LayerTreeHostDelegatedTestUnnamedResource |
| 1377 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1380 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1378 public: | 1381 public: |
| 1379 virtual void BeginTest() OVERRIDE { | 1382 virtual void BeginTest() OVERRIDE { |
| 1380 PostSetNeedsCommitToMainThread(); | 1383 PostSetNeedsCommitToMainThread(); |
| 1381 } | 1384 } |
| 1382 | 1385 |
| 1383 virtual void DidCommit() OVERRIDE { | 1386 virtual void DidCommit() OVERRIDE { |
| 1384 scoped_ptr<DelegatedFrameData> frame; | 1387 scoped_ptr<DelegatedFrameData> frame; |
| 1385 ReturnedResourceArray resources; | 1388 ReturnedResourceArray resources; |
| 1386 | 1389 |
| 1387 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1390 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1388 switch (next_source_frame_number) { | 1391 switch (next_source_frame_number) { |
| 1389 case 1: | 1392 case 1: |
| 1390 // This frame includes two resources in it, but only uses one. | 1393 // This frame includes two resources in it, but only uses one. |
| 1391 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1394 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1392 AddTransferableResource(frame.get(), 999); | 1395 AddTransferableResource(frame.get(), 999); |
| 1393 AddTextureQuad(frame.get(), 555); | 1396 AddTextureQuad(frame.get(), 555); |
| 1394 AddTransferableResource(frame.get(), 555); | 1397 AddTransferableResource(frame.get(), 555); |
| 1395 delegated_->SetFrameData(frame.Pass()); | 1398 SetFrameData(frame.Pass()); |
| 1396 break; | 1399 break; |
| 1397 case 2: | 1400 case 2: |
| 1398 // The unused resource should be returned. | 1401 // The unused resource should be returned. |
| 1399 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1402 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1400 { | 1403 { |
| 1401 unsigned expected[] = {999}; | 1404 unsigned expected[] = {999}; |
| 1402 EXPECT_RESOURCES(expected, resources); | 1405 EXPECT_RESOURCES(expected, resources); |
| 1403 EXPECT_TRUE(TestAndResetAvailable()); | 1406 EXPECT_TRUE(TestAndResetAvailable()); |
| 1404 } | 1407 } |
| 1405 | 1408 |
| 1406 EndTest(); | 1409 EndTest(); |
| 1407 break; | 1410 break; |
| 1408 } | 1411 } |
| 1409 } | 1412 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1420 host_impl->resource_provider()->GetChildToParentMap( | 1423 host_impl->resource_provider()->GetChildToParentMap( |
| 1421 delegated_impl->ChildId()); | 1424 delegated_impl->ChildId()); |
| 1422 | 1425 |
| 1423 // The layer only held on to the resource that was used. | 1426 // The layer only held on to the resource that was used. |
| 1424 EXPECT_EQ(1u, map.size()); | 1427 EXPECT_EQ(1u, map.size()); |
| 1425 EXPECT_EQ(1u, map.count(555)); | 1428 EXPECT_EQ(1u, map.count(555)); |
| 1426 | 1429 |
| 1427 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1430 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
| 1428 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); | 1431 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
| 1429 } | 1432 } |
| 1430 | |
| 1431 virtual void AfterTest() OVERRIDE {} | |
| 1432 }; | 1433 }; |
| 1433 | 1434 |
| 1434 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource); | 1435 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource); |
| 1435 | 1436 |
| 1436 class LayerTreeHostDelegatedTestDontLeakResource | 1437 class LayerTreeHostDelegatedTestDontLeakResource |
| 1437 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1438 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1438 public: | 1439 public: |
| 1439 virtual void BeginTest() OVERRIDE { | 1440 virtual void BeginTest() OVERRIDE { |
| 1440 PostSetNeedsCommitToMainThread(); | 1441 PostSetNeedsCommitToMainThread(); |
| 1441 } | 1442 } |
| 1442 | 1443 |
| 1443 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1444 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1444 scoped_ptr<DelegatedFrameData> frame; | 1445 scoped_ptr<DelegatedFrameData> frame; |
| 1445 ReturnedResourceArray resources; | 1446 ReturnedResourceArray resources; |
| 1446 | 1447 |
| 1447 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1448 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1448 switch (next_source_frame_number) { | 1449 switch (next_source_frame_number) { |
| 1449 case 1: | 1450 case 1: |
| 1450 // This frame includes two resources in it. | 1451 // This frame includes two resources in it. |
| 1451 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1452 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1452 AddTextureQuad(frame.get(), 999); | 1453 AddTextureQuad(frame.get(), 999); |
| 1453 AddTransferableResource(frame.get(), 999); | 1454 AddTransferableResource(frame.get(), 999); |
| 1454 AddTextureQuad(frame.get(), 555); | 1455 AddTextureQuad(frame.get(), 555); |
| 1455 AddTransferableResource(frame.get(), 555); | 1456 AddTransferableResource(frame.get(), 555); |
| 1456 delegated_->SetFrameData(frame.Pass()); | 1457 SetFrameData(frame.Pass()); |
| 1457 | 1458 |
| 1458 // But then we immediately stop using 999. | 1459 // But then we immediately stop using 999. |
| 1459 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1460 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1460 AddTextureQuad(frame.get(), 555); | 1461 AddTextureQuad(frame.get(), 555); |
| 1461 AddTransferableResource(frame.get(), 555); | 1462 AddTransferableResource(frame.get(), 555); |
| 1462 delegated_->SetFrameData(frame.Pass()); | 1463 SetFrameData(frame.Pass()); |
| 1463 break; | 1464 break; |
| 1464 case 2: | 1465 case 2: |
| 1465 // The unused resources should be returned. 555 is still used, but it's | 1466 // The unused resources should be returned. 555 is still used, but it's |
| 1466 // returned once to account for the first frame. | 1467 // returned once to account for the first frame. |
| 1467 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1468 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1468 { | 1469 { |
| 1469 unsigned expected[] = {555, 999}; | 1470 unsigned expected[] = {555, 999}; |
| 1470 EXPECT_RESOURCES(expected, resources); | 1471 EXPECT_RESOURCES(expected, resources); |
| 1471 EXPECT_TRUE(TestAndResetAvailable()); | 1472 EXPECT_TRUE(TestAndResetAvailable()); |
| 1472 } | 1473 } |
| 1473 // Send a frame with no resources in it. | 1474 // Send a frame with no resources in it. |
| 1474 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1475 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1475 delegated_->SetFrameData(frame.Pass()); | 1476 SetFrameData(frame.Pass()); |
| 1476 break; | 1477 break; |
| 1477 case 3: | 1478 case 3: |
| 1478 // The now unused resource 555 should be returned. | 1479 // The now unused resource 555 should be returned. |
| 1479 resources.clear(); | 1480 resources.clear(); |
| 1480 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1481 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1481 { | 1482 { |
| 1482 unsigned expected[] = {555}; | 1483 unsigned expected[] = {555}; |
| 1483 EXPECT_RESOURCES(expected, resources); | 1484 EXPECT_RESOURCES(expected, resources); |
| 1484 EXPECT_TRUE(TestAndResetAvailable()); | 1485 EXPECT_TRUE(TestAndResetAvailable()); |
| 1485 } | 1486 } |
| 1486 EndTest(); | 1487 EndTest(); |
| 1487 break; | 1488 break; |
| 1488 } | 1489 } |
| 1489 } | 1490 } |
| 1490 | 1491 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1505 EXPECT_EQ(1u, map.count(555)); | 1506 EXPECT_EQ(1u, map.count(555)); |
| 1506 | 1507 |
| 1507 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1508 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
| 1508 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); | 1509 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
| 1509 } | 1510 } |
| 1510 | 1511 |
| 1511 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1512 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1512 bool result) OVERRIDE { | 1513 bool result) OVERRIDE { |
| 1513 ReturnUnusedResourcesFromParent(host_impl); | 1514 ReturnUnusedResourcesFromParent(host_impl); |
| 1514 } | 1515 } |
| 1515 | |
| 1516 virtual void AfterTest() OVERRIDE {} | |
| 1517 }; | 1516 }; |
| 1518 | 1517 |
| 1519 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource); | 1518 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource); |
| 1520 | 1519 |
| 1521 class LayerTreeHostDelegatedTestResourceSentToParent | 1520 class LayerTreeHostDelegatedTestResourceSentToParent |
| 1522 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1521 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1523 public: | 1522 public: |
| 1524 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1523 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1525 scoped_ptr<DelegatedFrameData> frame; | 1524 scoped_ptr<DelegatedFrameData> frame; |
| 1526 ReturnedResourceArray resources; | 1525 ReturnedResourceArray resources; |
| 1527 | 1526 |
| 1528 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1527 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1529 switch (next_source_frame_number) { | 1528 switch (next_source_frame_number) { |
| 1530 case 1: | 1529 case 1: |
| 1531 // This frame includes two resources in it. | 1530 // This frame includes two resources in it. |
| 1532 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1531 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1533 AddTextureQuad(frame.get(), 999); | 1532 AddTextureQuad(frame.get(), 999); |
| 1534 AddTransferableResource(frame.get(), 999); | 1533 AddTransferableResource(frame.get(), 999); |
| 1535 AddTextureQuad(frame.get(), 555); | 1534 AddTextureQuad(frame.get(), 555); |
| 1536 AddTransferableResource(frame.get(), 555); | 1535 AddTransferableResource(frame.get(), 555); |
| 1537 delegated_->SetFrameData(frame.Pass()); | 1536 SetFrameData(frame.Pass()); |
| 1538 break; | 1537 break; |
| 1539 case 2: | 1538 case 2: |
| 1540 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1539 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1541 EXPECT_EQ(0u, resources.size()); | 1540 EXPECT_EQ(0u, resources.size()); |
| 1542 EXPECT_FALSE(TestAndResetAvailable()); | 1541 EXPECT_FALSE(TestAndResetAvailable()); |
| 1543 | 1542 |
| 1544 // 999 is in use in the grandparent compositor, generate a frame without | 1543 // 999 is in use in the grandparent compositor, generate a frame without |
| 1545 // it present. | 1544 // it present. |
| 1546 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1545 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1547 AddTextureQuad(frame.get(), 555); | 1546 AddTextureQuad(frame.get(), 555); |
| 1548 AddTransferableResource(frame.get(), 555); | 1547 AddTransferableResource(frame.get(), 555); |
| 1549 delegated_->SetFrameData(frame.Pass()); | 1548 SetFrameData(frame.Pass()); |
| 1550 break; | 1549 break; |
| 1551 case 3: | 1550 case 3: |
| 1552 // Since 999 is in the grandparent it is not returned. | 1551 // Since 999 is in the grandparent it is not returned. |
| 1553 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1552 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1554 EXPECT_EQ(0u, resources.size()); | 1553 EXPECT_EQ(0u, resources.size()); |
| 1555 EXPECT_FALSE(TestAndResetAvailable()); | 1554 EXPECT_FALSE(TestAndResetAvailable()); |
| 1556 | 1555 |
| 1557 // The impl side will get back the resource at some point. | 1556 // The impl side will get back the resource at some point. |
| 1558 ImplThreadTaskRunner()->PostTask(FROM_HERE, | 1557 ImplThreadTaskRunner()->PostTask(FROM_HERE, |
| 1559 receive_resource_on_thread_); | 1558 receive_resource_on_thread_); |
| 1560 break; | 1559 break; |
| 1561 } | 1560 } |
| 1562 } | 1561 } |
| 1563 | 1562 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1576 host_impl->ReclaimResources(&ack); | 1575 host_impl->ReclaimResources(&ack); |
| 1577 host_impl->OnSwapBuffersComplete(); | 1576 host_impl->OnSwapBuffersComplete(); |
| 1578 } | 1577 } |
| 1579 | 1578 |
| 1580 virtual void UnusedResourcesAreAvailable() OVERRIDE { | 1579 virtual void UnusedResourcesAreAvailable() OVERRIDE { |
| 1581 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); | 1580 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); |
| 1582 | 1581 |
| 1583 ReturnedResourceArray resources; | 1582 ReturnedResourceArray resources; |
| 1584 | 1583 |
| 1585 // 999 was returned from the grandparent and could be released. | 1584 // 999 was returned from the grandparent and could be released. |
| 1586 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1585 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1587 { | 1586 { |
| 1588 unsigned expected[] = {999}; | 1587 unsigned expected[] = {999}; |
| 1589 EXPECT_RESOURCES(expected, resources); | 1588 EXPECT_RESOURCES(expected, resources); |
| 1590 } | 1589 } |
| 1591 | 1590 |
| 1592 EndTest(); | 1591 EndTest(); |
| 1593 } | 1592 } |
| 1594 | 1593 |
| 1595 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1594 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1596 if (host_impl->active_tree()->source_frame_number() < 1) | 1595 if (host_impl->active_tree()->source_frame_number() < 1) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 // 999 should be released. | 1636 // 999 should be released. |
| 1638 EXPECT_EQ(1u, map.size()); | 1637 EXPECT_EQ(1u, map.size()); |
| 1639 EXPECT_EQ(1u, map.count(555)); | 1638 EXPECT_EQ(1u, map.count(555)); |
| 1640 | 1639 |
| 1641 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1640 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
| 1642 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1641 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); |
| 1643 break; | 1642 break; |
| 1644 } | 1643 } |
| 1645 } | 1644 } |
| 1646 | 1645 |
| 1647 virtual void AfterTest() OVERRIDE {} | |
| 1648 | |
| 1649 base::Closure receive_resource_on_thread_; | 1646 base::Closure receive_resource_on_thread_; |
| 1650 }; | 1647 }; |
| 1651 | 1648 |
| 1652 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( | 1649 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( |
| 1653 LayerTreeHostDelegatedTestResourceSentToParent); | 1650 LayerTreeHostDelegatedTestResourceSentToParent); |
| 1654 | 1651 |
| 1655 class LayerTreeHostDelegatedTestCommitWithoutTake | 1652 class LayerTreeHostDelegatedTestCommitWithoutTake |
| 1656 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1653 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1657 public: | 1654 public: |
| 1658 virtual void BeginTest() OVERRIDE { | 1655 virtual void BeginTest() OVERRIDE { |
| 1659 // Prevent drawing with resources that are sent to the grandparent. | 1656 // Prevent drawing with resources that are sent to the grandparent. |
| 1660 layer_tree_host()->SetViewportSize(gfx::Size()); | 1657 layer_tree_host()->SetViewportSize(gfx::Size()); |
| 1661 PostSetNeedsCommitToMainThread(); | 1658 PostSetNeedsCommitToMainThread(); |
| 1662 } | 1659 } |
| 1663 | 1660 |
| 1664 virtual void DidCommit() OVERRIDE { | 1661 virtual void DidCommit() OVERRIDE { |
| 1665 scoped_ptr<DelegatedFrameData> frame; | 1662 scoped_ptr<DelegatedFrameData> frame; |
| 1666 ReturnedResourceArray resources; | 1663 ReturnedResourceArray resources; |
| 1667 | 1664 |
| 1668 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1665 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1669 switch (next_source_frame_number) { | 1666 switch (next_source_frame_number) { |
| 1670 case 1: | 1667 case 1: |
| 1671 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1668 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1672 AddTextureQuad(frame.get(), 999); | 1669 AddTextureQuad(frame.get(), 999); |
| 1673 AddTransferableResource(frame.get(), 999); | 1670 AddTransferableResource(frame.get(), 999); |
| 1674 AddTextureQuad(frame.get(), 555); | 1671 AddTextureQuad(frame.get(), 555); |
| 1675 AddTransferableResource(frame.get(), 555); | 1672 AddTransferableResource(frame.get(), 555); |
| 1676 AddTextureQuad(frame.get(), 444); | 1673 AddTextureQuad(frame.get(), 444); |
| 1677 AddTransferableResource(frame.get(), 444); | 1674 AddTransferableResource(frame.get(), 444); |
| 1678 delegated_->SetFrameData(frame.Pass()); | 1675 SetFrameData(frame.Pass()); |
| 1679 break; | 1676 break; |
| 1680 case 2: | 1677 case 2: |
| 1681 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1678 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1682 EXPECT_EQ(0u, resources.size()); | 1679 EXPECT_EQ(0u, resources.size()); |
| 1683 EXPECT_FALSE(TestAndResetAvailable()); | 1680 EXPECT_FALSE(TestAndResetAvailable()); |
| 1684 | 1681 |
| 1685 // Stop using 999 and 444 in this frame and commit. | 1682 // Stop using 999 and 444 in this frame and commit. |
| 1686 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1683 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1687 AddTextureQuad(frame.get(), 555); | 1684 AddTextureQuad(frame.get(), 555); |
| 1688 AddTransferableResource(frame.get(), 555); | 1685 AddTransferableResource(frame.get(), 555); |
| 1689 delegated_->SetFrameData(frame.Pass()); | 1686 SetFrameData(frame.Pass()); |
| 1690 // 999 and 444 will be returned for frame 1, but not 555 since it's in | 1687 // 999 and 444 will be returned for frame 1, but not 555 since it's in |
| 1691 // the current frame. | 1688 // the current frame. |
| 1692 break; | 1689 break; |
| 1693 case 3: | 1690 case 3: |
| 1694 // Don't take resources here, but set a new frame that uses 999 again. | 1691 // Don't take resources here, but set a new frame that uses 999 again. |
| 1695 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1692 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1696 AddTextureQuad(frame.get(), 999); | 1693 AddTextureQuad(frame.get(), 999); |
| 1697 AddTransferableResource(frame.get(), 999); | 1694 AddTransferableResource(frame.get(), 999); |
| 1698 AddTextureQuad(frame.get(), 555); | 1695 AddTextureQuad(frame.get(), 555); |
| 1699 AddTransferableResource(frame.get(), 555); | 1696 AddTransferableResource(frame.get(), 555); |
| 1700 delegated_->SetFrameData(frame.Pass()); | 1697 SetFrameData(frame.Pass()); |
| 1701 break; | 1698 break; |
| 1702 case 4: | 1699 case 4: |
| 1703 // 555 from frame 1 and 2 isn't returned since it's still in use. 999 | 1700 // 555 from frame 1 and 2 isn't returned since it's still in use. 999 |
| 1704 // from frame 1 is returned though. | 1701 // from frame 1 is returned though. |
| 1705 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1702 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1706 { | 1703 { |
| 1707 unsigned expected[] = {444, 999}; | 1704 unsigned expected[] = {444, 999}; |
| 1708 EXPECT_RESOURCES(expected, resources); | 1705 EXPECT_RESOURCES(expected, resources); |
| 1709 EXPECT_TRUE(TestAndResetAvailable()); | 1706 EXPECT_TRUE(TestAndResetAvailable()); |
| 1710 } | 1707 } |
| 1711 | 1708 |
| 1712 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1709 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1713 delegated_->SetFrameData(frame.Pass()); | 1710 SetFrameData(frame.Pass()); |
| 1714 // 555 will be returned 3 times for frames 1 2 and 3, and 999 will be | 1711 // 555 will be returned 3 times for frames 1 2 and 3, and 999 will be |
| 1715 // returned once for frame 3. | 1712 // returned once for frame 3. |
| 1716 break; | 1713 break; |
| 1717 case 5: | 1714 case 5: |
| 1718 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1715 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1719 { | 1716 { |
| 1720 unsigned expected[] = {555, 555, 555, 999}; | 1717 unsigned expected[] = {555, 555, 555, 999}; |
| 1721 EXPECT_RESOURCES(expected, resources); | 1718 EXPECT_RESOURCES(expected, resources); |
| 1722 EXPECT_TRUE(TestAndResetAvailable()); | 1719 EXPECT_TRUE(TestAndResetAvailable()); |
| 1723 } | 1720 } |
| 1724 | 1721 |
| 1725 EndTest(); | 1722 EndTest(); |
| 1726 break; | 1723 break; |
| 1727 } | 1724 } |
| 1728 } | 1725 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 case 3: | 1758 case 3: |
| 1762 EXPECT_EQ(2u, map.size()); | 1759 EXPECT_EQ(2u, map.size()); |
| 1763 EXPECT_EQ(1u, map.count(999)); | 1760 EXPECT_EQ(1u, map.count(999)); |
| 1764 EXPECT_EQ(1u, map.count(555)); | 1761 EXPECT_EQ(1u, map.count(555)); |
| 1765 | 1762 |
| 1766 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 1763 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
| 1767 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); | 1764 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
| 1768 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); | 1765 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
| 1769 } | 1766 } |
| 1770 } | 1767 } |
| 1771 | |
| 1772 virtual void AfterTest() OVERRIDE {} | |
| 1773 }; | 1768 }; |
| 1774 | 1769 |
| 1775 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); | 1770 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); |
| 1776 | 1771 |
| 1777 class DelegatedFrameIsActivatedDuringCommit | 1772 class DelegatedFrameIsActivatedDuringCommit |
| 1778 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1773 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1779 protected: | 1774 protected: |
| 1780 DelegatedFrameIsActivatedDuringCommit() | 1775 DelegatedFrameIsActivatedDuringCommit() |
| 1781 : wait_thread_("WAIT"), | 1776 : wait_thread_("WAIT"), |
| 1782 wait_event_(false, false) { | 1777 wait_event_(false, false) { |
| 1783 wait_thread_.Start(); | 1778 wait_thread_.Start(); |
| 1784 } | 1779 } |
| 1785 | 1780 |
| 1786 virtual void BeginTest() OVERRIDE { | 1781 virtual void BeginTest() OVERRIDE { |
| 1787 activate_count_ = 0; | 1782 activate_count_ = 0; |
| 1788 | 1783 |
| 1789 scoped_ptr<DelegatedFrameData> frame = | 1784 scoped_ptr<DelegatedFrameData> frame = |
| 1790 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1785 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1791 AddTextureQuad(frame.get(), 999); | 1786 AddTextureQuad(frame.get(), 999); |
| 1792 AddTransferableResource(frame.get(), 999); | 1787 AddTransferableResource(frame.get(), 999); |
| 1793 delegated_->SetFrameData(frame.Pass()); | 1788 SetFrameData(frame.Pass()); |
| 1794 | 1789 |
| 1795 PostSetNeedsCommitToMainThread(); | 1790 PostSetNeedsCommitToMainThread(); |
| 1796 } | 1791 } |
| 1797 | 1792 |
| 1798 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1793 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1799 // Slow down activation so the main thread DidCommit() will run if | 1794 // Slow down activation so the main thread DidCommit() will run if |
| 1800 // not blocked. | 1795 // not blocked. |
| 1801 wait_thread_.message_loop()->PostDelayedTask( | 1796 wait_thread_.message_loop()->PostDelayedTask( |
| 1802 FROM_HERE, | 1797 FROM_HERE, |
| 1803 base::Bind(&base::WaitableEvent::Signal, | 1798 base::Bind(&base::WaitableEvent::Signal, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1821 void DidActivate() { | 1816 void DidActivate() { |
| 1822 base::AutoLock lock(activate_lock_); | 1817 base::AutoLock lock(activate_lock_); |
| 1823 switch (activate_count_) { | 1818 switch (activate_count_) { |
| 1824 case 1: { | 1819 case 1: { |
| 1825 // The first frame has been activated. Set a new frame, and | 1820 // The first frame has been activated. Set a new frame, and |
| 1826 // expect the next commit to finish *after* it is activated. | 1821 // expect the next commit to finish *after* it is activated. |
| 1827 scoped_ptr<DelegatedFrameData> frame = | 1822 scoped_ptr<DelegatedFrameData> frame = |
| 1828 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1823 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1829 AddTextureQuad(frame.get(), 555); | 1824 AddTextureQuad(frame.get(), 555); |
| 1830 AddTransferableResource(frame.get(), 555); | 1825 AddTransferableResource(frame.get(), 555); |
| 1831 delegated_->SetFrameData(frame.Pass()); | 1826 SetFrameData(frame.Pass()); |
| 1832 // So this commit number should complete after the second activate. | 1827 // So this commit number should complete after the second activate. |
| 1833 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | 1828 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); |
| 1834 break; | 1829 break; |
| 1835 } | 1830 } |
| 1836 case 2: | 1831 case 2: |
| 1837 // The second frame has been activated. Remove the layer from | 1832 // The second frame has been activated. Remove the layer from |
| 1838 // the tree to cause another commit/activation. The commit should | 1833 // the tree to cause another commit/activation. The commit should |
| 1839 // finish *after* the layer is removed from the active tree. | 1834 // finish *after* the layer is removed from the active tree. |
| 1840 delegated_->RemoveFromParent(); | 1835 delegated_->RemoveFromParent(); |
| 1841 // So this commit number should complete after the third activate. | 1836 // So this commit number should complete after the third activate. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1852 case 2: { | 1847 case 2: { |
| 1853 // The activate for the 2nd frame should have happened before now. | 1848 // The activate for the 2nd frame should have happened before now. |
| 1854 base::AutoLock lock(activate_lock_); | 1849 base::AutoLock lock(activate_lock_); |
| 1855 EXPECT_EQ(2, activate_count_); | 1850 EXPECT_EQ(2, activate_count_); |
| 1856 break; | 1851 break; |
| 1857 } | 1852 } |
| 1858 case 3: { | 1853 case 3: { |
| 1859 // The activate to remove the layer should have happened before now. | 1854 // The activate to remove the layer should have happened before now. |
| 1860 base::AutoLock lock(activate_lock_); | 1855 base::AutoLock lock(activate_lock_); |
| 1861 EXPECT_EQ(3, activate_count_); | 1856 EXPECT_EQ(3, activate_count_); |
| 1857 |
| 1858 ReturnedResourceArray resources; |
| 1859 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1860 { |
| 1861 unsigned expected[] = {999, 555}; |
| 1862 EXPECT_RESOURCES(expected, resources); |
| 1863 EXPECT_TRUE(TestAndResetAvailable()); |
| 1864 } |
| 1862 break; | 1865 break; |
| 1863 } | 1866 } |
| 1864 } | 1867 } |
| 1865 } | 1868 } |
| 1866 | 1869 |
| 1867 | |
| 1868 virtual void AfterTest() OVERRIDE {} | |
| 1869 | |
| 1870 base::Thread wait_thread_; | 1870 base::Thread wait_thread_; |
| 1871 base::WaitableEvent wait_event_; | 1871 base::WaitableEvent wait_event_; |
| 1872 base::Lock activate_lock_; | 1872 base::Lock activate_lock_; |
| 1873 int activate_count_; | 1873 int activate_count_; |
| 1874 }; | 1874 }; |
| 1875 | 1875 |
| 1876 SINGLE_AND_MULTI_THREAD_TEST_F( | 1876 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1877 DelegatedFrameIsActivatedDuringCommit); | 1877 DelegatedFrameIsActivatedDuringCommit); |
| 1878 | 1878 |
| 1879 class LayerTreeHostDelegatedTestTwoImplLayers |
| 1880 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1881 public: |
| 1882 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1883 |
| 1884 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1885 scoped_ptr<DelegatedFrameData> frame; |
| 1886 ReturnedResourceArray resources; |
| 1887 |
| 1888 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1889 switch (next_source_frame_number) { |
| 1890 case 1: |
| 1891 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1892 AddTextureQuad(frame.get(), 999); |
| 1893 AddTransferableResource(frame.get(), 999); |
| 1894 AddTextureQuad(frame.get(), 555); |
| 1895 AddTransferableResource(frame.get(), 555); |
| 1896 SetFrameData(frame.Pass()); |
| 1897 break; |
| 1898 case 2: |
| 1899 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1900 EXPECT_EQ(0u, resources.size()); |
| 1901 EXPECT_FALSE(TestAndResetAvailable()); |
| 1902 |
| 1903 // Remove the delegated layer and replace it with a new one. Use the |
| 1904 // same frame and resources for it. |
| 1905 delegated_->RemoveFromParent(); |
| 1906 delegated_ = CreateDelegatedLayer(frame_provider_.get()); |
| 1907 break; |
| 1908 case 3: |
| 1909 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1910 EXPECT_EQ(0u, resources.size()); |
| 1911 EXPECT_FALSE(TestAndResetAvailable()); |
| 1912 |
| 1913 // Use a frame with no resources in it. |
| 1914 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1915 SetFrameData(frame.Pass()); |
| 1916 break; |
| 1917 case 4: |
| 1918 // We gave one frame to the frame provider, so we should get one |
| 1919 // ref back for each resource. |
| 1920 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1921 { |
| 1922 unsigned expected[] = {555, 999}; |
| 1923 EXPECT_RESOURCES(expected, resources); |
| 1924 EXPECT_TRUE(TestAndResetAvailable()); |
| 1925 } |
| 1926 EndTest(); |
| 1927 break; |
| 1928 } |
| 1929 } |
| 1930 |
| 1931 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 1932 bool result) OVERRIDE { |
| 1933 ReturnUnusedResourcesFromParent(host_impl); |
| 1934 } |
| 1935 }; |
| 1936 |
| 1937 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestTwoImplLayers); |
| 1938 |
| 1939 class LayerTreeHostDelegatedTestTwoImplLayersTwoFrames |
| 1940 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 1941 public: |
| 1942 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1943 |
| 1944 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1945 scoped_ptr<DelegatedFrameData> frame; |
| 1946 ReturnedResourceArray resources; |
| 1947 |
| 1948 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 1949 switch (next_source_frame_number) { |
| 1950 case 1: |
| 1951 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1952 AddTextureQuad(frame.get(), 999); |
| 1953 AddTransferableResource(frame.get(), 999); |
| 1954 AddTextureQuad(frame.get(), 555); |
| 1955 AddTransferableResource(frame.get(), 555); |
| 1956 SetFrameData(frame.Pass()); |
| 1957 break; |
| 1958 case 2: |
| 1959 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1960 EXPECT_EQ(0u, resources.size()); |
| 1961 EXPECT_FALSE(TestAndResetAvailable()); |
| 1962 |
| 1963 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1964 AddTextureQuad(frame.get(), 999); |
| 1965 AddTransferableResource(frame.get(), 999); |
| 1966 AddTextureQuad(frame.get(), 555); |
| 1967 AddTransferableResource(frame.get(), 555); |
| 1968 |
| 1969 // Remove the delegated layer and replace it with a new one. Make a new |
| 1970 // frame but with the same resources for it. |
| 1971 delegated_->RemoveFromParent(); |
| 1972 delegated_ = NULL; |
| 1973 |
| 1974 frame_provider_->SetFrameData(frame.Pass()); |
| 1975 delegated_ = CreateDelegatedLayer(frame_provider_.get()); |
| 1976 break; |
| 1977 case 3: |
| 1978 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1979 EXPECT_EQ(0u, resources.size()); |
| 1980 EXPECT_FALSE(TestAndResetAvailable()); |
| 1981 |
| 1982 // Use a frame with no resources in it. |
| 1983 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 1984 SetFrameData(frame.Pass()); |
| 1985 break; |
| 1986 case 4: |
| 1987 // We gave two frames to the frame provider, so we should get two |
| 1988 // refs back for each resource. |
| 1989 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1990 { |
| 1991 unsigned expected[] = {555, 555, 999, 999}; |
| 1992 EXPECT_RESOURCES(expected, resources); |
| 1993 EXPECT_TRUE(TestAndResetAvailable()); |
| 1994 } |
| 1995 EndTest(); |
| 1996 break; |
| 1997 } |
| 1998 } |
| 1999 |
| 2000 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 2001 bool result) OVERRIDE { |
| 2002 ReturnUnusedResourcesFromParent(host_impl); |
| 2003 } |
| 2004 }; |
| 2005 |
| 2006 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 2007 LayerTreeHostDelegatedTestTwoImplLayersTwoFrames); |
| 2008 |
| 2009 class LayerTreeHostDelegatedTestTwoLayers |
| 2010 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 2011 public: |
| 2012 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 2013 |
| 2014 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 2015 scoped_ptr<DelegatedFrameData> frame; |
| 2016 ReturnedResourceArray resources; |
| 2017 |
| 2018 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 2019 switch (next_source_frame_number) { |
| 2020 case 1: |
| 2021 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 2022 AddTextureQuad(frame.get(), 999); |
| 2023 AddTransferableResource(frame.get(), 999); |
| 2024 AddTextureQuad(frame.get(), 555); |
| 2025 AddTransferableResource(frame.get(), 555); |
| 2026 |
| 2027 // Create a DelegatedRendererLayer using the frame. |
| 2028 SetFrameData(frame.Pass()); |
| 2029 |
| 2030 // Create a second DelegatedRendererLayer using the same frame provider. |
| 2031 delegated_thief_ = CreateDelegatedLayer(frame_provider_.get()); |
| 2032 break; |
| 2033 case 2: |
| 2034 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2035 EXPECT_EQ(0u, resources.size()); |
| 2036 EXPECT_FALSE(TestAndResetAvailable()); |
| 2037 |
| 2038 // Remove one delegated layer from the tree. No resources should be |
| 2039 // returned yet. |
| 2040 delegated_->RemoveFromParent(); |
| 2041 break; |
| 2042 case 3: |
| 2043 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2044 EXPECT_EQ(0u, resources.size()); |
| 2045 EXPECT_FALSE(TestAndResetAvailable()); |
| 2046 |
| 2047 // Put the first layer back, and remove the other layer. No resources |
| 2048 // should be returned yet. |
| 2049 root_->AddChild(delegated_); |
| 2050 delegated_thief_->RemoveFromParent(); |
| 2051 break; |
| 2052 case 4: |
| 2053 // Removing both layers from the tree should cause resources to be |
| 2054 // returned. |
| 2055 delegated_->RemoveFromParent(); |
| 2056 break; |
| 2057 case 5: |
| 2058 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2059 { |
| 2060 unsigned expected[] = {555, 999}; |
| 2061 EXPECT_RESOURCES(expected, resources); |
| 2062 EXPECT_TRUE(TestAndResetAvailable()); |
| 2063 } |
| 2064 EndTest(); |
| 2065 break; |
| 2066 } |
| 2067 } |
| 2068 |
| 2069 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 2070 bool result) OVERRIDE { |
| 2071 ReturnUnusedResourcesFromParent(host_impl); |
| 2072 } |
| 2073 |
| 2074 scoped_refptr<DelegatedRendererLayer> delegated_thief_; |
| 2075 }; |
| 2076 |
| 2077 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestTwoLayers); |
| 2078 |
| 2079 class LayerTreeHostDelegatedTestTwoLayersAfterCommit |
| 2080 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 2081 public: |
| 2082 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 2083 |
| 2084 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 2085 scoped_ptr<DelegatedFrameData> frame; |
| 2086 ReturnedResourceArray resources; |
| 2087 |
| 2088 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
| 2089 switch (next_source_frame_number) { |
| 2090 case 1: |
| 2091 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 2092 AddTextureQuad(frame.get(), 999); |
| 2093 AddTransferableResource(frame.get(), 999); |
| 2094 AddTextureQuad(frame.get(), 555); |
| 2095 AddTransferableResource(frame.get(), 555); |
| 2096 |
| 2097 // Create a DelegatedRendererLayer using the frame. |
| 2098 SetFrameData(frame.Pass()); |
| 2099 break; |
| 2100 case 2: |
| 2101 // Once the first layer is happily using the frame provider, make |
| 2102 // another layer steal it. |
| 2103 delegated_thief_ = CreateDelegatedLayer(frame_provider_.get()); |
| 2104 break; |
| 2105 case 3: |
| 2106 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2107 EXPECT_EQ(0u, resources.size()); |
| 2108 EXPECT_FALSE(TestAndResetAvailable()); |
| 2109 |
| 2110 // Remove one delegated layer from the tree. No resources should be |
| 2111 // returned yet. |
| 2112 delegated_->RemoveFromParent(); |
| 2113 break; |
| 2114 case 4: |
| 2115 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2116 EXPECT_EQ(0u, resources.size()); |
| 2117 EXPECT_FALSE(TestAndResetAvailable()); |
| 2118 |
| 2119 // Put the first layer back, and remove the other layer. No resources |
| 2120 // should be returned yet. |
| 2121 root_->AddChild(delegated_); |
| 2122 delegated_thief_->RemoveFromParent(); |
| 2123 break; |
| 2124 case 5: |
| 2125 // Removing both layers from the tree should cause resources to be |
| 2126 // returned. |
| 2127 delegated_->RemoveFromParent(); |
| 2128 break; |
| 2129 case 6: |
| 2130 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); |
| 2131 { |
| 2132 unsigned expected[] = {555, 999}; |
| 2133 EXPECT_RESOURCES(expected, resources); |
| 2134 EXPECT_TRUE(TestAndResetAvailable()); |
| 2135 } |
| 2136 EndTest(); |
| 2137 break; |
| 2138 } |
| 2139 } |
| 2140 |
| 2141 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 2142 bool result) OVERRIDE { |
| 2143 ReturnUnusedResourcesFromParent(host_impl); |
| 2144 } |
| 2145 |
| 2146 scoped_refptr<DelegatedRendererLayer> delegated_thief_; |
| 2147 }; |
| 2148 |
| 2149 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestTwoLayersAfterCommit); |
| 2150 |
| 1879 } // namespace | 2151 } // namespace |
| 1880 } // namespace cc | 2152 } // namespace cc |
| OLD | NEW |