Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / dm / DMPDFRasterizeTask.cpp
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "DMPDFRasterizeTask.h"
9 #include "DMUtil.h"
10 #include "DMWriteTask.h"
11 #include "SkBitmap.h"
12 #include "SkCanvas.h"
13 #include "SkStream.h"
14
15 namespace DM {
16
17 PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
18                                    SkStreamAsset* pdf,
19                                    RasterizePdfProc proc)
20     : CpuTask(parent)
21     , fName(UnderJoin(parent.name().c_str(), "rasterize"))
22     , fPdf(pdf)
23     , fRasterize(proc) {
24     SkASSERT(fPdf.get());
25     SkASSERT(fPdf->unique());
26 }
27
28 void PDFRasterizeTask::draw() {
29     SkBitmap bitmap;
30
31     if (fRasterize(fPdf.get(), &bitmap)) {
32         this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "PDF", bitmap)));
33     } else {
34         this->fail();
35     }
36 }
37
38 }  // namespace DM