OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_IMAGE_COPY_RASTER_WORKER_POOL_H_ | 5 #ifndef CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_ |
6 #define CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_ | 6 #define CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/synchronization/lock.h" |
11 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "cc/base/scoped_ptr_deque.h" |
12 #include "cc/output/context_provider.h" | 12 #include "cc/output/context_provider.h" |
13 #include "cc/resources/raster_worker_pool.h" | 13 #include "cc/resources/raster_worker_pool.h" |
14 #include "cc/resources/rasterizer.h" | 14 #include "cc/resources/rasterizer.h" |
| 15 #include "cc/resources/resource_provider.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 namespace debug { | 18 namespace debug { |
18 class ConvertableToTraceFormat; | 19 class ConvertableToTraceFormat; |
19 class TracedValue; | 20 class TracedValue; |
20 } | 21 } |
21 } | 22 } |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
24 class ResourcePool; | 25 class ResourcePool; |
(...skipping 16 matching lines...) Expand all Loading... |
41 // Overridden from RasterWorkerPool: | 42 // Overridden from RasterWorkerPool: |
42 virtual Rasterizer* AsRasterizer() OVERRIDE; | 43 virtual Rasterizer* AsRasterizer() OVERRIDE; |
43 | 44 |
44 // Overridden from Rasterizer: | 45 // Overridden from Rasterizer: |
45 virtual void SetClient(RasterizerClient* client) OVERRIDE; | 46 virtual void SetClient(RasterizerClient* client) OVERRIDE; |
46 virtual void Shutdown() OVERRIDE; | 47 virtual void Shutdown() OVERRIDE; |
47 virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE; | 48 virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE; |
48 virtual void CheckForCompletedTasks() OVERRIDE; | 49 virtual void CheckForCompletedTasks() OVERRIDE; |
49 | 50 |
50 // Overridden from RasterizerTaskClient: | 51 // Overridden from RasterizerTaskClient: |
51 virtual RasterBuffer* AcquireBufferForRaster(RasterTask* task) OVERRIDE; | 52 virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster( |
52 virtual void ReleaseBufferForRaster(RasterTask* task) OVERRIDE; | 53 const Resource* resource) OVERRIDE; |
| 54 virtual void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) OVERRIDE; |
| 55 |
| 56 // Schedule copying from |src| to |dst|. Returns the number of currently |
| 57 // pending copy operations. |
| 58 // Note: this can be called from a worker thread. |
| 59 size_t ScheduleCopy(scoped_ptr<ScopedResource> src, const Resource* dst); |
| 60 |
| 61 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } |
| 62 ResourceProvider* resource_provider() { return resource_provider_; } |
| 63 ResourcePool* resource_pool() { return resource_pool_; } |
53 | 64 |
54 protected: | 65 protected: |
55 ImageCopyRasterWorkerPool(base::SequencedTaskRunner* task_runner, | 66 ImageCopyRasterWorkerPool(base::SequencedTaskRunner* task_runner, |
56 TaskGraphRunner* task_graph_runner, | 67 TaskGraphRunner* task_graph_runner, |
57 ContextProvider* context_provider, | 68 ContextProvider* context_provider, |
58 ResourceProvider* resource_provider, | 69 ResourceProvider* resource_provider, |
59 ResourcePool* resource_pool); | 70 ResourcePool* resource_pool); |
60 | 71 |
61 private: | 72 private: |
62 struct RasterTaskState { | 73 struct ResourceCopyOperation { |
63 class TaskComparator { | 74 typedef ScopedPtrDeque<ResourceCopyOperation> Deque; |
64 public: | |
65 explicit TaskComparator(const RasterTask* task) : task_(task) {} | |
66 | 75 |
67 bool operator()(const RasterTaskState& state) const { | 76 ResourceCopyOperation(scoped_ptr<ScopedResource> src, const Resource* dst); |
68 return state.task == task_; | 77 ~ResourceCopyOperation(); |
69 } | |
70 | 78 |
71 private: | 79 scoped_ptr<ScopedResource> src; |
72 const RasterTask* task_; | 80 const Resource* dst; |
73 }; | |
74 | |
75 typedef std::vector<RasterTaskState> Vector; | |
76 | |
77 RasterTaskState(const RasterTask* task, ScopedResource* resource) | |
78 : task(task), resource(resource) {} | |
79 | |
80 const RasterTask* task; | |
81 ScopedResource* resource; | |
82 }; | 81 }; |
83 | 82 |
84 void OnRasterFinished(); | 83 void OnRasterFinished(); |
85 void OnRasterRequiredForActivationFinished(); | 84 void OnRasterRequiredForActivationFinished(); |
86 void FlushCopies(); | 85 void CopyResources(size_t count); |
87 scoped_refptr<base::debug::ConvertableToTraceFormat> StateAsValue() const; | 86 scoped_refptr<base::debug::ConvertableToTraceFormat> StateAsValue() const; |
88 void StagingStateAsValueInto(base::debug::TracedValue* staging_state) const; | 87 void StagingStateAsValueInto(base::debug::TracedValue* staging_state) const; |
89 | 88 |
90 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 89 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
91 TaskGraphRunner* task_graph_runner_; | 90 TaskGraphRunner* task_graph_runner_; |
92 const NamespaceToken namespace_token_; | 91 const NamespaceToken namespace_token_; |
93 RasterizerClient* client_; | 92 RasterizerClient* client_; |
94 ContextProvider* context_provider_; | 93 ContextProvider* context_provider_; |
95 ResourceProvider* resource_provider_; | 94 ResourceProvider* resource_provider_; |
96 ResourcePool* resource_pool_; | 95 ResourcePool* resource_pool_; |
97 | 96 |
98 RasterTaskState::Vector raster_task_states_; | |
99 | |
100 bool has_performed_copy_since_last_flush_; | |
101 | |
102 bool raster_tasks_pending_; | 97 bool raster_tasks_pending_; |
103 bool raster_tasks_required_for_activation_pending_; | 98 bool raster_tasks_required_for_activation_pending_; |
104 | 99 |
105 scoped_refptr<RasterizerTask> raster_finished_task_; | 100 scoped_refptr<RasterizerTask> raster_finished_task_; |
106 scoped_refptr<RasterizerTask> raster_required_for_activation_finished_task_; | 101 scoped_refptr<RasterizerTask> raster_required_for_activation_finished_task_; |
107 | 102 |
108 // Task graph used when scheduling tasks and vector used to gather | 103 // |pending_resource_copy_operations_lock_| must be acquired when accessing |
109 // completed tasks. | 104 // |pending_resource_copy_operations_|. |
| 105 base::Lock pending_resource_copy_operations_lock_; |
| 106 ResourceCopyOperation::Deque pending_resource_copy_operations_; |
| 107 |
| 108 // Callback used to copy a batch of resources. |
| 109 base::Closure copy_batch_of_resources_callback_; |
| 110 |
| 111 // Task graph used when scheduling tasks, vector used to gather completed |
| 112 // tasks and vector used to gather resource copy operations. |
110 TaskGraph graph_; | 113 TaskGraph graph_; |
111 Task::Vector completed_tasks_; | 114 Task::Vector completed_tasks_; |
112 | 115 |
113 base::WeakPtrFactory<ImageCopyRasterWorkerPool> | 116 base::WeakPtrFactory<ImageCopyRasterWorkerPool> |
114 raster_finished_weak_ptr_factory_; | 117 raster_finished_weak_ptr_factory_; |
| 118 base::WeakPtrFactory<ImageCopyRasterWorkerPool> |
| 119 copy_batch_of_resources_weak_ptr_factory_; |
115 | 120 |
116 DISALLOW_COPY_AND_ASSIGN(ImageCopyRasterWorkerPool); | 121 DISALLOW_COPY_AND_ASSIGN(ImageCopyRasterWorkerPool); |
117 }; | 122 }; |
118 | 123 |
119 } // namespace cc | 124 } // namespace cc |
120 | 125 |
121 #endif // CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_ | 126 #endif // CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_ |
OLD | NEW |