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

Side by Side Diff: src/pdf/SkPDFTypes.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/SkPDFTypes.h ('k') | src/pdf/SkPDFUtils.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 /*
2 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
3 * 4 *
4 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 6 * found in the LICENSE file.
6 */ 7 */
7 8
8 #include "SkDeflate.h" 9 #include "SkDeflate.h"
9 #include "SkPDFTypes.h" 10 #include "SkPDFTypes.h"
10 #include "SkPDFUtils.h" 11 #include "SkPDFUtils.h"
11 #include "SkStreamPriv.h" 12 #include "SkStreamPriv.h"
12 13
13 //////////////////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////////////////
14 15
15 SkString* pun(char* x) { return reinterpret_cast<SkString*>(x); } 16 SkString* pun(char* x) { return reinterpret_cast<SkString*>(x); }
16 const SkString* pun(const char* x) { 17 const SkString* pun(const char* x) {
17 return reinterpret_cast<const SkString*>(x); 18 return reinterpret_cast<const SkString*>(x);
18 } 19 }
19 20
20 SkPDFUnion::SkPDFUnion(Type t) : fType(t) {} 21 SkPDFUnion::SkPDFUnion(Type t) : fType(t) {}
21 22
22 SkPDFUnion::~SkPDFUnion() { 23 SkPDFUnion::~SkPDFUnion() {
23 switch (fType) { 24 switch (fType) {
24 case Type::kNameSkS: 25 case Type::kNameSkS:
25 case Type::kStringSkS: 26 case Type::kStringSkS:
26 pun(fSkString)->~SkString(); 27 pun(fSkString)->~SkString();
27 return; 28 return;
28 case Type::kObjRef: 29 case Type::kObjRef:
29 case Type::kObject: 30 case Type::kObject:
30 SkASSERT(fObject); 31 SkSafeUnref(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(std::move(other)); 41 new (this) SkPDFUnion(other.move());
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 std::move(u); 60 return u.move();
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 std::move(u); 64 return u.move();
65 default: 65 default:
66 return std::move(u); 66 return u.move();
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
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 std::move(u); 194 return u.move();
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 std::move(u); 200 return u.move();
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 std::move(u); 206 return u.move();
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 std::move(u); 214 return u.move();
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 std::move(u); 221 return u.move();
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 std::move(u); 227 return u.move();
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 std::move(u); 233 return u.move();
234 } 234 }
235 235
236 SkPDFUnion SkPDFUnion::ObjRef(sk_sp<SkPDFObject> objSp) { 236 SkPDFUnion SkPDFUnion::ObjRef(SkPDFObject* ptr) {
237 SkPDFUnion u(Type::kObjRef); 237 SkPDFUnion u(Type::kObjRef);
238 SkASSERT(objSp.get()); 238 SkASSERT(ptr);
239 u.fObject = objSp.release(); // take ownership into union{} 239 u.fObject = ptr;
240 return std::move(u); 240 return u.move();
241 } 241 }
242 242
243 SkPDFUnion SkPDFUnion::Object(sk_sp<SkPDFObject> objSp) { 243 SkPDFUnion SkPDFUnion::Object(SkPDFObject* ptr) {
244 SkPDFUnion u(Type::kObject); 244 SkPDFUnion u(Type::kObject);
245 SkASSERT(objSp.get()); 245 SkASSERT(ptr);
246 u.fObject = objSp.release(); // take ownership into union{} 246 u.fObject = ptr;
247 return std::move(u); 247 return u.move();
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
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) { 298 void SkPDFArray::append(SkPDFUnion&& value) { new (fValues.append()) SkPDFUnion( value.move()); }
299 new (fValues.append()) SkPDFUnion(std::move(value));
300 }
301 299
302 void SkPDFArray::appendInt(int32_t value) { 300 void SkPDFArray::appendInt(int32_t value) {
303 this->append(SkPDFUnion::Int(value)); 301 this->append(SkPDFUnion::Int(value));
304 } 302 }
305 303
306 void SkPDFArray::appendBool(bool value) { 304 void SkPDFArray::appendBool(bool value) {
307 this->append(SkPDFUnion::Bool(value)); 305 this->append(SkPDFUnion::Bool(value));
308 } 306 }
309 307
310 void SkPDFArray::appendScalar(SkScalar value) { 308 void SkPDFArray::appendScalar(SkScalar value) {
311 this->append(SkPDFUnion::Scalar(value)); 309 this->append(SkPDFUnion::Scalar(value));
312 } 310 }
313 311
314 void SkPDFArray::appendName(const char name[]) { 312 void SkPDFArray::appendName(const char name[]) {
315 this->append(SkPDFUnion::Name(SkString(name))); 313 this->append(SkPDFUnion::Name(SkString(name)));
316 } 314 }
317 315
318 void SkPDFArray::appendName(const SkString& name) { 316 void SkPDFArray::appendName(const SkString& name) {
319 this->append(SkPDFUnion::Name(name)); 317 this->append(SkPDFUnion::Name(name));
320 } 318 }
321 319
322 void SkPDFArray::appendString(const SkString& value) { 320 void SkPDFArray::appendString(const SkString& value) {
323 this->append(SkPDFUnion::String(value)); 321 this->append(SkPDFUnion::String(value));
324 } 322 }
325 323
326 void SkPDFArray::appendString(const char value[]) { 324 void SkPDFArray::appendString(const char value[]) {
327 this->append(SkPDFUnion::String(value)); 325 this->append(SkPDFUnion::String(value));
328 } 326 }
329 327
330 void SkPDFArray::appendObject(sk_sp<SkPDFObject> objSp) { 328 void SkPDFArray::appendObject(SkPDFObject* value) {
331 this->append(SkPDFUnion::Object(std::move(objSp))); 329 this->append(SkPDFUnion::Object(value));
332 } 330 }
333 331
334 void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) { 332 void SkPDFArray::appendObjRef(SkPDFObject* value) {
335 this->append(SkPDFUnion::ObjRef(std::move(objSp))); 333 this->append(SkPDFUnion::ObjRef(value));
336 } 334 }
337 335
338 /////////////////////////////////////////////////////////////////////////////// 336 ///////////////////////////////////////////////////////////////////////////////
339 337
340 SkPDFDict::SkPDFDict() {} 338 SkPDFDict::SkPDFDict() {}
341 339
342 SkPDFDict::~SkPDFDict() { this->clear(); } 340 SkPDFDict::~SkPDFDict() { this->clear(); }
343 341
344 SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); } 342 SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); }
345 343
(...skipping 22 matching lines...) Expand all
368 const SkPDFSubstituteMap& substitutes) const { 366 const SkPDFSubstituteMap& substitutes) const {
369 for (int i = 0; i < fRecords.count(); i++) { 367 for (int i = 0; i < fRecords.count(); i++) {
370 fRecords[i].fKey.addResources(catalog, substitutes); 368 fRecords[i].fKey.addResources(catalog, substitutes);
371 fRecords[i].fValue.addResources(catalog, substitutes); 369 fRecords[i].fValue.addResources(catalog, substitutes);
372 } 370 }
373 } 371 }
374 372
375 void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) { 373 void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) {
376 Record* rec = fRecords.append(); 374 Record* rec = fRecords.append();
377 SkASSERT(name.isName()); 375 SkASSERT(name.isName());
378 new (&rec->fKey) SkPDFUnion(std::move(name)); 376 new (&rec->fKey) SkPDFUnion(name.move());
379 new (&rec->fValue) SkPDFUnion(std::move(value)); 377 new (&rec->fValue) SkPDFUnion(value.move());
380 } 378 }
381 379
382 int SkPDFDict::size() const { return fRecords.count(); } 380 int SkPDFDict::size() const { return fRecords.count(); }
383 381
384 void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) { 382 void SkPDFDict::insertObjRef(const char key[], SkPDFObject* value) {
385 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); 383 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
386 } 384 }
387 void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) { 385 void SkPDFDict::insertObjRef(const SkString& key, SkPDFObject* value) {
388 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); 386 this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
389 } 387 }
390 388
391 void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) { 389 void SkPDFDict::insertObject(const char key[], SkPDFObject* value) {
392 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); 390 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
393 } 391 }
394 void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) { 392 void SkPDFDict::insertObject(const SkString& key, SkPDFObject* value) {
395 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); 393 this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
396 } 394 }
397 395
398 void SkPDFDict::insertBool(const char key[], bool value) { 396 void SkPDFDict::insertBool(const char key[], bool value) {
399 this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value)); 397 this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value));
400 } 398 }
401 399
402 void SkPDFDict::insertInt(const char key[], int32_t value) { 400 void SkPDFDict::insertInt(const char key[], int32_t value) {
403 this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value)); 401 this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value));
404 } 402 }
405 403
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 518
521 void SkPDFImageDumpStats() { 519 void SkPDFImageDumpStats() {
522 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" 520 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n"
523 "total PDF jpeg images: %d\n" 521 "total PDF jpeg images: %d\n"
524 "total PDF regular images: %d\n", 522 "total PDF regular images: %d\n",
525 gDrawImageCalls.load(), 523 gDrawImageCalls.load(),
526 gJpegImageObjects.load(), 524 gJpegImageObjects.load(),
527 gRegularImageObjects.load()); 525 gRegularImageObjects.load());
528 } 526 }
529 #endif // SK_PDF_IMAGE_STATS 527 #endif // SK_PDF_IMAGE_STATS
OLDNEW
« no previous file with comments | « src/pdf/SkPDFTypes.h ('k') | src/pdf/SkPDFUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698