summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 14:37:48 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 14:37:48 +0000
commit60c671ca9dc52bb7c6a0bac0773d526d9060e87a (patch)
tree24885879abfe576ff8fa1f1b70a3cee3a8b69623 /skia
parentfb630c1cdb74e955d343272a1c9b6ac2968e3a0c (diff)
downloadchromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.zip
chromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.tar.gz
chromium_src-60c671ca9dc52bb7c6a0bac0773d526d9060e87a.tar.bz2
Pass printing result to the browser.
The resulting PDF file will now be passed to the browser and be saved as "chromium_printing_test.pdf" under current directory. BUG=9847 TEST=printing on linux should now generate chromium_printing_test.pdf in download directory. Printing on Windows should still work. Patch contributed by minyu.huang@gmail.com Review URL: http://codereview.chromium.org/172115 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/vector_canvas.h19
-rw-r--r--skia/ext/vector_canvas_linux.cc22
-rw-r--r--skia/ext/vector_platform_device_linux.cc35
-rw-r--r--skia/ext/vector_platform_device_linux.h23
4 files changed, 51 insertions, 48 deletions
diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h
index 27f7598..d4f76f8 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -8,6 +8,10 @@
#include "skia/ext/platform_canvas.h"
#include "skia/ext/vector_platform_device.h"
+#if defined(__linux__)
+typedef struct _cairo cairo_t;
+#endif
+
namespace skia {
// This class is a specialization of the regular PlatformCanvas. It is designed
@@ -20,7 +24,8 @@ class VectorCanvas : public PlatformCanvas {
#if defined(WIN32)
VectorCanvas(HDC dc, int width, int height);
#elif defined(__linux__)
- VectorCanvas(int width, int height);
+ // Caller owns |context|. Ownership is not transferred.
+ VectorCanvas(cairo_t* context, int width, int height);
#endif
virtual ~VectorCanvas();
@@ -28,10 +33,11 @@ class VectorCanvas : public PlatformCanvas {
#if defined(WIN32)
bool initialize(HDC context, int width, int height);
#elif defined(__linux__)
- bool initialize(int width, int height);
+ // Ownership of |context| is not transferred.
+ bool initialize(cairo_t* context, int width, int height);
#endif
- virtual SkBounder* setBounder(SkBounder*);
+ virtual SkBounder* setBounder(SkBounder* bounder);
#if defined(WIN32) || defined(__linux__)
virtual SkDevice* createDevice(SkBitmap::Config config,
int width, int height,
@@ -40,12 +46,15 @@ class VectorCanvas : public PlatformCanvas {
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
private:
- // |is_opaque| is unused. |shared_section| is in fact the HDC used for output.
#if defined(WIN32)
+ // |shared_section| is in fact the HDC used for output. |is_opaque| is unused.
virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
HANDLE shared_section);
#elif defined(__linux__)
- virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque);
+ // Ownership of |context| is not transferred. |is_opaque| is unused.
+ virtual SkDevice* createPlatformDevice(cairo_t* context,
+ int width, int height,
+ bool is_opaque);
#endif
// Returns true if the top device is vector based and not bitmap based.
diff --git a/skia/ext/vector_canvas_linux.cc b/skia/ext/vector_canvas_linux.cc
index 95722c9..c3024f3 100644
--- a/skia/ext/vector_canvas_linux.cc
+++ b/skia/ext/vector_canvas_linux.cc
@@ -9,14 +9,14 @@
namespace skia {
-VectorCanvas::VectorCanvas(int width, int height) {
- bool initialized = initialize(width, height);
+VectorCanvas::VectorCanvas(cairo_t* context, int width, int height) {
+ bool initialized = initialize(context, width, height);
SkASSERT(initialized);
}
-bool VectorCanvas::initialize(int width, int height) {
- SkDevice* device = createPlatformDevice(width, height, true);
+bool VectorCanvas::initialize(cairo_t* context, int width, int height) {
+ SkDevice* device = createPlatformDevice(context, width, height, true);
if (!device)
return false;
@@ -29,19 +29,23 @@ SkDevice* VectorCanvas::createDevice(SkBitmap::Config config,
int width, int height,
bool is_opaque, bool isForLayer) {
SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(width, height, is_opaque);
+ return createPlatformDevice(NULL, width, height, is_opaque);
}
-SkDevice* VectorCanvas::createPlatformDevice(int width,
- int height, bool is_opaque) {
+SkDevice* VectorCanvas::createPlatformDevice(cairo_t* context,
+ int width,
+ int height,
+ bool is_opaque) {
// TODO(myhuang): Here we might also have similar issues as those on Windows
// (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383).
// Please note that is_opaque is true when we use this class for printing.
- if (!is_opaque) {
+ // Fallback to bitmap when context is NULL.
+ if (!is_opaque || NULL == context) {
return BitmapPlatformDevice::Create(width, height, is_opaque);
}
- PlatformDevice* device = VectorPlatformDevice::create(width, height);
+ PlatformDevice* device =
+ VectorPlatformDevice::create(context, width, height);
return device;
}
diff --git a/skia/ext/vector_platform_device_linux.cc b/skia/ext/vector_platform_device_linux.cc
index dde60f9..3b30ddf 100644
--- a/skia/ext/vector_platform_device_linux.cc
+++ b/skia/ext/vector_platform_device_linux.cc
@@ -4,48 +4,41 @@
#include "skia/ext/vector_platform_device.h"
-// TODO(myhuang): We have to decide or allow the user the choose the type
-// of the surface in the future.
-#include <cairo-pdf.h>
+#include <cairo.h>
#include "third_party/skia/include/core/SkTypeface.h"
namespace skia {
-VectorPlatformDevice* VectorPlatformDevice::create(int width, int height) {
+VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context,
+ int width, int height) {
+ SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS);
SkASSERT(width > 0);
SkASSERT(height > 0);
- // TODO(myhuang): Can we get rid of the bitmap? In this vetorial device,
- // the content of this bitmap is meaningless. However, it does occupy
+ // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device,
+ // the content of this bitmap might be meaningless. However, it does occupy
// lots of memory space.
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- return new VectorPlatformDevice(bitmap);
+ return new VectorPlatformDevice(context, bitmap);
}
-VectorPlatformDevice::VectorPlatformDevice(const SkBitmap& bitmap)
- : PlatformDevice(bitmap) {
+VectorPlatformDevice::VectorPlatformDevice(PlatformSurface context,
+ const SkBitmap& bitmap)
+ : PlatformDevice(bitmap), context_(context) {
SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
- // FIXME(myhuang): At this moment, we write the PDF file to the disk
- // for testing when we run chromium without sanboxing.
- surface_ = cairo_pdf_surface_create("chrome_printing_test.pdf",
- width(), height());
- SkASSERT(surface_);
- context_ = cairo_create(surface_);
- SkASSERT(context_);
+ // Increase the reference count to keep the context alive.
+ cairo_reference(context_);
transform_.reset();
}
VectorPlatformDevice::~VectorPlatformDevice() {
- SkASSERT(surface_);
- SkASSERT(context_);
-
+ // Un-ref |context_| since we referenced it in the constructor.
cairo_destroy(context_);
- cairo_surface_destroy(surface_);
}
void VectorPlatformDevice::drawBitmap(const SkDraw& draw,
@@ -163,7 +156,7 @@ void VectorPlatformDevice::drawPath(const SkDraw& draw,
current_points[3].fX, current_points[3].fY);
} break;
- case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point)
+ case SkPath::kClose_Verb: { // iter.next returns 1 point (the last pt).
cairo_close_path(context_);
} break;
diff --git a/skia/ext/vector_platform_device_linux.h b/skia/ext/vector_platform_device_linux.h
index 0cd9512..67f1c48 100644
--- a/skia/ext/vector_platform_device_linux.h
+++ b/skia/ext/vector_platform_device_linux.h
@@ -9,20 +9,18 @@
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkRegion.h"
-typedef struct _cairo_surface cairo_surface_t;
-
namespace skia {
// This device is basically a wrapper that provides a surface for SkCanvas
// to draw into. It is basically an adaptor which converts skia APIs into
-// cooresponding Cairo APIs and outputs to a Cairo PDF surface. Please NOTE
-// that since it is completely vectorial, the bitmap content in it is thus
+// cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that
+// since it is completely vectorial, the bitmap content in it is thus
// meaningless.
class VectorPlatformDevice : public PlatformDevice {
public:
- // Factory function.
- static VectorPlatformDevice* create(int width, int height);
-
+ // Factory function. Ownership of |context| is not transferred.
+ static VectorPlatformDevice* create(PlatformSurface context,
+ int width, int height);
virtual ~VectorPlatformDevice();
virtual bool IsVectorial() { return true; }
@@ -56,10 +54,12 @@ class VectorPlatformDevice : public PlatformDevice {
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint);
- virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
+ virtual void setMatrixClip(const SkMatrix& transform,
+ const SkRegion& region);
protected:
- explicit VectorPlatformDevice(const SkBitmap& bitmap);
+ explicit VectorPlatformDevice(PlatformSurface context,
+ const SkBitmap& bitmap);
private:
// Apply paint's color in the context.
@@ -95,11 +95,8 @@ class VectorPlatformDevice : public PlatformDevice {
// The current clipping region.
SkRegion clip_region_;
- // Context's target surface. It is a PS/PDF surface.
- cairo_surface_t* surface_;
-
// Device context.
- cairo_t* context_;
+ PlatformSurface context_;
// Copy & assign are not supported.
VectorPlatformDevice(const VectorPlatformDevice&);