• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
6 #define CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
7 
8 #include <deque>
9 #include <set>
10 #include <vector>
11 
12 #include "base/containers/hash_tables.h"
13 #include "cc/resources/raster_worker_pool.h"
14 
15 namespace cc {
16 
17 class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool {
18  public:
19   virtual ~PixelBufferRasterWorkerPool();
20 
Create(ResourceProvider * resource_provider,size_t num_threads,size_t max_transfer_buffer_usage_bytes)21   static scoped_ptr<RasterWorkerPool> Create(
22       ResourceProvider* resource_provider,
23       size_t num_threads,
24       size_t max_transfer_buffer_usage_bytes) {
25     return make_scoped_ptr<RasterWorkerPool>(
26         new PixelBufferRasterWorkerPool(resource_provider,
27                                         num_threads,
28                                         max_transfer_buffer_usage_bytes));
29   }
30 
31   // Overridden from WorkerPool:
32   virtual void Shutdown() OVERRIDE;
33   virtual void CheckForCompletedTasks() OVERRIDE;
34 
35   // Overridden from RasterWorkerPool:
36   virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE;
37   virtual GLenum GetResourceTarget() const OVERRIDE;
38   virtual ResourceFormat GetResourceFormat() const OVERRIDE;
39   virtual void OnRasterTasksFinished() OVERRIDE;
40   virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE;
41 
42  private:
43   PixelBufferRasterWorkerPool(ResourceProvider* resource_provider,
44                               size_t num_threads,
45                               size_t max_transfer_buffer_usage_bytes);
46 
47   void FlushUploads();
48   void CheckForCompletedUploads();
49   void ScheduleCheckForCompletedRasterTasks();
50   void CheckForCompletedRasterTasks();
51   void ScheduleMoreTasks();
52   void OnRasterTaskCompleted(
53       scoped_refptr<internal::RasterWorkerPoolTask> task,
54       bool was_canceled,
55       bool needs_upload);
56   void DidCompleteRasterTask(internal::RasterWorkerPoolTask* task);
57   unsigned PendingRasterTaskCount() const;
58   bool HasPendingTasks() const;
59   bool HasPendingTasksRequiredForActivation() const;
60 
61   const char* StateName() const;
62   scoped_ptr<base::Value> StateAsValue() const;
63   scoped_ptr<base::Value> ThrottleStateAsValue() const;
64 
65   bool shutdown_;
66 
67   TaskMap pixel_buffer_tasks_;
68 
69   typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > TaskDeque;
70   TaskDeque tasks_with_pending_upload_;
71   TaskDeque completed_tasks_;
72 
73   typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet;
74   TaskSet tasks_required_for_activation_;
75 
76   size_t scheduled_raster_task_count_;
77   size_t bytes_pending_upload_;
78   size_t max_bytes_pending_upload_;
79   bool has_performed_uploads_since_last_flush_;
80   base::CancelableClosure check_for_completed_raster_tasks_callback_;
81   bool check_for_completed_raster_tasks_pending_;
82 
83   bool should_notify_client_if_no_tasks_are_pending_;
84   bool should_notify_client_if_no_tasks_required_for_activation_are_pending_;
85   ResourceFormat format_;
86 
87   DISALLOW_COPY_AND_ASSIGN(PixelBufferRasterWorkerPool);
88 };
89 
90 }  // namespace cc
91 
92 #endif  // CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
93