• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  *
8  */
9 
10 #ifndef SkV8Example_DrawingMethods_DEFINED
11 #define SkV8Example_DrawingMethods_DEFINED
12 
13 #include <v8.h>
14 
15 class SkCanvas;
16 class Global;
17 
18 // DrawingMethods contains common functionality for both Context, Image2Builder,
19 // and DisplayListBuiler.
20 class DrawingMethods {
21 public:
DrawingMethods(Global * global)22     DrawingMethods(Global* global)
23             : fGlobal(global)
24     {}
~DrawingMethods()25     virtual ~DrawingMethods() {}
26 
27     // Retrieve the SkCanvas to draw on. May return NULL.
28     virtual SkCanvas* getCanvas() = 0;
29 
30     // Add the Javascript attributes and methods that DrawingMethods
31     // implements to the ObjectTemplate.
32     void addAttributesAndMethods(v8::Handle<v8::ObjectTemplate> tmpl);
33 
34 protected:
35     // Get the pointer out of obj.
36     static DrawingMethods* Unwrap(v8::Handle<v8::Object> obj);
37 
38     Global* fGlobal;
39 
40 private:
41     // JS Attributes
42     static void GetWidth(v8::Local<v8::String> name,
43                          const v8::PropertyCallbackInfo<v8::Value>& info);
44     static void GetHeight(v8::Local<v8::String> name,
45                           const v8::PropertyCallbackInfo<v8::Value>& info);
46 
47     // JS Methods
48     static void Save(const v8::FunctionCallbackInfo<v8::Value>& args);
49     static void Restore(const v8::FunctionCallbackInfo<v8::Value>& args);
50     static void Rotate(const v8::FunctionCallbackInfo<v8::Value>& args);
51     static void Translate(const v8::FunctionCallbackInfo<v8::Value>& args);
52     static void ResetTransform(const v8::FunctionCallbackInfo<v8::Value>& args);
53 
54     static void DrawPath(const v8::FunctionCallbackInfo<v8::Value>& args);
55 };
56 
57 #endif
58