Home | History | Annotate | Download | only in resources
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_
      6 #define CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/weak_ptr.h"
     11 #include "base/values.h"
     12 #include "cc/resources/raster_worker_pool.h"
     13 #include "cc/resources/rasterizer.h"
     14 
     15 namespace cc {
     16 class ResourcePool;
     17 class ResourceProvider;
     18 class ScopedResource;
     19 
     20 class CC_EXPORT ImageCopyRasterWorkerPool : public RasterWorkerPool,
     21                                             public Rasterizer,
     22                                             public RasterizerTaskClient {
     23  public:
     24   virtual ~ImageCopyRasterWorkerPool();
     25 
     26   static scoped_ptr<RasterWorkerPool> Create(
     27       base::SequencedTaskRunner* task_runner,
     28       TaskGraphRunner* task_graph_runner,
     29       ResourceProvider* resource_provider,
     30       ResourcePool* resource_pool);
     31 
     32   // Overridden from RasterWorkerPool:
     33   virtual Rasterizer* AsRasterizer() OVERRIDE;
     34 
     35   // Overridden from Rasterizer:
     36   virtual void SetClient(RasterizerClient* client) OVERRIDE;
     37   virtual void Shutdown() OVERRIDE;
     38   virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE;
     39   virtual void CheckForCompletedTasks() OVERRIDE;
     40 
     41   // Overridden from RasterizerTaskClient:
     42   virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) OVERRIDE;
     43   virtual void ReleaseCanvasForRaster(RasterTask* task) OVERRIDE;
     44 
     45  protected:
     46   ImageCopyRasterWorkerPool(base::SequencedTaskRunner* task_runner,
     47                             TaskGraphRunner* task_graph_runner,
     48                             ResourceProvider* resource_provider,
     49                             ResourcePool* resource_pool);
     50 
     51  private:
     52   struct RasterTaskState {
     53     class TaskComparator {
     54      public:
     55       explicit TaskComparator(const RasterTask* task) : task_(task) {}
     56 
     57       bool operator()(const RasterTaskState& state) const {
     58         return state.task == task_;
     59       }
     60 
     61      private:
     62       const RasterTask* task_;
     63     };
     64 
     65     typedef std::vector<RasterTaskState> Vector;
     66 
     67     RasterTaskState(const RasterTask* task, ScopedResource* resource)
     68         : task(task), resource(resource) {}
     69 
     70     const RasterTask* task;
     71     ScopedResource* resource;
     72   };
     73 
     74   void OnRasterFinished();
     75   void OnRasterRequiredForActivationFinished();
     76   void FlushCopies();
     77   scoped_ptr<base::Value> StateAsValue() const;
     78   scoped_ptr<base::Value> StagingStateAsValue() const;
     79 
     80   scoped_refptr<base::SequencedTaskRunner> task_runner_;
     81   TaskGraphRunner* task_graph_runner_;
     82   const NamespaceToken namespace_token_;
     83   RasterizerClient* client_;
     84   ResourceProvider* resource_provider_;
     85   ResourcePool* resource_pool_;
     86 
     87   RasterTaskState::Vector raster_task_states_;
     88 
     89   bool has_performed_copy_since_last_flush_;
     90 
     91   bool raster_tasks_pending_;
     92   bool raster_tasks_required_for_activation_pending_;
     93 
     94   base::WeakPtrFactory<ImageCopyRasterWorkerPool>
     95       raster_finished_weak_ptr_factory_;
     96 
     97   scoped_refptr<RasterizerTask> raster_finished_task_;
     98   scoped_refptr<RasterizerTask> raster_required_for_activation_finished_task_;
     99 
    100   // Task graph used when scheduling tasks and vector used to gather
    101   // completed tasks.
    102   TaskGraph graph_;
    103   Task::Vector completed_tasks_;
    104 
    105   DISALLOW_COPY_AND_ASSIGN(ImageCopyRasterWorkerPool);
    106 };
    107 
    108 }  // namespace cc
    109 
    110 #endif  // CC_RESOURCES_IMAGE_COPY_RASTER_WORKER_POOL_H_
    111