OLD | NEW |
1 // Copyright (c) 2009 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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "skia/ext/platform_device.h" | 9 #include "skia/ext/platform_device.h" |
10 #include "third_party/skia/include/core/SkMatrix.h" | 10 #include "third_party/skia/include/core/SkMatrix.h" |
11 #include "third_party/skia/include/core/SkRegion.h" | 11 #include "third_party/skia/include/core/SkRegion.h" |
12 | 12 |
13 namespace skia { | 13 namespace skia { |
14 | 14 |
15 class VectorPlatformDeviceFactory : public SkDeviceFactory { | 15 class VectorPlatformDeviceFactory : public SkDeviceFactory { |
16 public: | 16 public: |
| 17 static SkDevice* CreateDevice(cairo_t* context, int width, int height, |
| 18 bool isOpaque); |
| 19 |
| 20 // Overridden from SkDeviceFactory: |
17 virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height, | 21 virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height, |
18 bool isOpaque, bool isForLayer); | 22 bool isOpaque, bool isForLayer); |
19 | |
20 static SkDevice* CreateDevice(cairo_t* context, int width, int height, | |
21 bool isOpaque); | |
22 }; | 23 }; |
23 | 24 |
24 // This device is basically a wrapper that provides a surface for SkCanvas | 25 // This device is basically a wrapper that provides a surface for SkCanvas |
25 // to draw into. It is basically an adaptor which converts skia APIs into | 26 // to draw into. It is basically an adaptor which converts skia APIs into |
26 // cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that | 27 // cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that |
27 // since it is completely vectorial, the bitmap content in it is thus | 28 // since it is completely vectorial, the bitmap content in it is thus |
28 // meaningless. | 29 // meaningless. |
29 class VectorPlatformDevice : public PlatformDevice { | 30 class VectorPlatformDevice : public PlatformDevice { |
30 public: | 31 public: |
| 32 virtual ~VectorPlatformDevice(); |
| 33 |
31 // Factory function. Ownership of |context| is not transferred. | 34 // Factory function. Ownership of |context| is not transferred. |
32 static VectorPlatformDevice* create(PlatformSurface context, | 35 static VectorPlatformDevice* create(PlatformSurface context, |
33 int width, int height); | 36 int width, int height); |
34 virtual ~VectorPlatformDevice(); | |
35 | 37 |
| 38 // Clean up cached fonts. It is an error to call this while some |
| 39 // VectorPlatformDevice callee is still using fonts created for it by this |
| 40 // class. |
| 41 static void ClearFontCache(); |
| 42 |
| 43 // Overridden from SkDevice (through PlatformDevice): |
36 virtual SkDeviceFactory* getDeviceFactory(); | 44 virtual SkDeviceFactory* getDeviceFactory(); |
37 | 45 |
| 46 // Overridden from PlatformDevice: |
38 virtual bool IsVectorial(); | 47 virtual bool IsVectorial(); |
39 virtual PlatformSurface beginPlatformPaint(); | 48 virtual PlatformSurface beginPlatformPaint(); |
40 | |
41 // We translate following skia APIs into corresponding Cairo APIs. | |
42 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | 49 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
43 const SkMatrix& matrix, const SkPaint& paint); | 50 const SkMatrix& matrix, const SkPaint& paint); |
44 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, | 51 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, |
45 const SkPaint&); | 52 const SkPaint&); |
46 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint); | 53 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint); |
47 virtual void drawPath(const SkDraw& draw, const SkPath& path, | 54 virtual void drawPath(const SkDraw& draw, const SkPath& path, |
48 const SkPaint& paint); | 55 const SkPaint& paint); |
49 virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | 56 virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
50 size_t count, const SkPoint[], const SkPaint& paint); | 57 size_t count, const SkPoint[], const SkPaint& paint); |
51 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, | 58 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, |
(...skipping 10 matching lines...) Expand all Loading... |
62 const SkPaint& paint); | 69 const SkPaint& paint); |
63 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, | 70 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, |
64 int vertexCount, | 71 int vertexCount, |
65 const SkPoint verts[], const SkPoint texs[], | 72 const SkPoint verts[], const SkPoint texs[], |
66 const SkColor colors[], SkXfermode* xmode, | 73 const SkColor colors[], SkXfermode* xmode, |
67 const uint16_t indices[], int indexCount, | 74 const uint16_t indices[], int indexCount, |
68 const SkPaint& paint); | 75 const SkPaint& paint); |
69 virtual void setMatrixClip(const SkMatrix& transform, | 76 virtual void setMatrixClip(const SkMatrix& transform, |
70 const SkRegion& region); | 77 const SkRegion& region); |
71 | 78 |
72 // Clean up cached fonts. It is an error to call this while some | |
73 // VectorPlatformDevice callee is still using fonts created for it by this | |
74 // class. | |
75 static void ClearFontCache(); | |
76 | |
77 protected: | 79 protected: |
78 explicit VectorPlatformDevice(PlatformSurface context, | 80 explicit VectorPlatformDevice(PlatformSurface context, |
79 const SkBitmap& bitmap); | 81 const SkBitmap& bitmap); |
80 | 82 |
81 private: | 83 private: |
82 // Apply paint's color in the context. | 84 // Apply paint's color in the context. |
83 void ApplyPaintColor(const SkPaint& paint); | 85 void ApplyPaintColor(const SkPaint& paint); |
84 | 86 |
85 // Apply path's fill style in the context. | 87 // Apply path's fill style in the context. |
86 void ApplyFillStyle(const SkPath& path); | 88 void ApplyFillStyle(const SkPath& path); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 PlatformSurface context_; | 122 PlatformSurface context_; |
121 | 123 |
122 // Copy & assign are not supported. | 124 // Copy & assign are not supported. |
123 VectorPlatformDevice(const VectorPlatformDevice&); | 125 VectorPlatformDevice(const VectorPlatformDevice&); |
124 const VectorPlatformDevice& operator=(const VectorPlatformDevice&); | 126 const VectorPlatformDevice& operator=(const VectorPlatformDevice&); |
125 }; | 127 }; |
126 | 128 |
127 } // namespace skia | 129 } // namespace skia |
128 | 130 |
129 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ | 131 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_LINUX_H_ |
OLD | NEW |