blob: d32178b78b8293bc34d601d4d28be54ae29f3af9 [file] [log] [blame]
mtklein30bf3e22014-06-03 13:57:14 -07001/*
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"
mtklein30bf3e22014-06-03 13:57:14 -07009#include "DMUtil.h"
10#include "DMWriteTask.h"
11#include "SkBitmap.h"
12#include "SkCanvas.h"
13#include "SkStream.h"
14
15namespace DM {
16
17PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
halcanarya4c60942014-08-26 10:38:07 -070018 SkStreamAsset* pdf,
mtklein30bf3e22014-06-03 13:57:14 -070019 RasterizePdfProc proc)
20 : CpuTask(parent)
21 , fName(UnderJoin(parent.name().c_str(), "rasterize"))
halcanarya4c60942014-08-26 10:38:07 -070022 , fPdf(pdf)
23 , fRasterize(proc) {
24 SkASSERT(fPdf.get());
25 SkASSERT(fPdf->unique());
26}
mtklein30bf3e22014-06-03 13:57:14 -070027
28void PDFRasterizeTask::draw() {
mtklein30bf3e22014-06-03 13:57:14 -070029 SkBitmap bitmap;
30
halcanarya4c60942014-08-26 10:38:07 -070031 if (fRasterize(fPdf.get(), &bitmap)) {
mtkleinea65bfa2014-09-09 07:59:46 -070032 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "PDF", bitmap)));
mtkleine4d3e602014-06-06 09:28:43 -070033 } else {
34 this->fail();
mtklein30bf3e22014-06-03 13:57:14 -070035 }
36}
37
38} // namespace DM