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

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

Issue 870333002: Simplify reference management in SkPDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make Created 5 years, 10 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/SkPDFGraphicState.h ('k') | src/pdf/SkPDFImage.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 "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 bool SkPDFGraphicState::equals(const SkPaint& paint) const { 111 bool SkPDFGraphicState::equals(const SkPaint& paint) const {
112 return equivalent(paint, fPaint); 112 return equivalent(paint, fPaint);
113 } 113 }
114 114
115 SkPDFGraphicState::~SkPDFGraphicState() { 115 SkPDFGraphicState::~SkPDFGraphicState() {
116 SkAutoMutexAcquire lock(SkPDFCanon::GetPaintMutex()); 116 SkAutoMutexAcquire lock(SkPDFCanon::GetPaintMutex());
117 if (!fSMask) { 117 if (!fSMask) {
118 SkPDFCanon::GetCanon().removeGraphicState(this); 118 SkPDFCanon::GetCanon().removeGraphicState(this);
119 } 119 }
120 fResources.unrefAll();
121 }
122
123 void SkPDFGraphicState::getResources(
124 const SkTSet<SkPDFObject*>& knownResourceObjects,
125 SkTSet<SkPDFObject*>* newResourceObjects) {
126 GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
127 } 120 }
128 121
129 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { 122 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
130 populateDict(); 123 populateDict();
131 SkPDFDict::emitObject(stream, catalog); 124 SkPDFDict::emitObject(stream, catalog);
132 } 125 }
133 126
134 // static 127 // static
135 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( 128 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint(
136 const SkPaint& paint) { 129 const SkPaint& paint) {
(...skipping 30 matching lines...) Expand all
167 return invertFunction; 160 return invertFunction;
168 } 161 }
169 162
170 template <typename T> void unref(T* ptr) { ptr->unref(); } 163 template <typename T> void unref(T* ptr) { ptr->unref(); }
171 } // namespace 164 } // namespace
172 165
173 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, invertFunction, 166 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, invertFunction,
174 create_invert_function, unref<SkPDFObject>); 167 create_invert_function, unref<SkPDFObject>);
175 168
176 // static 169 // static
177 SkPDFObject* SkPDFGraphicState::GetInvertFunction() {
178 return invertFunction.get();
179 }
180
181 // static
182 SkPDFGraphicState* SkPDFGraphicState::GetSMaskGraphicState( 170 SkPDFGraphicState* SkPDFGraphicState::GetSMaskGraphicState(
183 SkPDFFormXObject* sMask, bool invert, SkPDFSMaskMode sMaskMode) { 171 SkPDFFormXObject* sMask, bool invert, SkPDFSMaskMode sMaskMode) {
184 // The practical chances of using the same mask more than once are unlikely 172 // The practical chances of using the same mask more than once are unlikely
185 // enough that it's not worth canonicalizing. 173 // enough that it's not worth canonicalizing.
186 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); 174 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask"));
187 if (sMaskMode == kAlpha_SMaskMode) { 175 if (sMaskMode == kAlpha_SMaskMode) {
188 sMaskDict->insertName("S", "Alpha"); 176 sMaskDict->insertName("S", "Alpha");
189 } else if (sMaskMode == kLuminosity_SMaskMode) { 177 } else if (sMaskMode == kLuminosity_SMaskMode) {
190 sMaskDict->insertName("S", "Luminosity"); 178 sMaskDict->insertName("S", "Luminosity");
191 } 179 }
192 sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref(); 180 sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref();
193 181
194 SkPDFGraphicState* result = new SkPDFGraphicState; 182 SkPDFGraphicState* result = new SkPDFGraphicState;
195 result->fPopulated = true; 183 result->fPopulated = true;
196 result->fSMask = true; 184 result->fSMask = true;
197 result->insertName("Type", "ExtGState"); 185 result->insertName("Type", "ExtGState");
198 result->insert("SMask", sMaskDict.get()); 186 result->insert("SMask", sMaskDict.get());
199 result->fResources.push(sMask);
200 sMask->ref();
201 187
202 if (invert) { 188 if (invert) {
203 SkPDFObject* invertFunction = GetInvertFunction(); 189 sMaskDict->insert("TR", new SkPDFObjRef(invertFunction.get()))->unref();
204 result->fResources.push(invertFunction);
205 invertFunction->ref();
206 sMaskDict->insert("TR", new SkPDFObjRef(invertFunction))->unref();
207 } 190 }
208 191
209 return result; 192 return result;
210 } 193 }
211 194
212 SkPDFGraphicState* SkPDFGraphicState::CreateNoSMaskGraphicState() { 195 SkPDFGraphicState* SkPDFGraphicState::CreateNoSMaskGraphicState() {
213 SkPDFGraphicState* noSMaskGS = SkNEW(SkPDFGraphicState); 196 SkPDFGraphicState* noSMaskGS = SkNEW(SkPDFGraphicState);
214 noSMaskGS->fPopulated = true; 197 noSMaskGS->fPopulated = true;
215 noSMaskGS->fSMask = true; 198 noSMaskGS->fSMask = true;
216 noSMaskGS->insertName("Type", "ExtGState"); 199 noSMaskGS->insertName("Type", "ExtGState");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 fPaint.getXfermode()->asMode(&xfermode); 256 fPaint.getXfermode()->asMode(&xfermode);
274 // If we don't support the mode, just use kSrcOver_Mode. 257 // If we don't support the mode, just use kSrcOver_Mode.
275 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || 258 if (xfermode < 0 || xfermode > SkXfermode::kLastMode ||
276 as_blend_mode(xfermode) == NULL) { 259 as_blend_mode(xfermode) == NULL) {
277 xfermode = SkXfermode::kSrcOver_Mode; 260 xfermode = SkXfermode::kSrcOver_Mode;
278 NOT_IMPLEMENTED("unsupported xfermode", false); 261 NOT_IMPLEMENTED("unsupported xfermode", false);
279 } 262 }
280 insertName("BM", as_blend_mode(xfermode)); 263 insertName("BM", as_blend_mode(xfermode));
281 } 264 }
282 } 265 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFGraphicState.h ('k') | src/pdf/SkPDFImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698