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

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

Issue 1773033002: SkPDF: use sk_make_sp<T> when it makes sense. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-08 (Tuesday) 06:54:33 EST 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/SkPDFMetadata.cpp » ('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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkPDFObject* 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 sk_sp<SkPDFArray> domainAndRange(new 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 sk_sp<SkPDFStream> invertFunction(new 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", SkRef(domainAndRange.get())); 144 invertFunction->insertObject("Domain", SkRef(domainAndRange.get()));
145 invertFunction->insertObject("Range", domainAndRange.release()); 145 invertFunction->insertObject("Range", domainAndRange.release());
146 return invertFunction.release(); 146 return invertFunction.release();
147 } 147 }
148 148
149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction); 149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction);
150 150
151 // static 151 // static
152 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, 152 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
153 bool invert, 153 bool invert,
154 SkPDFSMaskMode sMaskMode) { 154 SkPDFSMaskMode sMaskMode) {
155 // 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
156 // enough that it's not worth canonicalizing. 156 // enough that it's not worth canonicalizing.
157 sk_sp<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); 157 auto sMaskDict = sk_make_sp<SkPDFDict>("Mask");
158 if (sMaskMode == kAlpha_SMaskMode) { 158 if (sMaskMode == kAlpha_SMaskMode) {
159 sMaskDict->insertName("S", "Alpha"); 159 sMaskDict->insertName("S", "Alpha");
160 } else if (sMaskMode == kLuminosity_SMaskMode) { 160 } else if (sMaskMode == kLuminosity_SMaskMode) {
161 sMaskDict->insertName("S", "Luminosity"); 161 sMaskDict->insertName("S", "Luminosity");
162 } 162 }
163 sMaskDict->insertObjRef("G", SkRef(sMask)); 163 sMaskDict->insertObjRef("G", SkRef(sMask));
164 if (invert) { 164 if (invert) {
165 sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_fun ction))); 165 sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_fun ction)));
166 } 166 }
167 167
168 sk_sp<SkPDFDict> result(new SkPDFDict("ExtGState")); 168 auto result = sk_make_sp<SkPDFDict>("ExtGState");
169 result->insertObject("SMask", sMaskDict.release()); 169 result->insertObject("SMask", sMaskDict.release());
170 return result.release(); 170 return result.release();
171 } 171 }
172 172
173 static SkPDFDict* create_no_smask_graphic_state() { 173 static SkPDFDict* create_no_smask_graphic_state() {
174 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); 174 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState");
175 noSMaskGS->insertName("SMask", "None"); 175 noSMaskGS->insertName("SMask", "None");
176 return noSMaskGS; 176 return noSMaskGS;
177 } 177 }
178 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState); 178 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState);
179 179
180 // static 180 // static
181 SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() { 181 SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() {
182 return SkRef(noSMaskGraphicState.get(create_no_smask_graphic_state)); 182 return SkRef(noSMaskGraphicState.get(create_no_smask_graphic_state));
183 } 183 }
184 184
185 void SkPDFGraphicState::emitObject( 185 void SkPDFGraphicState::emitObject(
186 SkWStream* stream, 186 SkWStream* stream,
187 const SkPDFObjNumMap& objNumMap, 187 const SkPDFObjNumMap& objNumMap,
188 const SkPDFSubstituteMap& substitutes) const { 188 const SkPDFSubstituteMap& substitutes) const {
189 sk_sp<SkPDFDict> dict(new SkPDFDict("ExtGState")); 189 auto dict = sk_make_sp<SkPDFDict>("ExtGState");
190 dict->insertName("Type", "ExtGState"); 190 dict->insertName("Type", "ExtGState");
191 191
192 SkScalar alpha = SkIntToScalar(fAlpha) / 0xFF; 192 SkScalar alpha = SkIntToScalar(fAlpha) / 0xFF;
193 dict->insertScalar("CA", alpha); 193 dict->insertScalar("CA", alpha);
194 dict->insertScalar("ca", alpha); 194 dict->insertScalar("ca", alpha);
195 195
196 SkPaint::Cap strokeCap = (SkPaint::Cap)fStrokeCap; 196 SkPaint::Cap strokeCap = (SkPaint::Cap)fStrokeCap;
197 SkPaint::Join strokeJoin = (SkPaint::Join)fStrokeJoin; 197 SkPaint::Join strokeJoin = (SkPaint::Join)fStrokeJoin;
198 SkXfermode::Mode xferMode = (SkXfermode::Mode)fMode; 198 SkXfermode::Mode xferMode = (SkXfermode::Mode)fMode;
199 199
(...skipping 10 matching lines...) Expand all
210 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch"); 210 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch");
211 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2); 211 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2);
212 dict->insertInt("LJ", strokeJoin); 212 dict->insertInt("LJ", strokeJoin);
213 213
214 dict->insertScalar("LW", fStrokeWidth); 214 dict->insertScalar("LW", fStrokeWidth);
215 dict->insertScalar("ML", fStrokeMiter); 215 dict->insertScalar("ML", fStrokeMiter);
216 dict->insertBool("SA", true); // SA = Auto stroke adjustment. 216 dict->insertBool("SA", true); // SA = Auto stroke adjustment.
217 dict->insertName("BM", as_blend_mode(xferMode)); 217 dict->insertName("BM", as_blend_mode(xferMode));
218 dict->emitObject(stream, objNumMap, substitutes); 218 dict->emitObject(stream, objNumMap, substitutes);
219 } 219 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFMetadata.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698