aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFCanon.h
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-05 11:25:42 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-05 17:27:54 +0000
commit94fd66cc2502383628b2c5fb72a445460b752c35 (patch)
treed155d846ad63c613b0554c881c55ef40883f9a6a /src/pdf/SkPDFCanon.h
parent3a59665099da62835f54192ae9a4f2480e91c8ff (diff)
SkPDF: Refactor PDFShader to use ShTHashMap<>
my tests run ~14% faster. - Split out gradient shaders from image shaders. new compilation unit: SkPDFGradientShader - Common functions InverseTransformBBox and PopulateTilingPatternDict moved to SkPDFUtils - Split SkPDFShader::State into image and gradient structures. - SkPDFCanon is now a simpler structure, with no logic of its own. I am considering just moving all of its fields into SkPDFDocument - SkPDFShader::State (the image/fallback shader) now is POD, making the use of a hashmap for canonicalization straightforward. Formerly, we used a linear search. - Do not bother trying to canonicalize the falback image shader. - SkPDFGradientShader::Key is not POD; comparison of two objects requires looking at the contents of two variable-sized arrays. We now pre-calculate the hash of the arrays using SkOpts::hash and store a hash for the object in the fHash field. Using that hash, we can now canonicalize using a hashmap instead of a linar search! - several static functions renamed to follow style guidelines - stop using codeFunction function pointer; I find that less clear than it could be. - operator==() for SkPDFShader::State and SkPDFGradientShader::Key is now much simpler and can now be inlined. - SkArrayEqual template in SkPDFUtils.h No change to PDF output. BUG=skia:3585 Change-Id: I354ad1b600be6d6749abccb58d13db257370bc0b Reviewed-on: https://skia-review.googlesource.com/21376 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/pdf/SkPDFCanon.h')
-rw-r--r--src/pdf/SkPDFCanon.h25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
index d876443c17..1085387242 100644
--- a/src/pdf/SkPDFCanon.h
+++ b/src/pdf/SkPDFCanon.h
@@ -9,6 +9,7 @@
#include "SkPDFGraphicState.h"
#include "SkPDFShader.h"
+#include "SkPDFGradientShader.h"
#include "SkPixelSerializer.h"
#include "SkTDArray.h"
#include "SkTHash.h"
@@ -21,18 +22,17 @@ struct SkAdvancedTypefaceMetrics;
* The SkPDFCanon canonicalizes objects across PDF pages
* (SkPDFDevices) and across draw calls.
*/
-class SkPDFCanon : SkNoncopyable {
+class SkPDFCanon {
public:
~SkPDFCanon();
+ SkPDFCanon();
+ SkPDFCanon(const SkPDFCanon&) = delete;
+ SkPDFCanon& operator=(const SkPDFCanon&) = delete;
- sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const;
- void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State);
+ SkTHashMap<SkPDFShader::State, sk_sp<SkPDFObject>> fImageShaderMap;
- sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const;
- void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State);
-
- sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const;
- void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State);
+ SkPDFGradientShader::HashMap fAlphaGradientMap;
+ SkPDFGradientShader::HashMap fOpaqueGradientMap;
SkTHashMap<SkBitmapKey, sk_sp<SkPDFObject>> fPDFBitmapMap;
@@ -47,14 +47,5 @@ public:
sk_sp<SkPDFStream> fInvertFunction;
sk_sp<SkPDFDict> fNoSmaskGraphicState;
sk_sp<SkPDFArray> fRangeObject;
-
-private:
- struct ShaderRec {
- SkPDFShader::State fShaderState;
- sk_sp<SkPDFObject> fShaderObject;
- };
- SkTArray<ShaderRec> fFunctionShaderRecords;
- SkTArray<ShaderRec> fAlphaShaderRecords;
- SkTArray<ShaderRec> fImageShaderRecords;
};
#endif // SkPDFCanon_DEFINED