27 #define MSG_UPDATE (WM_APP + 1)
29 static RECT NormalGraphTextMargin = { 5, 5, 5, 5 };
30 static RECT NormalGraphTextPadding = { 3, 3, 3, 3 };
32 typedef struct _ET_GPU_CONTEXT
46 HWND SharedGraphHandle;
49 FLOAT CurrentGpuUsage;
50 ULONG CurrentMemUsage;
51 ULONG CurrentMemSharedUsage;
57 PH_CIRCULAR_BUFFER_FLOAT GpuHistory;
58 PH_CIRCULAR_BUFFER_ULONG MemoryHistory;
59 PH_CIRCULAR_BUFFER_ULONG MemorySharedHistory;
62 static INT_PTR CALLBACK GpuPanelDialogProc(
72 static VOID GpuPropCreateGraphs(
76 Context->GpuGraphHandle = CreateWindow(
79 WS_VISIBLE | WS_CHILD | WS_BORDER,
84 Context->WindowHandle,
91 Context->MemGraphHandle = CreateWindow(
94 WS_VISIBLE | WS_CHILD | WS_BORDER,
99 Context->WindowHandle,
106 Context->SharedGraphHandle = CreateWindow(
109 WS_VISIBLE | WS_CHILD | WS_BORDER,
114 Context->WindowHandle,
122 static VOID GpuPropCreatePanel(
128 Context->PanelHandle = CreateDialogParam(
131 Context->WindowHandle,
137 Context->PanelHandle,
140 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER
143 ShowWindow(Context->PanelHandle, SW_SHOW);
149 MapDialogRect(Context->WindowHandle, &margin);
152 &Context->LayoutManager,
153 Context->PanelHandle,
159 SendMessage(Context->WindowHandle, WM_SIZE, 0, 0);
162 static VOID GpuPropLayoutGraphs(
169 RECT margin = { 13, 13, 13, 13 };
170 RECT innerMargin = { 10, 20, 10, 10 };
177 Context->GpuGraphState.Valid =
FALSE;
178 Context->MemoryGraphState.Valid =
FALSE;
179 Context->MemorySharedGraphState.Valid =
FALSE;
181 GetClientRect(Context->WindowHandle, &clientRect);
184 GetWindowRect(Context->PanelHandle, &panelRect);
185 MapWindowPoints(NULL, Context->WindowHandle, (PPOINT)&panelRect, 2);
186 clientRect.bottom = panelRect.top + 10;
188 graphWidth = clientRect.right - margin.left - margin.right;
189 graphHeight = (clientRect.bottom - margin.top - margin.bottom - between * 2) / 3;
191 deferHandle = BeginDeferWindowPos(6);
193 deferHandle = DeferWindowPos(deferHandle, Context->GpuGroupBox, NULL, margin.left, margin.top, graphWidth, graphHeight, SWP_NOACTIVATE | SWP_NOZORDER);
194 deferHandle = DeferWindowPos(
196 Context->GpuGraphHandle,
198 margin.left + innerMargin.left,
199 margin.top + innerMargin.top,
200 graphWidth - innerMargin.left - innerMargin.right,
201 graphHeight - innerMargin.top - innerMargin.bottom,
202 SWP_NOACTIVATE | SWP_NOZORDER
205 deferHandle = DeferWindowPos(deferHandle, Context->MemGroupBox, NULL, margin.left, margin.top + graphHeight + between, graphWidth, graphHeight, SWP_NOACTIVATE | SWP_NOZORDER);
206 deferHandle = DeferWindowPos(
208 Context->MemGraphHandle,
210 margin.left + innerMargin.left,
211 margin.top + graphHeight + between + innerMargin.top,
212 graphWidth - innerMargin.left - innerMargin.right,
213 graphHeight - innerMargin.top - innerMargin.bottom,
214 SWP_NOACTIVATE | SWP_NOZORDER
217 deferHandle = DeferWindowPos(deferHandle, Context->SharedGroupBox, NULL, margin.left, margin.top + (graphHeight + between) * 2, graphWidth, graphHeight, SWP_NOACTIVATE | SWP_NOZORDER);
218 deferHandle = DeferWindowPos(
220 Context->SharedGraphHandle,
222 margin.left + innerMargin.left,
223 margin.top + (graphHeight + between) * 2 + innerMargin.top,
224 graphWidth - innerMargin.left - innerMargin.right,
225 graphHeight - innerMargin.top - innerMargin.bottom,
226 SWP_NOACTIVATE | SWP_NOZORDER
229 EndDeferWindowPos(deferHandle);
232 static VOID GpuPropUpdateGraphs(
236 Context->GpuGraphState.Valid =
FALSE;
237 Context->GpuGraphState.TooltipIndex = -1;
241 InvalidateRect(Context->GpuGraphHandle, NULL,
FALSE);
243 Context->MemoryGraphState.Valid =
FALSE;
244 Context->MemoryGraphState.TooltipIndex = -1;
248 InvalidateRect(Context->MemGraphHandle, NULL,
FALSE);
250 Context->MemorySharedGraphState.Valid =
FALSE;
251 Context->MemorySharedGraphState.TooltipIndex = -1;
255 InvalidateRect(Context->SharedGraphHandle, NULL,
FALSE);
258 static VOID GpuPropUpdatePanel(
265 if (Context->Block->ProcessItem->QueryHandle)
289 static VOID GpuPropUpdateInfo(
299 PhAddItemCircularBuffer_FLOAT(&Context->GpuHistory, Context->CurrentGpuUsage);
300 PhAddItemCircularBuffer_ULONG(&Context->MemoryHistory, Context->CurrentMemUsage);
301 PhAddItemCircularBuffer_ULONG(&Context->MemorySharedHistory, Context->CurrentMemSharedUsage);
304 static VOID NTAPI ProcessesUpdatedHandler(
305 _In_opt_ PVOID Parameter,
306 _In_opt_ PVOID Context
311 if (!context->Enabled)
314 if (context->WindowHandle)
316 PostMessage(context->WindowHandle,
MSG_UPDATE, 0, 0);
327 LPPROPSHEETPAGE propSheetPage;
334 context = propPageContext->
Context;
352 context->WindowHandle = hwndDlg;
354 context->Enabled =
TRUE;
355 context->GpuGroupBox = GetDlgItem(hwndDlg,
IDC_GROUPGPU);
356 context->MemGroupBox = GetDlgItem(hwndDlg,
IDC_GROUPMEM);
358 propPageContext->
Context = context;
366 PhInitializeCircularBuffer_FLOAT(&context->GpuHistory, sampleCount);
367 PhInitializeCircularBuffer_ULONG(&context->MemoryHistory, sampleCount);
368 PhInitializeCircularBuffer_ULONG(&context->MemorySharedHistory, sampleCount);
370 GpuPropCreateGraphs(context);
371 GpuPropCreatePanel(context);
372 GpuPropUpdateInfo(context);
373 GpuPropUpdatePanel(context);
377 ProcessesUpdatedHandler,
379 &context->ProcessesUpdatedRegistration
391 PhDeleteCircularBuffer_FLOAT(&context->GpuHistory);
392 PhDeleteCircularBuffer_ULONG(&context->MemoryHistory);
393 PhDeleteCircularBuffer_ULONG(&context->MemorySharedHistory);
395 if (context->GpuGraphHandle)
396 DestroyWindow(context->GpuGraphHandle);
397 if (context->MemGraphHandle)
398 DestroyWindow(context->MemGraphHandle);
399 if (context->SharedGraphHandle)
400 DestroyWindow(context->SharedGraphHandle);
401 if (context->PanelHandle)
402 DestroyWindow(context->PanelHandle);
418 LPNMHDR header = (LPNMHDR)lParam;
420 switch (header->code)
423 context->Enabled =
TRUE;
426 context->Enabled =
FALSE;
433 if (header->hwndFrom == context->GpuGraphHandle)
441 context->CurrentGpuUsage * 100
458 if (!context->GpuGraphState.Valid)
460 PhCopyCircularBuffer_FLOAT(&context->GpuHistory, context->GpuGraphState.Data1, drawInfo->
LineDataCount);
461 context->GpuGraphState.Valid =
TRUE;
464 else if (header->hwndFrom == context->MemGraphHandle)
480 &context->MemoryGraphState.
Text->sr,
481 &NormalGraphTextMargin,
482 &NormalGraphTextPadding,
494 &context->MemoryGraphState,
496 context->MemoryHistory.Count
499 if (!context->MemoryGraphState.Valid)
505 context->MemoryGraphState.Data1[i] = (FLOAT)PhGetItemCircularBuffer_ULONG(&context->MemoryHistory, i);
511 context->MemoryGraphState.Data1,
517 context->MemoryGraphState.Valid =
TRUE;
520 else if (header->hwndFrom == context->SharedGraphHandle)
544 &context->MemorySharedGraphState,
546 context->MemorySharedHistory.Count
549 if (!context->MemorySharedGraphState.Valid)
555 context->MemorySharedGraphState.Data1[i] = (FLOAT)PhGetItemCircularBuffer_ULONG(&context->MemorySharedHistory, i);
561 context->MemorySharedGraphState.Data1,
567 context->MemorySharedGraphState.Valid =
TRUE;
578 if (header->hwndFrom == context->GpuGraphHandle)
580 if (context->GpuGraphState.TooltipIndex != getTooltipText->
Index)
582 FLOAT gpuUsage = PhGetItemCircularBuffer_FLOAT(
583 &context->GpuHistory,
584 getTooltipText->
Index
593 getTooltipText->
Text = context->GpuGraphState.TooltipText->sr;
595 else if (header->hwndFrom == context->MemGraphHandle)
597 if (context->MemoryGraphState.TooltipIndex != getTooltipText->
Index)
599 ULONG gpuMemory = PhGetItemCircularBuffer_ULONG(
600 &context->MemoryHistory,
601 getTooltipText->
Index
609 getTooltipText->
Text = context->MemoryGraphState.TooltipText->sr;
611 else if (header->hwndFrom == context->SharedGraphHandle)
613 if (context->MemorySharedGraphState.TooltipIndex != getTooltipText->
Index)
615 ULONG gpuSharedMemory = PhGetItemCircularBuffer_ULONG(
616 &context->MemorySharedHistory,
617 getTooltipText->
Index
625 getTooltipText->
Text = context->MemorySharedGraphState.TooltipText->sr;
635 GpuPropUpdateInfo(context);
636 GpuPropUpdateGraphs(context);
637 GpuPropUpdatePanel(context);
642 GpuPropLayoutGraphs(context);