1/*
2 * Copyright 2013 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 SkLuaCanvas_DEFINED
9#define SkLuaCanvas_DEFINED
10
11#include "SkCanvas.h"
12#include "SkString.h"
13#include "SkVertices.h"
14
15struct lua_State;
16
17class SkLuaCanvas : public SkCanvas {
18public:
19    void pushThis();
20
21    SkLuaCanvas(int width, int height, lua_State*, const char function[]);
22    ~SkLuaCanvas() override;
23
24protected:
25    void willSave() override;
26    SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
27    void willRestore() override;
28
29    void didConcat(const SkMatrix&) override;
30    void didSetMatrix(const SkMatrix&) override;
31
32    void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
33    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
34                            const SkPaint&) override;
35    virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
36                               const SkPaint&) override;
37    virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
38                                SkScalar constY, const SkPaint&) override;
39    virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
40                                  const SkMatrix* matrix, const SkPaint&) override;
41    void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
42                           const SkRect* cull, const SkPaint& paint) override;
43    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
44                                const SkPaint& paint) override;
45
46    void onDrawPaint(const SkPaint&) override;
47    void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
48    void onDrawRect(const SkRect&, const SkPaint&) override;
49    void onDrawOval(const SkRect&, const SkPaint&) override;
50    void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
51    void onDrawRRect(const SkRRect&, const SkPaint&) override;
52    void onDrawPath(const SkPath&, const SkPaint&) override;
53    void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
54    void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
55                          SrcRectConstraint) override;
56    void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
57    void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
58                         const SkPaint*, SrcRectConstraint) override;
59    void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
60                          const SkPaint*) override;
61    void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
62
63    void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
64    void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
65    void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
66    void onClipRegion(const SkRegion&, SkClipOp) override;
67
68    void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
69
70private:
71    lua_State*  fL;
72    SkString    fFunc;
73
74    void sendverb(const char verb[]);
75
76    typedef SkCanvas INHERITED;
77};
78
79#endif
80