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.
5 #ifndef CC_LAYERS_DELEGATED_FRAME_RESOURCE_COLLECTION_H_
6 #define CC_LAYERS_DELEGATED_FRAME_RESOURCE_COLLECTION_H_
8 #include "base/containers/hash_tables.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/resources/return_callback.h"
14 #include "cc/resources/returned_resource.h"
15 #include "cc/resources/transferable_resource.h"
18 class BlockingTaskRunner
;
20 class CC_EXPORT DelegatedFrameResourceCollectionClient
{
22 // Called to inform the client that returned resources can be
23 // grabbed off the DelegatedFrameResourceCollection.
24 virtual void UnusedResourcesAreAvailable() = 0;
27 class CC_EXPORT DelegatedFrameResourceCollection
28 : public base::RefCounted
<DelegatedFrameResourceCollection
> {
30 DelegatedFrameResourceCollection();
32 void SetClient(DelegatedFrameResourceCollectionClient
* client
);
34 void TakeUnusedResourcesForChildCompositor(ReturnedResourceArray
* array
);
36 // Considers all resources as lost, and returns true if it held any resource
38 bool LoseAllResources();
40 // Methods for DelegatedFrameProvider.
41 void RefResources(const TransferableResourceArray
& resources
);
42 void UnrefResources(const ReturnedResourceArray
& returned
);
43 void ReceivedResources(const TransferableResourceArray
& resources
);
44 ReturnCallback
GetReturnResourcesCallbackForImplThread();
47 friend class base::RefCounted
<DelegatedFrameResourceCollection
>;
48 ~DelegatedFrameResourceCollection();
50 DelegatedFrameResourceCollectionClient
* client_
;
51 scoped_refptr
<BlockingTaskRunner
> main_thread_runner_
;
53 ReturnedResourceArray returned_resources_for_child_compositor_
;
54 bool lost_all_resources_
;
60 typedef base::hash_map
<unsigned, RefCount
> ResourceIdRefCountMap
;
61 ResourceIdRefCountMap resource_id_ref_count_map_
;
63 base::ThreadChecker main_thread_checker_
;
64 base::WeakPtrFactory
<DelegatedFrameResourceCollection
> weak_ptr_factory_
;
66 DISALLOW_COPY_AND_ASSIGN(DelegatedFrameResourceCollection
);
71 #endif // CC_LAYERS_DELEGATED_FRAME_RESOURCE_COLLECTION_H_