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.
5 #ifndef SKIA_EXT_VECTOR_PLATFORM_DEVICE_EMF_WIN_H_
6 #define SKIA_EXT_VECTOR_PLATFORM_DEVICE_EMF_WIN_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "skia/ext/platform_device.h"
11 #include "third_party/skia/include/core/SkMatrix.h"
12 #include "third_party/skia/include/core/SkRegion.h"
16 // A device is basically a wrapper around SkBitmap that provides a surface for
17 // SkCanvas to draw into. This specific device is not not backed by a surface
18 // and is thus unreadable. This is because the backend is completely vectorial.
19 // This device is a simple wrapper over a Windows device context (HDC) handle.
20 class VectorPlatformDeviceEmf
: public SkDevice
, public PlatformDevice
{
22 SK_API
static SkDevice
* CreateDevice(int width
, int height
, bool isOpaque
,
23 HANDLE shared_section
);
25 // Factory function. The DC is kept as the output context.
26 static SkDevice
* create(HDC dc
, int width
, int height
);
28 VectorPlatformDeviceEmf(HDC dc
, const SkBitmap
& bitmap
);
29 virtual ~VectorPlatformDeviceEmf();
31 // PlatformDevice methods
32 virtual PlatformSurface
BeginPlatformPaint() OVERRIDE
;
33 virtual void DrawToNativeContext(HDC dc
, int x
, int y
,
34 const RECT
* src_rect
) OVERRIDE
;
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
,
45 const SkMatrix
* prePathMatrix
= NULL
,
46 bool pathIsMutable
= false) OVERRIDE
;
47 virtual void drawBitmapRect(const SkDraw
& draw
, const SkBitmap
& bitmap
,
48 const SkRect
* src
, const SkRect
& dst
,
49 const SkPaint
& paint
) SK_OVERRIDE
;
50 virtual void drawBitmap(const SkDraw
& draw
, const SkBitmap
& bitmap
,
51 const SkIRect
* srcRectOrNull
,
52 const SkMatrix
& matrix
,
53 const SkPaint
& paint
) OVERRIDE
;
54 virtual void drawSprite(const SkDraw
& draw
, const SkBitmap
& bitmap
,
55 int x
, int y
, const SkPaint
& paint
) OVERRIDE
;
56 virtual void drawText(const SkDraw
& draw
, const void* text
, size_t len
,
57 SkScalar x
, SkScalar y
, const SkPaint
& paint
) OVERRIDE
;
58 virtual void drawPosText(const SkDraw
& draw
, const void* text
, size_t len
,
59 const SkScalar pos
[], SkScalar constY
,
60 int scalarsPerPos
, const SkPaint
& paint
) OVERRIDE
;
61 virtual void drawTextOnPath(const SkDraw
& draw
, const void* text
, size_t len
,
62 const SkPath
& path
, const SkMatrix
* matrix
,
63 const SkPaint
& paint
) OVERRIDE
;
64 virtual void drawVertices(const SkDraw
& draw
, SkCanvas::VertexMode
,
66 const SkPoint verts
[], const SkPoint texs
[],
67 const SkColor colors
[], SkXfermode
* xmode
,
68 const uint16_t indices
[], int indexCount
,
69 const SkPaint
& paint
) OVERRIDE
;
70 virtual void drawDevice(const SkDraw
& draw
, SkDevice
*, int x
, int y
,
71 const SkPaint
&) OVERRIDE
;
73 virtual void setMatrixClip(const SkMatrix
& transform
, const SkRegion
& region
,
74 const SkClipStack
&) OVERRIDE
;
76 void LoadClipRegion();
79 virtual SkDevice
* onCreateCompatibleDevice(SkBitmap::Config
, int width
,
80 int height
, bool isOpaque
,
81 Usage usage
) OVERRIDE
;
84 // Applies the SkPaint's painting properties in the current GDI context, if
85 // possible. If GDI can't support all paint's properties, returns false. It
86 // doesn't execute the "commands" in SkPaint.
87 bool ApplyPaint(const SkPaint
& paint
);
89 // Selects a new object in the device context. It can be a pen, a brush, a
90 // clipping region, a bitmap or a font. Returns the old selected object.
91 HGDIOBJ
SelectObject(HGDIOBJ object
);
93 // Creates a brush according to SkPaint's properties.
94 bool CreateBrush(bool use_brush
, const SkPaint
& paint
);
96 // Creates a pen according to SkPaint's properties.
97 bool CreatePen(bool use_pen
, const SkPaint
& paint
);
99 // Restores back the previous objects (pen, brush, etc) after a paint command.
102 // Creates a brush according to SkPaint's properties.
103 bool CreateBrush(bool use_brush
, COLORREF color
);
105 // Creates a pen according to SkPaint's properties.
106 bool CreatePen(bool use_pen
, COLORREF color
, int stroke_width
,
107 float stroke_miter
, DWORD pen_style
);
109 // Draws a bitmap in the the device, using the currently loaded matrix.
110 void InternalDrawBitmap(const SkBitmap
& bitmap
, int x
, int y
,
111 const SkPaint
& paint
);
113 // The Windows Device Context handle. It is the backend used with GDI drawing.
114 // This backend is write-only and vectorial.
117 // Translation assigned to the DC: we need to keep track of this separately
118 // so it can be updated even if the DC isn't created yet.
121 // The current clipping
122 SkRegion clip_region_
;
124 // Previously selected brush before the current drawing.
125 HGDIOBJ previous_brush_
;
127 // Previously selected pen before the current drawing.
128 HGDIOBJ previous_pen_
;
130 DISALLOW_COPY_AND_ASSIGN(VectorPlatformDeviceEmf
);
133 typedef void (*SkiaEnsureTypefaceCharactersAccessible
)
134 (const LOGFONT
& font
, const wchar_t* text
, unsigned int text_length
);
136 SK_API
void SetSkiaEnsureTypefaceCharactersAccessible(
137 SkiaEnsureTypefaceCharactersAccessible func
);
141 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_EMF_WIN_H_