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_RASTER_WORKER_POOL_H_ 6#define CC_RESOURCES_RASTER_WORKER_POOL_H_ 7 8#include "cc/resources/rasterizer.h" 9#include "ui/gfx/geometry/size.h" 10 11namespace base { 12class SequencedTaskRunner; 13} 14 15namespace cc { 16 17class CC_EXPORT RasterWorkerPool { 18 public: 19 static unsigned kBenchmarkRasterTaskPriority; 20 static unsigned kRasterFinishedTaskPriority; 21 static unsigned kRasterTaskPriorityBase; 22 23 RasterWorkerPool(); 24 virtual ~RasterWorkerPool(); 25 26 // Set the number of threads to use for the global TaskGraphRunner instance. 27 // This can only be called once and must be called prior to 28 // GetNumRasterThreads(). 29 static void SetNumRasterThreads(int num_threads); 30 31 // Returns the number of threads used for the global TaskGraphRunner instance. 32 static int GetNumRasterThreads(); 33 34 // Returns a pointer to the global TaskGraphRunner instance. 35 static TaskGraphRunner* GetTaskGraphRunner(); 36 37 // Utility function that can be used to create a "raster finished" task that 38 // posts |callback| to |task_runner| when run. 39 static scoped_refptr<RasterizerTask> CreateRasterFinishedTask( 40 base::SequencedTaskRunner* task_runner, 41 const base::Closure& callback); 42 43 // Utility function that can be used to call ::ScheduleOnOriginThread() for 44 // each task in |graph|. 45 static void ScheduleTasksOnOriginThread(RasterizerTaskClient* client, 46 TaskGraph* graph); 47 48 // Utility function that can be used to build a task graph. Inserts a node 49 // that represents |task| in |graph|. See TaskGraph definition for valid 50 // |priority| values. 51 static void InsertNodeForTask(TaskGraph* graph, 52 RasterizerTask* task, 53 unsigned priority, 54 size_t dependencies); 55 56 // Utility function that can be used to build a task graph. Inserts nodes that 57 // represent |task| and all its image decode dependencies in |graph|. 58 static void InsertNodesForRasterTask( 59 TaskGraph* graph, 60 RasterTask* task, 61 const ImageDecodeTask::Vector& decode_tasks, 62 unsigned priority); 63 64 // Utility functions that transparently create a temporary bitmap and copy 65 // pixels to buffer when necessary. 66 static void AcquireBitmapForBuffer(SkBitmap* bitmap, 67 uint8_t* buffer, 68 ResourceFormat format, 69 const gfx::Size& size, 70 int stride); 71 static void ReleaseBitmapForBuffer(SkBitmap* bitmap, 72 uint8_t* buffer, 73 ResourceFormat format); 74 75 // Type-checking downcast routine. 76 virtual Rasterizer* AsRasterizer() = 0; 77}; 78 79} // namespace cc 80 81#endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 82