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

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

Issue 1790023003: SkPDF: add drop() virtual to release resources early. (Closed) Base URL: https://skia.googlesource.com/skia.git@skpdf-global
Patch Set: free → release 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 | « bench/PDFBench.cpp ('k') | src/pdf/SkPDFDocument.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 2015 Google Inc. 2 * Copyright 2015 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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDeflate.h" 10 #include "SkDeflate.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 stream->writeStream(asset.get(), asset->getLength()); 375 stream->writeStream(asset.get(), asset->getLength());
376 pdf_stream_end(stream); 376 pdf_stream_end(stream);
377 } 377 }
378 378
379 //////////////////////////////////////////////////////////////////////////////// 379 ////////////////////////////////////////////////////////////////////////////////
380 380
381 namespace { 381 namespace {
382 // This SkPDFObject only outputs the alpha layer of the given bitmap. 382 // This SkPDFObject only outputs the alpha layer of the given bitmap.
383 class PDFAlphaBitmap final : public SkPDFObject { 383 class PDFAlphaBitmap final : public SkPDFObject {
384 public: 384 public:
385 PDFAlphaBitmap(const SkImage* image) : fImage(SkRef(image)) {} 385 PDFAlphaBitmap(const SkImage* image) : fImage(SkRef(image)) { SkASSERT(image ); }
386 ~PDFAlphaBitmap() {}
387 void emitObject(SkWStream* stream, 386 void emitObject(SkWStream* stream,
388 const SkPDFObjNumMap& objNumMap, 387 const SkPDFObjNumMap& objNumMap,
389 const SkPDFSubstituteMap& subs) const override { 388 const SkPDFSubstituteMap& subs) const override {
389 SkASSERT(fImage);
390 emit_image_xobject(stream, fImage.get(), true, nullptr, objNumMap, subs) ; 390 emit_image_xobject(stream, fImage.get(), true, nullptr, objNumMap, subs) ;
391 } 391 }
392 void drop() override { fImage = nullptr; }
392 393
393 private: 394 private:
394 sk_sp<const SkImage> fImage; 395 sk_sp<const SkImage> fImage;
395 }; 396 };
396 397
397 } // namespace 398 } // namespace
398 399
399 //////////////////////////////////////////////////////////////////////////////// 400 ////////////////////////////////////////////////////////////////////////////////
400 401
401 namespace { 402 namespace {
402 class PDFDefaultBitmap final : public SkPDFObject { 403 class PDFDefaultBitmap final : public SkPDFObject {
403 public: 404 public:
404 void emitObject(SkWStream* stream, 405 void emitObject(SkWStream* stream,
405 const SkPDFObjNumMap& objNumMap, 406 const SkPDFObjNumMap& objNumMap,
406 const SkPDFSubstituteMap& subs) const override { 407 const SkPDFSubstituteMap& subs) const override {
408 SkASSERT(fImage);
407 emit_image_xobject(stream, fImage.get(), false, fSMask, objNumMap, subs) ; 409 emit_image_xobject(stream, fImage.get(), false, fSMask, objNumMap, subs) ;
408 } 410 }
409 void addResources(SkPDFObjNumMap* catalog, 411 void addResources(SkPDFObjNumMap* catalog,
410 const SkPDFSubstituteMap& subs) const override { 412 const SkPDFSubstituteMap& subs) const override {
413 SkASSERT(fImage);
411 if (fSMask.get()) { 414 if (fSMask.get()) {
412 SkPDFObject* obj = subs.getSubstitute(fSMask.get()); 415 SkPDFObject* obj = subs.getSubstitute(fSMask.get());
413 SkASSERT(obj); 416 SkASSERT(obj);
414 catalog->addObjectRecursively(obj, subs); 417 catalog->addObjectRecursively(obj, subs);
415 } 418 }
416 } 419 }
420 void drop() override { fImage = nullptr; fSMask = nullptr; }
417 PDFDefaultBitmap(const SkImage* image, SkPDFObject* smask) 421 PDFDefaultBitmap(const SkImage* image, SkPDFObject* smask)
418 : fImage(SkRef(image)), fSMask(smask) {} 422 : fImage(SkRef(image)), fSMask(smask) { SkASSERT(fImage); }
419 423
420 private: 424 private:
421 sk_sp<const SkImage> fImage; 425 sk_sp<const SkImage> fImage;
422 const sk_sp<SkPDFObject> fSMask; 426 sk_sp<SkPDFObject> fSMask;
423 }; 427 };
424 } // namespace 428 } // namespace
425 429
426 //////////////////////////////////////////////////////////////////////////////// 430 ////////////////////////////////////////////////////////////////////////////////
427 431
428 namespace { 432 namespace {
429 /** 433 /**
430 * This PDFObject assumes that its constructor was handed YUV or 434 * This PDFObject assumes that its constructor was handed YUV or
431 * Grayscale JFIF Jpeg-encoded data that can be directly embedded 435 * Grayscale JFIF Jpeg-encoded data that can be directly embedded
432 * into a PDF. 436 * into a PDF.
433 */ 437 */
434 class PDFJpegBitmap final : public SkPDFObject { 438 class PDFJpegBitmap final : public SkPDFObject {
435 public: 439 public:
436 SkISize fSize; 440 SkISize fSize;
437 sk_sp<SkData> fData; 441 sk_sp<SkData> fData;
438 bool fIsYUV; 442 bool fIsYUV;
439 PDFJpegBitmap(SkISize size, SkData* data, bool isYUV) 443 PDFJpegBitmap(SkISize size, SkData* data, bool isYUV)
440 : fSize(size), fData(SkRef(data)), fIsYUV(isYUV) {} 444 : fSize(size), fData(SkRef(data)), fIsYUV(isYUV) { SkASSERT(data); }
441 void emitObject(SkWStream*, 445 void emitObject(SkWStream*,
442 const SkPDFObjNumMap&, 446 const SkPDFObjNumMap&,
443 const SkPDFSubstituteMap&) const override; 447 const SkPDFSubstituteMap&) const override;
448 void drop() override { fData = nullptr; }
444 }; 449 };
445 450
446 void PDFJpegBitmap::emitObject(SkWStream* stream, 451 void PDFJpegBitmap::emitObject(SkWStream* stream,
447 const SkPDFObjNumMap& objNumMap, 452 const SkPDFObjNumMap& objNumMap,
448 const SkPDFSubstituteMap& substituteMap) const { 453 const SkPDFSubstituteMap& substituteMap) const {
454 SkASSERT(fData);
449 SkPDFDict pdfDict("XObject"); 455 SkPDFDict pdfDict("XObject");
450 pdfDict.insertName("Subtype", "Image"); 456 pdfDict.insertName("Subtype", "Image");
451 pdfDict.insertInt("Width", fSize.width()); 457 pdfDict.insertInt("Width", fSize.width());
452 pdfDict.insertInt("Height", fSize.height()); 458 pdfDict.insertInt("Height", fSize.height());
453 if (fIsYUV) { 459 if (fIsYUV) {
454 pdfDict.insertName("ColorSpace", "DeviceRGB"); 460 pdfDict.insertName("ColorSpace", "DeviceRGB");
455 } else { 461 } else {
456 pdfDict.insertName("ColorSpace", "DeviceGray"); 462 pdfDict.insertName("ColorSpace", "DeviceGray");
457 } 463 }
458 pdfDict.insertInt("BitsPerComponent", 8); 464 pdfDict.insertInt("BitsPerComponent", 8);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 508 }
503 } 509 }
504 510
505 SkPDFObject* smask = 511 SkPDFObject* smask =
506 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image) ; 512 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image) ;
507 #ifdef SK_PDF_IMAGE_STATS 513 #ifdef SK_PDF_IMAGE_STATS
508 gRegularImageObjects.fetch_add(1); 514 gRegularImageObjects.fetch_add(1);
509 #endif 515 #endif
510 return new PDFDefaultBitmap(image, smask); 516 return new PDFDefaultBitmap(image, smask);
511 } 517 }
OLDNEW
« no previous file with comments | « bench/PDFBench.cpp ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698