blob: 092ef282bab041ad4f2512e163c7cdfa9925a07a [file] [log] [blame]
fmalita93957f42015-01-30 09:03:29 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkSVGDevice_DEFINED
9#define SkSVGDevice_DEFINED
10
Mike Reedc5e641c2017-02-17 14:38:11 -050011#include "SkClipStackDevice.h"
senorblanco900c3672016-04-27 11:31:23 -070012#include "SkTemplates.h"
fmalita93957f42015-01-30 09:03:29 -080013
fmalita93957f42015-01-30 09:03:29 -080014class SkXMLWriter;
15
Mike Reedc5e641c2017-02-17 14:38:11 -050016class SkSVGDevice : public SkClipStackDevice {
fmalita93957f42015-01-30 09:03:29 -080017public:
fmalita2aafe6f2015-02-06 12:51:10 -080018 static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer);
fmalita93957f42015-01-30 09:03:29 -080019
fmalita93957f42015-01-30 09:03:29 -080020protected:
Mike Reeda1361362017-03-07 09:37:29 -050021 void drawPaint(const SkPaint& paint) override;
22 void drawPoints(SkCanvas::PointMode mode, size_t count,
tfarina85665392015-05-04 06:40:31 -070023 const SkPoint[], const SkPaint& paint) override;
Mike Reeda1361362017-03-07 09:37:29 -050024 void drawRect(const SkRect& r, const SkPaint& paint) override;
25 void drawOval(const SkRect& oval, const SkPaint& paint) override;
26 void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
27 void drawPath(const SkPath& path,
tfarina85665392015-05-04 06:40:31 -070028 const SkPaint& paint,
halcanary96fcdcc2015-08-27 07:41:13 -070029 const SkMatrix* prePathMatrix = nullptr,
tfarina85665392015-05-04 06:40:31 -070030 bool pathIsMutable = false) override;
fmalita93957f42015-01-30 09:03:29 -080031
Mike Reeda1361362017-03-07 09:37:29 -050032 void drawBitmap(const SkBitmap& bitmap,
tfarina85665392015-05-04 06:40:31 -070033 const SkMatrix& matrix, const SkPaint& paint) override;
Mike Reeda1361362017-03-07 09:37:29 -050034 void drawSprite(const SkBitmap& bitmap,
tfarina85665392015-05-04 06:40:31 -070035 int x, int y, const SkPaint& paint) override;
Mike Reeda1361362017-03-07 09:37:29 -050036 void drawBitmapRect(const SkBitmap&,
tfarina85665392015-05-04 06:40:31 -070037 const SkRect* srcOrNull, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -070038 const SkPaint& paint, SkCanvas::SrcRectConstraint) override;
fmalita93957f42015-01-30 09:03:29 -080039
Mike Reeda1361362017-03-07 09:37:29 -050040 void drawText(const void* text, size_t len,
tfarina85665392015-05-04 06:40:31 -070041 SkScalar x, SkScalar y, const SkPaint& paint) override;
Mike Reeda1361362017-03-07 09:37:29 -050042 void drawPosText(const void* text, size_t len,
tfarina85665392015-05-04 06:40:31 -070043 const SkScalar pos[], int scalarsPerPos,
44 const SkPoint& offset, const SkPaint& paint) override;
Mike Reeda1361362017-03-07 09:37:29 -050045 void drawTextOnPath(const void* text, size_t len,
tfarina85665392015-05-04 06:40:31 -070046 const SkPath& path, const SkMatrix* matrix,
47 const SkPaint& paint) override;
Mike Reed2f6b5a42017-03-19 15:04:17 -040048 void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override;
fmalita93957f42015-01-30 09:03:29 -080049
Mike Reeda1361362017-03-07 09:37:29 -050050 void drawDevice(SkBaseDevice*, int x, int y,
tfarina85665392015-05-04 06:40:31 -070051 const SkPaint&) override;
fmalita93957f42015-01-30 09:03:29 -080052
53private:
fmalita2aafe6f2015-02-06 12:51:10 -080054 SkSVGDevice(const SkISize& size, SkXMLWriter* writer);
fmalita93957f42015-01-30 09:03:29 -080055 virtual ~SkSVGDevice();
56
Mike Reedc5e641c2017-02-17 14:38:11 -050057 struct MxCp;
58 void drawBitmapCommon(const MxCp&, const SkBitmap& bm, const SkPaint& paint);
fmalita827da232015-02-27 07:44:47 -080059
fmalita532faa92015-02-03 05:44:40 -080060 class AutoElement;
61 class ResourceBucket;
fmalita93957f42015-01-30 09:03:29 -080062
Ben Wagner145dbcd2016-11-03 14:40:50 -040063 SkXMLWriter* fWriter;
64 std::unique_ptr<AutoElement> fRootElement;
65 std::unique_ptr<ResourceBucket> fResourceBucket;
robertphillips9a53fd72015-06-22 09:46:59 -070066
Mike Reedc5e641c2017-02-17 14:38:11 -050067 typedef SkClipStackDevice INHERITED;
fmalita93957f42015-01-30 09:03:29 -080068};
69
70#endif // SkSVGDevice_DEFINED