OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/delegated_renderer_layer_impl.h" | 5 #include "cc/layers/delegated_renderer_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 bool DelegatedRendererLayerImpl::HasDelegatedContent() const { return true; } | 38 bool DelegatedRendererLayerImpl::HasDelegatedContent() const { return true; } |
39 | 39 |
40 bool DelegatedRendererLayerImpl::HasContributingDelegatedRenderPasses() const { | 40 bool DelegatedRendererLayerImpl::HasContributingDelegatedRenderPasses() const { |
41 // The root RenderPass for the layer is merged with its target | 41 // The root RenderPass for the layer is merged with its target |
42 // RenderPass in each frame. So we only have extra RenderPasses | 42 // RenderPass in each frame. So we only have extra RenderPasses |
43 // to merge when we have a non-root RenderPass present. | 43 // to merge when we have a non-root RenderPass present. |
44 return render_passes_in_draw_order_.size() > 1; | 44 return render_passes_in_draw_order_.size() > 1; |
45 } | 45 } |
46 | 46 |
47 static ResourceId ResourceRemapHelper( | |
48 bool* invalid_frame, | |
49 const ResourceProvider::ResourceIdMap& child_to_parent_map, | |
50 ResourceProvider::ResourceIdSet* resources_in_frame, | |
51 ResourceId id) { | |
52 ResourceProvider::ResourceIdMap::const_iterator it = | |
53 child_to_parent_map.find(id); | |
54 if (it == child_to_parent_map.end()) { | |
55 *invalid_frame = true; | |
56 return 0; | |
57 } | |
58 | |
59 DCHECK_EQ(it->first, id); | |
60 ResourceId remapped_id = it->second; | |
61 resources_in_frame->insert(id); | |
62 return remapped_id; | |
63 } | |
64 | |
65 void DelegatedRendererLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 47 void DelegatedRendererLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
66 LayerImpl::PushPropertiesTo(layer); | 48 LayerImpl::PushPropertiesTo(layer); |
67 | 49 |
68 DelegatedRendererLayerImpl* delegated_layer = | 50 DelegatedRendererLayerImpl* delegated_layer = |
69 static_cast<DelegatedRendererLayerImpl*>(layer); | 51 static_cast<DelegatedRendererLayerImpl*>(layer); |
70 | 52 |
71 // If we have a new child_id to give to the active layer, it should | 53 // If we have a new child_id to give to the active layer, it should |
72 // have already deleted its old child_id. | 54 // have already deleted its old child_id. |
73 DCHECK(delegated_layer->child_id_ == 0 || | 55 DCHECK(delegated_layer->child_id_ == 0 || |
74 delegated_layer->child_id_ == child_id_); | 56 delegated_layer->child_id_ == child_id_); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 #if defined(COMPILER_MSVC) | 109 #if defined(COMPILER_MSVC) |
128 resources_in_frame.reserve(reserve_size); | 110 resources_in_frame.reserve(reserve_size); |
129 #elif defined(COMPILER_GCC) | 111 #elif defined(COMPILER_GCC) |
130 // Pre-standard hash-tables only implement resize, which behaves similarly | 112 // Pre-standard hash-tables only implement resize, which behaves similarly |
131 // to reserve for these keys. Resizing to 0 may also be broken (particularly | 113 // to reserve for these keys. Resizing to 0 may also be broken (particularly |
132 // on stlport). | 114 // on stlport). |
133 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. | 115 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. |
134 if (reserve_size) | 116 if (reserve_size) |
135 resources_in_frame.resize(reserve_size); | 117 resources_in_frame.resize(reserve_size); |
136 #endif | 118 #endif |
137 DrawQuad::ResourceIteratorCallback remap_resources_to_parent_callback = | |
138 base::Bind(&ResourceRemapHelper, | |
139 &invalid_frame, | |
140 resource_map, | |
141 &resources_in_frame); | |
142 for (const auto& pass : render_pass_list) { | 119 for (const auto& pass : render_pass_list) { |
143 for (const auto& quad : pass->quad_list) | 120 for (const auto& quad : pass->quad_list) { |
144 quad->IterateResources(remap_resources_to_parent_callback); | 121 for (ResourceId& resource_id : quad->resources) { |
| 122 ResourceProvider::ResourceIdMap::const_iterator it = |
| 123 resource_map.find(resource_id); |
| 124 if (it == resource_map.end()) { |
| 125 invalid_frame = true; |
| 126 break; |
| 127 } |
| 128 |
| 129 DCHECK_EQ(it->first, resource_id); |
| 130 ResourceId remapped_id = it->second; |
| 131 resources_in_frame.insert(resource_id); |
| 132 resource_id = remapped_id; |
| 133 } |
| 134 } |
145 } | 135 } |
146 | 136 |
147 if (invalid_frame) { | 137 if (invalid_frame) { |
148 // Declare we are still using the last frame's resources. Drops ownership of | 138 // Declare we are still using the last frame's resources. Drops ownership of |
149 // any invalid resources, keeping only those in use by the active tree. | 139 // any invalid resources, keeping only those in use by the active tree. |
150 resource_provider->DeclareUsedResourcesFromChild(child_id_, resources_); | 140 resource_provider->DeclareUsedResourcesFromChild(child_id_, resources_); |
151 return; | 141 return; |
152 } | 142 } |
153 | 143 |
154 // Save the new frame's resources, but don't give them to the ResourceProvider | 144 // Save the new frame's resources, but don't give them to the ResourceProvider |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 if (own_child_id_) { | 516 if (own_child_id_) { |
527 ResourceProvider* provider = layer_tree_impl()->resource_provider(); | 517 ResourceProvider* provider = layer_tree_impl()->resource_provider(); |
528 provider->DestroyChild(child_id_); | 518 provider->DestroyChild(child_id_); |
529 } | 519 } |
530 | 520 |
531 resources_.clear(); | 521 resources_.clear(); |
532 child_id_ = 0; | 522 child_id_ = 0; |
533 } | 523 } |
534 | 524 |
535 } // namespace cc | 525 } // namespace cc |
OLD | NEW |