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" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 background_color, | 128 background_color, |
129 vertex_opacity, | 129 vertex_opacity, |
130 flipped, | 130 flipped, |
131 nearest_neighbor); | 131 nearest_neighbor); |
132 | 132 |
133 frame->render_pass_list.push_back(root_pass.Pass()); | 133 frame->render_pass_list.push_back(root_pass.Pass()); |
134 return frame.Pass(); | 134 return frame.Pass(); |
135 } | 135 } |
136 | 136 |
137 void AddTransferableResource(DelegatedFrameData* frame, | 137 void AddTransferableResource(DelegatedFrameData* frame, |
138 ResourceProvider::ResourceId resource_id) { | 138 ResourceId resource_id) { |
139 TransferableResource resource; | 139 TransferableResource resource; |
140 resource.id = resource_id; | 140 resource.id = resource_id; |
141 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 141 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
142 GLbyte arbitrary_mailbox[GL_MAILBOX_SIZE_CHROMIUM] = { | 142 GLbyte arbitrary_mailbox[GL_MAILBOX_SIZE_CHROMIUM] = { |
143 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, | 143 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, |
144 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, | 144 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, |
145 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4}; | 145 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4}; |
146 resource.mailbox_holder.mailbox.SetName(arbitrary_mailbox); | 146 resource.mailbox_holder.mailbox.SetName(arbitrary_mailbox); |
147 frame->resource_list.push_back(resource); | 147 frame->resource_list.push_back(resource); |
148 } | 148 } |
149 | 149 |
150 void AddTextureQuad(DelegatedFrameData* frame, | 150 void AddTextureQuad(DelegatedFrameData* frame, ResourceId resource_id) { |
151 ResourceProvider::ResourceId resource_id) { | |
152 RenderPass* render_pass = frame->render_pass_list[0]; | 151 RenderPass* render_pass = frame->render_pass_list[0]; |
153 SharedQuadState* sqs = render_pass->CreateAndAppendSharedQuadState(); | 152 SharedQuadState* sqs = render_pass->CreateAndAppendSharedQuadState(); |
154 TextureDrawQuad* quad = | 153 TextureDrawQuad* quad = |
155 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 154 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
156 float vertex_opacity[4] = { 1.f, 1.f, 1.f, 1.f }; | 155 float vertex_opacity[4] = { 1.f, 1.f, 1.f, 1.f }; |
157 quad->SetNew(sqs, | 156 quad->SetNew(sqs, |
158 gfx::Rect(0, 0, 10, 10), | 157 gfx::Rect(0, 0, 10, 10), |
159 gfx::Rect(0, 0, 10, 10), | 158 gfx::Rect(0, 0, 10, 10), |
160 gfx::Rect(0, 0, 10, 10), | 159 gfx::Rect(0, 0, 10, 10), |
161 resource_id, | 160 resource_id, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 output_rect, | 193 output_rect, |
195 id, | 194 id, |
196 0, | 195 0, |
197 gfx::Vector2dF(), | 196 gfx::Vector2dF(), |
198 gfx::Size(), | 197 gfx::Size(), |
199 filters, | 198 filters, |
200 gfx::Vector2dF(), | 199 gfx::Vector2dF(), |
201 background_filters); | 200 background_filters); |
202 } | 201 } |
203 | 202 |
204 static ResourceProvider::ResourceId AppendResourceId( | 203 static ResourceId AppendResourceId( |
205 std::vector<ResourceProvider::ResourceId>* resources_in_last_sent_frame, | 204 std::vector<ResourceId>* resources_in_last_sent_frame, |
206 ResourceProvider::ResourceId resource_id) { | 205 ResourceId resource_id) { |
207 resources_in_last_sent_frame->push_back(resource_id); | 206 resources_in_last_sent_frame->push_back(resource_id); |
208 return resource_id; | 207 return resource_id; |
209 } | 208 } |
210 | 209 |
211 void ReturnUnusedResourcesFromParent(LayerTreeHostImpl* host_impl) { | 210 void ReturnUnusedResourcesFromParent(LayerTreeHostImpl* host_impl) { |
212 DelegatedFrameData* delegated_frame_data = | 211 DelegatedFrameData* delegated_frame_data = |
213 output_surface()->last_sent_frame().delegated_frame_data.get(); | 212 output_surface()->last_sent_frame().delegated_frame_data.get(); |
214 if (!delegated_frame_data) | 213 if (!delegated_frame_data) |
215 return; | 214 return; |
216 | 215 |
217 std::vector<ResourceProvider::ResourceId> resources_in_last_sent_frame; | 216 std::vector<ResourceId> resources_in_last_sent_frame; |
218 for (size_t i = 0; i < delegated_frame_data->resource_list.size(); ++i) { | 217 for (size_t i = 0; i < delegated_frame_data->resource_list.size(); ++i) { |
219 resources_in_last_sent_frame.push_back( | 218 resources_in_last_sent_frame.push_back( |
220 delegated_frame_data->resource_list[i].id); | 219 delegated_frame_data->resource_list[i].id); |
221 } | 220 } |
222 | 221 |
223 std::vector<ResourceProvider::ResourceId> resources_to_return; | 222 std::vector<ResourceId> resources_to_return; |
224 | 223 |
225 const TransferableResourceArray& resources_held_by_parent = | 224 const TransferableResourceArray& resources_held_by_parent = |
226 output_surface()->resources_held_by_parent(); | 225 output_surface()->resources_held_by_parent(); |
227 for (size_t i = 0; i < resources_held_by_parent.size(); ++i) { | 226 for (size_t i = 0; i < resources_held_by_parent.size(); ++i) { |
228 ResourceProvider::ResourceId resource_in_parent = | 227 ResourceId resource_in_parent = resources_held_by_parent[i].id; |
229 resources_held_by_parent[i].id; | |
230 bool resource_in_parent_is_not_part_of_frame = | 228 bool resource_in_parent_is_not_part_of_frame = |
231 std::find(resources_in_last_sent_frame.begin(), | 229 std::find(resources_in_last_sent_frame.begin(), |
232 resources_in_last_sent_frame.end(), | 230 resources_in_last_sent_frame.end(), |
233 resource_in_parent) == resources_in_last_sent_frame.end(); | 231 resource_in_parent) == resources_in_last_sent_frame.end(); |
234 if (resource_in_parent_is_not_part_of_frame) | 232 if (resource_in_parent_is_not_part_of_frame) |
235 resources_to_return.push_back(resource_in_parent); | 233 resources_to_return.push_back(resource_in_parent); |
236 } | 234 } |
237 | 235 |
238 if (resources_to_return.empty()) | 236 if (resources_to_return.empty()) |
239 return; | 237 return; |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 | 795 |
798 const ResourceProvider::ResourceIdMap& map = | 796 const ResourceProvider::ResourceIdMap& map = |
799 host_impl->resource_provider()->GetChildToParentMap( | 797 host_impl->resource_provider()->GetChildToParentMap( |
800 delegated_impl->ChildId()); | 798 delegated_impl->ChildId()); |
801 | 799 |
802 // The frame's resource should be in the parent's resource provider. | 800 // The frame's resource should be in the parent's resource provider. |
803 EXPECT_EQ(2u, map.size()); | 801 EXPECT_EQ(2u, map.size()); |
804 EXPECT_EQ(1u, map.count(999)); | 802 EXPECT_EQ(1u, map.count(999)); |
805 EXPECT_EQ(1u, map.count(555)); | 803 EXPECT_EQ(1u, map.count(555)); |
806 | 804 |
807 ResourceProvider::ResourceId parent_resource_id1 = map.find(999)->second; | 805 ResourceId parent_resource_id1 = map.find(999)->second; |
808 EXPECT_NE(parent_resource_id1, 999u); | 806 EXPECT_NE(parent_resource_id1, 999u); |
809 ResourceProvider::ResourceId parent_resource_id2 = map.find(555)->second; | 807 ResourceId parent_resource_id2 = map.find(555)->second; |
810 EXPECT_NE(parent_resource_id2, 555u); | 808 EXPECT_NE(parent_resource_id2, 555u); |
811 | 809 |
812 // The resources in the quads should be remapped to the parent's namespace. | 810 // The resources in the quads should be remapped to the parent's namespace. |
813 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 811 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
814 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list.ElementAt(0)); | 812 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list.ElementAt(0)); |
815 EXPECT_EQ(parent_resource_id1, quad1->resource_id); | 813 EXPECT_EQ(parent_resource_id1, quad1->resource_id); |
816 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 814 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
817 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list.ElementAt(1)); | 815 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list.ElementAt(1)); |
818 EXPECT_EQ(parent_resource_id2, quad2->resource_id); | 816 EXPECT_EQ(parent_resource_id2, quad2->resource_id); |
819 | 817 |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 ReturnAllResourcesFromParent(host_impl); | 2283 ReturnAllResourcesFromParent(host_impl); |
2286 } | 2284 } |
2287 | 2285 |
2288 bool drew_with_pending_tree_; | 2286 bool drew_with_pending_tree_; |
2289 }; | 2287 }; |
2290 | 2288 |
2291 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostDelegatedTestActiveFrameIsValid); | 2289 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostDelegatedTestActiveFrameIsValid); |
2292 | 2290 |
2293 } // namespace | 2291 } // namespace |
2294 } // namespace cc | 2292 } // namespace cc |
OLD | NEW |