ScenicFramework / scenic_driver_local

Local rendering driver for Scenic
Apache License 2.0
9 stars 13 forks source link

Questions about the restructuring #48

Closed axelson closed 1 year ago

axelson commented 1 year ago

In investigating a fix for https://github.com/ScenicFramework/scenic_driver_local/issues/41 it looks like there's multiple issues that have cropped up after https://github.com/ScenicFramework/scenic_driver_local/pull/27

See

Admittedly my c is very rusty, so I may be a bit off base here.

Upon reviewing the code in https://github.com/ScenicFramework/scenic_driver_local/pull/27 more thoroughly I have a few questions:

crertel commented 1 year ago

At least with regards to void*, that's the usual way (IIRC) of hiding implementation details. NVGcontext assumes that you're using NanoVG, which isn't always that case, depending. I'd bet that's why it was done.

ringlej commented 1 year ago

Yes, that is the reason for the void*. The cairo work doesn't used NVGcontext. The rename from p_ctx to v_ctx was for 2 reasons:

  1. The v was to indicate that this is a void* and the implementation needs to cast it to the proper type of pointer
  2. The rename helps with the compiler telling me where this needed to be handled (as it did for you as well with the build breaking for bcm, etc...). It was then intended that at the top of a function where the casting is done, that the concreted pointer variable name would be called p_ctx so that the rest of the function could be left as is.

For example the intended usage pattern for casting would be something like this:

void device_begin_render(driver_data_t* p_data)
{
  NVGcontext* p_ctx = (NVGcontext*)p_data->v_ctx;

  glClear(GL_COLOR_BUFFER_BIT);

  nvgBeginFrame(p_ctx, g_device_info.width, g_device_info.height, g_device_info.ratio);

  // set the global transform
  nvgTransform(p_ctx,
               p_data->global_tx[0], p_data->global_tx[1],
               p_data->global_tx[2], p_data->global_tx[3],
               p_data->global_tx[4], p_data->global_tx[5]);
}
axelson commented 1 year ago

Thanks for the info, that all makes sense. I still think the rename from p_ctx to v_ctx could have been done as a followup to the initial PR, but splitting it out that way doesn't do anything functionally, it just makes the refactor easier to write/review. Closing this since my questions have been answered.