mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 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 "DMExpectationsTask.h" |
| 10 | #include "DMUtil.h" |
| 11 | #include "DMWriteTask.h" |
| 12 | #include "SkBitmap.h" |
| 13 | #include "SkCanvas.h" |
| 14 | #include "SkStream.h" |
| 15 | |
| 16 | namespace DM { |
| 17 | |
| 18 | PDFRasterizeTask::PDFRasterizeTask(const Task& parent, |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 19 | SkStreamAsset* pdf, |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 20 | RasterizePdfProc proc) |
| 21 | : CpuTask(parent) |
| 22 | , fName(UnderJoin(parent.name().c_str(), "rasterize")) |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 23 | , fPdf(pdf) |
| 24 | , fRasterize(proc) { |
| 25 | SkASSERT(fPdf.get()); |
| 26 | SkASSERT(fPdf->unique()); |
| 27 | } |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 28 | |
| 29 | void PDFRasterizeTask::draw() { |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 30 | SkBitmap bitmap; |
| 31 | |
halcanary | a4c6094 | 2014-08-26 10:38:07 -0700 | [diff] [blame] | 32 | if (fRasterize(fPdf.get(), &bitmap)) { |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 33 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 34 | } else { |
| 35 | this->fail(); |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | } // namespace DM |