MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PiuSVGImageBind

Function PiuSVGImageBind

modules/piu/Pebble/piuSVGImage.c:91–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89mxImport xsIntegerValue _xsmcGetBuffer(xsMachine *the, xsSlot *slot, void **data, xsUnsignedValue *count, xsBooleanValue writable);
90
91void PiuSVGImageBind(void* it, PiuApplication* application, PiuView* view)
92{
93 PiuSVGImage* self = it;
94 xsBeginHost((*self)->the);
95 xsVars(2);
96 GDrawCommandImage *dci = NULL;
97 GDrawCommandSequence *dcs = NULL;
98 if ((*self)->id) {
99 dci = gdraw_command_image_create_with_resource((*self)->id);
100 if (dci == NULL)
101 dcs = gdraw_command_sequence_create_with_resource((*self)->id);
102 }
103 else if ((*self)->path) {
104 void* data;
105 xsUnsignedValue count;
106 xsVar(0) = *((*self)->path);
107 xsVar(0) = xsNew1(xsGlobal, xsID_Resource, xsVar(0));
108 _xsmcGetBuffer(the, &xsVar(0), &data, &count, 0);
109 dci = (GDrawCommandImage *)(((uint8_t*)data) + PDCI_DATA_OFFSET);
110 if (!gdraw_command_image_validate(dci, count - PDCI_DATA_OFFSET)) {
111 dci = NULL;
112 dcs = (GDrawCommandSequence *)(((uint8_t*)data) + PDCS_DATA_OFFSET);
113 if (!gdraw_command_sequence_validate(dcs, count - PDCS_DATA_OFFSET)) {
114 dcs = NULL;
115 }
116 }
117 }
118 if (dci) {
119 (*self)->dci = dci;
120 GSize size = gdraw_command_image_get_bounds_size(dci);
121 (*self)->dataWidth = size.w;
122 (*self)->dataHeight = size.h;
123 }
124 else if (dcs) {
125 (*self)->dcs = dcs;
126 GSize size = gdraw_command_sequence_get_bounds_size(dcs);
127 (*self)->dataWidth = size.w;
128 (*self)->dataHeight = size.h;
129 uint32_t duration = 0;
130 uint32_t c = gdraw_command_sequence_get_num_frames(dcs);
131 for (uint32_t i = 0; i < c; i++) {
132 GDrawCommandFrame* dcf = gdraw_command_sequence_get_frame_by_index(dcs, 0);
133 duration += gdraw_command_frame_get_duration(dcf);
134 }
135 PiuIdle selfIdle = PiuContentUseIdle(it);
136 selfIdle->duration = duration;
137 (*self)->dcf = gdraw_command_sequence_get_frame_by_index(dcs, 0);
138 }
139 (*self)->cx = (xsNumberValue)(*self)->dataWidth / 2.0;
140 (*self)->cy = (xsNumberValue)(*self)->dataHeight / 2.0;
141 (*self)->sx = (*self)->sy = 1;
142 (*self)->o = 1;
143 (*self)->transforming = 1;
144 xsEndHost((*self)->the);
145 PiuContentBind(it, application, view);
146}
147
148void PiuSVGImageDelete(void* it)

Callers

nothing calls this directly

Calls 3

_xsmcGetBufferFunction · 0.85
PiuContentUseIdleFunction · 0.85
PiuContentBindFunction · 0.85

Tested by

no test coverage detected