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.
5 #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_
6 #define CC_RESOURCES_RASTER_WORKER_POOL_H_
8 #include "cc/resources/rasterizer.h"
11 class SequencedTaskRunner
;
16 class CC_EXPORT RasterWorkerPool
{
18 static unsigned kOnDemandRasterTaskPriority
;
19 static unsigned kBenchmarkRasterTaskPriority
;
20 static unsigned kRasterFinishedTaskPriority
;
21 static unsigned kRasterRequiredForActivationFinishedTaskPriority
;
22 static unsigned kRasterTaskPriorityBase
;
25 virtual ~RasterWorkerPool();
27 // Set the number of threads to use for the global TaskGraphRunner instance.
28 // This can only be called once and must be called prior to
29 // GetNumRasterThreads().
30 static void SetNumRasterThreads(int num_threads
);
32 // Returns the number of threads used for the global TaskGraphRunner instance.
33 static int GetNumRasterThreads();
35 // Returns a pointer to the global TaskGraphRunner instance.
36 static TaskGraphRunner
* GetTaskGraphRunner();
38 // Returns a unique clone index for the current thread. Guaranteed to be a
39 // value between 0 and GetNumRasterThreads() - 1.
40 static size_t GetPictureCloneIndexForCurrentThread();
42 // Utility function that can be used to create a "raster finished" task that
43 // posts |callback| to |task_runner| when run.
44 static scoped_refptr
<RasterizerTask
> CreateRasterFinishedTask(
45 base::SequencedTaskRunner
* task_runner
,
46 const base::Closure
& callback
);
48 // Utility function that can be used to create a "raster required for
49 // activation finished" task that posts |callback| to |task_runner| when run.
50 static scoped_refptr
<RasterizerTask
>
51 CreateRasterRequiredForActivationFinishedTask(
52 size_t tasks_required_for_activation_count
,
53 base::SequencedTaskRunner
* task_runner
,
54 const base::Closure
& callback
);
56 // Utility function that can be used to call ::ScheduleOnOriginThread() for
57 // each task in |graph|.
58 static void ScheduleTasksOnOriginThread(RasterizerTaskClient
* client
,
61 // Utility function that can be used to build a task graph. Inserts a node
62 // that represents |task| in |graph|. See TaskGraph definition for valid
64 static void InsertNodeForTask(TaskGraph
* graph
,
69 // Utility function that can be used to build a task graph. Inserts nodes that
70 // represent |task| and all its image decode dependencies in |graph|.
71 static void InsertNodesForRasterTask(
74 const ImageDecodeTask::Vector
& decode_tasks
,
77 // Type-checking downcast routine.
78 virtual Rasterizer
* AsRasterizer() = 0;
83 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_