| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/surface_aggregator.h" | 5 #include "cc/surfaces/surface_aggregator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
| 12 #include "cc/output/compositor_frame.h" | 12 #include "cc/output/compositor_frame.h" |
| 13 #include "cc/output/delegated_frame_data.h" | 13 #include "cc/output/delegated_frame_data.h" |
| 14 #include "cc/quads/draw_quad.h" | 14 #include "cc/quads/draw_quad.h" |
| 15 #include "cc/quads/render_pass_draw_quad.h" | 15 #include "cc/quads/render_pass_draw_quad.h" |
| 16 #include "cc/quads/shared_quad_state.h" | 16 #include "cc/quads/shared_quad_state.h" |
| 17 #include "cc/quads/surface_draw_quad.h" | 17 #include "cc/quads/surface_draw_quad.h" |
| 18 #include "cc/surfaces/surface.h" | 18 #include "cc/surfaces/surface.h" |
| 19 #include "cc/surfaces/surface_factory.h" | 19 #include "cc/surfaces/surface_factory.h" |
| 20 #include "cc/surfaces/surface_manager.h" | 20 #include "cc/surfaces/surface_manager.h" |
| 21 #include "cc/trees/blocking_task_runner.h" |
| 21 | 22 |
| 22 namespace cc { | 23 namespace cc { |
| 23 | 24 |
| 24 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager, | 25 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager, |
| 25 ResourceProvider* provider) | 26 ResourceProvider* provider) |
| 26 : manager_(manager), provider_(provider) { | 27 : manager_(manager), provider_(provider) { |
| 27 DCHECK(manager_); | 28 DCHECK(manager_); |
| 28 } | 29 } |
| 29 | 30 |
| 30 SurfaceAggregator::~SurfaceAggregator() {} | 31 SurfaceAggregator::~SurfaceAggregator() {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 47 } | 48 } |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 base::hash_map<RenderPassId, int> id_to_index_map_; | 51 base::hash_map<RenderPassId, int> id_to_index_map_; |
| 51 SurfaceId surface_id_; | 52 SurfaceId surface_id_; |
| 52 int next_index_; | 53 int next_index_; |
| 53 | 54 |
| 54 DISALLOW_COPY_AND_ASSIGN(RenderPassIdAllocator); | 55 DISALLOW_COPY_AND_ASSIGN(RenderPassIdAllocator); |
| 55 }; | 56 }; |
| 56 | 57 |
| 58 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, |
| 59 const ReturnedResourceArray& resources, |
| 60 BlockingTaskRunner* main_thread_task_runner) { |
| 61 surface_factory->UnrefResources(resources); |
| 62 } |
| 63 |
| 57 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, | 64 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, |
| 58 SurfaceId surface_id) { | 65 SurfaceId surface_id) { |
| 59 RenderPassIdAllocator* allocator = render_pass_allocator_map_.get(surface_id); | 66 RenderPassIdAllocator* allocator = render_pass_allocator_map_.get(surface_id); |
| 60 if (!allocator) { | 67 if (!allocator) { |
| 61 allocator = new RenderPassIdAllocator(surface_id); | 68 allocator = new RenderPassIdAllocator(surface_id); |
| 62 render_pass_allocator_map_.set(surface_id, make_scoped_ptr(allocator)); | 69 render_pass_allocator_map_.set(surface_id, make_scoped_ptr(allocator)); |
| 63 } | 70 } |
| 64 allocator->AddKnownPass(surface_local_pass_id); | 71 allocator->AddKnownPass(surface_local_pass_id); |
| 65 return allocator->Remap(surface_local_pass_id); | 72 return allocator->Remap(surface_local_pass_id); |
| 66 } | 73 } |
| 67 | 74 |
| 68 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 75 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
| 69 SurfaceToResourceChildIdMap::iterator it = | 76 SurfaceToResourceChildIdMap::iterator it = |
| 70 surface_id_to_resource_child_id_.find(surface->surface_id()); | 77 surface_id_to_resource_child_id_.find(surface->surface_id()); |
| 71 if (it == surface_id_to_resource_child_id_.end()) { | 78 if (it == surface_id_to_resource_child_id_.end()) { |
| 72 int child_id = provider_->CreateChild(base::Bind( | 79 int child_id = provider_->CreateChild( |
| 73 &SurfaceFactory::UnrefResources, surface->factory()->AsWeakPtr())); | 80 base::Bind(&UnrefHelper, surface->factory()->AsWeakPtr())); |
| 74 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 81 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
| 75 return child_id; | 82 return child_id; |
| 76 } else { | 83 } else { |
| 77 return it->second; | 84 return it->second; |
| 78 } | 85 } |
| 79 } | 86 } |
| 80 | 87 |
| 81 static ResourceProvider::ResourceId ResourceRemapHelper( | 88 static ResourceProvider::ResourceId ResourceRemapHelper( |
| 82 bool* invalid_frame, | 89 bool* invalid_frame, |
| 83 const ResourceProvider::ResourceIdMap& child_to_parent_map, | 90 const ResourceProvider::ResourceIdMap& child_to_parent_map, |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 contained_surfaces_.swap(previous_contained_surfaces_); | 353 contained_surfaces_.swap(previous_contained_surfaces_); |
| 347 contained_surfaces_.clear(); | 354 contained_surfaces_.clear(); |
| 348 | 355 |
| 349 // TODO(jamesr): Aggregate all resource references into the returned frame's | 356 // TODO(jamesr): Aggregate all resource references into the returned frame's |
| 350 // resource list. | 357 // resource list. |
| 351 | 358 |
| 352 return frame.Pass(); | 359 return frame.Pass(); |
| 353 } | 360 } |
| 354 | 361 |
| 355 } // namespace cc | 362 } // namespace cc |
| OLD | NEW |