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