summaryrefslogtreecommitdiffstats
path: root/cc/resources/gpu_raster_worker_pool.h
blob: d0913313a2698faa89bfe894e897e05c7b9e3f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_RESOURCES_GPU_RASTER_WORKER_POOL_H_
#define CC_RESOURCES_GPU_RASTER_WORKER_POOL_H_

#include "base/memory/weak_ptr.h"
#include "cc/resources/raster_worker_pool.h"
#include "cc/resources/rasterizer.h"

namespace cc {
class ContextProvider;
class ResourceProvider;

class CC_EXPORT GpuRasterWorkerPool : public RasterWorkerPool,
                                      public Rasterizer,
                                      public RasterizerTaskClient {
 public:
  virtual ~GpuRasterWorkerPool();

  static scoped_ptr<RasterWorkerPool> Create(
      base::SequencedTaskRunner* task_runner,
      ContextProvider* context_provider,
      ResourceProvider* resource_provider);

  // Overridden from RasterWorkerPool:
  virtual Rasterizer* AsRasterizer() OVERRIDE;

  // Overridden from Rasterizer:
  virtual void SetClient(RasterizerClient* client) OVERRIDE;
  virtual void Shutdown() OVERRIDE;
  virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE;
  virtual void CheckForCompletedTasks() OVERRIDE;

  // Overridden from RasterizerTaskClient:
  virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) OVERRIDE;
  virtual void ReleaseCanvasForRaster(RasterTask* task) OVERRIDE;

 private:
  GpuRasterWorkerPool(base::SequencedTaskRunner* task_runner,
                      ContextProvider* context_provider,
                      ResourceProvider* resource_provider);

  void OnRasterFinished();
  void OnRasterRequiredForActivationFinished();
  void ScheduleRunTasksOnOriginThread();
  void RunTasksOnOriginThread();
  void RunTaskOnOriginThread(RasterizerTask* task);

  scoped_refptr<base::SequencedTaskRunner> task_runner_;
  scoped_ptr<TaskGraphRunner> task_graph_runner_;
  const NamespaceToken namespace_token_;
  RasterizerClient* client_;
  ContextProvider* context_provider_;
  ResourceProvider* resource_provider_;

  bool run_tasks_on_origin_thread_pending_;

  bool raster_tasks_pending_;
  bool raster_tasks_required_for_activation_pending_;

  base::WeakPtrFactory<GpuRasterWorkerPool> raster_finished_weak_ptr_factory_;

  scoped_refptr<RasterizerTask> raster_finished_task_;
  scoped_refptr<RasterizerTask> raster_required_for_activation_finished_task_;

  // Task graph used when scheduling tasks and vector used to gather
  // completed tasks.
  TaskGraph graph_;
  Task::Vector completed_tasks_;

  base::WeakPtrFactory<GpuRasterWorkerPool> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(GpuRasterWorkerPool);
};

}  // namespace cc

#endif  // CC_RESOURCES_GPU_RASTER_WORKER_POOL_H_