blob: af4909aaaf7d7cc1e2a07dccc6c069b250e2faa6 [file] [log] [blame]
bungeman@google.come8f05922012-08-16 16:13:40 +00001/*
2 * Copyright 2012 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 SkDWriteToPath_DEFINED
9#define SkDWriteToPath_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkTypes.h"
Ben Wagner6cb6a072019-08-12 18:30:27 -040012#include "src/utils/win/SkObjBase.h"
bungeman@google.come8f05922012-08-16 16:13:40 +000013
14class SkPath;
15
16#include <dwrite.h>
17#include <d2d1.h>
18
19class SkDWriteGeometrySink : public IDWriteGeometrySink {
20private:
21 LONG fRefCount;
22 SkPath* fPath;
Ben Wagnerd38f00a2020-01-27 17:43:41 -050023 bool fStarted;
24 D2D1_POINT_2F fCurrent;
25
26 void goingTo(const D2D1_POINT_2F pt) {
27 if (!fStarted) {
28 fStarted = true;
29 fPath->moveTo(fCurrent.x, fCurrent.y);
30 }
31 fCurrent = pt;
32 }
33
34 bool currentIsNot(const D2D1_POINT_2F pt) {
35 return fCurrent.x != pt.x || fCurrent.y != pt.y;
36 }
bungeman@google.come8f05922012-08-16 16:13:40 +000037
bungeman@google.come8f05922012-08-16 16:13:40 +000038protected:
39 explicit SkDWriteGeometrySink(SkPath* path);
40 virtual ~SkDWriteGeometrySink();
41
42public:
Ben Wagner6cb6a072019-08-12 18:30:27 -040043 SK_STDMETHODIMP QueryInterface(REFIID iid, void **object) override;
44 SK_STDMETHODIMP_(ULONG) AddRef() override;
45 SK_STDMETHODIMP_(ULONG) Release() override;
bungeman@google.come8f05922012-08-16 16:13:40 +000046
Ben Wagner6cb6a072019-08-12 18:30:27 -040047 SK_STDMETHODIMP_(void) SetFillMode(D2D1_FILL_MODE fillMode) override;
48 SK_STDMETHODIMP_(void) SetSegmentFlags(D2D1_PATH_SEGMENT vertexFlags) override;
49 SK_STDMETHODIMP_(void) BeginFigure(D2D1_POINT_2F startPoint, D2D1_FIGURE_BEGIN figureBegin) override;
50 SK_STDMETHODIMP_(void) AddLines(const D2D1_POINT_2F *points, UINT pointsCount) override;
51 SK_STDMETHODIMP_(void) AddBeziers(const D2D1_BEZIER_SEGMENT *beziers, UINT beziersCount) override;
52 SK_STDMETHODIMP_(void) EndFigure(D2D1_FIGURE_END figureEnd) override;
53 SK_STDMETHODIMP Close() override;
bungeman@google.come8f05922012-08-16 16:13:40 +000054
55 static HRESULT Create(SkPath* path, IDWriteGeometrySink** geometryToPath);
56};
57
58#endif