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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 15004024: Only use skia::RefPtr for refcounting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment changes, SharePtr Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/test/skia_common.cc ('k') | skia/ext/refptr.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/pdf_metafile_skia.h" 5 #include "printing/pdf_metafile_skia.h"
6 6
7 #include "base/file_descriptor_posix.h" 7 #include "base/file_descriptor_posix.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "base/safe_numerics.h" 12 #include "base/safe_numerics.h"
13 #include "skia/ext/refptr.h"
13 #include "skia/ext/vector_platform_device_skia.h" 14 #include "skia/ext/vector_platform_device_skia.h"
14 #include "third_party/skia/include/core/SkData.h" 15 #include "third_party/skia/include/core/SkData.h"
15 #include "third_party/skia/include/core/SkRefCnt.h" 16 #include "third_party/skia/include/core/SkRefCnt.h"
16 #include "third_party/skia/include/core/SkScalar.h" 17 #include "third_party/skia/include/core/SkScalar.h"
17 #include "third_party/skia/include/core/SkStream.h" 18 #include "third_party/skia/include/core/SkStream.h"
18 #include "third_party/skia/include/core/SkTypeface.h" 19 #include "third_party/skia/include/core/SkTypeface.h"
19 #include "third_party/skia/include/pdf/SkPDFDevice.h" 20 #include "third_party/skia/include/pdf/SkPDFDevice.h"
20 #include "third_party/skia/include/pdf/SkPDFDocument.h" 21 #include "third_party/skia/include/pdf/SkPDFDocument.h"
21 #include "ui/gfx/point.h" 22 #include "ui/gfx/point.h"
22 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 25
25 #if defined(OS_MACOSX) 26 #if defined(OS_MACOSX)
26 #include "printing/pdf_metafile_cg_mac.h" 27 #include "printing/pdf_metafile_cg_mac.h"
27 #endif 28 #endif
28 29
29 namespace printing { 30 namespace printing {
30 31
31 struct PdfMetafileSkiaData { 32 struct PdfMetafileSkiaData {
32 SkRefPtr<SkPDFDevice> current_page_; 33 skia::RefPtr<SkPDFDevice> current_page_;
33 SkPDFDocument pdf_doc_; 34 SkPDFDocument pdf_doc_;
34 SkDynamicMemoryWStream pdf_stream_; 35 SkDynamicMemoryWStream pdf_stream_;
35 #if defined(OS_MACOSX) 36 #if defined(OS_MACOSX)
36 PdfMetafileCg pdf_cg_; 37 PdfMetafileCg pdf_cg_;
37 #endif 38 #endif
38 }; 39 };
39 40
40 PdfMetafileSkia::~PdfMetafileSkia() {} 41 PdfMetafileSkia::~PdfMetafileSkia() {}
41 42
42 bool PdfMetafileSkia::Init() { 43 bool PdfMetafileSkia::Init() {
(...skipping 13 matching lines...) Expand all
56 // Adjust for the margins and apply the scale factor. 57 // Adjust for the margins and apply the scale factor.
57 SkMatrix transform; 58 SkMatrix transform;
58 transform.setTranslate(SkIntToScalar(content_area.x()), 59 transform.setTranslate(SkIntToScalar(content_area.x()),
59 SkIntToScalar(content_area.y())); 60 SkIntToScalar(content_area.y()));
60 transform.preScale(SkFloatToScalar(scale_factor), 61 transform.preScale(SkFloatToScalar(scale_factor),
61 SkFloatToScalar(scale_factor)); 62 SkFloatToScalar(scale_factor));
62 63
63 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height()); 64 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height());
64 SkISize pdf_content_size = 65 SkISize pdf_content_size =
65 SkISize::Make(content_area.width(), content_area.height()); 66 SkISize::Make(content_area.width(), content_area.height());
66 SkRefPtr<SkPDFDevice> pdf_device = 67 skia::RefPtr<SkPDFDevice> pdf_device =
67 new skia::VectorPlatformDeviceSkia(pdf_page_size, pdf_content_size, 68 skia::AdoptRef(new skia::VectorPlatformDeviceSkia(
68 transform); 69 pdf_page_size, pdf_content_size, transform));
69 data_->current_page_ = pdf_device; 70 data_->current_page_ = pdf_device;
70 return pdf_device.get(); 71 return pdf_device.get();
71 } 72 }
72 73
73 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, 74 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
74 const gfx::Rect& content_area, 75 const gfx::Rect& content_area,
75 const float& scale_factor) { 76 const float& scale_factor) {
76 NOTREACHED(); 77 NOTREACHED();
77 return false; 78 return false;
78 } 79 }
79 80
80 bool PdfMetafileSkia::FinishPage() { 81 bool PdfMetafileSkia::FinishPage() {
81 DCHECK(data_->current_page_.get()); 82 DCHECK(data_->current_page_.get());
82 83
83 data_->pdf_doc_.appendPage(data_->current_page_.get()); 84 data_->pdf_doc_.appendPage(data_->current_page_.get());
84 page_outstanding_ = false; 85 page_outstanding_ = false;
85 return true; 86 return true;
86 } 87 }
87 88
88 bool PdfMetafileSkia::FinishDocument() { 89 bool PdfMetafileSkia::FinishDocument() {
89 // Don't do anything if we've already set the data in InitFromData. 90 // Don't do anything if we've already set the data in InitFromData.
90 if (data_->pdf_stream_.getOffset()) 91 if (data_->pdf_stream_.getOffset())
91 return true; 92 return true;
92 93
93 if (page_outstanding_) 94 if (page_outstanding_)
94 FinishPage(); 95 FinishPage();
95 96
96 data_->current_page_ = NULL; 97 data_->current_page_.clear();
97 98
98 int font_counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]; 99 int font_counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1];
99 data_->pdf_doc_.getCountOfFontTypes(font_counts); 100 data_->pdf_doc_.getCountOfFontTypes(font_counts);
100 for (int type = 0; 101 for (int type = 0;
101 type <= SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; 102 type <= SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
102 type++) { 103 type++) {
103 for (int count = 0; count < font_counts[type]; count++) { 104 for (int count = 0; count < font_counts[type]; count++) {
104 UMA_HISTOGRAM_ENUMERATION( 105 UMA_HISTOGRAM_ENUMERATION(
105 "PrintPreview.FontType", type, 106 "PrintPreview.FontType", type,
106 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); 107 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (data->size() == 0) 239 if (data->size() == 0)
239 return NULL; 240 return NULL;
240 241
241 PdfMetafileSkia* metafile = new PdfMetafileSkia; 242 PdfMetafileSkia* metafile = new PdfMetafileSkia;
242 metafile->InitFromData(data->bytes(), 243 metafile->InitFromData(data->bytes(),
243 base::checked_numeric_cast<uint32>(data->size())); 244 base::checked_numeric_cast<uint32>(data->size()));
244 return metafile; 245 return metafile;
245 } 246 }
246 247
247 } // namespace printing 248 } // namespace printing
OLDNEW
« no previous file with comments | « cc/test/skia_common.cc ('k') | skia/ext/refptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698