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_TILE_TASK_WORKER_POOL_H_
6 #define CC_RESOURCES_TILE_TASK_WORKER_POOL_H_
8 #include "base/threading/platform_thread.h"
9 #include "cc/resources/tile_task_runner.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/geometry/size.h"
14 class SequencedTaskRunner
;
19 class RenderingStatsInstrumentation
;
21 class CC_EXPORT TileTaskWorkerPool
{
23 static unsigned kBenchmarkTaskPriority
;
24 static unsigned kTaskSetFinishedTaskPriorityBase
;
25 static unsigned kTileTaskPriorityBase
;
28 virtual ~TileTaskWorkerPool();
30 // Set the number of threads to use for the global TaskGraphRunner instance.
31 // This can only be called once and must be called prior to
32 // GetNumWorkerThreads().
33 static void SetNumWorkerThreads(int num_threads
);
35 // Returns the number of threads used for the global TaskGraphRunner instance.
36 static int GetNumWorkerThreads();
38 // Set the priority of worker threads.
39 static void SetWorkerThreadPriority(base::ThreadPriority priority
);
41 // Returns a pointer to the global TaskGraphRunner instance.
42 static TaskGraphRunner
* GetTaskGraphRunner();
44 // Utility function that can be used to create a "Task set finished" task that
45 // posts |callback| to |task_runner| when run.
46 static scoped_refptr
<TileTask
> CreateTaskSetFinishedTask(
47 base::SequencedTaskRunner
* task_runner
,
48 const base::Closure
& callback
);
50 // Utility function that can be used to call ::ScheduleOnOriginThread() for
51 // each task in |graph|.
52 static void ScheduleTasksOnOriginThread(TileTaskClient
* client
,
55 // Utility function that can be used to build a task graph. Inserts a node
56 // that represents |task| in |graph|. See TaskGraph definition for valid
58 static void InsertNodeForTask(TaskGraph
* graph
,
63 // Utility function that can be used to build a task graph. Inserts nodes that
64 // represent |task| and all its image decode dependencies in |graph|.
65 static void InsertNodesForRasterTask(
68 const ImageDecodeTask::Vector
& decode_tasks
,
71 // Utility function that will create a temporary bitmap and copy pixels to
72 // |memory| when necessary.
73 static void PlaybackToMemory(void* memory
,
74 ResourceFormat format
,
75 const gfx::Size
& size
,
77 const RasterSource
* raster_source
,
78 const gfx::Rect
& rect
,
81 // Type-checking downcast routine.
82 virtual TileTaskRunner
* AsTileTaskRunner() = 0;
87 #endif // CC_RESOURCES_TILE_TASK_WORKER_POOL_H_