Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: src/doc/SkDocument_PDF.cpp

Issue 944643002: PDF: Now threadsafe! (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: formatting Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/pdf.gypi ('k') | src/pdf/SkPDFBitmap.h » ('j') | src/pdf/SkPDFDevice.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/doc/SkDocument_PDF.cpp
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index de65efe8c8cdaae59ddd7f0b4a35d464499fdfbc..1e54273522163a7693976f54c9651eeeece53338 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -6,21 +6,20 @@
*/
#include "SkDocument.h"
+#include "SkPDFCanon.h"
#include "SkPDFDocument.h"
#include "SkPDFDevice.h"
class SkDocument_PDF : public SkDocument {
public:
- SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool),
+ SkDocument_PDF(SkWStream* stream,
+ void (*doneProc)(SkWStream*, bool),
SkPicture::EncodeBitmap encoder,
SkScalar rasterDpi)
- : SkDocument(stream, doneProc)
- , fEncoder(encoder)
- , fRasterDpi(rasterDpi) {
- fDoc = SkNEW(SkPDFDocument);
- fCanvas = NULL;
- fDevice = NULL;
- }
+ : SkDocument(stream, doneProc)
+ , fDoc(SkNEW(SkPDFDocument))
+ , fEncoder(encoder)
+ , fRasterDpi(rasterDpi) {}
virtual ~SkDocument_PDF() {
// subclasses must call close() in their destructors
@@ -30,60 +29,55 @@ public:
protected:
virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
const SkRect& trimBox) SK_OVERRIDE {
- SkASSERT(NULL == fCanvas);
- SkASSERT(NULL == fDevice);
+ SkASSERT(!fCanvas.get());
+ SkASSERT(!fDevice.get());
- SkISize mediaBoxSize;
- mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
+ SkISize pageSize;
+ pageSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
- fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix::I()));
+ fDevice.reset(SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon));
if (fEncoder) {
fDevice->setDCTEncoder(fEncoder);
}
- if (fRasterDpi != 0) {
- fDevice->setRasterDpi(fRasterDpi);
- }
- fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
+ fCanvas.reset(SkNEW_ARGS(SkCanvas, (fDevice)));
fCanvas->clipRect(trimBox);
fCanvas->translate(trimBox.x(), trimBox.y());
- return fCanvas;
+ return fCanvas.get();
}
void onEndPage() SK_OVERRIDE {
- SkASSERT(fCanvas);
- SkASSERT(fDevice);
+ SkASSERT(fCanvas.get());
+ SkASSERT(fDevice.get());
fCanvas->flush();
- fDoc->appendPage(fDevice);
-
- fCanvas->unref();
- fDevice->unref();
+ fDoc->appendPage(fDevice.get());
- fCanvas = NULL;
- fDevice = NULL;
+ fCanvas.reset(NULL);
+ fDevice.reset(NULL);
}
bool onClose(SkWStream* stream) SK_OVERRIDE {
- SkASSERT(NULL == fCanvas);
- SkASSERT(NULL == fDevice);
+ SkASSERT(!fCanvas.get());
+ SkASSERT(!fDevice.get());
bool success = fDoc->emitPDF(stream);
- SkDELETE(fDoc);
- fDoc = NULL;
+ fDoc.free();
+ SkDEBUGCODE(fCanon.assertEmpty());
return success;
}
void onAbort() SK_OVERRIDE {
- SkDELETE(fDoc);
- fDoc = NULL;
+ fDoc.free();
+ SkDEBUGCODE(fCanon.assertEmpty());
}
private:
- SkPDFDocument* fDoc;
- SkPDFDevice* fDevice;
- SkCanvas* fCanvas;
+ SkPDFCanon fCanon;
+ SkAutoTDelete<SkPDFDocument> fDoc;
+ SkAutoTUnref<SkPDFDevice> fDevice;
+ SkAutoTUnref<SkCanvas> fCanvas;
SkPicture::EncodeBitmap fEncoder;
- SkScalar fRasterDpi;
+ SkScalar fRasterDpi;
};
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « gyp/pdf.gypi ('k') | src/pdf/SkPDFBitmap.h » ('j') | src/pdf/SkPDFDevice.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698