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

Function xs_poco_build

modules/commodetto/commodettoPocoCore.c:104–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102};
103
104void xs_poco_build(xsMachine *the)
105{
106 Poco poco;
107 int pixelsCount = xsmcToInteger(xsArg(2));
108 int pixelFormat = xsmcToInteger(xsArg(3));
109 int pixelsLength = ((pixelsCount * (int)CommodettoBitmapGetDepth(pixelFormat)) + 7) >> 3;
110 int displayListLength = xsmcToInteger(xsArg(4));
111 int rotation = xsmcToInteger(xsArg(5));
112 if (sizeof(void *) > 4)
113 displayListLength += displayListLength >> 1; // compensate for bigger pointers on 64-bit systems
114 int byteLength = pixelsLength + displayListLength;
115
116 if ((kPocoPixelFormat != pixelFormat) || (0 == pixelsLength))
117 xsErrorPrintf("unsupported pixel format");
118
119 if (rotation != kPocoRotation)
120 xsErrorPrintf("not configured for requested rotation");
121
122#if MODDEF_POCO_DMA
123 #if ESP32
124 poco = heap_caps_aligned_alloc(4, sizeof(PocoRecord) + byteLength + 8, MALLOC_CAP_DMA);
125 #else
126 #error DMA allocator
127 #endif
128#else
129 poco = c_malloc(sizeof(PocoRecord) + byteLength + 8); // overhang when dividing
130#endif
131 if (!poco)
132 xsErrorPrintf("no memory");
133 xsmcSetHostBuffer(xsThis, poco->pixels, pixelsLength);
134
135 xsSetHostHooks(xsThis, (xsHostHooks *)&xsPocoHooks);
136 poco->reservedPocoJS = NULL;
137
138#if pebble
139 poco->pebbleState = NULL;
140#endif
141
142 poco->width = (PocoDimension)xsmcToInteger(xsArg(0));
143 poco->height = (PocoDimension)xsmcToInteger(xsArg(1));
144 rotateDimensions(poco->width, poco->height);
145
146 poco->flags = 0;
147 if (xsmcTest(xsArg(6)))
148 poco->flags |= kPocoFlagDoubleBuffer;
149 if (xsmcTest(xsArg(7)))
150 poco->flags |= kPocoFlagAdaptInvalid;
151
152#if MODDEF_ECMA419_DISPLAY
153 poco->displayHooks = C_NULL;
154 poco->the = the;
155
156 if (xsmcHas(xsArg(11), xsID_configure))
157 poco->flags |= kPocoFlag419PixelOut;
158
159 xsDisplayHostHooks displayHooks = (xsDisplayHostHooks)xsGetHostHooksIf(xsArg(11));
160 if (displayHooks && (0 == c_strcmp(displayHooks->hooks.signature, "display"))) {
161 poco->displayHooks = displayHooks;

Callers

nothing calls this directly

Calls 2

CommodettoBitmapGetDepthFunction · 0.85
CFENewFunction · 0.70

Tested by

no test coverage detected