summaryrefslogtreecommitdiffstats
path: root/cc/raster_worker_pool.cc
blob: d461d8cbaae6bfae673e2c8ad6800c786cf49d1b (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
// Copyright 2012 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.

#include "cc/raster_worker_pool.h"

#include "cc/picture_pile_impl.h"

namespace cc {

namespace {

class RasterWorkerPoolTaskImpl : public internal::WorkerPoolTask {
 public:
  RasterWorkerPoolTaskImpl(PicturePileImpl* picture_pile,
                           const RasterWorkerPool::RasterCallback& task,
                           const base::Closure& reply)
      : internal::WorkerPoolTask(reply),
        picture_pile_(picture_pile),
        task_(task) {
    DCHECK(picture_pile_);
  }

  virtual void Run(RenderingStats* rendering_stats) OVERRIDE {
    task_.Run(picture_pile_.get(), rendering_stats);
  }

 private:
  scoped_refptr<PicturePileImpl> picture_pile_;
  RasterWorkerPool::RasterCallback task_;
};

}  // namespace

RasterWorkerPool::RasterWorkerPool(
    size_t num_threads, bool record_rendering_stats)
    : WorkerPool(num_threads, record_rendering_stats) {
}

RasterWorkerPool::~RasterWorkerPool() {
}

void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile,
                                              const RasterCallback& task,
                                              const base::Closure& reply) {
  Worker* worker = GetWorkerForNextTask();

  scoped_refptr<PicturePileImpl> picture_pile_clone =
      picture_pile->GetCloneForDrawingOnThread(worker);

  worker->PostTask(
      make_scoped_ptr(new RasterWorkerPoolTaskImpl(
                          picture_pile_clone.get(),
                          task,
                          reply)).PassAs<internal::WorkerPoolTask>());
}

}  // namespace cc