| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2588 const LayerTreeDebugState& new_debug_state) { | 2588 const LayerTreeDebugState& new_debug_state) { |
| 2589 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) | 2589 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) |
| 2590 return; | 2590 return; |
| 2591 if (debug_state_.continuous_painting != new_debug_state.continuous_painting) | 2591 if (debug_state_.continuous_painting != new_debug_state.continuous_painting) |
| 2592 paint_time_counter_->ClearHistory(); | 2592 paint_time_counter_->ClearHistory(); |
| 2593 | 2593 |
| 2594 debug_state_ = new_debug_state; | 2594 debug_state_ = new_debug_state; |
| 2595 SetFullRootLayerDamage(); | 2595 SetFullRootLayerDamage(); |
| 2596 } | 2596 } |
| 2597 | 2597 |
| 2598 void LayerTreeHostImpl::CreateUIResource( | 2598 void LayerTreeHostImpl::CreateUIResource(UIResourceId uid, |
| 2599 UIResourceId uid, | 2599 const UIResourceBitmap& bitmap) { |
| 2600 scoped_refptr<UIResourceBitmap> bitmap) { | |
| 2601 DCHECK_GT(uid, 0); | 2600 DCHECK_GT(uid, 0); |
| 2602 DCHECK_EQ(bitmap->GetFormat(), UIResourceBitmap::RGBA8); | 2601 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8); |
| 2603 | 2602 |
| 2604 GLint wrap_mode = 0; | 2603 GLint wrap_mode = 0; |
| 2605 switch (bitmap->GetWrapMode()) { | 2604 switch (bitmap.GetWrapMode()) { |
| 2606 case UIResourceBitmap::CLAMP_TO_EDGE: | 2605 case UIResourceBitmap::CLAMP_TO_EDGE: |
| 2607 wrap_mode = GL_CLAMP_TO_EDGE; | 2606 wrap_mode = GL_CLAMP_TO_EDGE; |
| 2608 break; | 2607 break; |
| 2609 case UIResourceBitmap::REPEAT: | 2608 case UIResourceBitmap::REPEAT: |
| 2610 wrap_mode = GL_REPEAT; | 2609 wrap_mode = GL_REPEAT; |
| 2611 break; | 2610 break; |
| 2612 } | 2611 } |
| 2613 | 2612 |
| 2614 // Allow for multiple creation requests with the same UIResourceId. The | 2613 // Allow for multiple creation requests with the same UIResourceId. The |
| 2615 // previous resource is simply deleted. | 2614 // previous resource is simply deleted. |
| 2616 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid); | 2615 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid); |
| 2617 if (id) | 2616 if (id) |
| 2618 DeleteUIResource(uid); | 2617 DeleteUIResource(uid); |
| 2619 id = resource_provider_->CreateResource( | 2618 id = resource_provider_->CreateResource( |
| 2620 bitmap->GetSize(), | 2619 bitmap.GetSize(), |
| 2621 resource_provider_->best_texture_format(), | 2620 resource_provider_->best_texture_format(), |
| 2622 wrap_mode, | 2621 wrap_mode, |
| 2623 ResourceProvider::TextureUsageAny); | 2622 ResourceProvider::TextureUsageAny); |
| 2624 | 2623 |
| 2625 ui_resource_map_[uid] = id; | 2624 ui_resource_map_[uid] = id; |
| 2626 resource_provider_->SetPixels(id, | 2625 resource_provider_->SetPixels(id, |
| 2627 reinterpret_cast<uint8_t*>(bitmap->GetPixels()), | 2626 bitmap.GetPixels(), |
| 2628 gfx::Rect(bitmap->GetSize()), | 2627 gfx::Rect(bitmap.GetSize()), |
| 2629 gfx::Rect(bitmap->GetSize()), | 2628 gfx::Rect(bitmap.GetSize()), |
| 2630 gfx::Vector2d(0, 0)); | 2629 gfx::Vector2d(0, 0)); |
| 2631 } | 2630 } |
| 2632 | 2631 |
| 2633 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) { | 2632 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) { |
| 2634 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid); | 2633 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid); |
| 2635 if (id) { | 2634 if (id) { |
| 2636 resource_provider_->DeleteResource(id); | 2635 resource_provider_->DeleteResource(id); |
| 2637 ui_resource_map_.erase(uid); | 2636 ui_resource_map_.erase(uid); |
| 2638 } | 2637 } |
| 2639 } | 2638 } |
| 2640 | 2639 |
| 2641 void LayerTreeHostImpl::DeleteAllUIResources() { | 2640 void LayerTreeHostImpl::DeleteAllUIResources() { |
| 2642 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin(); | 2641 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin(); |
| 2643 iter != ui_resource_map_.end(); | 2642 iter != ui_resource_map_.end(); |
| 2644 ++iter) { | 2643 ++iter) { |
| 2645 resource_provider_->DeleteResource(iter->second); | 2644 resource_provider_->DeleteResource(iter->second); |
| 2646 } | 2645 } |
| 2647 ui_resource_map_.clear(); | 2646 ui_resource_map_.clear(); |
| 2648 } | 2647 } |
| 2649 | 2648 |
| 2650 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( | 2649 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( |
| 2651 UIResourceId uid) const { | 2650 UIResourceId uid) const { |
| 2652 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); | 2651 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); |
| 2653 if (iter != ui_resource_map_.end()) | 2652 if (iter != ui_resource_map_.end()) |
| 2654 return iter->second; | 2653 return iter->second; |
| 2655 return 0; | 2654 return 0; |
| 2656 } | 2655 } |
| 2657 | 2656 |
| 2658 } // namespace cc | 2657 } // namespace cc |
| OLD | NEW |