diff options
author | Hal Canary <halcanary@google.com> | 2017-06-28 13:14:03 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-28 19:09:09 +0000 |
commit | c02de0b844fdb04e28e45ed5bbdd5eb0935c42d2 (patch) | |
tree | 7af66bdd955540e1040b4d3fead2027bb433031c /src | |
parent | 89cd35795f7cc3042084fb14fec27102c6e67f2c (diff) |
SkPDF: Clean up
- Use clearMaskOnGraphicState()
- SkPDFGraphicState::MakeNoSmaskGraphicState now moved to only caller.
- Get rid of clunky SkPDFUtils::GetCachedT
Change-Id: If76a1e915fc31e3ce2654fbe620ff44c1820c0e7
Reviewed-on: https://skia-review.googlesource.com/21142
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 12 | ||||
-rw-r--r-- | src/pdf/SkPDFGraphicState.cpp | 13 | ||||
-rw-r--r-- | src/pdf/SkPDFGraphicState.h | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 9 | ||||
-rw-r--r-- | src/pdf/SkPDFUtils.h | 9 |
5 files changed, 17 insertions, 28 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index f559e9081e..c81bd9b8b0 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -893,8 +893,11 @@ void SkPDFDevice::addSMaskGraphicState(sk_sp<SkPDFDevice> maskDevice, void SkPDFDevice::clearMaskOnGraphicState(SkDynamicMemoryWStream* contentStream) { // The no-softmask graphic state is used to "turn off" the mask for later draw calls. - auto noSMaskGS = SkPDFUtils::GetCachedT(&this->getCanon()->fNoSmaskGraphicState, - &SkPDFGraphicState::MakeNoSmaskGraphicState); + sk_sp<SkPDFDict>& noSMaskGS = this->getCanon()->fNoSmaskGraphicState; + if (!noSMaskGS) { + noSMaskGS = sk_make_sp<SkPDFDict>("ExtGState"); + noSMaskGS->insertName("SMask", "None"); + } SkPDFUtils::ApplyGraphicState(this->addGraphicStateResource(noSMaskGS.get()), contentStream); } @@ -1923,10 +1926,7 @@ void SkPDFDevice::drawFormXObjectWithMask(int xObjectIndex, } SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), content.stream()); SkPDFUtils::DrawFormXObject(xObjectIndex, content.stream()); - - sMaskGS = SkPDFUtils::GetCachedT(&fDocument->canon()->fNoSmaskGraphicState, - &SkPDFGraphicState::MakeNoSmaskGraphicState); - SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), content.stream()); + this->clearMaskOnGraphicState(content.stream()); } SkPDFDevice::ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack& clipStack, diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp index 8f54cb0693..6b7c502ccc 100644 --- a/src/pdf/SkPDFGraphicState.cpp +++ b/src/pdf/SkPDFGraphicState.cpp @@ -155,8 +155,11 @@ sk_sp<SkPDFDict> SkPDFGraphicState::GetSMaskGraphicState( if (invert) { // Instead of calling SkPDFGraphicState::MakeInvertFunction, // let the canon deduplicate this object. - sMaskDict->insertObjRef( - "TR", SkPDFUtils::GetCachedT(&canon->fInvertFunction, &make_invert_function)); + sk_sp<SkPDFStream>& invertFunction = canon->fInvertFunction; + if (!invertFunction) { + invertFunction = make_invert_function(); + } + sMaskDict->insertObjRef("TR", invertFunction); } auto result = sk_make_sp<SkPDFDict>("ExtGState"); @@ -164,12 +167,6 @@ sk_sp<SkPDFDict> SkPDFGraphicState::GetSMaskGraphicState( return result; } -sk_sp<SkPDFDict> SkPDFGraphicState::MakeNoSmaskGraphicState() { - auto noSMaskGS = sk_make_sp<SkPDFDict>("ExtGState"); - noSMaskGS->insertName("SMask", "None"); - return noSMaskGS; -} - void SkPDFGraphicState::emitObject( SkWStream* stream, const SkPDFObjNumMap& objNumMap) const { diff --git a/src/pdf/SkPDFGraphicState.h b/src/pdf/SkPDFGraphicState.h index 310c1cfb06..50b22686ac 100644 --- a/src/pdf/SkPDFGraphicState.h +++ b/src/pdf/SkPDFGraphicState.h @@ -51,8 +51,6 @@ public: SkPDFSMaskMode sMaskMode, SkPDFCanon* canon); - /** Make a graphic state that only unsets the soft mask. */ - static sk_sp<SkPDFDict> MakeNoSmaskGraphicState(); static sk_sp<SkPDFStream> MakeInvertFunction(); bool operator==(const SkPDFGraphicState& rhs) const { diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 9cf40d42e6..235d66341b 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -934,10 +934,13 @@ static sk_sp<SkPDFDict> make_function_shader(SkPDFCanon* canon, pdfShader->insertObject("Domain", domain); std::unique_ptr<SkStreamAsset> functionStream(functionCode.detachAsStream()); - sk_sp<SkPDFArray> rangeObject = - SkPDFUtils::GetCachedT(&canon->fRangeObject, &make_range_object); + + sk_sp<SkPDFArray>& rangeObject = canon->fRangeObject; + if (!rangeObject) { + rangeObject = make_range_object(); + } sk_sp<SkPDFStream> function = make_ps_function(std::move(functionStream), std::move(domain), - std::move(rangeObject)); + rangeObject); pdfShader->insertObjRef("Function", std::move(function)); } diff --git a/src/pdf/SkPDFUtils.h b/src/pdf/SkPDFUtils.h index 58453ae4d1..4d0447c194 100644 --- a/src/pdf/SkPDFUtils.h +++ b/src/pdf/SkPDFUtils.h @@ -103,15 +103,6 @@ inline void WriteUTF16beHex(SkDynamicMemoryWStream* wStream, SkUnichar utf32) { } } -template <class T> -static sk_sp<T> GetCachedT(sk_sp<T>* cachedT, sk_sp<T> (*makeNewT)()) { - if (*cachedT) { - return *cachedT; - } - *cachedT = (*makeNewT)(); - return *cachedT; -} - inline SkMatrix GetShaderLocalMatrix(const SkShader* shader) { SkMatrix localMatrix; if (sk_sp<SkShader> s = shader->makeAsALocalMatrixShader(&localMatrix)) { |