Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/pdf/SkPDFGraphicState.cpp

Issue 1775143002: Revert of SkPDF: Add sk_sp setters; .release() becomes std::move() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFResourceDict.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkOncePtr.h" 9 #include "SkOncePtr.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // since the emitObject() interface is non-const. But We 119 // since the emitObject() interface is non-const. But We
120 // promise that there is no way to mutate this object from 120 // promise that there is no way to mutate this object from
121 // here on out. 121 // here on out.
122 return SkRef(const_cast<SkPDFGraphicState*>(canonGS)); 122 return SkRef(const_cast<SkPDFGraphicState*>(canonGS));
123 } 123 }
124 SkPDFGraphicState* pdfGraphicState = new SkPDFGraphicState(paint); 124 SkPDFGraphicState* pdfGraphicState = new SkPDFGraphicState(paint);
125 canon->addGraphicState(pdfGraphicState); 125 canon->addGraphicState(pdfGraphicState);
126 return pdfGraphicState; 126 return pdfGraphicState;
127 } 127 }
128 128
129 static SkPDFStream* create_invert_function() { 129 static SkPDFObject* create_invert_function() {
130 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use 130 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
131 // a type 2 function, so we use a type 4 function. 131 // a type 2 function, so we use a type 4 function.
132 auto domainAndRange = sk_make_sp<SkPDFArray>(); 132 auto domainAndRange = sk_make_sp<SkPDFArray>();
133 domainAndRange->reserve(2); 133 domainAndRange->reserve(2);
134 domainAndRange->appendInt(0); 134 domainAndRange->appendInt(0);
135 domainAndRange->appendInt(1); 135 domainAndRange->appendInt(1);
136 136
137 static const char psInvert[] = "{1 exch sub}"; 137 static const char psInvert[] = "{1 exch sub}";
138 // Do not copy the trailing '\0' into the SkData. 138 // Do not copy the trailing '\0' into the SkData.
139 sk_sp<SkData> psInvertStream( 139 sk_sp<SkData> psInvertStream(
140 SkData::NewWithoutCopy(psInvert, strlen(psInvert))); 140 SkData::NewWithoutCopy(psInvert, strlen(psInvert)));
141 141
142 auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get()); 142 auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get());
143 invertFunction->insertInt("FunctionType", 4); 143 invertFunction->insertInt("FunctionType", 4);
144 invertFunction->insertObject("Domain", domainAndRange); 144 invertFunction->insertObject("Domain", SkRef(domainAndRange.get()));
145 invertFunction->insertObject("Range", std::move(domainAndRange)); 145 invertFunction->insertObject("Range", domainAndRange.release());
146 return invertFunction.release(); 146 return invertFunction.release();
147 } 147 }
148 148
149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFStream, invertFunction); 149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction);
150
151 static sk_sp<SkPDFStream> make_invert_function() {
152 return sk_sp<SkPDFStream>(
153 SkRef(invertFunction.get(create_invert_function)));
154 }
155 150
156 // static 151 // static
157 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, 152 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
158 bool invert, 153 bool invert,
159 SkPDFSMaskMode sMaskMode) { 154 SkPDFSMaskMode sMaskMode) {
160 // The practical chances of using the same mask more than once are unlikely 155 // The practical chances of using the same mask more than once are unlikely
161 // enough that it's not worth canonicalizing. 156 // enough that it's not worth canonicalizing.
162 auto sMaskDict = sk_make_sp<SkPDFDict>("Mask"); 157 auto sMaskDict = sk_make_sp<SkPDFDict>("Mask");
163 if (sMaskMode == kAlpha_SMaskMode) { 158 if (sMaskMode == kAlpha_SMaskMode) {
164 sMaskDict->insertName("S", "Alpha"); 159 sMaskDict->insertName("S", "Alpha");
165 } else if (sMaskMode == kLuminosity_SMaskMode) { 160 } else if (sMaskMode == kLuminosity_SMaskMode) {
166 sMaskDict->insertName("S", "Luminosity"); 161 sMaskDict->insertName("S", "Luminosity");
167 } 162 }
168 sMaskDict->insertObjRef("G", sk_sp<SkPDFFormXObject>(SkRef(sMask))); 163 sMaskDict->insertObjRef("G", SkRef(sMask));
169 if (invert) { 164 if (invert) {
170 sMaskDict->insertObjRef("TR", make_invert_function()); 165 sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_fun ction)));
171 } 166 }
172 167
173 auto result = sk_make_sp<SkPDFDict>("ExtGState"); 168 auto result = sk_make_sp<SkPDFDict>("ExtGState");
174 result->insertObject("SMask", std::move(sMaskDict)); 169 result->insertObject("SMask", sMaskDict.release());
175 return result.release(); 170 return result.release();
176 } 171 }
177 172
178 static SkPDFDict* create_no_smask_graphic_state() { 173 static SkPDFDict* create_no_smask_graphic_state() {
179 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); 174 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState");
180 noSMaskGS->insertName("SMask", "None"); 175 noSMaskGS->insertName("SMask", "None");
181 return noSMaskGS; 176 return noSMaskGS;
182 } 177 }
183 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState); 178 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState);
184 179
(...skipping 30 matching lines...) Expand all
215 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch"); 210 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch");
216 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2); 211 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2);
217 dict->insertInt("LJ", strokeJoin); 212 dict->insertInt("LJ", strokeJoin);
218 213
219 dict->insertScalar("LW", fStrokeWidth); 214 dict->insertScalar("LW", fStrokeWidth);
220 dict->insertScalar("ML", fStrokeMiter); 215 dict->insertScalar("ML", fStrokeMiter);
221 dict->insertBool("SA", true); // SA = Auto stroke adjustment. 216 dict->insertBool("SA", true); // SA = Auto stroke adjustment.
222 dict->insertName("BM", as_blend_mode(xferMode)); 217 dict->insertName("BM", as_blend_mode(xferMode));
223 dict->emitObject(stream, objNumMap, substitutes); 218 dict->emitObject(stream, objNumMap, substitutes);
224 } 219 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFResourceDict.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698