GHOST/WIN32: remove start time offset from getMilliSeconds #117618

Manually merged
Campbell Barton merged 1 commits from ideasman42/blender:pr-win32-time-offset into main 2024-02-07 23:25:08 +01:00

This isn't necessary and has been removed from macOS & X11,
Wayland never did this.

Besides removing the offset GetTickCount() has been replaced by
GetTickCount64 to prevent 32bit rollover when high resolution timers
aren't supported.


GetTickCount64 is supported by Windows Vista and newer.

This isn't necessary and has been removed from macOS & X11, Wayland never did this. Besides removing the offset GetTickCount() has been replaced by GetTickCount64 to prevent 32bit rollover when high resolution timers aren't supported. --- GetTickCount64 is supported by Windows Vista and newer.
Author
Owner

@blender-bot build windows

@blender-bot build windows
Campbell Barton force-pushed pr-win32-time-offset from c4a5970132 to c2390b4da5 2024-01-29 02:11:17 +01:00 Compare
Campbell Barton requested review from Harley Acheson 2024-01-29 02:26:32 +01:00
Campbell Barton force-pushed pr-win32-time-offset from c2390b4da5 to dcc54ad7c9 2024-01-29 02:28:27 +01:00 Compare
Campbell Barton requested review from Ray molenkamp 2024-01-29 02:30:40 +01:00
Member

@ideasman42

Sorry for the delay in looking at this.

With this PR we are saying that for these message times we don't care what the actual values are as we only care about the differences between them. So we can have the values be an amount of time since the computer was turned on, rather than from when blender was started. That does simplify things.

The only thing I noticed while testing this is a problem that already exists in that getMessageTime so it is hard to change that without fixing that too.

On Blender startup we currently call getMessageTime four times or so before we get any Windows messages in our queue. In that state the return of GetMessageTime() is zero. GetTickCount still gives a proper value so we end up calculating a delta that is a negative value equal to the number of ticks since the system was started.

I think we need that function to look something like?

static uint64_t getMessageTime(GHOST_SystemWin32 *system)
{
  /* Get difference between last message time and now. */
  int64_t t_delta = 0;
  int64_t message_time = GetMessageTime();
  if (message_time > 0) {
    t_delta = message_time - GetTickCount();
    /* Handle 32-bit rollover. */
    if (t_delta > 0) {
      t_delta -= int64_t(UINT32_MAX) + 1;
    }
  }

  /* Return message time as 64-bit milliseconds with the delta applied. */
  return system->getMilliSeconds() + t_delta;
}

@ideasman42 Sorry for the delay in looking at this. With this PR we are saying that for these message times we don't care what the actual values are as we only care about the differences between them. So we can have the values be an amount of time since the computer was turned on, rather than from when blender was started. That does simplify things. The only thing I noticed while testing this is a problem that already exists in that `getMessageTime` so it is hard to change that without fixing that too. On Blender startup we currently call `getMessageTime` four times or so before we get any Windows messages in our queue. In that state the return of GetMessageTime() is zero. `GetTickCount` still gives a proper value so we end up calculating a delta that is a negative value equal to the number of ticks since the system was started. I think we need that function to look something like? ``` static uint64_t getMessageTime(GHOST_SystemWin32 *system) { /* Get difference between last message time and now. */ int64_t t_delta = 0; int64_t message_time = GetMessageTime(); if (message_time > 0) { t_delta = message_time - GetTickCount(); /* Handle 32-bit rollover. */ if (t_delta > 0) { t_delta -= int64_t(UINT32_MAX) + 1; } } /* Return message time as 64-bit milliseconds with the delta applied. */ return system->getMilliSeconds() + t_delta; } ```
Member

ideally getMessageTime shouldn't be called unless we're handling a message, where do those 4 calls originate? can we eliminate them?

ideally `getMessageTime` shouldn't be called unless we're handling a message, where do those 4 calls originate? can we eliminate them?
Member

When we are creating the window, so within GHOST_WindowWin32() but near the very end of it, we call ::UpdateWindow(m_hWnd); with a comment of "Force an initial paint of the window" (GHOST_WindowWin32.cc at around line 209). This causes use to get WM_ACTIVATE, WM_SIZE, WM_MOVE, and then WM_PAINT. While processing these messages the return of GetMessageTime () is zero.

Yes, there is nothing that looks weird if UpdateWindow() is not called.

When we are creating the window, so within `GHOST_WindowWin32()` but near the very end of it, we call `::UpdateWindow(m_hWnd);` with a comment of "Force an initial paint of the window" (GHOST_WindowWin32.cc at around line 209). This causes use to get WM_ACTIVATE, WM_SIZE, WM_MOVE, and then WM_PAINT. While processing these messages the return of GetMessageTime () is zero. Yes, there is nothing that looks weird if UpdateWindow() is not called.
Member

@LazyDodo - So we could take this PR as it is, and remove that UpdateWindow() separately.

@LazyDodo - So we could take this PR as it is, and remove that UpdateWindow() separately.
Member

Looking into this further it looks like we can skip UpdateWindow. Will make a separate PR for that.

Looking into this further it looks like we can skip UpdateWindow. Will make a separate PR for that.
Harley Acheson approved these changes 2024-02-07 22:44:01 +01:00
Member

Further cleanup can be done, QueryPerformanceFrequency is guaranteed to return true on XP+ so m_hasPerformanceCounter will never ever be false...

Further cleanup can be done, `QueryPerformanceFrequency` is guaranteed to return true on XP+ so `m_hasPerformanceCounter` will never ever be false...
Campbell Barton manually merged commit 67c12236e6 into main 2024-02-07 23:25:08 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117618
No description provided.