aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-05 14:41:22 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-05 19:54:17 +0000
commit2d171397f863699eb7804b814994d4c2fcb00cb7 (patch)
tree271480713f481ee7209b8035c0415658484c25ef /src/pdf
parentc665e5b7df4ea044848105b8e934eac34aee3a9a (diff)
SkPDF: GradientShaderPatterns use one hashmap not two.
Change-Id: Icdebaf891884aa06bdc36ed930d7bab5400bd04f Reviewed-on: https://skia-review.googlesource.com/21529 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFCanon.h3
-rw-r--r--src/pdf/SkPDFGradientShader.cpp54
2 files changed, 26 insertions, 31 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
index 1085387242..41b19eefa4 100644
--- a/src/pdf/SkPDFCanon.h
+++ b/src/pdf/SkPDFCanon.h
@@ -31,8 +31,7 @@ public:
SkTHashMap<SkPDFShader::State, sk_sp<SkPDFObject>> fImageShaderMap;
- SkPDFGradientShader::HashMap fAlphaGradientMap;
- SkPDFGradientShader::HashMap fOpaqueGradientMap;
+ SkPDFGradientShader::HashMap fGradientPatternMap;
SkTHashMap<SkBitmapKey, sk_sp<SkPDFObject>> fPDFBitmapMap;
diff --git a/src/pdf/SkPDFGradientShader.cpp b/src/pdf/SkPDFGradientShader.cpp
index 0287678c28..dc11d64c46 100644
--- a/src/pdf/SkPDFGradientShader.cpp
+++ b/src/pdf/SkPDFGradientShader.cpp
@@ -783,17 +783,9 @@ static sk_sp<SkPDFDict> make_function_shader(SkPDFCanon* canon,
return pdfFunctionShader;
}
-
-static sk_sp<SkPDFObject> find_function_shader(SkPDFDocument* doc,
- SkPDFGradientShader::Key key) {
- SkPDFCanon* canon = doc->canon();
- if (sk_sp<SkPDFObject>* ptr = canon->fOpaqueGradientMap.find(key)) {
- return *ptr;
- }
- sk_sp<SkPDFObject> pdfShader = make_function_shader(doc->canon(), key);
- canon->fOpaqueGradientMap.set(std::move(key), pdfShader);
- return pdfShader;
-}
+static sk_sp<SkPDFObject> find_pdf_shader(SkPDFDocument* doc,
+ SkPDFGradientShader::Key key,
+ bool keyHasAlpha);
static sk_sp<SkPDFDict> get_gradient_resource_dict(SkPDFObject* functionShader,
SkPDFObject* gState) {
@@ -862,7 +854,7 @@ static sk_sp<SkPDFObject> create_smask_graphic_state(SkPDFDocument* doc,
luminosityState.fHash = hash(luminosityState);
SkASSERT(!gradient_has_alpha(luminosityState));
- sk_sp<SkPDFObject> luminosityShader = find_function_shader(doc, std::move(luminosityState));
+ sk_sp<SkPDFObject> luminosityShader = find_pdf_shader(doc, std::move(luminosityState), false);
sk_sp<SkPDFDict> resources = get_gradient_resource_dict(luminosityShader.get(), nullptr);
SkRect bbox = SkRect::Make(state.fBBox);
sk_sp<SkPDFObject> alphaMask = SkPDFMakeFormXObject(create_pattern_fill_content(-1, bbox),
@@ -886,7 +878,7 @@ static sk_sp<SkPDFStream> make_alpha_function_shader(SkPDFDocument* doc,
SkASSERT(!gradient_has_alpha(opaqueState));
SkRect bbox = SkRect::Make(state.fBBox);
- sk_sp<SkPDFObject> colorShader = find_function_shader(doc, std::move(opaqueState));
+ sk_sp<SkPDFObject> colorShader = find_pdf_shader(doc, std::move(opaqueState), false);
if (!colorShader) {
return nullptr;
}
@@ -906,8 +898,6 @@ static sk_sp<SkPDFStream> make_alpha_function_shader(SkPDFDocument* doc,
return alphaFunctionShader;
}
-
-
static SkPDFGradientShader::Key make_key(const SkShader* shader,
const SkMatrix& canvasTransform,
const SkIRect& bbox) {
@@ -931,6 +921,24 @@ static SkPDFGradientShader::Key make_key(const SkShader* shader,
return key;
}
+static sk_sp<SkPDFObject> find_pdf_shader(SkPDFDocument* doc,
+ SkPDFGradientShader::Key key,
+ bool keyHasAlpha) {
+ SkASSERT(gradient_has_alpha(key) == keyHasAlpha);
+ SkPDFCanon* canon = doc->canon();
+ if (sk_sp<SkPDFObject>* ptr = canon->fGradientPatternMap.find(key)) {
+ return *ptr;
+ }
+ sk_sp<SkPDFObject> pdfShader;
+ if (keyHasAlpha) {
+ pdfShader = make_alpha_function_shader(doc, key);
+ } else {
+ pdfShader = make_function_shader(canon, key);
+ }
+ canon->fGradientPatternMap.set(std::move(key), pdfShader);
+ return pdfShader;
+}
+
sk_sp<SkPDFObject> SkPDFGradientShader::Make(SkPDFDocument* doc,
SkShader* shader,
const SkMatrix& canvasTransform,
@@ -938,18 +946,6 @@ sk_sp<SkPDFObject> SkPDFGradientShader::Make(SkPDFDocument* doc,
SkASSERT(shader);
SkASSERT(SkShader::kNone_GradientType != shader->asAGradient(nullptr));
SkPDFGradientShader::Key key = make_key(shader, canvasTransform, bbox);
- // TODO(halcanary): measure to see if one hashmap is as fast as two.
- if (gradient_has_alpha(key)) {
- SkPDFCanon* canon = doc->canon();
- if (sk_sp<SkPDFObject>* ptr = canon->fAlphaGradientMap.find(key)) {
- return *ptr;
- }
- sk_sp<SkPDFObject> pdfShader = make_alpha_function_shader(doc, key);
- canon->fAlphaGradientMap.set(std::move(key), pdfShader);
- return pdfShader;
- } else {
- return find_function_shader(doc, std::move(key));
- }
+ bool alpha = gradient_has_alpha(key);
+ return find_pdf_shader(doc, std::move(key), alpha);
}
-
-