| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "embedders/openglui/common/extension.h" | 5 #include "embedders/openglui/common/extension.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "embedders/openglui/common/canvas_context.h" |
| 12 #include "embedders/openglui/common/graphics_handler.h" |
| 11 #include "embedders/openglui/common/log.h" | 13 #include "embedders/openglui/common/log.h" |
| 12 #include "embedders/openglui/common/opengl.h" | 14 #include "embedders/openglui/common/opengl.h" |
| 13 #include "include/dart_api.h" | 15 #include "include/dart_api.h" |
| 14 | 16 |
| 15 Dart_Handle HandleError(Dart_Handle handle) { | 17 Dart_Handle HandleError(Dart_Handle handle) { |
| 16 if (Dart_IsError(handle)) Dart_PropagateError(handle); | 18 if (Dart_IsError(handle)) Dart_PropagateError(handle); |
| 17 return handle; | 19 return handle; |
| 18 } | 20 } |
| 19 | 21 |
| 20 void CheckGLError(const char *function) { | 22 void CheckGLError(const char *function) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void SetBoolReturnValue(Dart_NativeArguments arguments, bool b) { | 148 void SetBoolReturnValue(Dart_NativeArguments arguments, bool b) { |
| 147 Dart_Handle result = HandleError(Dart_NewBoolean(b)); | 149 Dart_Handle result = HandleError(Dart_NewBoolean(b)); |
| 148 Dart_SetReturnValue(arguments, result); | 150 Dart_SetReturnValue(arguments, result); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void SetIntReturnValue(Dart_NativeArguments arguments, int v) { | 153 void SetIntReturnValue(Dart_NativeArguments arguments, int v) { |
| 152 Dart_Handle result = HandleError(Dart_NewInteger(v)); | 154 Dart_Handle result = HandleError(Dart_NewInteger(v)); |
| 153 Dart_SetReturnValue(arguments, result); | 155 Dart_SetReturnValue(arguments, result); |
| 154 } | 156 } |
| 155 | 157 |
| 158 void SetDoubleReturnValue(Dart_NativeArguments arguments, double v) { |
| 159 Dart_Handle result = HandleError(Dart_NewDouble(v)); |
| 160 Dart_SetReturnValue(arguments, result); |
| 161 } |
| 162 |
| 156 void SetStringReturnValue(Dart_NativeArguments arguments, const char* s) { | 163 void SetStringReturnValue(Dart_NativeArguments arguments, const char* s) { |
| 157 Dart_Handle result = HandleError(Dart_NewStringFromCString(s)); | 164 Dart_Handle result = HandleError(Dart_NewStringFromCString(s)); |
| 158 Dart_SetReturnValue(arguments, result); | 165 Dart_SetReturnValue(arguments, result); |
| 159 } | 166 } |
| 160 | 167 |
| 161 void Log(Dart_NativeArguments arguments) { | 168 void Log(Dart_NativeArguments arguments) { |
| 162 Dart_EnterScope(); | 169 Dart_EnterScope(); |
| 163 LOGI("%s", GetArgAsString(arguments, 0)); | 170 LOGI("%s", GetArgAsString(arguments, 0)); |
| 164 Dart_ExitScope(); | 171 Dart_ExitScope(); |
| 165 } | 172 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 187 int64_t seed; | 194 int64_t seed; |
| 188 HandleError(Dart_IntegerToInt64(seed_object, &seed)); | 195 HandleError(Dart_IntegerToInt64(seed_object, &seed)); |
| 189 srand(static_cast<unsigned>(seed)); | 196 srand(static_cast<unsigned>(seed)); |
| 190 success = true; | 197 success = true; |
| 191 } | 198 } |
| 192 } | 199 } |
| 193 SetBoolReturnValue(arguments, success); | 200 SetBoolReturnValue(arguments, success); |
| 194 Dart_ExitScope(); | 201 Dart_ExitScope(); |
| 195 } | 202 } |
| 196 | 203 |
| 204 void GetDeviceScreenWidth(Dart_NativeArguments arguments) { |
| 205 LOGI("GetDeviceScreenWidth"); |
| 206 Dart_EnterScope(); |
| 207 SetIntReturnValue(arguments, graphics->width()); |
| 208 Dart_ExitScope(); |
| 209 } |
| 210 |
| 211 void GetDeviceScreenHeight(Dart_NativeArguments arguments) { |
| 212 LOGI("GetDeviceScreenHeight"); |
| 213 Dart_EnterScope(); |
| 214 SetIntReturnValue(arguments, graphics->height()); |
| 215 Dart_ExitScope(); |
| 216 } |
| 217 |
| 197 void SwapBuffers(Dart_NativeArguments arguments) { | 218 void SwapBuffers(Dart_NativeArguments arguments) { |
| 198 LOGI("SwapBuffers"); | 219 LOGI("SwapBuffers"); |
| 199 Dart_EnterScope(); | 220 Dart_EnterScope(); |
| 200 GLSwapBuffers(); | 221 GLSwapBuffers(); |
| 201 CheckGLError("GLSwapBuffers"); | 222 CheckGLError("GLSwapBuffers"); |
| 202 Dart_ExitScope(); | 223 Dart_ExitScope(); |
| 203 } | 224 } |
| 204 | 225 |
| 205 void GLAttachShader(Dart_NativeArguments arguments) { | 226 void GLAttachShader(Dart_NativeArguments arguments) { |
| 206 LOGI("GLAttachShader"); | 227 LOGI("GLAttachShader"); |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 | 914 |
| 894 void PlaySample(Dart_NativeArguments arguments) { | 915 void PlaySample(Dart_NativeArguments arguments) { |
| 895 LOGI("PlaySample"); | 916 LOGI("PlaySample"); |
| 896 Dart_EnterScope(); | 917 Dart_EnterScope(); |
| 897 const char* what = GetArgAsString(arguments, 0); | 918 const char* what = GetArgAsString(arguments, 0); |
| 898 int rtn = PlaySoundSample(what); | 919 int rtn = PlaySoundSample(what); |
| 899 SetIntReturnValue(arguments, rtn); | 920 SetIntReturnValue(arguments, rtn); |
| 900 Dart_ExitScope(); | 921 Dart_ExitScope(); |
| 901 } | 922 } |
| 902 | 923 |
| 924 // 2D Canvas. |
| 925 |
| 926 // TODO(gram): this should be dynamic. |
| 927 #define MAX_CONTEXTS 16 |
| 928 CanvasContext* contexts[MAX_CONTEXTS] = { 0 }; |
| 929 |
| 930 CanvasContext* display_context; |
| 931 |
| 932 CanvasContext* Context2D(int handle) { |
| 933 if (handle < 0 || handle >= MAX_CONTEXTS) { |
| 934 return NULL; |
| 935 } |
| 936 return contexts[handle]; |
| 937 } |
| 938 |
| 939 void C2DCreateNativeContext(Dart_NativeArguments arguments) { |
| 940 LOGI("In C2DCreateNativeContext"); |
| 941 Dart_EnterScope(); |
| 942 |
| 943 int handle = GetArgAsInt(arguments, 0); |
| 944 int width = GetArgAsInt(arguments, 1); |
| 945 int height = GetArgAsInt(arguments, 2); |
| 946 |
| 947 // ASSERT(handle >= 0 && handle < MAX_CONTEXTS && |
| 948 // contexts[handle] == NULL) |
| 949 CanvasContext* rtn = new CanvasContext(width, height); |
| 950 rtn->Create(); |
| 951 if (display_context == NULL) { |
| 952 display_context = rtn; |
| 953 } |
| 954 contexts[handle] = rtn; |
| 955 Dart_ExitScope(); |
| 956 LOGI("Out C2DCreateNativeContext"); |
| 957 } |
| 958 |
| 959 void C2DSetWidth(Dart_NativeArguments arguments) { |
| 960 LOGI("In C2DSetWidth"); |
| 961 Dart_EnterScope(); |
| 962 int handle = GetArgAsInt(arguments, 0); |
| 963 int width = GetArgAsInt(arguments, 1); |
| 964 SetIntReturnValue(arguments, Context2D(handle)->setWidth(width)); |
| 965 Dart_ExitScope(); |
| 966 LOGI("Out C2DSetWidth"); |
| 967 } |
| 968 |
| 969 void C2DSetHeight(Dart_NativeArguments arguments) { |
| 970 LOGI("In C2DSetHeight"); |
| 971 Dart_EnterScope(); |
| 972 int handle = GetArgAsInt(arguments, 0); |
| 973 int height = GetArgAsInt(arguments, 1); |
| 974 SetIntReturnValue(arguments, Context2D(handle)->setHeight(height)); |
| 975 Dart_ExitScope(); |
| 976 LOGI("Out C2DSetHeight"); |
| 977 } |
| 978 |
| 979 void C2DSetGlobalAlpha(Dart_NativeArguments arguments) { |
| 980 LOGI("In C2DSetGlobalAlpha"); |
| 981 Dart_EnterScope(); |
| 982 int handle = GetArgAsInt(arguments, 0); |
| 983 double alpha = GetArgAsDouble(arguments, 1); |
| 984 alpha = MIN(1.0, MAX(alpha, 0.0)); |
| 985 Context2D(handle)->setGlobalAlpha(alpha); |
| 986 SetDoubleReturnValue(arguments, alpha); |
| 987 Dart_ExitScope(); |
| 988 LOGI("Out C2DSetGlobalAlpha"); |
| 989 } |
| 990 |
| 991 void C2DSetFillStyle(Dart_NativeArguments arguments) { |
| 992 LOGI("In C2DSetFillStyle"); |
| 993 Dart_EnterScope(); |
| 994 int handle = GetArgAsInt(arguments, 0); |
| 995 Dart_Handle whatHandle = HandleError(Dart_GetNativeArgument(arguments, 1)); |
| 996 if (Dart_IsString(whatHandle)) { |
| 997 const char* color = GetArgAsString(arguments, 1); |
| 998 Context2D(handle)->setFillColor(color); |
| 999 } else { // Texture from gradient or image. |
| 1000 } |
| 1001 Dart_ExitScope(); |
| 1002 LOGI("Out C2DSetFillStyle"); |
| 1003 } |
| 1004 |
| 1005 void C2DSetFont(Dart_NativeArguments arguments) { |
| 1006 LOGI("In C2DSetFont"); |
| 1007 Dart_EnterScope(); |
| 1008 int handle = GetArgAsInt(arguments, 0); |
| 1009 const char* font = GetArgAsString(arguments, 1); |
| 1010 SetStringReturnValue(arguments, Context2D(handle)->setFont(font)); |
| 1011 Dart_ExitScope(); |
| 1012 LOGI("Out C2DSetFont"); |
| 1013 } |
| 1014 |
| 1015 void C2DSetGlobalCompositeOperation(Dart_NativeArguments arguments) { |
| 1016 LOGI("In C2DSetGlobalCompositeOperation"); |
| 1017 Dart_EnterScope(); |
| 1018 int handle = GetArgAsInt(arguments, 0); |
| 1019 const char* op = GetArgAsString(arguments, 1); |
| 1020 Context2D(handle)->setGlobalCompositeOperation(op); |
| 1021 Dart_ExitScope(); |
| 1022 LOGI("Out C2DSetGlobalCompositeOperation"); |
| 1023 } |
| 1024 |
| 1025 void C2DSetLineCap(Dart_NativeArguments arguments) { |
| 1026 LOGI("In C2DSetLineCap"); |
| 1027 Dart_EnterScope(); |
| 1028 int handle = GetArgAsInt(arguments, 0); |
| 1029 const char* lc = GetArgAsString(arguments, 1); |
| 1030 Context2D(handle)->setLineCap(lc); |
| 1031 Dart_ExitScope(); |
| 1032 LOGI("Out C2DSetLineCap"); |
| 1033 } |
| 1034 |
| 1035 void C2DSetLineJoin(Dart_NativeArguments arguments) { |
| 1036 LOGI("In C2DSetLineJoin"); |
| 1037 Dart_EnterScope(); |
| 1038 int handle = GetArgAsInt(arguments, 0); |
| 1039 const char* lj = GetArgAsString(arguments, 1); |
| 1040 Context2D(handle)->setLineJoin(lj); |
| 1041 Dart_ExitScope(); |
| 1042 LOGI("Out C2DSetLineJoin"); |
| 1043 } |
| 1044 |
| 1045 void C2DSetLineWidth(Dart_NativeArguments arguments) { |
| 1046 LOGI("In C2DSetLineWidth"); |
| 1047 Dart_EnterScope(); |
| 1048 int handle = GetArgAsInt(arguments, 0); |
| 1049 double w = GetArgAsDouble(arguments, 1); |
| 1050 Context2D(handle)->setLineWidth(w); |
| 1051 Dart_ExitScope(); |
| 1052 LOGI("Out C2DSetLineWidth"); |
| 1053 } |
| 1054 |
| 1055 void C2DSetMiterLimit(Dart_NativeArguments arguments) { |
| 1056 LOGI("In C2DSetMiterLimit"); |
| 1057 Dart_EnterScope(); |
| 1058 int handle = GetArgAsInt(arguments, 0); |
| 1059 double w = GetArgAsDouble(arguments, 1); |
| 1060 Context2D(handle)->setMiterLimit(w); |
| 1061 Dart_ExitScope(); |
| 1062 LOGI("Out C2DSetMiterLimit"); |
| 1063 } |
| 1064 |
| 1065 void C2DSetShadowBlur(Dart_NativeArguments arguments) { |
| 1066 LOGI("In C2DSetShadowBlur"); |
| 1067 Dart_EnterScope(); |
| 1068 int handle = GetArgAsInt(arguments, 0); |
| 1069 double blur = GetArgAsDouble(arguments, 1); |
| 1070 Context2D(handle)->setShadowBlur(blur); |
| 1071 Dart_ExitScope(); |
| 1072 LOGI("Out C2DSetShadowBlur"); |
| 1073 } |
| 1074 |
| 1075 void C2DSetShadowColor(Dart_NativeArguments arguments) { |
| 1076 LOGI("In C2DSetShadowColor"); |
| 1077 Dart_EnterScope(); |
| 1078 int handle = GetArgAsInt(arguments, 0); |
| 1079 const char* color = GetArgAsString(arguments, 1); |
| 1080 Context2D(handle)->setShadowColor(color); |
| 1081 Dart_ExitScope(); |
| 1082 LOGI("Out C2DSetShadowColor"); |
| 1083 } |
| 1084 |
| 1085 void C2DSetShadowOffsetX(Dart_NativeArguments arguments) { |
| 1086 LOGI("In C2DSetShadowOffsetX"); |
| 1087 Dart_EnterScope(); |
| 1088 int handle = GetArgAsInt(arguments, 0); |
| 1089 double offset = GetArgAsDouble(arguments, 1); |
| 1090 Context2D(handle)->setShadowOffsetX(offset); |
| 1091 Dart_ExitScope(); |
| 1092 LOGI("Out C2DSetShadowOffsetX"); |
| 1093 } |
| 1094 |
| 1095 void C2DSetShadowOffsetY(Dart_NativeArguments arguments) { |
| 1096 LOGI("In C2DSetShadowOffsetY"); |
| 1097 Dart_EnterScope(); |
| 1098 int handle = GetArgAsInt(arguments, 0); |
| 1099 double offset = GetArgAsDouble(arguments, 1); |
| 1100 Context2D(handle)->setShadowOffsetY(offset); |
| 1101 Dart_ExitScope(); |
| 1102 LOGI("Out C2DSetShadowOffsetY"); |
| 1103 } |
| 1104 |
| 1105 void C2DSetStrokeStyle(Dart_NativeArguments arguments) { |
| 1106 LOGI("In C2DSetStrokeStyle"); |
| 1107 Dart_EnterScope(); |
| 1108 int handle = GetArgAsInt(arguments, 0); |
| 1109 const char* color = GetArgAsString(arguments, 1); |
| 1110 Context2D(handle)->setStrokeColor(color); |
| 1111 Dart_ExitScope(); |
| 1112 LOGI("Out C2DSetStrokeStyle"); |
| 1113 } |
| 1114 |
| 1115 void C2DSetTextAlign(Dart_NativeArguments arguments) { |
| 1116 LOGI("In C2DSetTextAlign"); |
| 1117 Dart_EnterScope(); |
| 1118 int handle = GetArgAsInt(arguments, 0); |
| 1119 const char* align = GetArgAsString(arguments, 1); |
| 1120 SetStringReturnValue(arguments, Context2D(handle)->setTextAlign(align)); |
| 1121 Dart_ExitScope(); |
| 1122 LOGI("Out C2DSetTextAlign"); |
| 1123 } |
| 1124 |
| 1125 void C2DSetTextBaseline(Dart_NativeArguments arguments) { |
| 1126 LOGI("In C2DSetTextBaseline"); |
| 1127 Dart_EnterScope(); |
| 1128 int handle = GetArgAsInt(arguments, 0); |
| 1129 const char* baseline = GetArgAsString(arguments, 1); |
| 1130 SetStringReturnValue(arguments, Context2D(handle)->setTextBaseline(baseline)); |
| 1131 Dart_ExitScope(); |
| 1132 LOGI("Out C2DSetTextBaseline"); |
| 1133 } |
| 1134 |
| 1135 void C2DGetImageSmoothingEnabled(Dart_NativeArguments arguments) { |
| 1136 LOGI("In C2DGetImageSmoothingEnabled"); |
| 1137 Dart_EnterScope(); |
| 1138 int handle = GetArgAsInt(arguments, 0); |
| 1139 SetDoubleReturnValue(arguments, Context2D(handle)->imageSmoothingEnabled()); |
| 1140 Dart_ExitScope(); |
| 1141 LOGI("Out C2DGetImageSmoothingEnabled"); |
| 1142 } |
| 1143 |
| 1144 void C2DArc(Dart_NativeArguments arguments) { |
| 1145 LOGI("In C2DArc"); |
| 1146 Dart_EnterScope(); |
| 1147 int handle = GetArgAsInt(arguments, 0); |
| 1148 double x = GetArgAsDouble(arguments, 1); |
| 1149 double y = GetArgAsDouble(arguments, 2); |
| 1150 double r = GetArgAsDouble(arguments, 3); |
| 1151 double a1 = GetArgAsDouble(arguments, 4); |
| 1152 double a2 = GetArgAsDouble(arguments, 5); |
| 1153 bool anticlockwise = GetArgAsBool(arguments, 6); |
| 1154 Context2D(handle)->Arc(x, y, r, a1, a2, anticlockwise); |
| 1155 Dart_ExitScope(); |
| 1156 LOGI("Out C2DArc"); |
| 1157 } |
| 1158 |
| 1159 void C2DArcTo(Dart_NativeArguments arguments) { |
| 1160 LOGI("In C2DArcTo"); |
| 1161 Dart_EnterScope(); |
| 1162 int handle = GetArgAsInt(arguments, 0); |
| 1163 double x1 = GetArgAsDouble(arguments, 1); |
| 1164 double y1 = GetArgAsDouble(arguments, 2); |
| 1165 double x2 = GetArgAsDouble(arguments, 3); |
| 1166 double y2 = GetArgAsDouble(arguments, 4); |
| 1167 double radius = GetArgAsDouble(arguments, 5); |
| 1168 Context2D(handle)->ArcTo(x1, y1, x2, y2, radius); |
| 1169 Dart_ExitScope(); |
| 1170 LOGI("Out C2DArcTo"); |
| 1171 } |
| 1172 |
| 1173 void C2DBeginPath(Dart_NativeArguments arguments) { |
| 1174 LOGI("In C2DBeginPath"); |
| 1175 Dart_EnterScope(); |
| 1176 int handle = GetArgAsInt(arguments, 0); |
| 1177 Context2D(handle)->BeginPath(); |
| 1178 Dart_ExitScope(); |
| 1179 LOGI("Out C2DBeginPath"); |
| 1180 } |
| 1181 |
| 1182 void C2DBezierCurveTo(Dart_NativeArguments arguments) { |
| 1183 LOGI("In C2DBezierCurveTo"); |
| 1184 Dart_EnterScope(); |
| 1185 int handle = GetArgAsInt(arguments, 0); |
| 1186 double cp1x = GetArgAsDouble(arguments, 1); |
| 1187 double cp1y = GetArgAsDouble(arguments, 2); |
| 1188 double cp2x = GetArgAsDouble(arguments, 3); |
| 1189 double cp2y = GetArgAsDouble(arguments, 4); |
| 1190 double x = GetArgAsDouble(arguments, 5); |
| 1191 double y = GetArgAsDouble(arguments, 6); |
| 1192 Context2D(handle)->BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); |
| 1193 Dart_ExitScope(); |
| 1194 LOGI("Out C2DBezierCurveTo"); |
| 1195 } |
| 1196 |
| 1197 void C2DClearRect(Dart_NativeArguments arguments) { |
| 1198 LOGI("In C2DClearRect"); |
| 1199 Dart_EnterScope(); |
| 1200 int handle = GetArgAsInt(arguments, 0); |
| 1201 double left = GetArgAsDouble(arguments, 1); |
| 1202 double top = GetArgAsDouble(arguments, 2); |
| 1203 double width = GetArgAsDouble(arguments, 3); |
| 1204 double height = GetArgAsDouble(arguments, 4); |
| 1205 Context2D(handle)->ClearRect(left, top, width, height); |
| 1206 Dart_ExitScope(); |
| 1207 LOGI("Out C2DClearRect"); |
| 1208 } |
| 1209 |
| 1210 void C2DClip(Dart_NativeArguments arguments) { |
| 1211 LOGI("In C2DClip"); |
| 1212 Dart_EnterScope(); |
| 1213 int handle = GetArgAsInt(arguments, 0); |
| 1214 Context2D(handle)->Clip(); |
| 1215 Dart_ExitScope(); |
| 1216 LOGI("Out C2DClip"); |
| 1217 } |
| 1218 |
| 1219 void C2DClosePath(Dart_NativeArguments arguments) { |
| 1220 LOGI("In C2DClosePath"); |
| 1221 Dart_EnterScope(); |
| 1222 int handle = GetArgAsInt(arguments, 0); |
| 1223 Context2D(handle)->ClosePath(); |
| 1224 Dart_ExitScope(); |
| 1225 LOGI("Out C2DClosePath"); |
| 1226 } |
| 1227 |
| 1228 void C2DCreateImageDataFromDimensions(Dart_NativeArguments arguments) { |
| 1229 LOGI("In C2DCreateImageDataFromDimensions"); |
| 1230 Dart_EnterScope(); |
| 1231 // int handle = GetArgAsInt(arguments, 0); |
| 1232 // double sw = GetArgAsDouble(arguments, 1); |
| 1233 // double sh = GetArgAsDouble(arguments, 2); |
| 1234 // GLubyte* pixels = (GLubyte*)calloc(sw * sh * 4, sizeof(GLubyte)); |
| 1235 // ImageData* imageData = new ImageData(sw, sh, pixels); |
| 1236 // TODO(gram): How do we create a Dart ImageData object from this? |
| 1237 Dart_ExitScope(); |
| 1238 LOGI("Out C2DCreateImageDataFromDimensions"); |
| 1239 } |
| 1240 |
| 1241 void C2DDrawImage(Dart_NativeArguments arguments) { |
| 1242 LOGI("In C2DDrawImage"); |
| 1243 Dart_EnterScope(); |
| 1244 int handle = GetArgAsInt(arguments, 0); |
| 1245 const char* src_url = GetArgAsString(arguments, 1); |
| 1246 int sx = GetArgAsInt(arguments, 2); |
| 1247 int sy = GetArgAsInt(arguments, 3); |
| 1248 bool has_src_dimensions = GetArgAsBool(arguments, 4); |
| 1249 int sw = GetArgAsInt(arguments, 5); |
| 1250 int sh = GetArgAsInt(arguments, 6); |
| 1251 int dx = GetArgAsInt(arguments, 7); |
| 1252 int dy = GetArgAsInt(arguments, 8); |
| 1253 bool has_dst_dimensions = GetArgAsBool(arguments, 9); |
| 1254 int dw = GetArgAsInt(arguments, 10); |
| 1255 int dh = GetArgAsInt(arguments, 11); |
| 1256 Context2D(handle)->DrawImage(src_url, |
| 1257 sx, sy, has_src_dimensions, sw, sh, |
| 1258 dx, dy, has_dst_dimensions, dw, dh); |
| 1259 Dart_ExitScope(); |
| 1260 LOGI("Out C2DDrawImage"); |
| 1261 } |
| 1262 |
| 1263 void C2DFill(Dart_NativeArguments arguments) { |
| 1264 LOGI("In C2DFill"); |
| 1265 Dart_EnterScope(); |
| 1266 int handle = GetArgAsInt(arguments, 0); |
| 1267 Context2D(handle)->Fill(); |
| 1268 Dart_ExitScope(); |
| 1269 LOGI("Out C2DFill"); |
| 1270 } |
| 1271 |
| 1272 void C2DFillRect(Dart_NativeArguments arguments) { |
| 1273 LOGI("In C2DFillRect"); |
| 1274 Dart_EnterScope(); |
| 1275 int handle = GetArgAsInt(arguments, 0); |
| 1276 double left = GetArgAsDouble(arguments, 1); |
| 1277 double top = GetArgAsDouble(arguments, 2); |
| 1278 double width = GetArgAsDouble(arguments, 3); |
| 1279 double height = GetArgAsDouble(arguments, 4); |
| 1280 Context2D(handle)->FillRect(left, top, width, height); |
| 1281 Dart_ExitScope(); |
| 1282 LOGI("Out C2DFillRect"); |
| 1283 } |
| 1284 |
| 1285 void C2DFillText(Dart_NativeArguments arguments) { |
| 1286 LOGI("In C2DFillText"); |
| 1287 Dart_EnterScope(); |
| 1288 int handle = GetArgAsInt(arguments, 0); |
| 1289 const char* text = GetArgAsString(arguments, 1); |
| 1290 double x = GetArgAsDouble(arguments, 2); |
| 1291 double y = GetArgAsDouble(arguments, 3); |
| 1292 double maxWidth = GetArgAsDouble(arguments, 4); |
| 1293 Context2D(handle)->FillText(text, x, y, maxWidth); |
| 1294 Dart_ExitScope(); |
| 1295 LOGI("Out C2DFillText"); |
| 1296 } |
| 1297 |
| 1298 void C2DGetImageData(Dart_NativeArguments arguments) { |
| 1299 LOGI("In C2DGetImageData"); |
| 1300 Dart_EnterScope(); |
| 1301 // TODO(gram): Complete this. |
| 1302 // int handle = GetArgAsInt(arguments, 0); |
| 1303 // double sx = GetArgAsDouble(arguments, 1); |
| 1304 // double sy = GetArgAsDouble(arguments, 2); |
| 1305 // double sw = GetArgAsDouble(arguments, 3); |
| 1306 // double sh = GetArgAsDouble(arguments, 4); |
| 1307 // ... = Context2D(handle)->GetImageData(text, x, y, maxWidth); |
| 1308 Dart_ExitScope(); |
| 1309 LOGI("Out C2DGetImageData"); |
| 1310 } |
| 1311 |
| 1312 void C2DLineTo(Dart_NativeArguments arguments) { |
| 1313 LOGI("In C2DLineTo"); |
| 1314 Dart_EnterScope(); |
| 1315 int handle = GetArgAsInt(arguments, 0); |
| 1316 double x = GetArgAsDouble(arguments, 1); |
| 1317 double y = GetArgAsDouble(arguments, 2); |
| 1318 Context2D(handle)->LineTo(x, y); |
| 1319 Dart_ExitScope(); |
| 1320 LOGI("Out C2DLineTo"); |
| 1321 } |
| 1322 |
| 1323 void C2DMeasureText(Dart_NativeArguments arguments) { |
| 1324 LOGI("In C2DMeasureText"); |
| 1325 Dart_EnterScope(); |
| 1326 int handle = GetArgAsInt(arguments, 0); |
| 1327 const char* text = GetArgAsString(arguments, 1); |
| 1328 float width = Context2D(handle)->MeasureText(text); |
| 1329 SetDoubleReturnValue(arguments, width); |
| 1330 Dart_ExitScope(); |
| 1331 LOGI("Out C2DMeasureText"); |
| 1332 } |
| 1333 |
| 1334 void C2DMoveTo(Dart_NativeArguments arguments) { |
| 1335 LOGI("IN C2DMoveTo"); |
| 1336 Dart_EnterScope(); |
| 1337 int handle = GetArgAsInt(arguments, 0); |
| 1338 double x = GetArgAsDouble(arguments, 1); |
| 1339 double y = GetArgAsDouble(arguments, 2); |
| 1340 Context2D(handle)->MoveTo(x, y); |
| 1341 Dart_ExitScope(); |
| 1342 LOGI("Out C2DMoveTo"); |
| 1343 } |
| 1344 |
| 1345 void C2DPutImageData(Dart_NativeArguments arguments) { |
| 1346 LOGI("IN C2DPutImageData"); |
| 1347 Dart_EnterScope(); |
| 1348 int handle = GetArgAsInt(arguments, 0); |
| 1349 // Get object arguments 2 |
| 1350 // BindingImageData* imageData = GetArgAsObject(arguments, 1); |
| 1351 double dx = GetArgAsDouble(arguments, 2); |
| 1352 double dy = GetArgAsDouble(arguments, 3); |
| 1353 Context2D(handle)->PutImageData(NULL, dx, dy); |
| 1354 Dart_ExitScope(); |
| 1355 LOGI("Out C2DPutImageData"); |
| 1356 } |
| 1357 |
| 1358 void C2DQuadraticCurveTo(Dart_NativeArguments arguments) { |
| 1359 LOGI("In C2DQuadraticCurveTo"); |
| 1360 Dart_EnterScope(); |
| 1361 int handle = GetArgAsInt(arguments, 0); |
| 1362 double cpx = GetArgAsDouble(arguments, 1); |
| 1363 double cpy = GetArgAsDouble(arguments, 2); |
| 1364 double x = GetArgAsDouble(arguments, 3); |
| 1365 double y = GetArgAsDouble(arguments, 4); |
| 1366 Context2D(handle)->QuadraticCurveTo(cpx, cpy, x, y); |
| 1367 Dart_ExitScope(); |
| 1368 LOGI("Out C2DQuadraticCurveTo"); |
| 1369 } |
| 1370 |
| 1371 void C2DRect(Dart_NativeArguments arguments) { |
| 1372 LOGI("In C2DRect"); |
| 1373 Dart_EnterScope(); |
| 1374 int handle = GetArgAsInt(arguments, 0); |
| 1375 double x = GetArgAsDouble(arguments, 1); |
| 1376 double y = GetArgAsDouble(arguments, 2); |
| 1377 double w = GetArgAsDouble(arguments, 3); |
| 1378 double h = GetArgAsDouble(arguments, 4); |
| 1379 Context2D(handle)->Rect(x, y, w, h); |
| 1380 Dart_ExitScope(); |
| 1381 LOGI("Out C2DRect"); |
| 1382 } |
| 1383 |
| 1384 void C2DRestore(Dart_NativeArguments arguments) { |
| 1385 LOGI("In C2DRestore"); |
| 1386 Dart_EnterScope(); |
| 1387 int handle = GetArgAsInt(arguments, 0); |
| 1388 Context2D(handle)->Restore(); |
| 1389 Dart_ExitScope(); |
| 1390 LOGI("Out C2DRestore"); |
| 1391 } |
| 1392 |
| 1393 void C2DRotate(Dart_NativeArguments arguments) { |
| 1394 LOGI("In C2DRotate"); |
| 1395 Dart_EnterScope(); |
| 1396 int handle = GetArgAsInt(arguments, 0); |
| 1397 double a = GetArgAsDouble(arguments, 1); |
| 1398 Context2D(handle)->Rotate(a); |
| 1399 Dart_ExitScope(); |
| 1400 LOGI("Out C2DRotate"); |
| 1401 } |
| 1402 |
| 1403 void C2DSave(Dart_NativeArguments arguments) { |
| 1404 LOGI("In C2DSave"); |
| 1405 Dart_EnterScope(); |
| 1406 int handle = GetArgAsInt(arguments, 0); |
| 1407 Context2D(handle)->Save(); |
| 1408 Dart_ExitScope(); |
| 1409 LOGI("Out C2DSave"); |
| 1410 } |
| 1411 |
| 1412 void C2DScale(Dart_NativeArguments arguments) { |
| 1413 LOGI("In C2DScale"); |
| 1414 Dart_EnterScope(); |
| 1415 int handle = GetArgAsInt(arguments, 0); |
| 1416 double sx = GetArgAsDouble(arguments, 1); |
| 1417 double sy = GetArgAsDouble(arguments, 2); |
| 1418 Context2D(handle)->Scale(sx, sy); |
| 1419 Dart_ExitScope(); |
| 1420 LOGI("Out C2DScale"); |
| 1421 } |
| 1422 |
| 1423 void C2DSetLineDash(Dart_NativeArguments arguments) { |
| 1424 LOGI("In C2DSetLineDash"); |
| 1425 Dart_EnterScope(); |
| 1426 int handle = GetArgAsInt(arguments, 0); |
| 1427 int len; |
| 1428 float* dash = static_cast<float*>(GetArgsAsFloatList(arguments, 1, &len)); |
| 1429 if (dash != NULL) { |
| 1430 Context2D(handle)->setLineDash(dash, len); |
| 1431 delete[] dash; |
| 1432 } |
| 1433 Dart_ExitScope(); |
| 1434 LOGI("Out C2DSetLineDash"); |
| 1435 } |
| 1436 |
| 1437 void C2DSetLineDashOffset(Dart_NativeArguments arguments) { |
| 1438 LOGI("In C2DSetLineDashOffset"); |
| 1439 Dart_EnterScope(); |
| 1440 int handle = GetArgAsInt(arguments, 0); |
| 1441 double offset = GetArgAsDouble(arguments, 1); |
| 1442 Context2D(handle)->setLineDashOffset(offset); |
| 1443 Dart_ExitScope(); |
| 1444 LOGI("Out C2DSetLineDashOffset"); |
| 1445 } |
| 1446 |
| 1447 void C2DSetTransform(Dart_NativeArguments arguments) { |
| 1448 LOGI("In C2DSetTransform"); |
| 1449 Dart_EnterScope(); |
| 1450 int handle = GetArgAsInt(arguments, 0); |
| 1451 double m11 = GetArgAsDouble(arguments, 1); |
| 1452 double m12 = GetArgAsDouble(arguments, 2); |
| 1453 double m21 = GetArgAsDouble(arguments, 3); |
| 1454 double m22 = GetArgAsDouble(arguments, 4); |
| 1455 double dx = GetArgAsDouble(arguments, 5); |
| 1456 double dy = GetArgAsDouble(arguments, 6); |
| 1457 Context2D(handle)->setTransform(m11, m12, m21, m22, dx, dy); |
| 1458 Dart_ExitScope(); |
| 1459 LOGI("Out C2DSetTransform"); |
| 1460 } |
| 1461 |
| 1462 void C2DStroke(Dart_NativeArguments arguments) { |
| 1463 LOGI("In C2DStroke"); |
| 1464 Dart_EnterScope(); |
| 1465 int handle = GetArgAsInt(arguments, 0); |
| 1466 Context2D(handle)->Stroke(); |
| 1467 Dart_ExitScope(); |
| 1468 LOGI("Out C2DStroke"); |
| 1469 } |
| 1470 |
| 1471 void C2DStrokeRect(Dart_NativeArguments arguments) { |
| 1472 LOGI("In C2DStrokeRect"); |
| 1473 Dart_EnterScope(); |
| 1474 int handle = GetArgAsInt(arguments, 0); |
| 1475 double left = GetArgAsDouble(arguments, 1); |
| 1476 double top = GetArgAsDouble(arguments, 2); |
| 1477 double width = GetArgAsDouble(arguments, 3); |
| 1478 double height = GetArgAsDouble(arguments, 4); |
| 1479 Context2D(handle)->StrokeRect(left, top, width, height); |
| 1480 Dart_ExitScope(); |
| 1481 LOGI("Out C2DStrokeRect"); |
| 1482 } |
| 1483 |
| 1484 void C2DStrokeText(Dart_NativeArguments arguments) { |
| 1485 LOGI("In C2DStrokeText"); |
| 1486 Dart_EnterScope(); |
| 1487 int handle = GetArgAsInt(arguments, 0); |
| 1488 const char* text = GetArgAsString(arguments, 1); |
| 1489 double x = GetArgAsDouble(arguments, 2); |
| 1490 double y = GetArgAsDouble(arguments, 3); |
| 1491 double maxWidth = GetArgAsDouble(arguments, 4); |
| 1492 Context2D(handle)->StrokeText(text, x, y, maxWidth); |
| 1493 Dart_ExitScope(); |
| 1494 LOGI("Out C2DStrokeText"); |
| 1495 } |
| 1496 |
| 1497 void C2DTransform(Dart_NativeArguments arguments) { |
| 1498 LOGI("In C2DTransform"); |
| 1499 Dart_EnterScope(); |
| 1500 int handle = GetArgAsInt(arguments, 0); |
| 1501 double m11 = GetArgAsDouble(arguments, 1); |
| 1502 double m12 = GetArgAsDouble(arguments, 2); |
| 1503 double m21 = GetArgAsDouble(arguments, 3); |
| 1504 double m22 = GetArgAsDouble(arguments, 4); |
| 1505 double dx = GetArgAsDouble(arguments, 5); |
| 1506 double dy = GetArgAsDouble(arguments, 6); |
| 1507 Context2D(handle)->Transform(m11, m12, m21, m22, dx, dy); |
| 1508 Dart_ExitScope(); |
| 1509 LOGI("Out C2DTransform"); |
| 1510 } |
| 1511 |
| 1512 void C2DTranslate(Dart_NativeArguments arguments) { |
| 1513 LOGI("In C2DTranslate"); |
| 1514 Dart_EnterScope(); |
| 1515 int handle = GetArgAsInt(arguments, 0); |
| 1516 double x = GetArgAsDouble(arguments, 1); |
| 1517 double y = GetArgAsDouble(arguments, 2); |
| 1518 Context2D(handle)->Translate(x, y); |
| 1519 Dart_ExitScope(); |
| 1520 LOGI("Out C2DTranslate"); |
| 1521 } |
| 1522 |
| 903 struct FunctionLookup { | 1523 struct FunctionLookup { |
| 904 const char* name; | 1524 const char* name; |
| 905 Dart_NativeFunction function; | 1525 Dart_NativeFunction function; |
| 906 }; | 1526 }; |
| 907 | 1527 |
| 908 FunctionLookup function_list[] = { | 1528 FunctionLookup function_list[] = { |
| 909 {"Log", Log}, | 1529 {"Log", Log}, |
| 910 {"LogError", LogError}, | 1530 {"LogError", LogError}, |
| 911 {"SystemRand", SystemRand}, | 1531 {"SystemRand", SystemRand}, |
| 912 {"SystemSrand", SystemSrand}, | 1532 {"SystemSrand", SystemSrand}, |
| 913 {"SwapBuffers", SwapBuffers}, | 1533 {"SwapBuffers", SwapBuffers}, |
| 1534 {"GetDeviceScreenWidth", GetDeviceScreenWidth}, |
| 1535 {"GetDeviceScreenHeight", GetDeviceScreenHeight}, |
| 914 {"GLAttachShader", GLAttachShader}, | 1536 {"GLAttachShader", GLAttachShader}, |
| 915 {"GLBindBuffer", GLBindBuffer}, | 1537 {"GLBindBuffer", GLBindBuffer}, |
| 916 {"GLBufferData", GLBufferData}, | 1538 {"GLBufferData", GLBufferData}, |
| 917 {"GLClear", GLClear}, | 1539 {"GLClear", GLClear}, |
| 918 {"GLClearColor", GLClearColor}, | 1540 {"GLClearColor", GLClearColor}, |
| 919 {"GLClearDepth", GLClearDepth}, | 1541 {"GLClearDepth", GLClearDepth}, |
| 920 {"GLCompileShader", GLCompileShader}, | 1542 {"GLCompileShader", GLCompileShader}, |
| 921 {"GLCreateBuffer", GLCreateBuffer}, | 1543 {"GLCreateBuffer", GLCreateBuffer}, |
| 922 {"GLCreateProgram", GLCreateProgram}, | 1544 {"GLCreateProgram", GLCreateProgram}, |
| 923 {"GLCreateShader", GLCreateShader}, | 1545 {"GLCreateShader", GLCreateShader}, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 {"GLGetShaderInfoLog", GLGetShaderInfoLog}, | 1588 {"GLGetShaderInfoLog", GLGetShaderInfoLog}, |
| 967 {"GLGetProgramInfoLog", GLGetProgramInfoLog}, | 1589 {"GLGetProgramInfoLog", GLGetProgramInfoLog}, |
| 968 {"RandomArray_ServicePort", RandomArrayServicePort}, | 1590 {"RandomArray_ServicePort", RandomArrayServicePort}, |
| 969 | 1591 |
| 970 // Audio support. | 1592 // Audio support. |
| 971 {"PlayBackground", PlayBackground}, | 1593 {"PlayBackground", PlayBackground}, |
| 972 {"StopBackground", StopBackground}, | 1594 {"StopBackground", StopBackground}, |
| 973 {"LoadSample", LoadSample}, | 1595 {"LoadSample", LoadSample}, |
| 974 {"PlaySample", PlaySample}, | 1596 {"PlaySample", PlaySample}, |
| 975 | 1597 |
| 1598 // 2D Support |
| 1599 |
| 1600 { "C2DCreateNativeContext", C2DCreateNativeContext}, |
| 1601 |
| 1602 // Property getters/setters. |
| 1603 |
| 1604 { "C2DSetWidth", C2DSetWidth}, |
| 1605 { "C2DSetHeight", C2DSetHeight}, |
| 1606 { "C2DSetGlobalAlpha", C2DSetGlobalAlpha}, |
| 1607 { "C2DSetFillStyle", C2DSetFillStyle}, |
| 1608 { "C2DSetFont", C2DSetFont}, |
| 1609 { "C2DSetGlobalCompositeOperation", C2DSetGlobalCompositeOperation}, |
| 1610 { "C2DSetLineCap", C2DSetLineCap}, |
| 1611 { "C2DSetLineJoin", C2DSetLineJoin}, |
| 1612 { "C2DSetLineWidth", C2DSetLineWidth}, |
| 1613 { "C2DSetMiterLimit", C2DSetMiterLimit}, |
| 1614 { "C2DSetShadowBlur", C2DSetShadowBlur}, |
| 1615 { "C2DSetShadowColor", C2DSetShadowColor}, |
| 1616 { "C2DSetShadowOffsetX", C2DSetShadowOffsetX}, |
| 1617 { "C2DSetShadowOffsetY", C2DSetShadowOffsetY}, |
| 1618 { "C2DSetStrokeStyle", C2DSetStrokeStyle}, |
| 1619 { "C2DSetTextAlign", C2DSetTextAlign}, |
| 1620 { "C2DSetTextBaseline", C2DSetTextBaseline}, |
| 1621 { "C2DGetImageSmoothingEnabled", C2DGetImageSmoothingEnabled}, |
| 1622 |
| 1623 // Methods. |
| 1624 { "C2DArc", C2DArc}, |
| 1625 { "C2DArcTo", C2DArcTo}, |
| 1626 { "C2DBeginPath", C2DBeginPath}, |
| 1627 { "C2DBezierCurveTo", C2DBezierCurveTo}, |
| 1628 { "C2DClearRect", C2DClearRect}, |
| 1629 { "C2DClip", C2DClip}, |
| 1630 { "C2DClosePath", C2DClosePath}, |
| 1631 { "C2DCreateImageDataFromDimensions", C2DCreateImageDataFromDimensions}, |
| 1632 { "C2DDrawImage", C2DDrawImage}, |
| 1633 { "C2DFill", C2DFill}, |
| 1634 { "C2DFillRect", C2DFillRect}, |
| 1635 { "C2DFillText", C2DFillText}, |
| 1636 { "C2DGetImageData", C2DGetImageData}, |
| 1637 { "C2DLineTo", C2DLineTo}, |
| 1638 { "C2DMeasureText", C2DMeasureText}, |
| 1639 { "C2DMoveTo", C2DMoveTo}, |
| 1640 { "C2DPutImageData", C2DPutImageData}, |
| 1641 { "C2DQuadraticCurveTo", C2DQuadraticCurveTo}, |
| 1642 { "C2DRect", C2DRect}, |
| 1643 { "C2DRestore", C2DRestore}, |
| 1644 { "C2DRotate", C2DRotate}, |
| 1645 { "C2DSave", C2DSave}, |
| 1646 { "C2DScale", C2DScale}, |
| 1647 { "C2DSetLineDash", C2DSetLineDash}, |
| 1648 { "C2DSetLineDashOffset", C2DSetLineDashOffset}, |
| 1649 { "C2DSetTransform", C2DSetTransform}, |
| 1650 { "C2DStroke", C2DStroke}, |
| 1651 { "C2DStrokeRect", C2DStrokeRect}, |
| 1652 { "C2DStrokeText", C2DStrokeText}, |
| 1653 { "C2DTransform", C2DTransform}, |
| 1654 { "C2DTranslate", C2DTranslate}, |
| 976 {NULL, NULL}}; | 1655 {NULL, NULL}}; |
| 977 | 1656 |
| 978 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | 1657 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { |
| 979 if (!Dart_IsString(name)) return NULL; | 1658 if (!Dart_IsString(name)) return NULL; |
| 980 Dart_NativeFunction result = NULL; | 1659 Dart_NativeFunction result = NULL; |
| 981 Dart_EnterScope(); | 1660 Dart_EnterScope(); |
| 982 const char* cname; | 1661 const char* cname; |
| 983 HandleError(Dart_StringToCString(name, &cname)); | 1662 HandleError(Dart_StringToCString(name, &cname)); |
| 984 for (int i = 0; function_list[i].name != NULL; ++i) { | 1663 for (int i = 0; function_list[i].name != NULL; ++i) { |
| 985 if (strcmp(function_list[i].name, cname) == 0) { | 1664 if (strcmp(function_list[i].name, cname) == 0) { |
| 986 result = function_list[i].function; | 1665 result = function_list[i].function; |
| 987 break; | 1666 break; |
| 988 } | 1667 } |
| 989 } | 1668 } |
| 990 Dart_ExitScope(); | 1669 Dart_ExitScope(); |
| 991 return result; | 1670 return result; |
| 992 } | 1671 } |
| 993 | |
| OLD | NEW |