OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 VectorDevice_h | |
6 #define VectorDevice_h | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/gfx/platform_device_win.h" | |
10 #include "SkMatrix.h" | |
11 #include "SkRegion.h" | |
12 | |
13 namespace gfx { | |
14 | |
15 // A device is basically a wrapper around SkBitmap that provides a surface for | |
16 // SkCanvas to draw into. This specific device is not not backed by a surface | |
17 // and is thus unreadable. This is because the backend is completely vectorial. | |
18 // This device is a simple wrapper over a Windows device context (HDC) handle. | |
19 class VectorDevice : public PlatformDeviceWin { | |
20 public: | |
21 // Factory function. The DC is kept as the output context. | |
22 static VectorDevice* create(HDC dc, int width, int height); | |
23 | |
24 VectorDevice(HDC dc, const SkBitmap& bitmap); | |
25 virtual ~VectorDevice(); | |
26 | |
27 virtual HDC getBitmapDC() { | |
28 return hdc_; | |
29 } | |
30 | |
31 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint); | |
32 virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | |
33 size_t count, const SkPoint[], const SkPaint& paint); | |
34 virtual void drawRect(const SkDraw& draw, const SkRect& r, | |
35 const SkPaint& paint); | |
36 virtual void drawPath(const SkDraw& draw, const SkPath& path, | |
37 const SkPaint& paint); | |
38 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | |
39 const SkMatrix& matrix, const SkPaint& paint); | |
40 virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | |
41 int x, int y, const SkPaint& paint); | |
42 virtual void drawText(const SkDraw& draw, const void* text, size_t len, | |
43 SkScalar x, SkScalar y, const SkPaint& paint); | |
44 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, | |
45 const SkScalar pos[], SkScalar constY, | |
46 int scalarsPerPos, const SkPaint& paint); | |
47 virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len, | |
48 const SkPath& path, const SkMatrix* matrix, | |
49 const SkPaint& paint); | |
50 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, | |
51 int vertexCount, | |
52 const SkPoint verts[], const SkPoint texs[], | |
53 const SkColor colors[], SkXfermode* xmode, | |
54 const uint16_t indices[], int indexCount, | |
55 const SkPaint& paint); | |
56 virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y, | |
57 const SkPaint&); | |
58 | |
59 | |
60 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); | |
61 virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); | |
62 virtual bool IsVectorial() { return true; } | |
63 | |
64 void LoadClipRegion(); | |
65 | |
66 private: | |
67 // Applies the SkPaint's painting properties in the current GDI context, if | |
68 // possible. If GDI can't support all paint's properties, returns false. It | |
69 // doesn't execute the "commands" in SkPaint. | |
70 bool ApplyPaint(const SkPaint& paint); | |
71 | |
72 // Selects a new object in the device context. It can be a pen, a brush, a | |
73 // clipping region, a bitmap or a font. Returns the old selected object. | |
74 HGDIOBJ SelectObject(HGDIOBJ object); | |
75 | |
76 // Creates a brush according to SkPaint's properties. | |
77 bool CreateBrush(bool use_brush, const SkPaint& paint); | |
78 | |
79 // Creates a pen according to SkPaint's properties. | |
80 bool CreatePen(bool use_pen, const SkPaint& paint); | |
81 | |
82 // Restores back the previous objects (pen, brush, etc) after a paint command. | |
83 void Cleanup(); | |
84 | |
85 // Creates a brush according to SkPaint's properties. | |
86 bool CreateBrush(bool use_brush, COLORREF color); | |
87 | |
88 // Creates a pen according to SkPaint's properties. | |
89 bool CreatePen(bool use_pen, COLORREF color, int stroke_width, | |
90 float stroke_miter, DWORD pen_style); | |
91 | |
92 // Draws a bitmap in the the device, using the currently loaded matrix. | |
93 void InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, | |
94 const SkPaint& paint); | |
95 | |
96 // The Windows Device Context handle. It is the backend used with GDI drawing. | |
97 // This backend is write-only and vectorial. | |
98 HDC hdc_; | |
99 | |
100 // Translation assigned to the DC: we need to keep track of this separately | |
101 // so it can be updated even if the DC isn't created yet. | |
102 SkMatrix transform_; | |
103 | |
104 // The current clipping | |
105 SkRegion clip_region_; | |
106 | |
107 // Previously selected brush before the current drawing. | |
108 HGDIOBJ previous_brush_; | |
109 | |
110 // Previously selected pen before the current drawing. | |
111 HGDIOBJ previous_pen_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(VectorDevice); | |
114 }; | |
115 | |
116 } // namespace gfx | |
117 | |
118 #endif // VectorDevice_h | |
119 | |
OLD | NEW |