blob: 40b9d8bfbca8788dcfea37b256a9968de66bd99e [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"
9#include "DMExpectationsTask.h"
10#include "DMUtil.h"
11#include "DMWriteTask.h"
12#include "SkBitmap.h"
13#include "SkCanvas.h"
14#include "SkStream.h"
15
16namespace DM {
17
18PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
halcanarya4c60942014-08-26 10:38:07 -070019 SkStreamAsset* pdf,
mtklein30bf3e22014-06-03 13:57:14 -070020 RasterizePdfProc proc)
21 : CpuTask(parent)
22 , fName(UnderJoin(parent.name().c_str(), "rasterize"))
halcanarya4c60942014-08-26 10:38:07 -070023 , fPdf(pdf)
24 , fRasterize(proc) {
25 SkASSERT(fPdf.get());
26 SkASSERT(fPdf->unique());
27}
mtklein30bf3e22014-06-03 13:57:14 -070028
29void PDFRasterizeTask::draw() {
mtklein30bf3e22014-06-03 13:57:14 -070030 SkBitmap bitmap;
31
halcanarya4c60942014-08-26 10:38:07 -070032 if (fRasterize(fPdf.get(), &bitmap)) {
mtklein30bf3e22014-06-03 13:57:14 -070033 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtkleine4d3e602014-06-06 09:28:43 -070034 } else {
35 this->fail();
mtklein30bf3e22014-06-03 13:57:14 -070036 }
37}
38
39} // namespace DM