2025-01-22 05:30 AM
Hello everyone,
I am trying to use the Vector Renderer to draw lines because it utilizes GPU2D, which offers faster rendering compared to the Canvas. Below is the code I am using for this purpose:
void TestWidget::draw(const touchgfx::Rect& invalidatedArea) const
{
if (numPoints < 2)
{
return; // Nothing to draw
}
VectorRenderer* vectorRenderer = VectorRenderer::getInstance();
// Configure the vector renderer
Rect absoluteRect = getAbsoluteRect();
vectorRenderer->setup(absoluteRect, invalidatedArea);
vectorRenderer->setMode(VectorRenderer::STROKE);
vectorRenderer->setStrokeWidth(lineWidth);
vectorRenderer->setColor(lineColor);
touchgfx::Matrix3x3 transformationMatrix;
transformationMatrix.scale(scale);
transformationMatrix.translate(deltaX, deltaY);
// Apply the transformation matrix
vectorRenderer->setTransformationMatrix(transformationMatrix);
// Prepare command and coordinate arrays
uint8_t cmds[MAX_POINTS] = {0};
float coords[MAX_POINTS * 2] = {0};
cmds[0] = VectorPrimitives::VECTOR_PRIM_MOVE; // First command is MoveTo
coords[0] = points[0].x; // Initial x
coords[1] = points[0].y; // Initial y
for (int i = 1; i < numPoints; ++i)
{
cmds[i] = VectorPrimitives::VECTOR_PRIM_LINE; // Subsequent commands are LineTo
coords[i * 2] = points[i].x; // x-coordinate
coords[i * 2 + 1] = points[i].y; // y-coordinate
}
// Optionally, define a bounding box (not mandatory)
float bbox[4] = {
absoluteRect.x, absoluteRect.y,
absoluteRect.width, absoluteRect.height
};
// Draw the path
vectorRenderer->drawPath(cmds, numPoints, coords, numPoints, bbox);
vectorRenderer->tearDown();
}
Problem Description
The issue arises when:
This results in an assertion error in the following code:
nema_buffer_t nema_buffer_create_pool(int pool, int size)
{
nema_buffer_t bo;
memset(&bo, 0, sizeof(bo));
bo.base_virt = tsi_malloc_pool(pool, size);
bo.base_phys = (uint32_t)bo.base_virt;
bo.size = size;
bo.fd = 0;
assert(bo.base_virt != 0 && "Unable to allocate memory in nema_buffer_create_pool");
return bo;
}
Question
When I set the bounding box for the drawing path, my assumption is that the Vector Renderer should not allocate memory exceeding the screen’s size. However, it appears that the assertion failure occurs because memory allocation fails (bo.base_virt == 0).
Does anyone know why the renderer might still attempt to allocate additional memory outside the defined bounding box, especially when the transformation matrix is scaled?