1 // Copyright 2012 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_RESOURCE_UPDATE_CONTROLLER_H_
6 #define CC_RESOURCE_UPDATE_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time.h"
12 #include "cc/cc_export.h"
13 #include "cc/resource_update_queue.h"
17 class ResourceProvider
;
20 class ResourceUpdateControllerClient
{
22 virtual void readyToFinalizeTextureUpdates() = 0;
25 virtual ~ResourceUpdateControllerClient() { }
28 class CC_EXPORT ResourceUpdateController
{
30 static scoped_ptr
<ResourceUpdateController
> create(ResourceUpdateControllerClient
* client
, Thread
* thread
, scoped_ptr
<ResourceUpdateQueue
> queue
, ResourceProvider
* resourceProvider
)
32 return make_scoped_ptr(new ResourceUpdateController(client
, thread
, queue
.Pass(), resourceProvider
));
34 static size_t maxPartialTextureUpdates();
36 virtual ~ResourceUpdateController();
38 // Discard uploads to textures that were evicted on the impl thread.
39 void discardUploadsToEvictedResources();
41 void performMoreUpdates(base::TimeTicks timeLimit
);
45 // Virtual for testing.
46 virtual base::TimeTicks
now() const;
47 virtual base::TimeDelta
updateMoreTexturesTime() const;
48 virtual size_t updateMoreTexturesSize() const;
51 ResourceUpdateController(ResourceUpdateControllerClient
*, Thread
*, scoped_ptr
<ResourceUpdateQueue
>, ResourceProvider
*);
54 static size_t maxFullUpdatesPerTick(ResourceProvider
*);
56 size_t maxBlockingUpdates() const;
57 base::TimeDelta
pendingUpdateTime() const;
59 void updateTexture(ResourceUpdate
);
61 // This returns true when there were textures left to update.
62 bool updateMoreTexturesIfEnoughTimeRemaining();
63 void updateMoreTexturesNow();
66 ResourceUpdateControllerClient
* m_client
;
67 scoped_ptr
<ResourceUpdateQueue
> m_queue
;
68 bool m_contentsTexturesPurged
;
69 ResourceProvider
* m_resourceProvider
;
70 base::TimeTicks m_timeLimit
;
71 size_t m_textureUpdatesPerTick
;
72 bool m_firstUpdateAttempt
;
74 base::WeakPtrFactory
<ResourceUpdateController
> m_weakFactory
;
77 DISALLOW_COPY_AND_ASSIGN(ResourceUpdateController
);
82 #endif // CC_RESOURCE_UPDATE_CONTROLLER_H_