|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 #ifndef __GLCANVAS_MODULE_H |
|
17 #define __GLCANVAS_MODULE_H |
|
18 |
|
19 #include "Python.h" |
|
20 |
|
21 #include "symbian_python_ext_util.h" |
|
22 #include <stdlib.h> |
|
23 |
|
24 #include <GLES/gl.h> |
|
25 #include <GLES/egl.h> |
|
26 #include "coecntrl.h" |
|
27 #include <aknappui.h> |
|
28 #include "CAppuifwEventBindingArray.h" |
|
29 #include "Python_appui.h" |
|
30 |
|
31 #define GLCANVAS_DEFAULT_DEPTH_SIZE (16) |
|
32 |
|
33 // UI Control api name. If this ever changes in appui/appuifw/appuifwmodule.cpp, it must be changed here also! |
|
34 #define UICONTROLAPI_NAME "_uicontrolapi" |
|
35 #define MY_APPUI ((get_app())->ob_data->appui) |
|
36 |
|
37 // comment this out to disable debug messages |
|
38 #define DEBUG_GLCANVAS |
|
39 |
|
40 #define DEBUGMSG(msg) do { RDebug::Print(_L(msg)); } while(0) |
|
41 #define DEBUGMSG1(msg,arg1) do { RDebug::Print(_L(msg),arg1); } while(0) |
|
42 #define DEBUGMSG2(msg,arg1,arg2) do { RDebug::Print(_L(msg),arg1,arg2); } while(0) |
|
43 #define DEBUGMSG3(msg,arg1,arg2,arg3) do { RDebug::Print(_L(msg),arg1,arg2,arg3); } while(0) |
|
44 #define DEBUGMSG4(msg,arg1,arg2,arg3,arg4) do { RDebug::Print(_L(msg),arg1,arg2,arg3,arg4); } while(0) |
|
45 |
|
46 #define RETURN_PYNONE do { Py_INCREF(Py_None); return Py_None; } while(0) |
|
47 |
|
48 #ifndef EKA2 |
|
49 class CGLCanvas : public CCoeControl |
|
50 #else |
|
51 NONSHARABLE_CLASS(CGLCanvas) : public CCoeControl |
|
52 #endif |
|
53 { |
|
54 public: |
|
55 CGLCanvas(PyObject *, PyObject *, PyObject *); |
|
56 int CreateContext(EGLint *attrib_list); |
|
57 virtual ~CGLCanvas(); |
|
58 virtual void ConstructL(const TRect& aRect, |
|
59 const CCoeControl* aParent, CAmarettoAppUi* aAppui); |
|
60 private: //data |
|
61 // The display where the graphics are drawn |
|
62 EGLDisplay iEglDisplay; |
|
63 |
|
64 // The rendering context |
|
65 EGLContext iEglContext; |
|
66 |
|
67 // The window where the graphics are drawn |
|
68 EGLSurface iEglSurface; |
|
69 |
|
70 public: //data |
|
71 // Frame counter variable |
|
72 int iFrame; |
|
73 void swapBuffers(); |
|
74 void makeCurrent(); |
|
75 int iOpenGLInitialized; |
|
76 void redraw() const; |
|
77 |
|
78 EGLint *GenerateEglAttributes(PyObject *); |
|
79 PyObject *GetRedrawCallBack(); |
|
80 PyObject *GetEventCallBack(); |
|
81 PyObject *GetResizeCallBack(); |
|
82 |
|
83 void SetRedrawCallBack(PyObject *); |
|
84 void SetEventCallBack(PyObject *); |
|
85 void SetResizeCallBack(PyObject *); |
|
86 |
|
87 protected: |
|
88 virtual void SizeChanged(); |
|
89 private: |
|
90 virtual void Draw(const TRect& aRect) const; |
|
91 virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
92 TEventCode aType); |
|
93 |
|
94 int GetBufferSize(); |
|
95 virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
96 private: |
|
97 PyObject *iDrawCallback; |
|
98 PyObject *iEventCallback; |
|
99 PyObject *iResizeCallback; |
|
100 const CCoeControl *myParent; |
|
101 CAmarettoAppUi* myAppui; |
|
102 }; |
|
103 |
|
104 // Forward declaration |
|
105 class CAppuifwEventBindingArray; |
|
106 |
|
107 struct GLCanvas_object { |
|
108 PyObject_VAR_HEAD |
|
109 CGLCanvas *ob_control; |
|
110 CAppuifwEventBindingArray *ob_event_bindings; |
|
111 ControlName control_name; |
|
112 // NOTE: fields above this line must match struct _control_object! |
|
113 PyObject *ob_drawcallback; |
|
114 PyObject *ob_eventcallback; |
|
115 PyObject *ob_resizecallback; |
|
116 }; |
|
117 |
|
118 /** Borrowed from appuifwmodule.cpp |
|
119 * appuifw.Application object type representation |
|
120 */ |
|
121 |
|
122 struct Application_data; |
|
123 |
|
124 struct Application_data { |
|
125 Application_data(CAmarettoAppUi* aAppUi, Application_object* /*aOp*/): |
|
126 appui(aAppUi)/*, ob_exit_key_cb(aOp,aAppUi), ob_event_cb(aOp,aAppUi), |
|
127 ob_command_cb(aOp,aAppUi), ob_menu_cb(aOp,aAppUi), |
|
128 ob_tab_cb(aOp,aAppUi), ob_focus_cb(aOp,aAppUi)*/ |
|
129 { |
|
130 rsc_offset = (-1); |
|
131 //appui->SetMenuDynInitFunc(&(ob_menu_cb)); |
|
132 //appui->SetMenuCommandFunc(&(ob_command_cb)); |
|
133 } |
|
134 ~Application_data() { |
|
135 if (rsc_offset != (-1)) |
|
136 (CEikonEnv::Static())->DeleteResourceFile(rsc_offset); |
|
137 /*appui->SetMenuDynInitFunc(NULL); |
|
138 appui->SetMenuCommandFunc(NULL); |
|
139 appui->SetExitFunc(NULL); |
|
140 appui->SetHostedControl(NULL, NULL); |
|
141 appui->SetFocusFunc(NULL);*/ |
|
142 } |
|
143 |
|
144 CAmarettoAppUi* appui; |
|
145 TInt rsc_offset; |
|
146 /*CAmarettoCallback ob_exit_key_cb; |
|
147 CAmarettoCallback ob_event_cb; |
|
148 CAmarettoCallback ob_command_cb; |
|
149 CAmarettoCallback ob_menu_cb; |
|
150 CAmarettoCallback ob_tab_cb; |
|
151 CAmarettoCallback ob_focus_cb;*/ |
|
152 }; |
|
153 |
|
154 |
|
155 // Prototypes for functions in glcanvas_util.cpp |
|
156 Application_object* get_app(); |
|
157 TInt app_callback_handler(void *func, void *arg); |
|
158 void *glcanvas_alloc(size_t size); |
|
159 void glcanvas_free(void *ptr); |
|
160 void _uicontrolapi_decref(void *control_obj); |
|
161 |
|
162 |
|
163 |
|
164 #endif // __GLCANVAS_MODULE_H |