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

Side by Side Diff: src/pdf/SkPDFImage.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/SkPDFImage.h ('k') | src/pdf/SkPDFPage.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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 "SkPDFImage.h" 8 #include "SkPDFImage.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 srcRect.height()), 497 srcRect.height()),
498 encoder)); 498 encoder));
499 } 499 }
500 } else { 500 } else {
501 image = SkNEW_ARGS(SkPDFImage, (NULL, bitmap, false, srcRect, encoder)); 501 image = SkNEW_ARGS(SkPDFImage, (NULL, bitmap, false, srcRect, encoder));
502 } 502 }
503 if (alphaData.get() != NULL) { 503 if (alphaData.get() != NULL) {
504 SkAutoTUnref<SkPDFImage> mask( 504 SkAutoTUnref<SkPDFImage> mask(
505 SkNEW_ARGS(SkPDFImage, (alphaData.get(), bitmap, 505 SkNEW_ARGS(SkPDFImage, (alphaData.get(), bitmap,
506 true, srcRect, NULL))); 506 true, srcRect, NULL)));
507 image->addSMask(mask); 507 image->insert("SMask", new SkPDFObjRef(mask))->unref();
508 } 508 }
509
510 return image; 509 return image;
511 } 510 }
512 511
513 SkPDFImage::~SkPDFImage() { 512 SkPDFImage::~SkPDFImage() {}
514 fResources.unrefAll();
515 }
516
517 SkPDFImage* SkPDFImage::addSMask(SkPDFImage* mask) {
518 fResources.push(mask);
519 mask->ref();
520 insert("SMask", new SkPDFObjRef(mask))->unref();
521 return mask;
522 }
523
524 void SkPDFImage::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
525 SkTSet<SkPDFObject*>* newResourceObjects) {
526 GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
527 }
528 513
529 SkPDFImage::SkPDFImage(SkStream* stream, 514 SkPDFImage::SkPDFImage(SkStream* stream,
530 const SkBitmap& bitmap, 515 const SkBitmap& bitmap,
531 bool isAlpha, 516 bool isAlpha,
532 const SkIRect& srcRect, 517 const SkIRect& srcRect,
533 SkPicture::EncodeBitmap encoder) 518 SkPicture::EncodeBitmap encoder)
534 : fIsAlpha(isAlpha), 519 : fIsAlpha(isAlpha),
535 fSrcRect(srcRect), 520 fSrcRect(srcRect),
536 fEncoder(encoder) { 521 fEncoder(encoder) {
537 522
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 * This PDFObject assumes that its constructor was handed 651 * This PDFObject assumes that its constructor was handed
667 * Jpeg-encoded data that can be directly embedded into a PDF. 652 * Jpeg-encoded data that can be directly embedded into a PDF.
668 */ 653 */
669 class PDFJPEGImage : public SkPDFObject { 654 class PDFJPEGImage : public SkPDFObject {
670 SkAutoTUnref<SkData> fData; 655 SkAutoTUnref<SkData> fData;
671 int fWidth; 656 int fWidth;
672 int fHeight; 657 int fHeight;
673 public: 658 public:
674 PDFJPEGImage(SkData* data, int width, int height) 659 PDFJPEGImage(SkData* data, int width, int height)
675 : fData(SkRef(data)), fWidth(width), fHeight(height) {} 660 : fData(SkRef(data)), fWidth(width), fHeight(height) {}
676 virtual void getResources(const SkTSet<SkPDFObject*>&,
677 SkTSet<SkPDFObject*>*) SK_OVERRIDE {}
678 virtual void emitObject( 661 virtual void emitObject(
679 SkWStream* stream, 662 SkWStream* stream,
680 SkPDFCatalog* catalog, bool indirect) SK_OVERRIDE { 663 SkPDFCatalog* catalog, bool indirect) SK_OVERRIDE {
681 if (indirect) { 664 if (indirect) {
682 this->emitIndirectObject(stream, catalog); 665 this->emitIndirectObject(stream, catalog);
683 return; 666 return;
684 } 667 }
685 SkASSERT(fData.get()); 668 SkASSERT(fData.get());
686 const char kPrefaceFormat[] = 669 const char kPrefaceFormat[] =
687 "<<" 670 "<<"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { 727 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) {
745 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); 728 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap));
746 if (is_jfif_jpeg(encodedData)) { 729 if (is_jfif_jpeg(encodedData)) {
747 return SkNEW_ARGS(PDFJPEGImage, 730 return SkNEW_ARGS(PDFJPEGImage,
748 (encodedData, bitmap.width(), bitmap.height())); 731 (encodedData, bitmap.width(), bitmap.height()));
749 } 732 }
750 } 733 }
751 #endif 734 #endif
752 return SkPDFImage::CreateImage(bitmap, subset, encoder); 735 return SkPDFImage::CreateImage(bitmap, subset, encoder);
753 } 736 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFImage.h ('k') | src/pdf/SkPDFPage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698