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

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: friend class 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 : 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::ReturnResources(
41 const ReturnedResourceArray& returned) {
42 DCHECK(main_thread_checker_.CalledOnValidThread());
43 returned_resources_for_child_compositor_.insert(
44 returned_resources_for_child_compositor_.end(),
45 returned.begin(),
46 returned.end());
47 if (client_ && !returned.empty())
48 client_->UnusedResourcesAreAvailable();
49 }
50
51 void DelegatedFrameResourceCollection::RefResources(
52 const TransferableResourceArray& resources) {
53 DCHECK(main_thread_checker_.CalledOnValidThread());
54 for (size_t i = 0; i < resources.size(); ++i)
55 resource_id_ref_count_map_[resources[i].id].refs_to_wait_for++;
56 }
57
58 ReturnCallback
59 DelegatedFrameResourceCollection::GetReturnResourcesCallbackForImplThread() {
60 return base::Bind(
61 &DelegatedFrameResourceCollection::UnrefResourcesOnImplThread,
62 this,
63 main_thread_runner_);
64 }
65
66 void DelegatedFrameResourceCollection::UnrefResources(
67 const ReturnedResourceArray& returned) {
68 DCHECK(main_thread_checker_.CalledOnValidThread());
69
70 ReturnedResourceArray to_return;
71
72 for (size_t i = 0; i < returned.size(); ++i) {
73 ResourceIdRefCountMap::iterator it =
74 resource_id_ref_count_map_.find(returned[i].id);
75 DCHECK(it != resource_id_ref_count_map_.end());
76 DCHECK_GE(it->second.refs_to_wait_for, returned[i].count);
77 it->second.refs_to_wait_for -= returned[i].count;
78 if (it->second.refs_to_wait_for == 0) {
79 to_return.push_back(returned[i]);
80 to_return.back().count = it->second.refs_to_return;
81 resource_id_ref_count_map_.erase(it);
82 }
83 }
84 ReturnResources(to_return);
85 }
86
87 void DelegatedFrameResourceCollection::UnrefResourcesOnImplThread(
88 scoped_refptr<BlockingTaskRunner> main_thread_runner,
89 const ReturnedResourceArray& returned) {
90 main_thread_runner->PostTask(
91 FROM_HERE,
92 base::Bind(
93 &DelegatedFrameResourceCollection::UnrefResources, this, returned));
94 }
95
96 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698