| 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 #ifndef SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ | 5 #ifndef SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ |
| 6 #define SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ | 6 #define SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ |
| 7 | 7 |
| 8 #include "skia/ext/platform_device.h" | 8 #include "skia/ext/platform_device.h" |
| 9 #include "third_party/skia/include/core/SkMatrix.h" | 9 #include "third_party/skia/include/core/SkMatrix.h" |
| 10 #include "third_party/skia/include/core/SkRegion.h" | 10 #include "third_party/skia/include/core/SkRegion.h" |
| 11 | 11 |
| 12 typedef struct _cairo_surface cairo_surface_t; | |
| 13 | |
| 14 namespace skia { | 12 namespace skia { |
| 15 | 13 |
| 16 // This device is basically a wrapper that provides a surface for SkCanvas | 14 // This device is basically a wrapper that provides a surface for SkCanvas |
| 17 // to draw into. It is basically an adaptor which converts skia APIs into | 15 // to draw into. It is basically an adaptor which converts skia APIs into |
| 18 // cooresponding Cairo APIs and outputs to a Cairo PDF surface. Please NOTE | 16 // cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that |
| 19 // that since it is completely vectorial, the bitmap content in it is thus | 17 // since it is completely vectorial, the bitmap content in it is thus |
| 20 // meaningless. | 18 // meaningless. |
| 21 class VectorPlatformDevice : public PlatformDevice { | 19 class VectorPlatformDevice : public PlatformDevice { |
| 22 public: | 20 public: |
| 23 // Factory function. | 21 // Factory function. Ownership of |context| is not transferred. |
| 24 static VectorPlatformDevice* create(int width, int height); | 22 static VectorPlatformDevice* create(PlatformSurface context, |
| 25 | 23 int width, int height); |
| 26 virtual ~VectorPlatformDevice(); | 24 virtual ~VectorPlatformDevice(); |
| 27 | 25 |
| 28 virtual bool IsVectorial() { return true; } | 26 virtual bool IsVectorial() { return true; } |
| 29 virtual PlatformSurface beginPlatformPaint() { return context_; } | 27 virtual PlatformSurface beginPlatformPaint() { return context_; } |
| 30 | 28 |
| 31 // We translate following skia APIs into corresponding Cairo APIs. | 29 // We translate following skia APIs into corresponding Cairo APIs. |
| 32 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | 30 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
| 33 const SkMatrix& matrix, const SkPaint& paint); | 31 const SkMatrix& matrix, const SkPaint& paint); |
| 34 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, | 32 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, |
| 35 const SkPaint&); | 33 const SkPaint&); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 SkScalar x, SkScalar y, const SkPaint& paint); | 47 SkScalar x, SkScalar y, const SkPaint& paint); |
| 50 virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len, | 48 virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len, |
| 51 const SkPath& path, const SkMatrix* matrix, | 49 const SkPath& path, const SkMatrix* matrix, |
| 52 const SkPaint& paint); | 50 const SkPaint& paint); |
| 53 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, | 51 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, |
| 54 int vertexCount, | 52 int vertexCount, |
| 55 const SkPoint verts[], const SkPoint texs[], | 53 const SkPoint verts[], const SkPoint texs[], |
| 56 const SkColor colors[], SkXfermode* xmode, | 54 const SkColor colors[], SkXfermode* xmode, |
| 57 const uint16_t indices[], int indexCount, | 55 const uint16_t indices[], int indexCount, |
| 58 const SkPaint& paint); | 56 const SkPaint& paint); |
| 59 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); | 57 virtual void setMatrixClip(const SkMatrix& transform, |
| 58 const SkRegion& region); |
| 60 | 59 |
| 61 protected: | 60 protected: |
| 62 explicit VectorPlatformDevice(const SkBitmap& bitmap); | 61 explicit VectorPlatformDevice(PlatformSurface context, |
| 62 const SkBitmap& bitmap); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // Apply paint's color in the context. | 65 // Apply paint's color in the context. |
| 66 void ApplyPaintColor(const SkPaint& paint); | 66 void ApplyPaintColor(const SkPaint& paint); |
| 67 | 67 |
| 68 // Apply path's fill style in the context. | 68 // Apply path's fill style in the context. |
| 69 void ApplyFillStyle(const SkPath& path); | 69 void ApplyFillStyle(const SkPath& path); |
| 70 | 70 |
| 71 // Apply paint's stroke style in the context. | 71 // Apply paint's stroke style in the context. |
| 72 void ApplyStrokeStyle(const SkPaint& paint); | 72 void ApplyStrokeStyle(const SkPaint& paint); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 | 88 |
| 89 // Use matrix to set up context's transformation. | 89 // Use matrix to set up context's transformation. |
| 90 void LoadTransformToContext(const SkMatrix& matrix); | 90 void LoadTransformToContext(const SkMatrix& matrix); |
| 91 | 91 |
| 92 // Transformation assigned to the context. | 92 // Transformation assigned to the context. |
| 93 SkMatrix transform_; | 93 SkMatrix transform_; |
| 94 | 94 |
| 95 // The current clipping region. | 95 // The current clipping region. |
| 96 SkRegion clip_region_; | 96 SkRegion clip_region_; |
| 97 | 97 |
| 98 // Context's target surface. It is a PS/PDF surface. | |
| 99 cairo_surface_t* surface_; | |
| 100 | |
| 101 // Device context. | 98 // Device context. |
| 102 cairo_t* context_; | 99 PlatformSurface context_; |
| 103 | 100 |
| 104 // Copy & assign are not supported. | 101 // Copy & assign are not supported. |
| 105 VectorPlatformDevice(const VectorPlatformDevice&); | 102 VectorPlatformDevice(const VectorPlatformDevice&); |
| 106 const VectorPlatformDevice& operator=(const VectorPlatformDevice&); | 103 const VectorPlatformDevice& operator=(const VectorPlatformDevice&); |
| 107 }; | 104 }; |
| 108 | 105 |
| 109 } // namespace skia | 106 } // namespace skia |
| 110 | 107 |
| 111 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ | 108 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ |
| 112 | 109 |
| OLD | NEW |