| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "skia/ext/vector_platform_device.h" | 5 #include "skia/ext/vector_platform_device.h" |
| 6 | 6 |
| 7 // TODO(myhuang): We have to decide or allow the user the choose the type | 7 #include <cairo.h> |
| 8 // of the surface in the future. | |
| 9 #include <cairo-pdf.h> | |
| 10 | 8 |
| 11 #include "third_party/skia/include/core/SkTypeface.h" | 9 #include "third_party/skia/include/core/SkTypeface.h" |
| 12 | 10 |
| 13 namespace skia { | 11 namespace skia { |
| 14 | 12 |
| 15 VectorPlatformDevice* VectorPlatformDevice::create(int width, int height) { | 13 VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context, |
| 14 int width, int height) { |
| 15 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); |
| 16 SkASSERT(width > 0); | 16 SkASSERT(width > 0); |
| 17 SkASSERT(height > 0); | 17 SkASSERT(height > 0); |
| 18 | 18 |
| 19 // TODO(myhuang): Can we get rid of the bitmap? In this vetorial device, | 19 // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device, |
| 20 // the content of this bitmap is meaningless. However, it does occupy | 20 // the content of this bitmap might be meaningless. However, it does occupy |
| 21 // lots of memory space. | 21 // lots of memory space. |
| 22 SkBitmap bitmap; | 22 SkBitmap bitmap; |
| 23 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 23 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 24 | 24 |
| 25 return new VectorPlatformDevice(bitmap); | 25 return new VectorPlatformDevice(context, bitmap); |
| 26 } | 26 } |
| 27 | 27 |
| 28 VectorPlatformDevice::VectorPlatformDevice(const SkBitmap& bitmap) | 28 VectorPlatformDevice::VectorPlatformDevice(PlatformSurface context, |
| 29 : PlatformDevice(bitmap) { | 29 const SkBitmap& bitmap) |
| 30 : PlatformDevice(bitmap), context_(context) { |
| 30 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 31 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| 31 | 32 |
| 32 // FIXME(myhuang): At this moment, we write the PDF file to the disk | 33 // Increase the reference count to keep the context alive. |
| 33 // for testing when we run chromium without sanboxing. | 34 cairo_reference(context_); |
| 34 surface_ = cairo_pdf_surface_create("chrome_printing_test.pdf", | |
| 35 width(), height()); | |
| 36 SkASSERT(surface_); | |
| 37 context_ = cairo_create(surface_); | |
| 38 SkASSERT(context_); | |
| 39 | 35 |
| 40 transform_.reset(); | 36 transform_.reset(); |
| 41 } | 37 } |
| 42 | 38 |
| 43 VectorPlatformDevice::~VectorPlatformDevice() { | 39 VectorPlatformDevice::~VectorPlatformDevice() { |
| 44 SkASSERT(surface_); | 40 // Un-ref |context_| since we referenced it in the constructor. |
| 45 SkASSERT(context_); | |
| 46 | |
| 47 cairo_destroy(context_); | 41 cairo_destroy(context_); |
| 48 cairo_surface_destroy(surface_); | |
| 49 } | 42 } |
| 50 | 43 |
| 51 void VectorPlatformDevice::drawBitmap(const SkDraw& draw, | 44 void VectorPlatformDevice::drawBitmap(const SkDraw& draw, |
| 52 const SkBitmap& bitmap, | 45 const SkBitmap& bitmap, |
| 53 const SkMatrix& matrix, | 46 const SkMatrix& matrix, |
| 54 const SkPaint& paint) { | 47 const SkPaint& paint) { |
| 55 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 48 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| 56 | 49 |
| 57 // Load the temporary matrix. This is what will translate, rotate and resize | 50 // Load the temporary matrix. This is what will translate, rotate and resize |
| 58 // the bitmap. | 51 // the bitmap. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 current_points[2].fX, current_points[2].fY); | 149 current_points[2].fX, current_points[2].fY); |
| 157 } break; | 150 } break; |
| 158 | 151 |
| 159 case SkPath::kCubic_Verb: { // iter.next returns 4 points | 152 case SkPath::kCubic_Verb: { // iter.next returns 4 points |
| 160 cairo_curve_to(context_, | 153 cairo_curve_to(context_, |
| 161 current_points[1].fX, current_points[1].fY, | 154 current_points[1].fX, current_points[1].fY, |
| 162 current_points[2].fX, current_points[2].fY, | 155 current_points[2].fX, current_points[2].fY, |
| 163 current_points[3].fX, current_points[3].fY); | 156 current_points[3].fX, current_points[3].fY); |
| 164 } break; | 157 } break; |
| 165 | 158 |
| 166 case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point) | 159 case SkPath::kClose_Verb: { // iter.next returns 1 point (the last pt). |
| 167 cairo_close_path(context_); | 160 cairo_close_path(context_); |
| 168 } break; | 161 } break; |
| 169 | 162 |
| 170 case SkPath::kDone_Verb: { // iter.next returns 0 points | 163 case SkPath::kDone_Verb: { // iter.next returns 0 points |
| 171 } break; | 164 } break; |
| 172 | 165 |
| 173 default: { | 166 default: { |
| 174 // Should not reach here! | 167 // Should not reach here! |
| 175 SkASSERT(false); | 168 SkASSERT(false); |
| 176 } break; | 169 } break; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 m.xy = matrix[SkMatrix::kMSkewX]; | 478 m.xy = matrix[SkMatrix::kMSkewX]; |
| 486 m.x0 = matrix[SkMatrix::kMTransX]; | 479 m.x0 = matrix[SkMatrix::kMTransX]; |
| 487 m.yx = matrix[SkMatrix::kMSkewY]; | 480 m.yx = matrix[SkMatrix::kMSkewY]; |
| 488 m.yy = matrix[SkMatrix::kMScaleY]; | 481 m.yy = matrix[SkMatrix::kMScaleY]; |
| 489 m.y0 = matrix[SkMatrix::kMTransY]; | 482 m.y0 = matrix[SkMatrix::kMTransY]; |
| 490 cairo_set_matrix(context_, &m); | 483 cairo_set_matrix(context_, &m); |
| 491 } | 484 } |
| 492 | 485 |
| 493 } // namespace skia | 486 } // namespace skia |
| 494 | 487 |
| OLD | NEW |