aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFCanon.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-01-21 09:59:14 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-21 09:59:14 -0800
commitfb62b3d423fa34c672df42f47017dbef087d19e9 (patch)
tree014428ea2ca480f62b55d3d63db5115df577bff6 /src/pdf/SkPDFCanon.h
parent1c60dfe7ca0db010fa3118a1a2c7ff4c09136ab0 (diff)
SkPDFCanon
SkPDFCanon's fields and methods will eventually become part of SkPDFDocument/SkDocument_PDF. For now, it exists as a singleton to preflight that transition. This replaces three global arrays in SkPDFFont, SkPDFShader, and SkPDFGraphicsContext. This code is still thread-unsafe (http://skbug.com/2683), but moving this functionality into SkPDFDocument will fix that. This CL does not change pdf output from either GMs or SKPs. This change also simplifies some code around the SkPDFCanon methods. BUG=skia:2683 Review URL: https://codereview.chromium.org/842253003
Diffstat (limited to 'src/pdf/SkPDFCanon.h')
-rw-r--r--src/pdf/SkPDFCanon.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
new file mode 100644
index 0000000000..5a06a465dd
--- /dev/null
+++ b/src/pdf/SkPDFCanon.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkPDFCanon_DEFINED
+#define SkPDFCanon_DEFINED
+
+#include "SkPDFShader.h"
+#include "SkThread.h"
+#include "SkTDArray.h"
+
+struct SkIRect;
+class SkMatrix;
+class SkPDFFont;
+class SkPDFGraphicState;
+class SkPaint;
+class SkShader;
+
+// This class's fields and methods will eventually become part of
+// SkPDFDocument/SkDocument_PDF. For now, it exists as a singleton to
+// preflight that transition. This replaces three global arrays in
+// SkPDFFont, SkPDFShader, and SkPDFGraphicsContext.
+//
+// IF YOU ARE LOOKING AT THIS API PLEASE DO NOT WRITE THE CHANGE
+// YOU ARE ABOUT TO WRITE WITHOUT TALKING TO HALCANARY@.
+//
+// Note that this class does not create, delete, reference or
+// dereference the SkPDFObject objects that it indexes. It is up to
+// the caller to manage the lifetime of these objects.
+class SkPDFCanon : SkNoncopyable {
+public:
+ SkPDFCanon();
+ ~SkPDFCanon();
+
+ static SkPDFCanon& GetCanon();
+
+ // This mutexes will be removed once this class is subsumed into
+ // SkPDFDocument.
+ static SkBaseMutex& GetFontMutex();
+ static SkBaseMutex& GetShaderMutex();
+ static SkBaseMutex& GetPaintMutex();
+
+ // Returns exact match if there is one. If not, it returns NULL.
+ // If there is no exact match, but there is a related font, we
+ // still return NULL, but also set *relatedFont.
+ SkPDFFont* findFont(uint32_t fontID,
+ uint16_t glyphID,
+ SkPDFFont** relatedFont) const;
+ void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
+ void removeFont(SkPDFFont*);
+
+ SkPDFShader* findShader(const SkPDFShader::State&) const;
+ void addShader(SkPDFShader*);
+ void removeShader(SkPDFShader*);
+
+ SkPDFGraphicState* findGraphicState(const SkPaint&) const;
+ void addGraphicState(SkPDFGraphicState*);
+ void removeGraphicState(SkPDFGraphicState*);
+
+private:
+ struct FontRec {
+ SkPDFFont* fFont;
+ uint32_t fFontID;
+ uint16_t fGlyphID;
+ };
+ SkTDArray<FontRec> fFontRecords;
+
+ SkTDArray<SkPDFShader*> fShaderRecords;
+
+ SkTDArray<SkPDFGraphicState*> fGraphicStateRecords;
+};
+#endif // SkPDFCanon_DEFINED