aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMPDFRasterizeTask.cpp
blob: d32178b78b8293bc34d601d4d28be54ae29f3af9 (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
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "DMPDFRasterizeTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkStream.h"

namespace DM {

PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
                                   SkStreamAsset* pdf,
                                   RasterizePdfProc proc)
    : CpuTask(parent)
    , fName(UnderJoin(parent.name().c_str(), "rasterize"))
    , fPdf(pdf)
    , fRasterize(proc) {
    SkASSERT(fPdf.get());
    SkASSERT(fPdf->unique());
}

void PDFRasterizeTask::draw() {
    SkBitmap bitmap;

    if (fRasterize(fPdf.get(), &bitmap)) {
        this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "PDF", bitmap)));
    } else {
        this->fail();
    }
}

}  // namespace DM