GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / resources / resource_update_controller.h
blob1946df47c1636468a2f75ff36aba065c1891a6f2
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_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_
6 #define CC_RESOURCES_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/time.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/resources/resource_update_queue.h"
15 namespace base { class SingleThreadTaskRunner; }
17 namespace cc {
19 class ResourceProvider;
21 class ResourceUpdateControllerClient {
22 public:
23 virtual void ReadyToFinalizeTextureUpdates() = 0;
25 protected:
26 virtual ~ResourceUpdateControllerClient() {}
29 class CC_EXPORT ResourceUpdateController {
30 public:
31 static scoped_ptr<ResourceUpdateController> Create(
32 ResourceUpdateControllerClient* client,
33 base::SingleThreadTaskRunner* task_runner,
34 scoped_ptr<ResourceUpdateQueue> queue,
35 ResourceProvider* resource_provider) {
36 return make_scoped_ptr(new ResourceUpdateController(
37 client, task_runner, queue.Pass(), resource_provider));
39 static size_t MaxPartialTextureUpdates();
41 virtual ~ResourceUpdateController();
43 // Discard uploads to textures that were evicted on the impl thread.
44 void DiscardUploadsToEvictedResources();
46 void PerformMoreUpdates(base::TimeTicks time_limit);
47 void Finalize();
50 // Virtual for testing.
51 virtual size_t UpdateMoreTexturesSize() const;
52 virtual base::TimeTicks UpdateMoreTexturesCompletionTime();
54 protected:
55 ResourceUpdateController(ResourceUpdateControllerClient* client,
56 base::SingleThreadTaskRunner* task_runner,
57 scoped_ptr<ResourceUpdateQueue> queue,
58 ResourceProvider* resource_provider);
60 private:
61 static size_t MaxFullUpdatesPerTick(ResourceProvider* resource_provider);
63 size_t MaxBlockingUpdates() const;
65 void UpdateTexture(ResourceUpdate update);
67 // This returns true when there were textures left to update.
68 bool UpdateMoreTexturesIfEnoughTimeRemaining();
69 void UpdateMoreTexturesNow();
70 void OnTimerFired();
72 ResourceUpdateControllerClient* client_;
73 scoped_ptr<ResourceUpdateQueue> queue_;
74 ResourceProvider* resource_provider_;
75 base::TimeTicks time_limit_;
76 size_t texture_updates_per_tick_;
77 bool first_update_attempt_;
78 base::SingleThreadTaskRunner* task_runner_;
79 bool task_posted_;
80 bool ready_to_finalize_;
81 base::WeakPtrFactory<ResourceUpdateController> weak_factory_;
83 DISALLOW_COPY_AND_ASSIGN(ResourceUpdateController);
86 } // namespace cc
88 #endif // CC_RESOURCES_RESOURCE_UPDATE_CONTROLLER_H_