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

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

Issue 313823004: Add assertHeld() to SkMutex. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more Created 6 years, 6 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/core/SkScaledImageCache.cpp ('k') | src/ports/SkMutex_pthread.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 "SkPDFFormXObject.h" 8 #include "SkPDFFormXObject.h"
9 #include "SkPDFGraphicState.h" 9 #include "SkPDFGraphicState.h"
10 #include "SkPDFUtils.h" 10 #include "SkPDFUtils.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 SkPDFDict::emitObject(stream, catalog, indirect); 75 SkPDFDict::emitObject(stream, catalog, indirect);
76 } 76 }
77 77
78 // static 78 // static
79 size_t SkPDFGraphicState::getOutputSize(SkPDFCatalog* catalog, bool indirect) { 79 size_t SkPDFGraphicState::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
80 populateDict(); 80 populateDict();
81 return SkPDFDict::getOutputSize(catalog, indirect); 81 return SkPDFDict::getOutputSize(catalog, indirect);
82 } 82 }
83 83
84 // static 84 // static
85 SkTDArray<SkPDFGraphicState::GSCanonicalEntry>& 85 SkTDArray<SkPDFGraphicState::GSCanonicalEntry>& SkPDFGraphicState::CanonicalPain ts() {
86 SkPDFGraphicState::CanonicalPaints() { 86 CanonicalPaintsMutex().assertHeld();
87 // This initialization is only thread safe with gcc.
88 static SkTDArray<SkPDFGraphicState::GSCanonicalEntry> gCanonicalPaints; 87 static SkTDArray<SkPDFGraphicState::GSCanonicalEntry> gCanonicalPaints;
89 return gCanonicalPaints; 88 return gCanonicalPaints;
90 } 89 }
91 90
92 // static 91 // static
93 SkBaseMutex& SkPDFGraphicState::CanonicalPaintsMutex() { 92 SkBaseMutex& SkPDFGraphicState::CanonicalPaintsMutex() {
94 // This initialization is only thread safe with gcc or when
95 // POD-style mutex initialization is used.
96 SK_DECLARE_STATIC_MUTEX(gCanonicalPaintsMutex); 93 SK_DECLARE_STATIC_MUTEX(gCanonicalPaintsMutex);
97 return gCanonicalPaintsMutex; 94 return gCanonicalPaintsMutex;
98 } 95 }
99 96
100 // static 97 // static
101 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( 98 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint(const SkPaint& pai nt) {
102 const SkPaint& paint) {
103 SkAutoMutexAcquire lock(CanonicalPaintsMutex()); 99 SkAutoMutexAcquire lock(CanonicalPaintsMutex());
104 int index = Find(paint); 100 int index = Find(paint);
105 if (index >= 0) { 101 if (index >= 0) {
106 CanonicalPaints()[index].fGraphicState->ref(); 102 CanonicalPaints()[index].fGraphicState->ref();
107 return CanonicalPaints()[index].fGraphicState; 103 return CanonicalPaints()[index].fGraphicState;
108 } 104 }
109 GSCanonicalEntry newEntry(new SkPDFGraphicState(paint)); 105 GSCanonicalEntry newEntry(new SkPDFGraphicState(paint));
110 CanonicalPaints().push(newEntry); 106 CanonicalPaints().push(newEntry);
111 return newEntry.fGraphicState; 107 return newEntry.fGraphicState;
112 } 108 }
113 109
114 // static 110 // static
115 SkPDFObject* SkPDFGraphicState::GetInvertFunction() { 111 SkPDFObject* SkPDFGraphicState::GetInvertFunction() {
116 // This assumes that canonicalPaintsMutex is held. 112 // This assumes that canonicalPaintsMutex is held.
113 CanonicalPaintsMutex().assertHeld();
117 static SkPDFStream* invertFunction = NULL; 114 static SkPDFStream* invertFunction = NULL;
118 if (!invertFunction) { 115 if (!invertFunction) {
119 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use 116 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
120 // a type 2 function, so we use a type 4 function. 117 // a type 2 function, so we use a type 4 function.
121 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); 118 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray);
122 domainAndRange->reserve(2); 119 domainAndRange->reserve(2);
123 domainAndRange->appendInt(0); 120 domainAndRange->appendInt(0);
124 domainAndRange->appendInt(1); 121 domainAndRange->appendInt(1);
125 122
126 static const char psInvert[] = "{1 exch sub}"; 123 static const char psInvert[] = "{1 exch sub}";
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 noSMaskGS->fSMask = true; 175 noSMaskGS->fSMask = true;
179 noSMaskGS->insertName("Type", "ExtGState"); 176 noSMaskGS->insertName("Type", "ExtGState");
180 noSMaskGS->insertName("SMask", "None"); 177 noSMaskGS->insertName("SMask", "None");
181 } 178 }
182 noSMaskGS->ref(); 179 noSMaskGS->ref();
183 return noSMaskGS; 180 return noSMaskGS;
184 } 181 }
185 182
186 // static 183 // static
187 int SkPDFGraphicState::Find(const SkPaint& paint) { 184 int SkPDFGraphicState::Find(const SkPaint& paint) {
185 CanonicalPaintsMutex().assertHeld();
188 GSCanonicalEntry search(&paint); 186 GSCanonicalEntry search(&paint);
189 return CanonicalPaints().find(search); 187 return CanonicalPaints().find(search);
190 } 188 }
191 189
192 SkPDFGraphicState::SkPDFGraphicState() 190 SkPDFGraphicState::SkPDFGraphicState()
193 : fPopulated(false), 191 : fPopulated(false),
194 fSMask(false) { 192 fSMask(false) {
195 } 193 }
196 194
197 SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint) 195 SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 277 }
280 if (bXfermodeName < 0 || bXfermodeName > SkXfermode::kLastMode || 278 if (bXfermodeName < 0 || bXfermodeName > SkXfermode::kLastMode ||
281 blend_mode_from_xfermode(bXfermodeName) == NULL) { 279 blend_mode_from_xfermode(bXfermodeName) == NULL) {
282 bXfermodeName = SkXfermode::kSrcOver_Mode; 280 bXfermodeName = SkXfermode::kSrcOver_Mode;
283 } 281 }
284 const char* bXfermodeString = blend_mode_from_xfermode(bXfermodeName); 282 const char* bXfermodeString = blend_mode_from_xfermode(bXfermodeName);
285 SkASSERT(bXfermodeString != NULL); 283 SkASSERT(bXfermodeString != NULL);
286 284
287 return strcmp(aXfermodeString, bXfermodeString) == 0; 285 return strcmp(aXfermodeString, bXfermodeString) == 0;
288 } 286 }
OLDNEW
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | src/ports/SkMutex_pthread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698