1 // Copyright 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "cc/trees/layer_tree_impl.h" 6 7 #include "base/debug/trace_event.h" 8 #include "cc/animation/keyframed_animation_curve.h" 9 #include "cc/animation/scrollbar_animation_controller.h" 10 #include "cc/debug/traced_value.h" 11 #include "cc/layers/heads_up_display_layer_impl.h" 12 #include "cc/layers/render_surface_impl.h" 13 #include "cc/layers/scrollbar_layer_impl.h" 14 #include "cc/trees/layer_tree_host_common.h" 15 #include "cc/trees/layer_tree_host_impl.h" 16 #include "ui/gfx/size_conversions.h" 17 #include "ui/gfx/vector2d_conversions.h" 18 19 namespace cc { 20 21 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) 22 : layer_tree_host_impl_(layer_tree_host_impl), 23 source_frame_number_(-1), 24 hud_layer_(0), 25 root_scroll_layer_(NULL), 26 currently_scrolling_layer_(NULL), 27 root_layer_scroll_offset_delegate_(NULL), 28 background_color_(0), 29 has_transparent_background_(false), 30 page_scale_factor_(1), 31 page_scale_delta_(1), 32 sent_page_scale_delta_(1), 33 min_page_scale_factor_(0), 34 max_page_scale_factor_(0), 35 scrolling_layer_id_from_previous_tree_(0), 36 contents_textures_purged_(false), 37 viewport_size_invalid_(false), 38 needs_update_draw_properties_(true), 39 needs_full_tree_sync_(true) { 40 } 41 42 LayerTreeImpl::~LayerTreeImpl() { 43 // Need to explicitly clear the tree prior to destroying this so that 44 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. 45 root_layer_.reset(); 46 } 47 48 static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) { 49 if (!layer) 50 return NULL; 51 52 if (layer->scrollable()) 53 return layer; 54 55 for (size_t i = 0; i < layer->children().size(); ++i) { 56 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]); 57 if (found) 58 return found; 59 } 60 61 return NULL; 62 } 63 64 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { 65 if (root_scroll_layer_) 66 root_scroll_layer_->SetScrollOffsetDelegate(NULL); 67 root_layer_ = layer.Pass(); 68 currently_scrolling_layer_ = NULL; 69 root_scroll_layer_ = NULL; 70 71 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 72 } 73 74 void LayerTreeImpl::FindRootScrollLayer() { 75 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get()); 76 77 if (root_scroll_layer_) { 78 UpdateMaxScrollOffset(); 79 root_scroll_layer_->SetScrollOffsetDelegate( 80 root_layer_scroll_offset_delegate_); 81 } 82 83 if (scrolling_layer_id_from_previous_tree_) { 84 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( 85 root_layer_.get(), 86 scrolling_layer_id_from_previous_tree_); 87 } 88 89 scrolling_layer_id_from_previous_tree_ = 0; 90 } 91 92 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { 93 // Clear all data structures that have direct references to the layer tree. 94 scrolling_layer_id_from_previous_tree_ = 95 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; 96 if (root_scroll_layer_) 97 root_scroll_layer_->SetScrollOffsetDelegate(NULL); 98 root_scroll_layer_ = NULL; 99 currently_scrolling_layer_ = NULL; 100 101 render_surface_layer_list_.clear(); 102 set_needs_update_draw_properties(); 103 return root_layer_.Pass(); 104 } 105 106 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { 107 // The request queue should have been processed and does not require a push. 108 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); 109 110 target_tree->SetLatencyInfo(latency_info_); 111 latency_info_.Clear(); 112 target_tree->SetPageScaleFactorAndLimits( 113 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor()); 114 target_tree->SetPageScaleDelta( 115 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta()); 116 target_tree->set_sent_page_scale_delta(1); 117 118 // This should match the property synchronization in 119 // LayerTreeHost::finishCommitOnImplThread(). 120 target_tree->set_source_frame_number(source_frame_number()); 121 target_tree->set_background_color(background_color()); 122 target_tree->set_has_transparent_background(has_transparent_background()); 123 124 if (ContentsTexturesPurged()) 125 target_tree->SetContentsTexturesPurged(); 126 else 127 target_tree->ResetContentsTexturesPurged(); 128 129 if (ViewportSizeInvalid()) 130 target_tree->SetViewportSizeInvalid(); 131 else 132 target_tree->ResetViewportSizeInvalid(); 133 134 if (hud_layer()) 135 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( 136 LayerTreeHostCommon::FindLayerInSubtree( 137 target_tree->root_layer(), hud_layer()->id()))); 138 else 139 target_tree->set_hud_layer(NULL); 140 } 141 142 LayerImpl* LayerTreeImpl::RootScrollLayer() const { 143 return root_scroll_layer_; 144 } 145 146 LayerImpl* LayerTreeImpl::RootContainerLayer() const { 147 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; 148 } 149 150 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { 151 DCHECK(IsActiveTree()); 152 return currently_scrolling_layer_; 153 } 154 155 void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { 156 if (currently_scrolling_layer_ == layer) 157 return; 158 159 if (currently_scrolling_layer_ && 160 currently_scrolling_layer_->scrollbar_animation_controller()) 161 currently_scrolling_layer_->scrollbar_animation_controller()-> 162 DidScrollGestureEnd(CurrentPhysicalTimeTicks()); 163 currently_scrolling_layer_ = layer; 164 if (layer && layer->scrollbar_animation_controller()) 165 layer->scrollbar_animation_controller()->DidScrollGestureBegin(); 166 } 167 168 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { 169 SetCurrentlyScrollingLayer(NULL); 170 scrolling_layer_id_from_previous_tree_ = 0; 171 } 172 173 void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, 174 float min_page_scale_factor, float max_page_scale_factor) { 175 if (!page_scale_factor) 176 return; 177 178 min_page_scale_factor_ = min_page_scale_factor; 179 max_page_scale_factor_ = max_page_scale_factor; 180 page_scale_factor_ = page_scale_factor; 181 182 if (root_layer_scroll_offset_delegate_) { 183 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( 184 total_page_scale_factor()); 185 } 186 } 187 188 void LayerTreeImpl::SetPageScaleDelta(float delta) { 189 // Clamp to the current min/max limits. 190 float total = page_scale_factor_ * delta; 191 if (min_page_scale_factor_ && total < min_page_scale_factor_) 192 delta = min_page_scale_factor_ / page_scale_factor_; 193 else if (max_page_scale_factor_ && total > max_page_scale_factor_) 194 delta = max_page_scale_factor_ / page_scale_factor_; 195 196 if (delta == page_scale_delta_) 197 return; 198 199 page_scale_delta_ = delta; 200 201 if (IsActiveTree()) { 202 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); 203 if (pending_tree) { 204 DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); 205 pending_tree->SetPageScaleDelta( 206 page_scale_delta_ / sent_page_scale_delta_); 207 } 208 } 209 210 UpdateMaxScrollOffset(); 211 set_needs_update_draw_properties(); 212 213 if (root_layer_scroll_offset_delegate_) { 214 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( 215 total_page_scale_factor()); 216 } 217 } 218 219 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { 220 return gfx::ScaleSize(layer_tree_host_impl_->UnscaledScrollableViewportSize(), 221 1.0f / total_page_scale_factor()); 222 } 223 224 void LayerTreeImpl::UpdateMaxScrollOffset() { 225 LayerImpl* root_scroll = RootScrollLayer(); 226 if (!root_scroll || !root_scroll->children().size()) 227 return; 228 229 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - 230 gfx::RectF(ScrollableViewportSize()).bottom_right(); 231 232 // The viewport may be larger than the contents in some cases, such as 233 // having a vertical scrollbar but no horizontal overflow. 234 max_scroll.SetToMax(gfx::Vector2dF()); 235 236 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); 237 } 238 239 static void ApplySentScrollDeltasOn(LayerImpl* layer) { 240 layer->ApplySentScrollDeltas(); 241 } 242 243 void LayerTreeImpl::ApplySentScrollAndScaleDeltas() { 244 DCHECK(IsActiveTree()); 245 246 page_scale_factor_ *= sent_page_scale_delta_; 247 page_scale_delta_ /= sent_page_scale_delta_; 248 sent_page_scale_delta_ = 1.f; 249 250 if (!root_layer()) 251 return; 252 253 LayerTreeHostCommon::CallFunctionForSubtree( 254 root_layer(), base::Bind(&ApplySentScrollDeltasOn)); 255 } 256 257 void LayerTreeImpl::UpdateSolidColorScrollbars() { 258 DCHECK(settings().solid_color_scrollbars); 259 260 LayerImpl* root_scroll = RootScrollLayer(); 261 DCHECK(root_scroll); 262 DCHECK(IsActiveTree()); 263 264 gfx::RectF scrollable_viewport( 265 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()), 266 ScrollableViewportSize()); 267 float vertical_adjust = 0.0f; 268 if (RootContainerLayer()) 269 vertical_adjust = 270 layer_tree_host_impl_->UnscaledScrollableViewportSize().height() - 271 RootContainerLayer()->bounds().height(); 272 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) { 273 horiz->SetVerticalAdjust(vertical_adjust); 274 horiz->SetVisibleToTotalLengthRatio( 275 scrollable_viewport.width() / ScrollableSize().width()); 276 } 277 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { 278 vertical->SetVerticalAdjust(vertical_adjust); 279 vertical->SetVisibleToTotalLengthRatio( 280 scrollable_viewport.height() / ScrollableSize().height()); 281 } 282 } 283 284 void LayerTreeImpl::UpdateDrawProperties() { 285 if (IsActiveTree() && RootScrollLayer() && RootContainerLayer()) 286 UpdateRootScrollLayerSizeDelta(); 287 288 if (settings().solid_color_scrollbars && 289 IsActiveTree() && 290 RootScrollLayer()) { 291 UpdateSolidColorScrollbars(); 292 } 293 294 needs_update_draw_properties_ = false; 295 render_surface_layer_list_.clear(); 296 297 // For max_texture_size. 298 if (!layer_tree_host_impl_->renderer()) 299 return; 300 301 if (!root_layer()) 302 return; 303 304 { 305 TRACE_EVENT2("cc", 306 "LayerTreeImpl::UpdateDrawProperties", 307 "IsActive", 308 IsActiveTree(), 309 "SourceFrameNumber", 310 source_frame_number_); 311 bool can_render_to_separate_surface = 312 !output_surface()->ForcedDrawToSoftwareDevice(); 313 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( 314 root_layer(), 315 layer_tree_host_impl_->DeviceViewport().size(), 316 layer_tree_host_impl_->DeviceTransform(), 317 device_scale_factor(), 318 total_page_scale_factor(), 319 root_scroll_layer_ ? root_scroll_layer_->parent() : NULL, 320 MaxTextureSize(), 321 settings().can_use_lcd_text, 322 can_render_to_separate_surface, 323 settings().layer_transforms_should_scale_layer_contents, 324 layer_tree_host_impl_->device_viewport_valid_for_tile_management(), 325 &render_surface_layer_list_); 326 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 327 } 328 329 DCHECK(!needs_update_draw_properties_) << 330 "CalcDrawProperties should not set_needs_update_draw_properties()"; 331 } 332 333 const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { 334 // If this assert triggers, then the list is dirty. 335 DCHECK(!needs_update_draw_properties_); 336 return render_surface_layer_list_; 337 } 338 339 gfx::Size LayerTreeImpl::ScrollableSize() const { 340 if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) 341 return gfx::Size(); 342 return root_scroll_layer_->children()[0]->bounds(); 343 } 344 345 LayerImpl* LayerTreeImpl::LayerById(int id) { 346 LayerIdMap::iterator iter = layer_id_map_.find(id); 347 return iter != layer_id_map_.end() ? iter->second : NULL; 348 } 349 350 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { 351 DCHECK(!LayerById(layer->id())); 352 layer_id_map_[layer->id()] = layer; 353 } 354 355 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { 356 DCHECK(LayerById(layer->id())); 357 layer_id_map_.erase(layer->id()); 358 } 359 360 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { 361 pending_tree->SetCurrentlyScrollingLayer( 362 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), 363 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); 364 pending_tree->SetLatencyInfo(latency_info_); 365 latency_info_.Clear(); 366 } 367 368 static void DidBecomeActiveRecursive(LayerImpl* layer) { 369 layer->DidBecomeActive(); 370 for (size_t i = 0; i < layer->children().size(); ++i) 371 DidBecomeActiveRecursive(layer->children()[i]); 372 } 373 374 void LayerTreeImpl::DidBecomeActive() { 375 if (!root_layer()) 376 return; 377 378 DidBecomeActiveRecursive(root_layer()); 379 FindRootScrollLayer(); 380 } 381 382 bool LayerTreeImpl::ContentsTexturesPurged() const { 383 return contents_textures_purged_; 384 } 385 386 void LayerTreeImpl::SetContentsTexturesPurged() { 387 if (contents_textures_purged_) 388 return; 389 contents_textures_purged_ = true; 390 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 391 } 392 393 void LayerTreeImpl::ResetContentsTexturesPurged() { 394 if (!contents_textures_purged_) 395 return; 396 contents_textures_purged_ = false; 397 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 398 } 399 400 bool LayerTreeImpl::ViewportSizeInvalid() const { 401 return viewport_size_invalid_; 402 } 403 404 void LayerTreeImpl::SetViewportSizeInvalid() { 405 viewport_size_invalid_ = true; 406 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 407 } 408 409 void LayerTreeImpl::ResetViewportSizeInvalid() { 410 viewport_size_invalid_ = false; 411 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 412 } 413 414 Proxy* LayerTreeImpl::proxy() const { 415 return layer_tree_host_impl_->proxy(); 416 } 417 418 const LayerTreeSettings& LayerTreeImpl::settings() const { 419 return layer_tree_host_impl_->settings(); 420 } 421 422 const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const { 423 return layer_tree_host_impl_->GetRendererCapabilities(); 424 } 425 426 OutputSurface* LayerTreeImpl::output_surface() const { 427 return layer_tree_host_impl_->output_surface(); 428 } 429 430 ResourceProvider* LayerTreeImpl::resource_provider() const { 431 return layer_tree_host_impl_->resource_provider(); 432 } 433 434 TileManager* LayerTreeImpl::tile_manager() const { 435 return layer_tree_host_impl_->tile_manager(); 436 } 437 438 FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { 439 return layer_tree_host_impl_->fps_counter(); 440 } 441 442 PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { 443 return layer_tree_host_impl_->paint_time_counter(); 444 } 445 446 MemoryHistory* LayerTreeImpl::memory_history() const { 447 return layer_tree_host_impl_->memory_history(); 448 } 449 450 bool LayerTreeImpl::IsActiveTree() const { 451 return layer_tree_host_impl_->active_tree() == this; 452 } 453 454 bool LayerTreeImpl::IsPendingTree() const { 455 return layer_tree_host_impl_->pending_tree() == this; 456 } 457 458 bool LayerTreeImpl::IsRecycleTree() const { 459 return layer_tree_host_impl_->recycle_tree() == this; 460 } 461 462 LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { 463 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); 464 if (!tree) 465 return NULL; 466 return tree->LayerById(id); 467 } 468 469 LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { 470 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); 471 if (!tree) 472 return NULL; 473 return tree->LayerById(id); 474 } 475 476 int LayerTreeImpl::MaxTextureSize() const { 477 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; 478 } 479 480 bool LayerTreeImpl::PinchGestureActive() const { 481 return layer_tree_host_impl_->pinch_gesture_active(); 482 } 483 484 base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const { 485 return layer_tree_host_impl_->CurrentFrameTimeTicks(); 486 } 487 488 base::Time LayerTreeImpl::CurrentFrameTime() const { 489 return layer_tree_host_impl_->CurrentFrameTime(); 490 } 491 492 base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const { 493 return layer_tree_host_impl_->CurrentPhysicalTimeTicks(); 494 } 495 496 void LayerTreeImpl::SetNeedsCommit() { 497 layer_tree_host_impl_->SetNeedsCommit(); 498 } 499 500 gfx::Rect LayerTreeImpl::DeviceViewport() const { 501 return layer_tree_host_impl_->DeviceViewport(); 502 } 503 504 bool LayerTreeImpl::DeviceViewportValidForTileManagement() const { 505 return layer_tree_host_impl_->device_viewport_valid_for_tile_management(); 506 } 507 508 void LayerTreeImpl::SetNeedsRedraw() { 509 layer_tree_host_impl_->SetNeedsRedraw(); 510 } 511 512 const LayerTreeDebugState& LayerTreeImpl::debug_state() const { 513 return layer_tree_host_impl_->debug_state(); 514 } 515 516 float LayerTreeImpl::device_scale_factor() const { 517 return layer_tree_host_impl_->device_scale_factor(); 518 } 519 520 DebugRectHistory* LayerTreeImpl::debug_rect_history() const { 521 return layer_tree_host_impl_->debug_rect_history(); 522 } 523 524 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { 525 return layer_tree_host_impl_->animation_registrar(); 526 } 527 528 scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { 529 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 530 TracedValue::MakeDictIntoImplicitSnapshot( 531 state.get(), "cc::LayerTreeImpl", this); 532 533 state->Set("root_layer", root_layer_->AsValue().release()); 534 535 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue()); 536 typedef LayerIterator<LayerImpl, 537 LayerImplList, 538 RenderSurfaceImpl, 539 LayerIteratorActions::BackToFront> LayerIteratorType; 540 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); 541 for (LayerIteratorType it = LayerIteratorType::Begin( 542 &render_surface_layer_list_); it != end; ++it) { 543 if (!it.represents_itself()) 544 continue; 545 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release()); 546 } 547 548 state->Set("render_surface_layer_list", 549 render_surface_layer_list.release()); 550 return state.PassAs<base::Value>(); 551 } 552 553 void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( 554 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { 555 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate) 556 return; 557 558 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; 559 560 if (root_scroll_layer_) { 561 root_scroll_layer_->SetScrollOffsetDelegate( 562 root_layer_scroll_offset_delegate_); 563 } 564 565 if (root_layer_scroll_offset_delegate_) { 566 root_layer_scroll_offset_delegate_->SetScrollableSize(ScrollableSize()); 567 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( 568 total_page_scale_factor()); 569 } 570 } 571 572 void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { 573 LayerImpl* root_scroll = RootScrollLayer(); 574 LayerImpl* root_container = RootContainerLayer(); 575 DCHECK(root_scroll); 576 DCHECK(root_container); 577 DCHECK(IsActiveTree()); 578 579 gfx::Vector2dF scrollable_viewport_size = 580 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF(); 581 582 gfx::Vector2dF original_viewport_size = 583 gfx::RectF(root_container->bounds()).bottom_right() - 584 gfx::PointF(); 585 original_viewport_size.Scale(1 / page_scale_factor()); 586 587 root_scroll->SetFixedContainerSizeDelta( 588 scrollable_viewport_size - original_viewport_size); 589 } 590 591 void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) { 592 latency_info_.MergeWith(latency_info); 593 } 594 595 const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() { 596 return latency_info_; 597 } 598 599 void LayerTreeImpl::ClearLatencyInfo() { 600 latency_info_.Clear(); 601 } 602 603 void LayerTreeImpl::WillModifyTilePriorities() { 604 layer_tree_host_impl_->SetNeedsManageTiles(); 605 } 606 607 void LayerTreeImpl::set_ui_resource_request_queue( 608 const UIResourceRequestQueue& queue) { 609 ui_resource_request_queue_ = queue; 610 } 611 612 ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource( 613 UIResourceId uid) const { 614 return layer_tree_host_impl_->ResourceIdForUIResource(uid); 615 } 616 617 void LayerTreeImpl::ProcessUIResourceRequestQueue() { 618 while (ui_resource_request_queue_.size() > 0) { 619 UIResourceRequest req = ui_resource_request_queue_.front(); 620 ui_resource_request_queue_.pop_front(); 621 622 switch (req.type) { 623 case UIResourceRequest::UIResourceCreate: 624 layer_tree_host_impl_->CreateUIResource(req.id, req.bitmap); 625 break; 626 case UIResourceRequest::UIResourceDelete: 627 layer_tree_host_impl_->DeleteUIResource(req.id); 628 break; 629 default: 630 NOTREACHED(); 631 break; 632 } 633 } 634 } 635 636 void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { 637 // Only the active tree needs to know about layers with copy requests, as 638 // they are aborted if not serviced during draw. 639 DCHECK(IsActiveTree()); 640 641 DCHECK(std::find(layers_with_copy_output_request_.begin(), 642 layers_with_copy_output_request_.end(), 643 layer) == layers_with_copy_output_request_.end()); 644 layers_with_copy_output_request_.push_back(layer); 645 } 646 647 void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { 648 // Only the active tree needs to know about layers with copy requests, as 649 // they are aborted if not serviced during draw. 650 DCHECK(IsActiveTree()); 651 652 std::vector<LayerImpl*>::iterator it = std::find( 653 layers_with_copy_output_request_.begin(), 654 layers_with_copy_output_request_.end(), 655 layer); 656 DCHECK(it != layers_with_copy_output_request_.end()); 657 layers_with_copy_output_request_.erase(it); 658 } 659 660 const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest() 661 const { 662 // Only the active tree needs to know about layers with copy requests, as 663 // they are aborted if not serviced during draw. 664 DCHECK(IsActiveTree()); 665 666 return layers_with_copy_output_request_; 667 } 668 669 } // namespace cc 670