MCPcopy Create free account
hub / github.com/GNOME/gjs / getDeviceScale_func

Function getDeviceScale_func

modules/cairo-surface.cpp:200–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200GJS_JSAPI_RETURN_CONVENTION
201static bool getDeviceScale_func(JSContext* cx, unsigned argc, JS::Value* vp) {
202 GJS_GET_THIS(cx, argc, vp, args, obj);
203
204 if (argc > 0) {
205 gjs_throw(cx, "Surface.getDeviceScale() takes no arguments");
206 return false;
207 }
208
209 cairo_surface_t* surface = CairoSurface::for_js(cx, obj);
210 if (!surface)
211 return false;
212
213 double x_scale, y_scale;
214 cairo_surface_get_device_scale(surface, &x_scale, &y_scale);
215 // cannot error
216
217 JS::RootedValueArray<2> elements(cx);
218 elements[0].setNumber(JS::CanonicalizeNaN(x_scale));
219 elements[1].setNumber(JS::CanonicalizeNaN(y_scale));
220 JS::RootedObject retval(cx, JS::NewArrayObject(cx, elements));
221 if (!retval)
222 return false;
223
224 args.rval().setObject(*retval);
225 return true;
226}
227
228const JSFunctionSpec CairoSurface::proto_funcs[] = {
229 JS_FN("flush", flush_func, 0, 0),

Callers

nothing calls this directly

Calls 1

gjs_throwFunction · 0.85

Tested by

no test coverage detected