| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ |
| 6 #define CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ | 6 #define CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
| 13 #include "cc/resources/resource_update_queue.h" | 13 #include "cc/resources/resource_update_queue.h" |
| 14 | 14 |
| 15 namespace base { class SingleThreadTaskRunner; } |
| 16 |
| 15 namespace cc { | 17 namespace cc { |
| 16 | 18 |
| 17 class ResourceProvider; | 19 class ResourceProvider; |
| 18 class Thread; | |
| 19 | 20 |
| 20 class ResourceUpdateControllerClient { | 21 class ResourceUpdateControllerClient { |
| 21 public: | 22 public: |
| 22 virtual void ReadyToFinalizeTextureUpdates() = 0; | 23 virtual void ReadyToFinalizeTextureUpdates() = 0; |
| 23 | 24 |
| 24 protected: | 25 protected: |
| 25 virtual ~ResourceUpdateControllerClient() {} | 26 virtual ~ResourceUpdateControllerClient() {} |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 class CC_EXPORT ResourceUpdateController { | 29 class CC_EXPORT ResourceUpdateController { |
| 29 public: | 30 public: |
| 30 static scoped_ptr<ResourceUpdateController> Create( | 31 static scoped_ptr<ResourceUpdateController> Create( |
| 31 ResourceUpdateControllerClient* client, | 32 ResourceUpdateControllerClient* client, |
| 32 Thread* thread, | 33 base::SingleThreadTaskRunner* task_runner, |
| 33 scoped_ptr<ResourceUpdateQueue> queue, | 34 scoped_ptr<ResourceUpdateQueue> queue, |
| 34 ResourceProvider* resource_provider) { | 35 ResourceProvider* resource_provider) { |
| 35 return make_scoped_ptr(new ResourceUpdateController( | 36 return make_scoped_ptr(new ResourceUpdateController( |
| 36 client, thread, queue.Pass(), resource_provider)); | 37 client, task_runner, queue.Pass(), resource_provider)); |
| 37 } | 38 } |
| 38 static size_t MaxPartialTextureUpdates(); | 39 static size_t MaxPartialTextureUpdates(); |
| 39 | 40 |
| 40 virtual ~ResourceUpdateController(); | 41 virtual ~ResourceUpdateController(); |
| 41 | 42 |
| 42 // Discard uploads to textures that were evicted on the impl thread. | 43 // Discard uploads to textures that were evicted on the impl thread. |
| 43 void DiscardUploadsToEvictedResources(); | 44 void DiscardUploadsToEvictedResources(); |
| 44 | 45 |
| 45 void PerformMoreUpdates(base::TimeTicks time_limit); | 46 void PerformMoreUpdates(base::TimeTicks time_limit); |
| 46 void Finalize(); | 47 void Finalize(); |
| 47 | 48 |
| 48 | 49 |
| 49 // Virtual for testing. | 50 // Virtual for testing. |
| 50 virtual base::TimeTicks Now() const; | 51 virtual base::TimeTicks Now() const; |
| 51 virtual base::TimeDelta UpdateMoreTexturesTime() const; | 52 virtual base::TimeDelta UpdateMoreTexturesTime() const; |
| 52 virtual size_t UpdateMoreTexturesSize() const; | 53 virtual size_t UpdateMoreTexturesSize() const; |
| 53 | 54 |
| 54 protected: | 55 protected: |
| 55 ResourceUpdateController(ResourceUpdateControllerClient* client, | 56 ResourceUpdateController(ResourceUpdateControllerClient* client, |
| 56 Thread* thread, | 57 base::SingleThreadTaskRunner* task_runner, |
| 57 scoped_ptr<ResourceUpdateQueue> queue, | 58 scoped_ptr<ResourceUpdateQueue> queue, |
| 58 ResourceProvider* resource_provider); | 59 ResourceProvider* resource_provider); |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 static size_t MaxFullUpdatesPerTick(ResourceProvider* resource_provider); | 62 static size_t MaxFullUpdatesPerTick(ResourceProvider* resource_provider); |
| 62 | 63 |
| 63 size_t MaxBlockingUpdates() const; | 64 size_t MaxBlockingUpdates() const; |
| 64 base::TimeDelta PendingUpdateTime() const; | 65 base::TimeDelta PendingUpdateTime() const; |
| 65 | 66 |
| 66 void UpdateTexture(ResourceUpdate update); | 67 void UpdateTexture(ResourceUpdate update); |
| 67 | 68 |
| 68 // This returns true when there were textures left to update. | 69 // This returns true when there were textures left to update. |
| 69 bool UpdateMoreTexturesIfEnoughTimeRemaining(); | 70 bool UpdateMoreTexturesIfEnoughTimeRemaining(); |
| 70 void UpdateMoreTexturesNow(); | 71 void UpdateMoreTexturesNow(); |
| 71 void OnTimerFired(); | 72 void OnTimerFired(); |
| 72 | 73 |
| 73 ResourceUpdateControllerClient* client_; | 74 ResourceUpdateControllerClient* client_; |
| 74 scoped_ptr<ResourceUpdateQueue> queue_; | 75 scoped_ptr<ResourceUpdateQueue> queue_; |
| 75 bool contents_textures_purged_; | 76 bool contents_textures_purged_; |
| 76 ResourceProvider* resource_provider_; | 77 ResourceProvider* resource_provider_; |
| 77 base::TimeTicks time_limit_; | 78 base::TimeTicks time_limit_; |
| 78 size_t texture_updates_per_tick_; | 79 size_t texture_updates_per_tick_; |
| 79 bool first_update_attempt_; | 80 bool first_update_attempt_; |
| 80 Thread* thread_; | 81 base::SingleThreadTaskRunner* task_runner_; |
| 81 base::WeakPtrFactory<ResourceUpdateController> weak_factory_; | 82 base::WeakPtrFactory<ResourceUpdateController> weak_factory_; |
| 82 bool task_posted_; | 83 bool task_posted_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(ResourceUpdateController); | 85 DISALLOW_COPY_AND_ASSIGN(ResourceUpdateController); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 } // namespace cc | 88 } // namespace cc |
| 88 | 89 |
| 89 #endif // CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ | 90 #endif // CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_ |
| OLD | NEW |