OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SKIA_EXT_VECTOR_PLATFORM_DEVICE_CAIRO_LINUX_H_ | |
6 #define SKIA_EXT_VECTOR_PLATFORM_DEVICE_CAIRO_LINUX_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/compiler_specific.h" | |
11 #include "skia/ext/platform_device.h" | |
12 #include "third_party/skia/include/core/SkMatrix.h" | |
13 #include "third_party/skia/include/core/SkRegion.h" | |
14 | |
15 namespace skia { | |
16 | |
17 // This device is basically a wrapper that provides a surface for SkCanvas | |
18 // to draw into. It is basically an adaptor which converts skia APIs into | |
19 // cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that | |
20 // since it is completely vectorial, the bitmap content in it is thus | |
21 // meaningless. | |
22 class SK_API VectorPlatformDeviceCairo : public PlatformDevice, | |
23 public SkDevice { | |
24 public: | |
25 virtual ~VectorPlatformDeviceCairo(); | |
26 | |
27 static SkDevice* CreateDevice(cairo_t* context, int width, int height, | |
28 bool isOpaque); | |
29 | |
30 // Clean up cached fonts. It is an error to call this while some | |
31 // VectorPlatformDeviceCairo callee is still using fonts created for it by | |
32 // this class. | |
33 static void ClearFontCache(); | |
34 | |
35 // Overridden from SkDevice | |
36 virtual uint32_t getDeviceCapabilities(); | |
37 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) OVERRIDE; | |
38 virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | |
39 size_t count, const SkPoint[], | |
40 const SkPaint& paint) OVERRIDE; | |
41 virtual void drawRect(const SkDraw& draw, const SkRect& r, | |
42 const SkPaint& paint) OVERRIDE; | |
43 virtual void drawPath(const SkDraw& draw, const SkPath& path, | |
44 const SkPaint& paint, | |
45 const SkMatrix* prePathMatrix = NULL, | |
46 bool pathIsMutable = false) OVERRIDE; | |
47 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | |
48 const SkIRect* srcRectOrNull, | |
49 const SkMatrix& matrix, | |
50 const SkPaint& paint) OVERRIDE; | |
51 virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | |
52 int x, int y, const SkPaint& paint) OVERRIDE; | |
53 virtual void drawText(const SkDraw& draw, const void* text, size_t len, | |
54 SkScalar x, SkScalar y, const SkPaint& paint) OVERRIDE; | |
55 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, | |
56 const SkScalar pos[], SkScalar constY, | |
57 int scalarsPerPos, const SkPaint& paint) OVERRIDE; | |
58 virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len, | |
59 const SkPath& path, const SkMatrix* matrix, | |
60 const SkPaint& paint) OVERRIDE; | |
61 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, | |
62 int vertexCount, | |
63 const SkPoint verts[], const SkPoint texs[], | |
64 const SkColor colors[], SkXfermode* xmode, | |
65 const uint16_t indices[], int indexCount, | |
66 const SkPaint& paint) OVERRIDE; | |
67 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, | |
68 const SkPaint&) OVERRIDE; | |
69 | |
70 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, | |
71 const SkClipStack&) OVERRIDE; | |
72 | |
73 // Overridden from PlatformDevice | |
74 virtual PlatformSurface BeginPlatformPaint() OVERRIDE; | |
75 virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, | |
76 const PlatformRect* src_rect) OVERRIDE; | |
77 | |
78 protected: | |
79 VectorPlatformDeviceCairo(PlatformSurface context, const SkBitmap& bitmap); | |
80 | |
81 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, | |
82 int height, bool isOpaque, | |
83 Usage usage) OVERRIDE; | |
84 | |
85 private: | |
86 // Apply paint's color in the context. | |
87 void ApplyPaintColor(const SkPaint& paint); | |
88 | |
89 // Apply path's fill style in the context. | |
90 void ApplyFillStyle(const SkPath& path); | |
91 | |
92 // Apply paint's stroke style in the context. | |
93 void ApplyStrokeStyle(const SkPaint& paint); | |
94 | |
95 // Perform painting. | |
96 void DoPaintStyle(const SkPaint& paint); | |
97 | |
98 // Draws a bitmap in the the device, using the currently loaded matrix. | |
99 void InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, | |
100 const SkPaint& paint); | |
101 | |
102 // Set up the clipping region for the context. Please note that now we only | |
103 // use the bounding box of the region for clipping. | |
104 // TODO(myhuang): Support non-rectangular clipping. | |
105 void LoadClipRegion(const SkRegion& clip); | |
106 | |
107 // Use identity matrix to set up context's transformation. | |
108 void LoadIdentityTransformToContext(); | |
109 | |
110 // Use matrix to set up context's transformation. | |
111 void LoadTransformToContext(const SkMatrix& matrix); | |
112 | |
113 // Selects the font associated with |font_id| in |context|. | |
114 // Return true on success. | |
115 bool SelectFontById(uint32_t font_id); | |
116 | |
117 // Transformation assigned to the context. | |
118 SkMatrix transform_; | |
119 | |
120 // The current clipping region. | |
121 SkRegion clip_region_; | |
122 | |
123 // Device context. | |
124 PlatformSurface context_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(VectorPlatformDeviceCairo); | |
127 }; | |
128 | |
129 } // namespace skia | |
130 | |
131 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_CAIRO_LINUX_H_ | |
OLD | NEW |