when I use JUCE_DIRECT2D, I show an ui without animation, the cpu is about 10%(win10),I think the problem is same as Direct2D, CPU utilization, and continuous WM_PAINT messages described here.
When I wrapper it with BeginPaint and EndPaint, the cpu is down to 0.
Is my version of handlePaintMessage right?
original code
void handlePaintMessage()
{
#if JUCE_DIRECT2D
if (direct2DContext != nullptr)
{
RECT r;
if (GetUpdateRect (hwnd, &r, false))``
{
direct2DContext->start();
direct2DContext->clipToRectangle (rectangleFromRECT (r));
handlePaint (*direct2DContext);
direct2DContext->end();
}
}
else
#endif
my version:
void handlePaintMessage()
{
#if JUCE_DIRECT2D
if (direct2DContext != nullptr)
{
RECT r;
if (GetUpdateRect (hwnd, &r, false))
{
PAINTSTRUCT paintStruct;
HDC dc = BeginPaint(hwnd, &paintStruct);
direct2DContext->start();
direct2DContext->clipToRectangle (rectangleFromRECT (r));
handlePaint (*direct2DContext);
direct2DContext->end();
EndPaint(hwnd, &paintStruct);
}
}
else
#endif