gn vim: apply to *.gni also
[chromium-blink-merge.git] / skia / ext / vector_platform_device_emf_win.h
blob8d5b39385082325568d2fc751feaa046ba403d1c
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"
14 namespace skia {
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 // TODO(robertphillips): Once Skia's SkBaseDevice is refactored to remove
21 // the bitmap-specific entry points, this class should derive from it.
22 class VectorPlatformDeviceEmf : public SkBitmapDevice, public PlatformDevice {
23 public:
24 SK_API static SkBaseDevice* CreateDevice(int width, int height, bool isOpaque,
25 HANDLE shared_section);
27 // Factory function. The DC is kept as the output context.
28 static SkBaseDevice* create(HDC dc, int width, int height);
30 VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap);
31 virtual ~VectorPlatformDeviceEmf();
33 // PlatformDevice methods
34 virtual PlatformSurface BeginPlatformPaint() override;
35 virtual void DrawToNativeContext(HDC dc, int x, int y,
36 const RECT* src_rect) override;
37 // SkBaseDevice methods.
38 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) override;
39 virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
40 size_t count, const SkPoint[],
41 const SkPaint& paint) override;
42 virtual void drawRect(const SkDraw& draw, const SkRect& r,
43 const SkPaint& paint) override;
44 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
45 const SkPaint& paint) override;
46 virtual void drawPath(const SkDraw& draw, const SkPath& path,
47 const SkPaint& paint,
48 const SkMatrix* prePathMatrix = NULL,
49 bool pathIsMutable = false) override;
50 virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
51 const SkRect* src, const SkRect& dst,
52 const SkPaint& paint,
53 SkCanvas::DrawBitmapRectFlags flags) override;
54 virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
55 const SkMatrix& matrix,
56 const SkPaint& paint) override;
57 virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
58 int x, int y, const SkPaint& paint) override;
59 virtual void drawText(const SkDraw& draw, const void* text, size_t len,
60 SkScalar x, SkScalar y, const SkPaint& paint) override;
61 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len,
62 const SkScalar pos[], int scalarsPerPos,
63 const SkPoint& offset, const SkPaint& paint) override;
64 virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len,
65 const SkPath& path, const SkMatrix* matrix,
66 const SkPaint& paint) override;
67 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode,
68 int vertexCount,
69 const SkPoint verts[], const SkPoint texs[],
70 const SkColor colors[], SkXfermode* xmode,
71 const uint16_t indices[], int indexCount,
72 const SkPaint& paint) override;
73 virtual void drawDevice(const SkDraw& draw, SkBaseDevice*, int x, int y,
74 const SkPaint&) override;
76 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
77 const SkClipStack&) override;
79 void LoadClipRegion();
81 protected:
82 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo& info) override;
84 private:
85 // Applies the SkPaint's painting properties in the current GDI context, if
86 // possible. If GDI can't support all paint's properties, returns false. It
87 // doesn't execute the "commands" in SkPaint.
88 bool ApplyPaint(const SkPaint& paint);
90 // Selects a new object in the device context. It can be a pen, a brush, a
91 // clipping region, a bitmap or a font. Returns the old selected object.
92 HGDIOBJ SelectObject(HGDIOBJ object);
94 // Creates a brush according to SkPaint's properties.
95 bool CreateBrush(bool use_brush, const SkPaint& paint);
97 // Creates a pen according to SkPaint's properties.
98 bool CreatePen(bool use_pen, const SkPaint& paint);
100 // Restores back the previous objects (pen, brush, etc) after a paint command.
101 void Cleanup();
103 // Creates a brush according to SkPaint's properties.
104 bool CreateBrush(bool use_brush, COLORREF color);
106 // Creates a pen according to SkPaint's properties.
107 bool CreatePen(bool use_pen, COLORREF color, int stroke_width,
108 float stroke_miter, DWORD pen_style);
110 // Draws a bitmap in the the device, using the currently loaded matrix.
111 void InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
112 const SkPaint& paint);
114 // The Windows Device Context handle. It is the backend used with GDI drawing.
115 // This backend is write-only and vectorial.
116 HDC hdc_;
118 // Translation assigned to the DC: we need to keep track of this separately
119 // so it can be updated even if the DC isn't created yet.
120 SkMatrix transform_;
122 // The current clipping
123 SkRegion clip_region_;
125 // Previously selected brush before the current drawing.
126 HGDIOBJ previous_brush_;
128 // Previously selected pen before the current drawing.
129 HGDIOBJ previous_pen_;
131 DISALLOW_COPY_AND_ASSIGN(VectorPlatformDeviceEmf);
134 typedef void (*SkiaEnsureTypefaceCharactersAccessible)
135 (const LOGFONT& font, const wchar_t* text, unsigned int text_length);
137 SK_API void SetSkiaEnsureTypefaceCharactersAccessible(
138 SkiaEnsureTypefaceCharactersAccessible func);
140 } // namespace skia
142 #endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_EMF_WIN_H_