19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Copyright 2013 Google Inc.
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Use of this source code is governed by a BSD-style license that can be
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * found in the LICENSE file.
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef SkLuaCanvas_DEFINED
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SkLuaCanvas_DEFINED
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SkCanvas.h"
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SkString.h"
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct lua_State;
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallclass SkLuaCanvas : public SkCanvas {
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallpublic:
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    void pushThis();
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SkLuaCanvas(int width, int height, lua_State*, const char function[]);
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual ~SkLuaCanvas();
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            const SkPaint& paint) SK_OVERRIDE;
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            const SkPaint* paint) SK_OVERRIDE;
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                      const SkRect& dst, const SkPaint* paint,
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                      DrawBitmapRectFlags flags) SK_OVERRIDE;
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  const SkPaint* paint) SK_OVERRIDE;
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            const SkPaint* paint) SK_OVERRIDE;
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawVertices(VertexMode vmode, int vertexCount,
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                              const SkPoint vertices[], const SkPoint texs[],
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                              const SkColor colors[], SkXfermode* xmode,
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                              const uint16_t indices[], int indexCount,
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                              const SkPaint& paint) SK_OVERRIDE;
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallprotected:
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void willSave(SaveFlags) SK_OVERRIDE;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    virtual void willRestore() SK_OVERRIDE;
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
51    virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
52    virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
53
54    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
55    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
56                            const SkPaint&) SK_OVERRIDE;
57    virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
58                               const SkPaint&) SK_OVERRIDE;
59    virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
60                                SkScalar constY, const SkPaint&) SK_OVERRIDE;
61    virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
62                                  const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
63
64    virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
65    virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
66    virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
67    virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
68
69    virtual void onDrawPicture(const SkPicture*) SK_OVERRIDE;
70
71private:
72    lua_State*  fL;
73    SkString    fFunc;
74
75    void sendverb(const char verb[]);
76
77    typedef SkCanvas INHERITED;
78};
79
80#endif
81