Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / cc / resources / image_copy_raster_worker_pool.h
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
3 // found in the LICENSE file.
4
5 #ifndef CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_
6 #define CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_
7
8 #include <vector>
9
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "cc/output/context_provider.h"
13 #include "cc/resources/raster_worker_pool.h"
14 #include "cc/resources/rasterizer.h"
15
16 namespace base {
17 namespace debug {
18 class ConvertableToTraceFormat;
19 class TracedValue;
20 }
21 }
22
23 namespace cc {
24 class ResourcePool;
25 class ResourceProvider;
26 class ScopedResource;
27
28 class CC_EXPORT ImageCopyRasterWorkerPool : public RasterWorkerPool,
29                                             public Rasterizer,
30                                             public RasterizerTaskClient {
31  public:
32   virtual ~ImageCopyRasterWorkerPool();
33
34   static scoped_ptr<RasterWorkerPool> Create(
35       base::SequencedTaskRunner* task_runner,
36       TaskGraphRunner* task_graph_runner,
37       ContextProvider* context_provider,
38       ResourceProvider* resource_provider,
39       ResourcePool* resource_pool);
40
41   // Overridden from RasterWorkerPool:
42   virtual Rasterizer* AsRasterizer() OVERRIDE;
43
44   // Overridden from Rasterizer:
45   virtual void SetClient(RasterizerClient* client) OVERRIDE;
46   virtual void Shutdown() OVERRIDE;
47   virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE;
48   virtual void CheckForCompletedTasks() OVERRIDE;
49
50   // Overridden from RasterizerTaskClient:
51   virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) OVERRIDE;
52   virtual void ReleaseCanvasForRaster(RasterTask* task) OVERRIDE;
53
54  protected:
55   ImageCopyRasterWorkerPool(base::SequencedTaskRunner* task_runner,
56                             TaskGraphRunner* task_graph_runner,
57                             ContextProvider* context_provider,
58                             ResourceProvider* resource_provider,
59                             ResourcePool* resource_pool);
60
61  private:
62   struct RasterTaskState {
63     class TaskComparator {
64      public:
65       explicit TaskComparator(const RasterTask* task) : task_(task) {}
66
67       bool operator()(const RasterTaskState& state) const {
68         return state.task == task_;
69       }
70
71      private:
72       const RasterTask* task_;
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   };
83
84   void OnRasterFinished();
85   void OnRasterRequiredForActivationFinished();
86   void FlushCopies();
87   scoped_refptr<base::debug::ConvertableToTraceFormat> StateAsValue() const;
88   void StagingStateAsValueInto(base::debug::TracedValue* staging_state) const;
89
90   scoped_refptr<base::SequencedTaskRunner> task_runner_;
91   TaskGraphRunner* task_graph_runner_;
92   const NamespaceToken namespace_token_;
93   RasterizerClient* client_;
94   ContextProvider* context_provider_;
95   ResourceProvider* resource_provider_;
96   ResourcePool* resource_pool_;
97
98   RasterTaskState::Vector raster_task_states_;
99
100   bool has_performed_copy_since_last_flush_;
101
102   bool raster_tasks_pending_;
103   bool raster_tasks_required_for_activation_pending_;
104
105   base::WeakPtrFactory<ImageCopyRasterWorkerPool>
106       raster_finished_weak_ptr_factory_;
107
108   scoped_refptr<RasterizerTask> raster_finished_task_;
109   scoped_refptr<RasterizerTask> raster_required_for_activation_finished_task_;
110
111   // Task graph used when scheduling tasks and vector used to gather
112   // completed tasks.
113   TaskGraph graph_;
114   Task::Vector completed_tasks_;
115
116   DISALLOW_COPY_AND_ASSIGN(ImageCopyRasterWorkerPool);
117 };
118
119 }  // namespace cc
120
121 #endif  // CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_