Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: cc/layers/delegated_frame_resource_collection.cc

Issue 26023004: aura: Allow delegated frames to be used by more than one impl layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: frameprovider: nits Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 DelegatedFrameResourceCollectionClient* client)
14 : client_(client),
15 main_thread_runner_(BlockingTaskRunner::current()),
16 weak_ptrs_(this) {
17 DCHECK(main_thread_checker_.CalledOnValidThread());
18 }
19
20 DelegatedFrameResourceCollection::~DelegatedFrameResourceCollection() {
21 DCHECK_EQ(0u, returned_resources_for_child_compositor_.size());
22 DCHECK(main_thread_checker_.CalledOnValidThread());
23 }
24
25 void DelegatedFrameResourceCollection::TakeUnusedResourcesForChildCompositor(
26 ReturnedResourceArray* array) {
27 DCHECK(main_thread_checker_.CalledOnValidThread());
28 DCHECK(array->empty());
29 array->swap(returned_resources_for_child_compositor_);
30 }
31
32 void DelegatedFrameResourceCollection::ReceivedResources(
33 const TransferableResourceArray& resources) {
34 DCHECK(main_thread_checker_.CalledOnValidThread());
35 for (size_t i = 0; i < resources.size(); ++i)
36 resource_id_ref_count_map_[resources[i].id].refs_to_return++;
37 }
38
39 void DelegatedFrameResourceCollection::ReturnResources(
40 const ReturnedResourceArray& returned) {
41 DCHECK(main_thread_checker_.CalledOnValidThread());
42 returned_resources_for_child_compositor_.insert(
43 returned_resources_for_child_compositor_.end(),
44 returned.begin(),
45 returned.end());
46 if (client_ && !returned.empty())
47 client_->UnusedResourcesAreAvailable();
48 }
49
50 void DelegatedFrameResourceCollection::RefResources(
51 const TransferableResourceArray& resources) {
52 DCHECK(main_thread_checker_.CalledOnValidThread());
53 for (size_t i = 0; i < resources.size(); ++i)
54 resource_id_ref_count_map_[resources[i].id].refs_to_wait_for++;
55 }
56
57 ReturnCallback
58 DelegatedFrameResourceCollection::GetReturnResourcesCallbackForImplThread() {
59 return base::Bind(
60 &DelegatedFrameResourceCollection::UnrefResourcesOnImplThread,
61 main_thread_runner_,
62 weak_ptrs_.GetWeakPtr());
63 }
64
65 void DelegatedFrameResourceCollection::UnrefResources(
66 const ReturnedResourceArray& returned) {
67 DCHECK(main_thread_checker_.CalledOnValidThread());
68
69 ReturnedResourceArray to_return;
70
71 for (size_t i = 0; i < returned.size(); ++i) {
72 ResourceIdRefCountMap::iterator it =
73 resource_id_ref_count_map_.find(returned[i].id);
74 DCHECK(it != resource_id_ref_count_map_.end());
75 DCHECK_GE(it->second.refs_to_wait_for, returned[i].count);
76 it->second.refs_to_wait_for -= returned[i].count;
77 if (it->second.refs_to_wait_for == 0) {
78 to_return.push_back(returned[i]);
79 to_return.back().count = it->second.refs_to_return;
80 resource_id_ref_count_map_.erase(it);
81 }
82 }
83 ReturnResources(to_return);
84 }
85
86 // static
87 void DelegatedFrameResourceCollection::UnrefResourcesOnImplThread(
88 scoped_refptr<BlockingTaskRunner> main_thread_runner,
89 base::WeakPtr<DelegatedFrameResourceCollection> self,
90 const ReturnedResourceArray& returned) {
91 main_thread_runner->PostTask(
92 FROM_HERE,
93 base::Bind(
94 &DelegatedFrameResourceCollection::UnrefResources, self, returned));
95 }
96
97 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698