| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_RASTER_TILE_TASK_RUNNER_H_ | 5 #ifndef CC_RASTER_TILE_TASK_RUNNER_H_ |
| 6 #define CC_RASTER_TILE_TASK_RUNNER_H_ | 6 #define CC_RASTER_TILE_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "cc/raster/task_graph_runner.h" | 13 #include "cc/raster/task_graph_runner.h" |
| 14 #include "cc/resources/resource_format.h" | 14 #include "cc/resources/resource_format.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 class ImageDecodeTask; | 17 class ImageDecodeTask; |
| 18 class RasterTask; | 18 class RasterTask; |
| 19 class Resource; | 19 class Resource; |
| 20 class RasterBuffer; | 20 class RasterBuffer; |
| 21 | 21 |
| 22 const TaskTypeId kRasterTaskTypeId = kDefaultTaskTypeId + 1; |
| 23 const TaskTypeId kImageDecodeTaskTypeId = kDefaultTaskTypeId + 2; |
| 24 |
| 22 class CC_EXPORT TileTaskClient { | 25 class CC_EXPORT TileTaskClient { |
| 23 public: | 26 public: |
| 24 virtual std::unique_ptr<RasterBuffer> AcquireBufferForRaster( | 27 virtual std::unique_ptr<RasterBuffer> AcquireBufferForRaster( |
| 25 const Resource* resource, | 28 const Resource* resource, |
| 26 uint64_t resource_content_id, | 29 uint64_t resource_content_id, |
| 27 uint64_t previous_content_id) = 0; | 30 uint64_t previous_content_id) = 0; |
| 28 virtual void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) = 0; | 31 virtual void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) = 0; |
| 29 | 32 |
| 30 protected: | 33 protected: |
| 31 virtual ~TileTaskClient() {} | 34 virtual ~TileTaskClient() {} |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 class CC_EXPORT TileTask : public Task { | 37 class CC_EXPORT TileTask : public Task { |
| 35 public: | 38 public: |
| 36 typedef std::vector<scoped_refptr<TileTask>> Vector; | 39 typedef std::vector<scoped_refptr<TileTask>> Vector; |
| 37 | 40 |
| 38 virtual void ScheduleOnOriginThread(TileTaskClient* client) = 0; | |
| 39 virtual void CompleteOnOriginThread(TileTaskClient* client) = 0; | |
| 40 | |
| 41 void WillSchedule(); | |
| 42 void DidSchedule(); | |
| 43 bool HasBeenScheduled() const; | |
| 44 | |
| 45 void WillComplete(); | |
| 46 void DidComplete(); | 41 void DidComplete(); |
| 47 bool HasCompleted() const; | 42 bool HasCompleted() const; |
| 48 | 43 |
| 49 protected: | 44 protected: |
| 50 TileTask(); | 45 TileTask(); |
| 51 ~TileTask() override; | 46 ~TileTask() override; |
| 52 | 47 |
| 53 bool did_schedule_; | |
| 54 bool did_complete_; | 48 bool did_complete_; |
| 55 }; | 49 }; |
| 56 | 50 |
| 57 class CC_EXPORT ImageDecodeTask : public TileTask { | 51 class CC_EXPORT ImageDecodeTask : public TileTask { |
| 58 public: | 52 public: |
| 59 typedef std::vector<scoped_refptr<ImageDecodeTask>> Vector; | 53 typedef std::vector<scoped_refptr<ImageDecodeTask>> Vector; |
| 60 | 54 |
| 61 protected: | 55 protected: |
| 62 ImageDecodeTask(); | 56 ImageDecodeTask(); |
| 63 ~ImageDecodeTask() override; | 57 ~ImageDecodeTask() override; |
| 64 }; | 58 }; |
| 65 | 59 |
| 66 class CC_EXPORT RasterTask : public TileTask { | 60 class CC_EXPORT RasterTask : public TileTask { |
| 67 public: | 61 public: |
| 68 typedef std::vector<scoped_refptr<RasterTask>> Vector; | 62 typedef std::vector<scoped_refptr<RasterTask>> Vector; |
| 69 | 63 |
| 70 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } | 64 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } |
| 71 | 65 |
| 72 protected: | 66 protected: |
| 73 explicit RasterTask(ImageDecodeTask::Vector* dependencies); | 67 explicit RasterTask(ImageDecodeTask::Vector* dependencies); |
| 74 ~RasterTask() override; | 68 ~RasterTask() override; |
| 75 | 69 |
| 76 private: | 70 private: |
| 77 ImageDecodeTask::Vector dependencies_; | 71 ImageDecodeTask::Vector dependencies_; |
| 78 }; | 72 }; |
| 79 | 73 |
| 80 // This interface can be used to schedule and run tile tasks. | 74 // This interface can be used to schedule and run tile tasks. |
| 81 // The client can call CheckForCompletedTasks() at any time to dispatch | 75 // The client can call CollectCompletedTasks() at any time to process |
| 82 // pending completion callbacks for all tasks that have finished running. | 76 // all completed tasks at the moment that have finished running or cancelled. |
| 83 class CC_EXPORT TileTaskRunner { | 77 class CC_EXPORT TileTaskRunner { |
| 84 public: | 78 public: |
| 85 // Tells the worker pool to shutdown after canceling all previously scheduled | 79 // Tells the worker pool to shutdown after canceling all previously scheduled |
| 86 // tasks. Reply callbacks are still guaranteed to run when | 80 // tasks. Reply callbacks are still guaranteed to run when |
| 87 // CheckForCompletedTasks() is called. | 81 // CollectCompletedTasks() is called. |
| 88 virtual void Shutdown() = 0; | 82 virtual void Shutdown() = 0; |
| 89 | 83 |
| 90 // Schedule running of tile tasks in |graph| and all dependencies. | 84 // Schedule running of tile tasks in |graph| and all dependencies. |
| 91 // Previously scheduled tasks that are not in |graph| will be canceled unless | 85 // Previously scheduled tasks that are not in |graph| will be canceled unless |
| 92 // already running. Once scheduled, reply callbacks are guaranteed to run for | 86 // already running. Once scheduled, reply callbacks are guaranteed to run for |
| 93 // all tasks even if they later get canceled by another call to | 87 // all tasks even if they later get canceled by another call to |
| 94 // ScheduleTasks(). | 88 // ScheduleTasks(). |
| 95 virtual void ScheduleTasks(TaskGraph* graph) = 0; | 89 virtual void ScheduleTasks(TaskGraph* graph) = 0; |
| 96 | 90 |
| 97 // Check for completed tasks and dispatch reply callbacks. | 91 // Collect completed tasks. |
| 98 virtual void CheckForCompletedTasks() = 0; | 92 virtual void CollectCompletedTasks(Task::Vector* completed_tasks) = 0; |
| 99 | 93 |
| 100 // Returns the format to use for the tiles. | 94 // Returns the format to use for the tiles. |
| 101 virtual ResourceFormat GetResourceFormat(bool must_support_alpha) const = 0; | 95 virtual ResourceFormat GetResourceFormat(bool must_support_alpha) const = 0; |
| 102 | 96 |
| 103 // Determine if the resource requires swizzling. | 97 // Determine if the resource requires swizzling. |
| 104 virtual bool GetResourceRequiresSwizzle(bool must_support_alpha) const = 0; | 98 virtual bool GetResourceRequiresSwizzle(bool must_support_alpha) const = 0; |
| 105 | 99 |
| 100 // TODO(prashant.n): This will be removed soon. Don't use this. |
| 101 virtual TileTaskClient* AsTileTaskClient() = 0; |
| 102 |
| 106 protected: | 103 protected: |
| 107 // Check if resource format matches output format. | 104 // Check if resource format matches output format. |
| 108 static bool ResourceFormatRequiresSwizzle(ResourceFormat format); | 105 static bool ResourceFormatRequiresSwizzle(ResourceFormat format); |
| 109 | 106 |
| 110 virtual ~TileTaskRunner() {} | 107 virtual ~TileTaskRunner() {} |
| 111 }; | 108 }; |
| 112 | 109 |
| 113 } // namespace cc | 110 } // namespace cc |
| 114 | 111 |
| 115 #endif // CC_RASTER_TILE_TASK_RUNNER_H_ | 112 #endif // CC_RASTER_TILE_TASK_RUNNER_H_ |
| OLD | NEW |