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

Side by Side Diff: printing/pdf_ps_metafile_cairo.cc

Issue 6733036: Make PluginInstance::PrintPDFOutput-metafile implementation agnostic on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_ps_metafile_cairo.h" 5 #include "printing/pdf_ps_metafile_cairo.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <cairo.h> 9 #include <cairo.h>
10 #include <cairo-pdf.h> 10 #include <cairo-pdf.h>
11 11
12 #include "base/eintr_wrapper.h" 12 #include "base/eintr_wrapper.h"
13 #include "base/file_descriptor_posix.h" 13 #include "base/file_descriptor_posix.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "printing/units.h" 16 #include "printing/units.h"
17 #include "skia/ext/vector_platform_device_linux.h" 17 #include "skia/ext/vector_platform_device_linux.h"
18 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
20 20
21 namespace { 21 namespace {
22 22
23 const cairo_user_data_key_t kPdfMetafileKey = {0};
24
25 // Tests if |surface| is valid. 23 // Tests if |surface| is valid.
26 bool IsSurfaceValid(cairo_surface_t* surface) { 24 bool IsSurfaceValid(cairo_surface_t* surface) {
27 return cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS; 25 return cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS;
28 } 26 }
29 27
30 // Tests if |context| is valid. 28 // Tests if |context| is valid.
31 bool IsContextValid(cairo_t* context) { 29 bool IsContextValid(cairo_t* context) {
32 return cairo_status(context) == CAIRO_STATUS_SUCCESS; 30 return cairo_status(context) == CAIRO_STATUS_SUCCESS;
33 } 31 }
34 32
(...skipping 21 matching lines...) Expand all
56 DCHECK(dst_buffer); 54 DCHECK(dst_buffer);
57 DCHECK(src_data); 55 DCHECK(src_data);
58 DCHECK_GT(src_data_length, 0u); 56 DCHECK_GT(src_data_length, 0u);
59 57
60 std::string* buffer = reinterpret_cast<std::string*>(dst_buffer); 58 std::string* buffer = reinterpret_cast<std::string*>(dst_buffer);
61 buffer->append(reinterpret_cast<const char*>(src_data), src_data_length); 59 buffer->append(reinterpret_cast<const char*>(src_data), src_data_length);
62 60
63 return CAIRO_STATUS_SUCCESS; 61 return CAIRO_STATUS_SUCCESS;
64 } 62 }
65 63
66 void DestroyContextData(void* data) {
67 // Nothing to be done here.
68 }
69
70 } // namespace 64 } // namespace
71 65
72 namespace printing { 66 namespace printing {
73 67
74 PdfPsMetafile::PdfPsMetafile() 68 PdfPsMetafile::PdfPsMetafile()
75 : surface_(NULL), 69 : surface_(NULL),
76 context_(NULL), 70 context_(NULL),
77 current_data_(NULL) { 71 current_data_(NULL) {
78 } 72 }
79 73
(...skipping 23 matching lines...) Expand all
103 97
104 // Creates a context. 98 // Creates a context.
105 context_ = cairo_create(surface_); 99 context_ = cairo_create(surface_);
106 if (!IsContextValid(context_)) { 100 if (!IsContextValid(context_)) {
107 DLOG(ERROR) << "Cannot create Cairo context for PdfPsMetafile!"; 101 DLOG(ERROR) << "Cannot create Cairo context for PdfPsMetafile!";
108 CleanUpContext(&context_); 102 CleanUpContext(&context_);
109 CleanUpSurface(&surface_); 103 CleanUpSurface(&surface_);
110 return false; 104 return false;
111 } 105 }
112 106
113 cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData);
114 return true; 107 return true;
115 } 108 }
116 109
117 bool PdfPsMetafile::InitFromData(const void* src_buffer, 110 bool PdfPsMetafile::InitFromData(const void* src_buffer,
118 uint32 src_buffer_size) { 111 uint32 src_buffer_size) {
119 if (src_buffer == NULL || src_buffer_size == 0) 112 if (src_buffer == NULL || src_buffer_size == 0)
120 return false; 113 return false;
121 114
122 raw_data_ = std::string(reinterpret_cast<const char*>(src_buffer), 115 raw_data_ = std::string(reinterpret_cast<const char*>(src_buffer),
123 src_buffer_size); 116 src_buffer_size);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (HANDLE_EINTR(close(fd.fd)) < 0) { 243 if (HANDLE_EINTR(close(fd.fd)) < 0) {
251 DPLOG(WARNING) << "close"; 244 DPLOG(WARNING) << "close";
252 success = false; 245 success = false;
253 } 246 }
254 } 247 }
255 248
256 return success; 249 return success;
257 } 250 }
258 #endif // if defined(OS_CHROMEOS) 251 #endif // if defined(OS_CHROMEOS)
259 252
260 PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) {
261 return reinterpret_cast<PdfPsMetafile*>(
262 cairo_get_user_data(context, &kPdfMetafileKey));
263 }
264
265 void PdfPsMetafile::CleanUpAll() { 253 void PdfPsMetafile::CleanUpAll() {
266 CleanUpContext(&context_); 254 CleanUpContext(&context_);
267 CleanUpSurface(&surface_); 255 CleanUpSurface(&surface_);
268 cairo_data_.clear(); 256 cairo_data_.clear();
269 raw_data_.clear(); 257 raw_data_.clear();
270 skia::VectorPlatformDevice::ClearFontCache(); 258 skia::VectorPlatformDevice::ClearFontCache();
271 } 259 }
272 260
273 } // namespace printing 261 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698