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

Side by Side Diff: src/pdf/SkPDFDevice.h

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 unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPDFDevice_DEFINED 10 #ifndef SkPDFDevice_DEFINED
11 #define SkPDFDevice_DEFINED 11 #define SkPDFDevice_DEFINED
12 12
13 #include "SkDevice.h" 13 #include "SkDevice.h"
14 #include "SkBitmap.h" 14 #include "SkBitmap.h"
15 #include "SkCanvas.h" 15 #include "SkCanvas.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "SkPath.h" 17 #include "SkPath.h"
18 #include "SkPicture.h" 18 #include "SkPicture.h"
19 #include "SkRect.h" 19 #include "SkRect.h"
20 #include "SkRefCnt.h" 20 #include "SkRefCnt.h"
21 #include "SkStream.h" 21 #include "SkStream.h"
22 #include "SkTDArray.h" 22 #include "SkTDArray.h"
23 #include "SkTemplates.h" 23 #include "SkTemplates.h"
24 24
25 class SkPDFArray; 25 class SkPDFArray;
26 class SkPDFCanon;
26 class SkPDFDevice; 27 class SkPDFDevice;
27 class SkPDFDict; 28 class SkPDFDict;
28 class SkPDFFont; 29 class SkPDFFont;
29 class SkPDFFormXObject; 30 class SkPDFFormXObject;
30 class SkPDFGlyphSetMap; 31 class SkPDFGlyphSetMap;
31 class SkPDFGraphicState; 32 class SkPDFGraphicState;
32 class SkPDFObject; 33 class SkPDFObject;
33 class SkPDFResourceDict; 34 class SkPDFResourceDict;
34 class SkPDFShader; 35 class SkPDFShader;
35 class SkPDFStream; 36 class SkPDFStream;
36 class SkRRect; 37 class SkRRect;
37 template <typename T> class SkTSet; 38 template <typename T> class SkTSet;
38 39
39 // Private classes. 40 // Private classes.
40 struct ContentEntry; 41 struct ContentEntry;
41 struct GraphicStateEntry; 42 struct GraphicStateEntry;
42 struct NamedDestination; 43 struct NamedDestination;
43 44
44 /** \class SkPDFDevice 45 /** \class SkPDFDevice
45 46
46 The drawing context for the PDF backend. 47 The drawing context for the PDF backend.
47 */ 48 */
48 class SkPDFDevice : public SkBaseDevice { 49 class SkPDFDevice : public SkBaseDevice {
49 public: 50 public:
50 /** Create a PDF drawing context with the given width and height. 51 /** Create a PDF drawing context. SkPDFDevice applies a
51 * 72 points/in means letter paper is 612x792. 52 * scale-and-translate transform to move the origin from the
52 * @param pageSize Page size in points. 53 * bottom left (PDF default) to the top left (Skia default).
53 * @param contentSize The content size of the page in points. This will be 54 * @param pageSize Page size in point units.
54 * combined with the initial transform to determine the drawing area 55 * 1 point == 127/360 mm == 1/72 inch
55 * (as reported by the width and height methods). Anything outside 56 * @param rasterDpi the DPI at which features without native PDF
56 * of the drawing area will be clipped. 57 * support will be rasterized (e.g. draw image with
57 * @param initialTransform The initial transform to apply to the page. 58 * perspective, draw text with perspective, ...). A
58 * This may be useful to, for example, move the origin in and 59 * larger DPI would create a PDF that reflects the
59 * over a bit to account for a margin, scale the canvas, 60 * original intent with better fidelity, but it can make
60 * or apply a rotation. Note1: the SkPDFDevice also applies 61 * for larger PDF files too, which would use more memory
61 * a scale+translate transform to move the origin from the 62 * while rendering, and it would be slower to be processed
62 * bottom left (PDF default) to the top left. Note2: drawDevice 63 * or sent online or to printer. A good choice is
63 * (used by layer restore) draws the device after this initial 64 * SK_ScalarDefaultRasterDPI(72.0f).
64 * transform is applied, so the PDF device does an 65 * @param SkPDFCanon. Should be non-null, and shared by all
65 * inverse scale+translate to accommodate the one that SkPDFDevice 66 * devices in a document.
66 * always does.
67 */ 67 */
68 // Deprecated, please use SkDocument::CreatePdf() instead. 68 static SkPDFDevice* Create(SkISize pageSize,
69 SK_API SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, 69 SkScalar rasterDpi,
70 const SkMatrix& initialTransform); 70 SkPDFCanon* canon) {
71 SK_API virtual ~SkPDFDevice(); 71 return SkNEW_ARGS(SkPDFDevice, (pageSize, rasterDpi, canon, true));
72 }
73
74 /** Create a PDF drawing context without fipping the y-axis. */
75 static SkPDFDevice* CreateUnflipped(SkISize pageSize,
mtklein 2015/02/19 23:50:38 This seems like 3 CLs: 1) The PDF canvas is now j
hal.canary 2015/02/20 01:22:28 Will do.
76 SkScalar rasterDpi,
77 SkPDFCanon* canon) {
78 return SkNEW_ARGS(SkPDFDevice, (pageSize, rasterDpi, canon, false));
79 }
80
81 virtual ~SkPDFDevice();
72 82
73 /** These are called inside the per-device-layer loop for each draw call. 83 /** These are called inside the per-device-layer loop for each draw call.
74 When these are called, we have already applied any saveLayer operations, 84 When these are called, we have already applied any saveLayer operations,
75 and are handling any looping from the paint, and any effects from the 85 and are handling any looping from the paint, and any effects from the
76 DrawFilter. 86 DrawFilter.
77 */ 87 */
78 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; 88 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
79 void drawPoints(const SkDraw&, SkCanvas::PointMode mode, 89 void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
80 size_t count, const SkPoint[], 90 size_t count, const SkPoint[],
81 const SkPaint& paint) SK_OVERRIDE; 91 const SkPaint& paint) SK_OVERRIDE;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return fInitialTransform; 191 return fInitialTransform;
182 } 192 }
183 193
184 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font 194 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
185 * that shows on this device. 195 * that shows on this device.
186 */ 196 */
187 const SkPDFGlyphSetMap& getFontGlyphUsage() const { 197 const SkPDFGlyphSetMap& getFontGlyphUsage() const {
188 return *(fFontGlyphUsage.get()); 198 return *(fFontGlyphUsage.get());
189 } 199 }
190 200
191
192 /**
193 * rasterDpi - the DPI at which features without native PDF support
194 * will be rasterized (e.g. draw image with perspective,
195 * draw text with perspective, ...)
196 * A larger DPI would create a PDF that reflects the original
197 * intent with better fidelity, but it can make for larger
198 * PDF files too, which would use more memory while rendering,
199 * and it would be slower to be processed or sent online or
200 * to printer.
201 */
202 void setRasterDpi(SkScalar rasterDpi) {
203 fRasterDpi = rasterDpi;
204 }
205
206 protected: 201 protected:
207 const SkBitmap& onAccessBitmap() SK_OVERRIDE { 202 const SkBitmap& onAccessBitmap() SK_OVERRIDE {
208 return fLegacyBitmap; 203 return fLegacyBitmap;
209 } 204 }
210 205
211 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE ; 206 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE ;
212 207
213 private: 208 private:
214 // TODO(vandebo): push most of SkPDFDevice's state into a core object in 209 // TODO(vandebo): push most of SkPDFDevice's state into a core object in
215 // order to get the right access levels without using friend. 210 // order to get the right access levels without using friend.
(...skipping 16 matching lines...) Expand all
232 SkAutoTDelete<ContentEntry> fContentEntries; 227 SkAutoTDelete<ContentEntry> fContentEntries;
233 ContentEntry* fLastContentEntry; 228 ContentEntry* fLastContentEntry;
234 SkAutoTDelete<ContentEntry> fMarginContentEntries; 229 SkAutoTDelete<ContentEntry> fMarginContentEntries;
235 ContentEntry* fLastMarginContentEntry; 230 ContentEntry* fLastMarginContentEntry;
236 DrawingArea fDrawingArea; 231 DrawingArea fDrawingArea;
237 232
238 const SkClipStack* fClipStack; 233 const SkClipStack* fClipStack;
239 234
240 // Accessor and setter functions based on the current DrawingArea. 235 // Accessor and setter functions based on the current DrawingArea.
241 SkAutoTDelete<ContentEntry>* getContentEntries(); 236 SkAutoTDelete<ContentEntry>* getContentEntries();
242 ContentEntry* getLastContentEntry();
243 void setLastContentEntry(ContentEntry* contentEntry);
244 237
245 // Glyph ids used for each font on this device. 238 // Glyph ids used for each font on this device.
246 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; 239 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
247 240
248 SkPicture::EncodeBitmap fEncoder; 241 SkPicture::EncodeBitmap fEncoder;
249 SkScalar fRasterDpi; 242 SkScalar fRasterDpi;
250 243
251 SkBitmap fLegacyBitmap; 244 SkBitmap fLegacyBitmap;
252 245
253 SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, 246 SkPDFCanon* fCanon; // Owned by SkDocument_PDF
254 const SkRegion& existingClipRegion); 247 ////////////////////////////////////////////////////////////////////////////
248
249 SkPDFDevice(SkISize pageSize,
250 SkScalar rasterDpi,
251 SkPDFCanon* canon,
252 bool flip);
253
254 ContentEntry* getLastContentEntry();
255 void setLastContentEntry(ContentEntry* contentEntry);
255 256
256 // override from SkBaseDevice 257 // override from SkBaseDevice
257 SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE; 258 SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
258 259
259 void init(); 260 void init();
260 void cleanUp(bool clearFontUsage); 261 void cleanUp(bool clearFontUsage);
261 SkPDFFormXObject* createFormXObjectFromDevice(); 262 SkPDFFormXObject* createFormXObjectFromDevice();
262 263
263 void drawFormXObjectWithMask(int xObjectIndex, 264 void drawFormXObjectWithMask(int xObjectIndex,
264 SkPDFFormXObject* mask, 265 SkPDFFormXObject* mask,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 328
328 typedef SkBaseDevice INHERITED; 329 typedef SkBaseDevice INHERITED;
329 330
330 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create 331 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create
331 // an SkPDFDevice 332 // an SkPDFDevice
332 //friend class SkDocument_PDF; 333 //friend class SkDocument_PDF;
333 //friend class SkPDFImageShader; 334 //friend class SkPDFImageShader;
334 }; 335 };
335 336
336 #endif 337 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | src/pdf/SkPDFGraphicState.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698