aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-25 00:41:30 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-25 00:41:30 +0000
commit19e3c1ed1b20ce93cc092d25c3637b62f90c5bc5 (patch)
tree7a25c9d9f34d06302f3def7c1b2e1074ed37dec1
parent13d14a9dbd2cf0a9654045cc967e92626690631a (diff)
[PDF] Reuse the invert function object for xform object masks.
Review URL: http://codereview.appspot.com/4557046 git-svn-id: http://skia.googlecode.com/svn/trunk@1417 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/pdf/SkPDFGraphicState.h2
-rw-r--r--src/pdf/SkPDFGraphicState.cpp51
2 files changed, 32 insertions, 21 deletions
diff --git a/include/pdf/SkPDFGraphicState.h b/include/pdf/SkPDFGraphicState.h
index b43c1076c4..49809a4c03 100644
--- a/include/pdf/SkPDFGraphicState.h
+++ b/include/pdf/SkPDFGraphicState.h
@@ -98,6 +98,8 @@ private:
void populateDict();
+ static SkPDFObject* GetInvertFunction();
+
static int find(const SkPaint& paint);
};
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index 48203f6ca5..b08bf24c26 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -117,6 +117,32 @@ SkPDFGraphicState* SkPDFGraphicState::getGraphicStateForPaint(
}
// static
+SkPDFObject* SkPDFGraphicState::GetInvertFunction() {
+ // This assumes that canonicalPaintsMutex is held.
+ static SkPDFStream* invertFunction = NULL;
+ if (!invertFunction) {
+ // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
+ // a type 2 function, so we use a type 4 function.
+ SkRefPtr<SkPDFArray> domainAndRange = new SkPDFArray;
+ domainAndRange->unref(); // SkRefPtr and new both took a reference.
+ domainAndRange->reserve(2);
+ domainAndRange->append(new SkPDFInt(0))->unref();
+ domainAndRange->append(new SkPDFInt(1))->unref();
+
+ static const char psInvert[] = "{1 exch sub}";
+ SkRefPtr<SkMemoryStream> psInvertStream =
+ new SkMemoryStream(&psInvert, strlen(psInvert), true);
+ psInvertStream->unref(); // SkRefPtr and new both took a reference.
+
+ invertFunction = new SkPDFStream(psInvertStream.get());
+ invertFunction->insert("FunctionType", new SkPDFInt(4))->unref();
+ invertFunction->insert("Domain", domainAndRange.get());
+ invertFunction->insert("Range", domainAndRange.get());
+ }
+ return invertFunction;
+}
+
+// static
SkPDFGraphicState* SkPDFGraphicState::getSMaskGraphicState(
SkPDFFormXObject* sMask, bool invert) {
// The practical chances of using the same mask more than once are unlikely
@@ -137,27 +163,10 @@ SkPDFGraphicState* SkPDFGraphicState::getSMaskGraphicState(
sMask->ref();
if (invert) {
- // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
- // a type 2 function, so we use a type 4 function.
- SkRefPtr<SkPDFArray> domainAndRange = new SkPDFArray;
- domainAndRange->unref(); // SkRefPtr and new both took a reference.
- domainAndRange->reserve(2);
- domainAndRange->append(new SkPDFInt(0))->unref();
- domainAndRange->append(new SkPDFInt(1))->unref();
-
- static const char psInvert[] = "{1 exch sub}";
- SkRefPtr<SkMemoryStream> psInvertStream =
- new SkMemoryStream(&psInvert, strlen(psInvert), true);
- psInvertStream->unref(); // SkRefPtr and new both took a reference.
-
- SkRefPtr<SkPDFStream> invertFunc =
- new SkPDFStream(psInvertStream.get());
- result->fResources.push(invertFunc.get()); // Pass the ref from new.
- invertFunc->insert("FunctionType", new SkPDFInt(4))->unref();
- invertFunc->insert("Domain", domainAndRange.get());
- invertFunc->insert("Range", domainAndRange.get());
-
- sMaskDict->insert("TR", new SkPDFObjRef(invertFunc.get()))->unref();
+ SkPDFObject* invertFunction = GetInvertFunction();
+ result->fResources.push(invertFunction);
+ invertFunction->ref();
+ sMaskDict->insert("TR", new SkPDFObjRef(invertFunction))->unref();
}
return result;