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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 1863223002: Convert //printing to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « printing/pdf_metafile_skia.h ('k') | printing/printed_document.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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 SkSize page_size_; 51 SkSize page_size_;
52 SkRect content_area_; 52 SkRect content_area_;
53 float scale_factor_; 53 float scale_factor_;
54 sk_sp<SkPicture> content_; 54 sk_sp<SkPicture> content_;
55 }; 55 };
56 56
57 bool WriteAssetToBuffer(const SkStreamAsset* asset, 57 bool WriteAssetToBuffer(const SkStreamAsset* asset,
58 void* buffer, 58 void* buffer,
59 size_t size) { 59 size_t size) {
60 // Calling duplicate() keeps original asset state unchanged. 60 // Calling duplicate() keeps original asset state unchanged.
61 scoped_ptr<SkStreamAsset> assetCopy(asset->duplicate()); 61 std::unique_ptr<SkStreamAsset> assetCopy(asset->duplicate());
62 size_t length = assetCopy->getLength(); 62 size_t length = assetCopy->getLength();
63 if (length > size) 63 if (length > size)
64 return false; 64 return false;
65 return (length == assetCopy->read(buffer, length)); 65 return (length == assetCopy->read(buffer, length));
66 } 66 }
67 67
68 SkTime::DateTime TimeToSkTime(base::Time time) { 68 SkTime::DateTime TimeToSkTime(base::Time time) {
69 base::Time::Exploded exploded; 69 base::Time::Exploded exploded;
70 time.UTCExplode(&exploded); 70 time.UTCExplode(&exploded);
71 SkTime::DateTime skdate; 71 SkTime::DateTime skdate;
72 skdate.fTimeZoneMinutes = 0; 72 skdate.fTimeZoneMinutes = 0;
73 skdate.fYear = exploded.year; 73 skdate.fYear = exploded.year;
74 skdate.fMonth = exploded.month; 74 skdate.fMonth = exploded.month;
75 skdate.fDayOfWeek = exploded.day_of_week; 75 skdate.fDayOfWeek = exploded.day_of_week;
76 skdate.fDay = exploded.day_of_month; 76 skdate.fDay = exploded.day_of_month;
77 skdate.fHour = exploded.hour; 77 skdate.fHour = exploded.hour;
78 skdate.fMinute = exploded.minute; 78 skdate.fMinute = exploded.minute;
79 skdate.fSecond = exploded.second; 79 skdate.fSecond = exploded.second;
80 return skdate; 80 return skdate;
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 namespace printing { 85 namespace printing {
86 86
87 struct PdfMetafileSkiaData { 87 struct PdfMetafileSkiaData {
88 SkPictureRecorder recorder_; // Current recording 88 SkPictureRecorder recorder_; // Current recording
89 89
90 std::vector<Page> pages_; 90 std::vector<Page> pages_;
91 scoped_ptr<SkStreamAsset> pdf_data_; 91 std::unique_ptr<SkStreamAsset> pdf_data_;
92 92
93 #if defined(OS_MACOSX) 93 #if defined(OS_MACOSX)
94 PdfMetafileCg pdf_cg_; 94 PdfMetafileCg pdf_cg_;
95 #endif 95 #endif
96 }; 96 };
97 97
98 PdfMetafileSkia::~PdfMetafileSkia() {} 98 PdfMetafileSkia::~PdfMetafileSkia() {}
99 99
100 bool PdfMetafileSkia::Init() { 100 bool PdfMetafileSkia::Init() {
101 return true; 101 return true;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 250 }
251 return data_->pdf_cg_.RenderPage(page_number, context, rect, params); 251 return data_->pdf_cg_.RenderPage(page_number, context, rect, params);
252 } 252 }
253 #endif 253 #endif
254 254
255 bool PdfMetafileSkia::SaveTo(base::File* file) const { 255 bool PdfMetafileSkia::SaveTo(base::File* file) const {
256 if (GetDataSize() == 0U) 256 if (GetDataSize() == 0U)
257 return false; 257 return false;
258 258
259 // Calling duplicate() keeps original asset state unchanged. 259 // Calling duplicate() keeps original asset state unchanged.
260 scoped_ptr<SkStreamAsset> asset(data_->pdf_data_->duplicate()); 260 std::unique_ptr<SkStreamAsset> asset(data_->pdf_data_->duplicate());
261 261
262 const size_t maximum_buffer_size = 1024 * 1024; 262 const size_t maximum_buffer_size = 1024 * 1024;
263 std::vector<char> buffer(std::min(maximum_buffer_size, asset->getLength())); 263 std::vector<char> buffer(std::min(maximum_buffer_size, asset->getLength()));
264 do { 264 do {
265 size_t read_size = asset->read(&buffer[0], buffer.size()); 265 size_t read_size = asset->read(&buffer[0], buffer.size());
266 if (read_size == 0) 266 if (read_size == 0)
267 break; 267 break;
268 DCHECK_GE(buffer.size(), read_size); 268 DCHECK_GE(buffer.size(), read_size);
269 if (!file->WriteAtCurrentPos(&buffer[0], 269 if (!file->WriteAtCurrentPos(&buffer[0],
270 base::checked_cast<int>(read_size))) { 270 base::checked_cast<int>(read_size))) {
(...skipping 18 matching lines...) Expand all
289 289
290 if (!fd.auto_close) 290 if (!fd.auto_close)
291 file.TakePlatformFile(); 291 file.TakePlatformFile();
292 return result; 292 return result;
293 } 293 }
294 #endif 294 #endif
295 295
296 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) { 296 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {
297 } 297 }
298 298
299 scoped_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage() { 299 std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage() {
300 // If we only ever need the metafile for the last page, should we 300 // If we only ever need the metafile for the last page, should we
301 // only keep a handle on one SkPicture? 301 // only keep a handle on one SkPicture?
302 scoped_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia); 302 std::unique_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia);
303 303
304 if (data_->pages_.size() == 0) 304 if (data_->pages_.size() == 0)
305 return metafile; 305 return metafile;
306 306
307 if (data_->recorder_.getRecordingCanvas()) // page outstanding 307 if (data_->recorder_.getRecordingCanvas()) // page outstanding
308 return metafile; 308 return metafile;
309 309
310 const Page& page = data_->pages_.back(); 310 const Page& page = data_->pages_.back();
311 311
312 metafile->data_->pages_.push_back(page); 312 metafile->data_->pages_.push_back(page);
313 313
314 if (!metafile->FinishDocument()) // Generate PDF. 314 if (!metafile->FinishDocument()) // Generate PDF.
315 metafile.reset(); 315 metafile.reset();
316 316
317 return metafile; 317 return metafile;
318 } 318 }
319 319
320 } // namespace printing 320 } // namespace printing
OLDNEW
« no previous file with comments | « printing/pdf_metafile_skia.h ('k') | printing/printed_document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698