OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "SkDeflate.h" | 8 #include "SkDeflate.h" |
10 #include "SkPDFTypes.h" | 9 #include "SkPDFTypes.h" |
11 #include "SkPDFUtils.h" | 10 #include "SkPDFUtils.h" |
12 #include "SkStreamPriv.h" | 11 #include "SkStreamPriv.h" |
13 | 12 |
14 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
15 | 14 |
16 SkString* pun(char* x) { return reinterpret_cast<SkString*>(x); } | 15 SkString* pun(char* x) { return reinterpret_cast<SkString*>(x); } |
17 const SkString* pun(const char* x) { | 16 const SkString* pun(const char* x) { |
18 return reinterpret_cast<const SkString*>(x); | 17 return reinterpret_cast<const SkString*>(x); |
19 } | 18 } |
20 | 19 |
21 SkPDFUnion::SkPDFUnion(Type t) : fType(t) {} | 20 SkPDFUnion::SkPDFUnion(Type t) : fType(t) {} |
22 | 21 |
23 SkPDFUnion::~SkPDFUnion() { | 22 SkPDFUnion::~SkPDFUnion() { |
24 switch (fType) { | 23 switch (fType) { |
25 case Type::kNameSkS: | 24 case Type::kNameSkS: |
26 case Type::kStringSkS: | 25 case Type::kStringSkS: |
27 pun(fSkString)->~SkString(); | 26 pun(fSkString)->~SkString(); |
28 return; | 27 return; |
29 case Type::kObjRef: | 28 case Type::kObjRef: |
30 case Type::kObject: | 29 case Type::kObject: |
31 SkSafeUnref(fObject); | 30 SkASSERT(fObject); |
| 31 fObject->unref(); |
32 return; | 32 return; |
33 default: | 33 default: |
34 return; | 34 return; |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 SkPDFUnion& SkPDFUnion::operator=(SkPDFUnion&& other) { | 38 SkPDFUnion& SkPDFUnion::operator=(SkPDFUnion&& other) { |
39 if (this != &other) { | 39 if (this != &other) { |
40 this->~SkPDFUnion(); | 40 this->~SkPDFUnion(); |
41 new (this) SkPDFUnion(other.move()); | 41 new (this) SkPDFUnion(std::move(other)); |
42 } | 42 } |
43 return *this; | 43 return *this; |
44 } | 44 } |
45 | 45 |
46 SkPDFUnion::SkPDFUnion(SkPDFUnion&& other) { | 46 SkPDFUnion::SkPDFUnion(SkPDFUnion&& other) { |
47 SkASSERT(this != &other); | 47 SkASSERT(this != &other); |
48 memcpy(this, &other, sizeof(*this)); | 48 memcpy(this, &other, sizeof(*this)); |
49 other.fType = Type::kDestroyed; | 49 other.fType = Type::kDestroyed; |
50 } | 50 } |
51 | 51 |
52 #if 0 | 52 #if 0 |
53 SkPDFUnion SkPDFUnion::copy() const { | 53 SkPDFUnion SkPDFUnion::copy() const { |
54 SkPDFUnion u(fType); | 54 SkPDFUnion u(fType); |
55 memcpy(&u, this, sizeof(u)); | 55 memcpy(&u, this, sizeof(u)); |
56 switch (fType) { | 56 switch (fType) { |
57 case Type::kNameSkS: | 57 case Type::kNameSkS: |
58 case Type::kStringSkS: | 58 case Type::kStringSkS: |
59 new (pun(u.fSkString)) SkString (
*pun(fSkString)); | 59 new (pun(u.fSkString)) SkString(*pun(fSkString)); |
60 return u.move(); | 60 return u; |
61 case Type::kObjRef: | 61 case Type::kObjRef: |
62 case Type::kObject: | 62 case Type::kObject: |
63 SkRef(u.fObject); | 63 SkRef(u.fObject); |
64 return u.move(); | 64 return u; |
65 default: | 65 default: |
66 return u.move(); | 66 return u; |
67 } | 67 } |
68 } | 68 } |
69 SkPDFUnion& SkPDFUnion::operator=(const SkPDFUnion& other) { | 69 SkPDFUnion& SkPDFUnion::operator=(const SkPDFUnion& other) { |
70 return *this = other.copy(); | 70 return *this = other.copy(); |
71 } | 71 } |
72 SkPDFUnion::SkPDFUnion(const SkPDFUnion& other) { | 72 SkPDFUnion::SkPDFUnion(const SkPDFUnion& other) { |
73 *this = other.copy(); | 73 *this = other.copy(); |
74 } | 74 } |
75 #endif | 75 #endif |
76 | 76 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 fObject->addResources(objNumMap, substituteMap); | 184 fObject->addResources(objNumMap, substituteMap); |
185 return; | 185 return; |
186 default: | 186 default: |
187 SkDEBUGFAIL("SkPDFUnion::addResources with bad type"); | 187 SkDEBUGFAIL("SkPDFUnion::addResources with bad type"); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 SkPDFUnion SkPDFUnion::Int(int32_t value) { | 191 SkPDFUnion SkPDFUnion::Int(int32_t value) { |
192 SkPDFUnion u(Type::kInt); | 192 SkPDFUnion u(Type::kInt); |
193 u.fIntValue = value; | 193 u.fIntValue = value; |
194 return u.move(); | 194 return u; |
195 } | 195 } |
196 | 196 |
197 SkPDFUnion SkPDFUnion::Bool(bool value) { | 197 SkPDFUnion SkPDFUnion::Bool(bool value) { |
198 SkPDFUnion u(Type::kBool); | 198 SkPDFUnion u(Type::kBool); |
199 u.fBoolValue = value; | 199 u.fBoolValue = value; |
200 return u.move(); | 200 return u; |
201 } | 201 } |
202 | 202 |
203 SkPDFUnion SkPDFUnion::Scalar(SkScalar value) { | 203 SkPDFUnion SkPDFUnion::Scalar(SkScalar value) { |
204 SkPDFUnion u(Type::kScalar); | 204 SkPDFUnion u(Type::kScalar); |
205 u.fScalarValue = value; | 205 u.fScalarValue = value; |
206 return u.move(); | 206 return u; |
207 } | 207 } |
208 | 208 |
209 SkPDFUnion SkPDFUnion::Name(const char* value) { | 209 SkPDFUnion SkPDFUnion::Name(const char* value) { |
210 SkPDFUnion u(Type::kName); | 210 SkPDFUnion u(Type::kName); |
211 SkASSERT(value); | 211 SkASSERT(value); |
212 SkASSERT(is_valid_name(value)); | 212 SkASSERT(is_valid_name(value)); |
213 u.fStaticString = value; | 213 u.fStaticString = value; |
214 return u.move(); | 214 return u; |
215 } | 215 } |
216 | 216 |
217 SkPDFUnion SkPDFUnion::String(const char* value) { | 217 SkPDFUnion SkPDFUnion::String(const char* value) { |
218 SkPDFUnion u(Type::kString); | 218 SkPDFUnion u(Type::kString); |
219 SkASSERT(value); | 219 SkASSERT(value); |
220 u.fStaticString = value; | 220 u.fStaticString = value; |
221 return u.move(); | 221 return u; |
222 } | 222 } |
223 | 223 |
224 SkPDFUnion SkPDFUnion::Name(const SkString& s) { | 224 SkPDFUnion SkPDFUnion::Name(const SkString& s) { |
225 SkPDFUnion u(Type::kNameSkS); | 225 SkPDFUnion u(Type::kNameSkS); |
226 new (pun(u.fSkString)) SkString(s); | 226 new (pun(u.fSkString)) SkString(s); |
227 return u.move(); | 227 return u; |
228 } | 228 } |
229 | 229 |
230 SkPDFUnion SkPDFUnion::String(const SkString& s) { | 230 SkPDFUnion SkPDFUnion::String(const SkString& s) { |
231 SkPDFUnion u(Type::kStringSkS); | 231 SkPDFUnion u(Type::kStringSkS); |
232 new (pun(u.fSkString)) SkString(s); | 232 new (pun(u.fSkString)) SkString(s); |
233 return u.move(); | 233 return u; |
234 } | 234 } |
235 | 235 |
236 SkPDFUnion SkPDFUnion::ObjRef(SkPDFObject* ptr) { | 236 SkPDFUnion SkPDFUnion::ObjRef(sk_sp<SkPDFObject> objSp) { |
237 SkPDFUnion u(Type::kObjRef); | 237 SkPDFUnion u(Type::kObjRef); |
238 SkASSERT(ptr); | 238 SkASSERT(objSp.get()); |
239 u.fObject = ptr; | 239 u.fObject = objSp.release(); // take ownership into union{} |
240 return u.move(); | 240 return u; |
241 } | 241 } |
242 | 242 |
243 SkPDFUnion SkPDFUnion::Object(SkPDFObject* ptr) { | 243 SkPDFUnion SkPDFUnion::Object(sk_sp<SkPDFObject> objSp) { |
244 SkPDFUnion u(Type::kObject); | 244 SkPDFUnion u(Type::kObject); |
245 SkASSERT(ptr); | 245 SkASSERT(objSp.get()); |
246 u.fObject = ptr; | 246 u.fObject = objSp.release(); // take ownership into union{} |
247 return u.move(); | 247 return u; |
248 } | 248 } |
249 | 249 |
250 //////////////////////////////////////////////////////////////////////////////// | 250 //////////////////////////////////////////////////////////////////////////////// |
251 | 251 |
252 #if 0 // Enable if needed. | 252 #if 0 // Enable if needed. |
253 void SkPDFAtom::emitObject(SkWStream* stream, | 253 void SkPDFAtom::emitObject(SkWStream* stream, |
254 const SkPDFObjNumMap& objNumMap, | 254 const SkPDFObjNumMap& objNumMap, |
255 const SkPDFSubstituteMap& substitutes) const { | 255 const SkPDFSubstituteMap& substitutes) const { |
256 fValue.emitObject(stream, objNumMap, substitutes); | 256 fValue.emitObject(stream, objNumMap, substitutes); |
257 } | 257 } |
(...skipping 30 matching lines...) Expand all Loading... |
288 stream->writeText("]"); | 288 stream->writeText("]"); |
289 } | 289 } |
290 | 290 |
291 void SkPDFArray::addResources(SkPDFObjNumMap* catalog, | 291 void SkPDFArray::addResources(SkPDFObjNumMap* catalog, |
292 const SkPDFSubstituteMap& substitutes) const { | 292 const SkPDFSubstituteMap& substitutes) const { |
293 for (const SkPDFUnion& value : fValues) { | 293 for (const SkPDFUnion& value : fValues) { |
294 value.addResources(catalog, substitutes); | 294 value.addResources(catalog, substitutes); |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 void SkPDFArray::append(SkPDFUnion&& value) { new (fValues.append()) SkPDFUnion(
value.move()); } | 298 void SkPDFArray::append(SkPDFUnion&& value) { |
| 299 new (fValues.append()) SkPDFUnion(std::move(value)); |
| 300 } |
299 | 301 |
300 void SkPDFArray::appendInt(int32_t value) { | 302 void SkPDFArray::appendInt(int32_t value) { |
301 this->append(SkPDFUnion::Int(value)); | 303 this->append(SkPDFUnion::Int(value)); |
302 } | 304 } |
303 | 305 |
304 void SkPDFArray::appendBool(bool value) { | 306 void SkPDFArray::appendBool(bool value) { |
305 this->append(SkPDFUnion::Bool(value)); | 307 this->append(SkPDFUnion::Bool(value)); |
306 } | 308 } |
307 | 309 |
308 void SkPDFArray::appendScalar(SkScalar value) { | 310 void SkPDFArray::appendScalar(SkScalar value) { |
309 this->append(SkPDFUnion::Scalar(value)); | 311 this->append(SkPDFUnion::Scalar(value)); |
310 } | 312 } |
311 | 313 |
312 void SkPDFArray::appendName(const char name[]) { | 314 void SkPDFArray::appendName(const char name[]) { |
313 this->append(SkPDFUnion::Name(SkString(name))); | 315 this->append(SkPDFUnion::Name(SkString(name))); |
314 } | 316 } |
315 | 317 |
316 void SkPDFArray::appendName(const SkString& name) { | 318 void SkPDFArray::appendName(const SkString& name) { |
317 this->append(SkPDFUnion::Name(name)); | 319 this->append(SkPDFUnion::Name(name)); |
318 } | 320 } |
319 | 321 |
320 void SkPDFArray::appendString(const SkString& value) { | 322 void SkPDFArray::appendString(const SkString& value) { |
321 this->append(SkPDFUnion::String(value)); | 323 this->append(SkPDFUnion::String(value)); |
322 } | 324 } |
323 | 325 |
324 void SkPDFArray::appendString(const char value[]) { | 326 void SkPDFArray::appendString(const char value[]) { |
325 this->append(SkPDFUnion::String(value)); | 327 this->append(SkPDFUnion::String(value)); |
326 } | 328 } |
327 | 329 |
328 void SkPDFArray::appendObject(SkPDFObject* value) { | 330 void SkPDFArray::appendObject(sk_sp<SkPDFObject> objSp) { |
329 this->append(SkPDFUnion::Object(value)); | 331 this->append(SkPDFUnion::Object(std::move(objSp))); |
330 } | 332 } |
331 | 333 |
332 void SkPDFArray::appendObjRef(SkPDFObject* value) { | 334 void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) { |
333 this->append(SkPDFUnion::ObjRef(value)); | 335 this->append(SkPDFUnion::ObjRef(std::move(objSp))); |
334 } | 336 } |
335 | 337 |
336 /////////////////////////////////////////////////////////////////////////////// | 338 /////////////////////////////////////////////////////////////////////////////// |
337 | 339 |
338 SkPDFDict::SkPDFDict() {} | 340 SkPDFDict::SkPDFDict() {} |
339 | 341 |
340 SkPDFDict::~SkPDFDict() { this->clear(); } | 342 SkPDFDict::~SkPDFDict() { this->clear(); } |
341 | 343 |
342 SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); } | 344 SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); } |
343 | 345 |
(...skipping 22 matching lines...) Expand all Loading... |
366 const SkPDFSubstituteMap& substitutes) const { | 368 const SkPDFSubstituteMap& substitutes) const { |
367 for (int i = 0; i < fRecords.count(); i++) { | 369 for (int i = 0; i < fRecords.count(); i++) { |
368 fRecords[i].fKey.addResources(catalog, substitutes); | 370 fRecords[i].fKey.addResources(catalog, substitutes); |
369 fRecords[i].fValue.addResources(catalog, substitutes); | 371 fRecords[i].fValue.addResources(catalog, substitutes); |
370 } | 372 } |
371 } | 373 } |
372 | 374 |
373 void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) { | 375 void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) { |
374 Record* rec = fRecords.append(); | 376 Record* rec = fRecords.append(); |
375 SkASSERT(name.isName()); | 377 SkASSERT(name.isName()); |
376 new (&rec->fKey) SkPDFUnion(name.move()); | 378 new (&rec->fKey) SkPDFUnion(std::move(name)); |
377 new (&rec->fValue) SkPDFUnion(value.move()); | 379 new (&rec->fValue) SkPDFUnion(std::move(value)); |
378 } | 380 } |
379 | 381 |
380 int SkPDFDict::size() const { return fRecords.count(); } | 382 int SkPDFDict::size() const { return fRecords.count(); } |
381 | 383 |
382 void SkPDFDict::insertObjRef(const char key[], SkPDFObject* value) { | 384 void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) { |
383 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value)); | 385 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
384 } | 386 } |
385 void SkPDFDict::insertObjRef(const SkString& key, SkPDFObject* value) { | 387 void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) { |
386 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value)); | 388 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
387 } | 389 } |
388 | 390 |
389 void SkPDFDict::insertObject(const char key[], SkPDFObject* value) { | 391 void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) { |
390 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value)); | 392 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
391 } | 393 } |
392 void SkPDFDict::insertObject(const SkString& key, SkPDFObject* value) { | 394 void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) { |
393 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value)); | 395 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
394 } | 396 } |
395 | 397 |
396 void SkPDFDict::insertBool(const char key[], bool value) { | 398 void SkPDFDict::insertBool(const char key[], bool value) { |
397 this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value)); | 399 this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value)); |
398 } | 400 } |
399 | 401 |
400 void SkPDFDict::insertInt(const char key[], int32_t value) { | 402 void SkPDFDict::insertInt(const char key[], int32_t value) { |
401 this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value)); | 403 this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value)); |
402 } | 404 } |
403 | 405 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 520 |
519 void SkPDFImageDumpStats() { | 521 void SkPDFImageDumpStats() { |
520 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" | 522 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" |
521 "total PDF jpeg images: %d\n" | 523 "total PDF jpeg images: %d\n" |
522 "total PDF regular images: %d\n", | 524 "total PDF regular images: %d\n", |
523 gDrawImageCalls.load(), | 525 gDrawImageCalls.load(), |
524 gJpegImageObjects.load(), | 526 gJpegImageObjects.load(), |
525 gRegularImageObjects.load()); | 527 gRegularImageObjects.load()); |
526 } | 528 } |
527 #endif // SK_PDF_IMAGE_STATS | 529 #endif // SK_PDF_IMAGE_STATS |
OLD | NEW |