| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/layers/delegated_frame_resource_collection.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "cc/trees/blocking_task_runner.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 DelegatedFrameResourceCollection::DelegatedFrameResourceCollection() |
| 13 : client_(NULL), main_thread_runner_(BlockingTaskRunner::current()) { |
| 14 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 15 } |
| 16 |
| 17 DelegatedFrameResourceCollection::~DelegatedFrameResourceCollection() { |
| 18 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 19 } |
| 20 |
| 21 void DelegatedFrameResourceCollection::SetClient( |
| 22 DelegatedFrameResourceCollectionClient* client) { |
| 23 client_ = client; |
| 24 } |
| 25 |
| 26 void DelegatedFrameResourceCollection::TakeUnusedResourcesForChildCompositor( |
| 27 ReturnedResourceArray* array) { |
| 28 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 29 DCHECK(array->empty()); |
| 30 array->swap(returned_resources_for_child_compositor_); |
| 31 } |
| 32 |
| 33 void DelegatedFrameResourceCollection::ReceivedResources( |
| 34 const TransferableResourceArray& resources) { |
| 35 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 36 for (size_t i = 0; i < resources.size(); ++i) |
| 37 resource_id_ref_count_map_[resources[i].id].refs_to_return++; |
| 38 } |
| 39 |
| 40 void DelegatedFrameResourceCollection::UnrefResources( |
| 41 const ReturnedResourceArray& returned) { |
| 42 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 43 |
| 44 ReturnedResourceArray to_return; |
| 45 |
| 46 for (size_t i = 0; i < returned.size(); ++i) { |
| 47 ResourceIdRefCountMap::iterator it = |
| 48 resource_id_ref_count_map_.find(returned[i].id); |
| 49 DCHECK(it != resource_id_ref_count_map_.end()); |
| 50 DCHECK_GE(it->second.refs_to_wait_for, returned[i].count); |
| 51 it->second.refs_to_wait_for -= returned[i].count; |
| 52 if (it->second.refs_to_wait_for == 0) { |
| 53 to_return.push_back(returned[i]); |
| 54 to_return.back().count = it->second.refs_to_return; |
| 55 resource_id_ref_count_map_.erase(it); |
| 56 } |
| 57 } |
| 58 |
| 59 if (to_return.empty()) |
| 60 return; |
| 61 |
| 62 returned_resources_for_child_compositor_.insert( |
| 63 returned_resources_for_child_compositor_.end(), |
| 64 to_return.begin(), |
| 65 to_return.end()); |
| 66 if (client_) |
| 67 client_->UnusedResourcesAreAvailable(); |
| 68 } |
| 69 |
| 70 void DelegatedFrameResourceCollection::RefResources( |
| 71 const TransferableResourceArray& resources) { |
| 72 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 73 for (size_t i = 0; i < resources.size(); ++i) |
| 74 resource_id_ref_count_map_[resources[i].id].refs_to_wait_for++; |
| 75 } |
| 76 |
| 77 ReturnCallback |
| 78 DelegatedFrameResourceCollection::GetReturnResourcesCallbackForImplThread() { |
| 79 return base::Bind( |
| 80 &DelegatedFrameResourceCollection::UnrefResourcesOnImplThread, |
| 81 this, |
| 82 main_thread_runner_); |
| 83 } |
| 84 |
| 85 void DelegatedFrameResourceCollection::UnrefResourcesOnImplThread( |
| 86 scoped_refptr<BlockingTaskRunner> main_thread_runner, |
| 87 const ReturnedResourceArray& returned) { |
| 88 main_thread_runner->PostTask( |
| 89 FROM_HERE, |
| 90 base::Bind( |
| 91 &DelegatedFrameResourceCollection::UnrefResources, this, returned)); |
| 92 } |
| 93 |
| 94 } // namespace cc |
| OLD | NEW |