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

Side by Side Diff: src/pdf/SkPDFCanon.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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #ifndef SkPDFCanon_DEFINED 7 #ifndef SkPDFCanon_DEFINED
8 #define SkPDFCanon_DEFINED 8 #define SkPDFCanon_DEFINED
9 9
10 #include "SkPDFShader.h" 10 #include "SkPDFShader.h"
11 #include "SkThread.h"
12 #include "SkTDArray.h" 11 #include "SkTDArray.h"
13 12
14 struct SkIRect;
15 class SkBitmap; 13 class SkBitmap;
16 class SkMatrix;
17 class SkPDFFont; 14 class SkPDFFont;
18 class SkPDFGraphicState; 15 class SkPDFGraphicState;
19 class SkPDFBitmap; 16 class SkPDFBitmap;
20 class SkPaint; 17 class SkPaint;
21 18
22 // This class's fields and methods will eventually become part of
23 // SkPDFDocument/SkDocument_PDF. For now, it exists as a singleton to
24 // preflight that transition. This replaces three global arrays in
25 // SkPDFFont, SkPDFShader, and SkPDFGraphicsContext.
26 //
27 // IF YOU ARE LOOKING AT THIS API PLEASE DO NOT WRITE THE CHANGE
28 // YOU ARE ABOUT TO WRITE WITHOUT TALKING TO HALCANARY@.
29 //
30 // Note that this class does not create, delete, reference or 19 // Note that this class does not create, delete, reference or
31 // dereference the SkPDFObject objects that it indexes. It is up to 20 // dereference the SkPDFObject objects that it indexes. It is up to
32 // the caller to manage the lifetime of these objects. 21 // the caller to manage the lifetime of these objects.
33 class SkPDFCanon : SkNoncopyable { 22 class SkPDFCanon : SkNoncopyable {
34 public: 23 public:
35 SkPDFCanon(); 24 SkPDFCanon();
36 ~SkPDFCanon(); 25 ~SkPDFCanon();
37 26
38 static SkPDFCanon& GetCanon();
39
40 // This mutexes will be removed once this class is subsumed into
41 // SkPDFDocument.
42 static SkBaseMutex& GetFontMutex();
43 static SkBaseMutex& GetShaderMutex();
44 static SkBaseMutex& GetPaintMutex();
45 static SkBaseMutex& GetBitmapMutex();
46
47 // Returns exact match if there is one. If not, it returns NULL. 27 // Returns exact match if there is one. If not, it returns NULL.
48 // If there is no exact match, but there is a related font, we 28 // If there is no exact match, but there is a related font, we
49 // still return NULL, but also set *relatedFont. 29 // still return NULL, but also set *relatedFont.
50 SkPDFFont* findFont(uint32_t fontID, 30 SkPDFFont* findFont(uint32_t fontID,
51 uint16_t glyphID, 31 uint16_t glyphID,
52 SkPDFFont** relatedFont) const; 32 SkPDFFont** relatedFont) const;
53 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); 33 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
54 void removeFont(SkPDFFont*); 34 void removeFont(SkPDFFont*);
55 35
56 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; 36 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const;
57 void addFunctionShader(SkPDFFunctionShader*); 37 void addFunctionShader(SkPDFFunctionShader*);
58 void removeFunctionShader(SkPDFFunctionShader*); 38 void removeFunctionShader(SkPDFFunctionShader*);
59 39
60 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; 40 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const;
61 void addAlphaShader(SkPDFAlphaFunctionShader*); 41 void addAlphaShader(SkPDFAlphaFunctionShader*);
62 void removeAlphaShader(SkPDFAlphaFunctionShader*); 42 void removeAlphaShader(SkPDFAlphaFunctionShader*);
63 43
64 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; 44 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const;
65 void addImageShader(SkPDFImageShader*); 45 void addImageShader(SkPDFImageShader*);
66 void removeImageShader(SkPDFImageShader*); 46 void removeImageShader(SkPDFImageShader*);
67 47
68 SkPDFGraphicState* findGraphicState(const SkPaint&) const; 48 SkPDFGraphicState* findGraphicState(const SkPaint&) const;
69 void addGraphicState(SkPDFGraphicState*); 49 void addGraphicState(SkPDFGraphicState*);
70 void removeGraphicState(SkPDFGraphicState*); 50 void removeGraphicState(SkPDFGraphicState*);
71 51
72 SkPDFBitmap* findBitmap(const SkBitmap&) const; 52 SkPDFBitmap* findBitmap(const SkBitmap&) const;
73 void addBitmap(SkPDFBitmap*); 53 void addBitmap(SkPDFBitmap*);
74 void removeBitmap(SkPDFBitmap*); 54 void removeBitmap(SkPDFBitmap*);
75 55
56 void assertEmpty() const {
57 SkASSERT(fFontRecords.isEmpty());
58 SkASSERT(fFunctionShaderRecords.isEmpty());
59 SkASSERT(fAlphaShaderRecords.isEmpty());
60 SkASSERT(fImageShaderRecords.isEmpty());
61 SkASSERT(fGraphicStateRecords.isEmpty());
62 SkASSERT(fBitmapRecords.isEmpty());
63 }
64
76 private: 65 private:
77 struct FontRec { 66 struct FontRec {
78 SkPDFFont* fFont; 67 SkPDFFont* fFont;
79 uint32_t fFontID; 68 uint32_t fFontID;
80 uint16_t fGlyphID; 69 uint16_t fGlyphID;
81 }; 70 };
82 SkTDArray<FontRec> fFontRecords; 71 SkTDArray<FontRec> fFontRecords;
83 72
84 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; 73 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords;
85 74
86 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; 75 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords;
87 76
88 SkTDArray<SkPDFImageShader*> fImageShaderRecords; 77 SkTDArray<SkPDFImageShader*> fImageShaderRecords;
89 78
90 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords; 79 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords;
91 80
92 SkTDArray<SkPDFBitmap*> fBitmapRecords; 81 SkTDArray<SkPDFBitmap*> fBitmapRecords;
93 }; 82 };
94 #endif // SkPDFCanon_DEFINED 83 #endif // SkPDFCanon_DEFINED
OLDNEW
« no previous file with comments | « src/pdf/SkPDFBitmap.cpp ('k') | src/pdf/SkPDFCanon.cpp » ('j') | src/pdf/SkPDFDevice.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698