On Thu Nov 23 19:02:38 2023 +0000, Brendan McGrath wrote:
My apologies for misunderstanding previously, I thought the intent for using `d2d_factory` was just to hide the details of the factory locking mechanism from device. I think I needed a better understanding on the why. When you say "use it for everything": did you want me to remove the existing `ID2D1Factory *factory`? And then replace all uses of it with the `d2d_factory`. So I would effectively mirror the public API, but have it use `d2d_factory` instead (declaring them in `d2d1_private.h`). And then to create inline helpers using the `d2d_factory`, I would need to move the `d2d_factory` definition in to `d2d1_private.h`. Let me know if I've got that right.
As an alternative, maybe I could store the `ID2D1Multithread` instead and make `ID2D1Multithread_Enter` and `ID2D1Multithread_Leave` calls in `d2d_device_context_draw`. It does add the overhead of the indirect call to `EnterCriticalSection`, but it would be insignificant compared to the `EnterCriticalSection` call itself (not to mention all the indirect ID3D11 calls that are already in `d2d_device_context_draw`).
This approach has the advantage of leaving the factory implementation in `factory.c` (i.e. not leaking it in to `d2d1_private.h`) and at least removes the call to `ID2D1Factory_QueryInterface` in every draw.