UI: Region polling support #105088

Merged
Julian Eisel merged 39 commits from JulianEisel/blender:temp-region-poll into main 2023-04-05 15:30:46 +02:00
Member

Introduces ARegionType.poll() as a way to dynamically add/remove a region. The region is still there internally, but is not accessible to the user.

Previously editors would to this manually, by either removing/adding regions altogether, or hiding them, unsetting their alignment (so no AZones are added I assume) and removing their event handlers. Polling makes this much simpler.

We plan to use this in #102879.

This patch refactors multiple editors to use region polling:

  • File Browser
  • Sequencer
  • Clip Editor
  • Preferences

Notes:

  • Previously, editors would lazy-create some of the regions. Versioning is added here to ensure they are always there. Could be a separate patch.
  • Some editors reuse a region in different display modes, and so additional work needs to be done to reinit regions they become available or the mode changes. Typically V2D_IS_INIT is unset for that, which isn't great. Could be improved, but not a new issue.

Behavior change:

  • When the Preferences are opened as a regular editor, the "execution" region in the preferences that displays the Save Preferences button would still be there, but empty with a scrollbar.
    This patch makes it disappear entirely.

Implementation

  • Introduces ARegionType.poll()
  • Before a window is drawn, all contained regions have their poll checked, and the result is stored in a flag (RGN_FLAG_POLL_FAILED - runtime-only flag).
  • If the result of the poll changes, the area is re-initialized and event handlers are added/removed.
  • UI code checks the flag as needed.
Introduces *ARegionType.poll()* as a way to dynamically add/remove a region. The region is still there internally, but is not accessible to the user. Previously editors would to this manually, by either removing/adding regions altogether, or hiding them, unsetting their alignment (so no AZones are added I assume) and removing their event handlers. Polling makes this much simpler. We plan to use this in #102879. This patch refactors multiple editors to use region polling: - File Browser - Sequencer - Clip Editor - Preferences Notes: - Previously, editors would lazy-create some of the regions. Versioning is added here to ensure they are always there. Could be a separate patch. - Some editors reuse a region in different display modes, and so additional work needs to be done to reinit regions they become available or the mode changes. Typically `V2D_IS_INIT` is unset for that, which isn't great. Could be improved, but not a new issue. Behavior change: - When the Preferences are opened as a regular editor, the "execution" region in the preferences that displays the *Save Preferences* button would still be there, but empty with a scrollbar. <img src="https://projects.blender.org/attachments/56e2e54d-ca76-4073-af06-b786b59262b2" width="400"/> This patch makes it disappear entirely. ## Implementation - Introduces `ARegionType.poll()` - Before a window is drawn, all contained regions have their poll checked, and the result is stored in a flag (`RGN_FLAG_POLL_FAILED` - runtime-only flag). - If the result of the poll changes, the area is re-initialized and event handlers are added/removed. - UI code checks the flag as needed.
Julian Eisel added 25 commits 2023-02-22 18:32:05 +01:00
33bcc4f430 Initial "All" asset library loading support
An "All" asset library can be selected in the Asset Browser and asset
view templates now, and that will load all assets from all asset
libraries. Preview loading, drag & drop and asset catalogs don't work
yet.
d51212c4f0 Integrate "All" library better with the asset system
Now it actually loads data from all asset libraries when this is
selected. The asset representations still need to be loaded by the file
browser backend, this won't change for now.

This adds the concept of nested asset libraries, which I'd prefer to
keep as implementation detail and not expose in the API. But for now
it's needed (for the asset representation loading by the file browser
backend).
126136baab Fix missing asset previews and broken drag & drop in "All" library
Together with the changes made in master, all this does is making sure
the assets are loaded and removed using the correct asset library nested
within the "All" library. Now full paths for the assets can be built
correctly from the asset identifier, which fixes preview loading and
drag & drop.
fb2303fb73 Avoid ugly nested library storage
We actually don't have to do this, since we can just iterate over all
loaded libraries after calling the loading for the "All" asset library.
af5d225653 Load catalogs for "All" asset library
Merges the catalog definitions from all asset libraries in to the
storage of the "All" one, builds the catalog tree and refreshes data as
needed. This doesn't allow writing changes back to the catalog
definition files, so the UI probably shouldn't allow edits.
ecc25bc62e Use "All" library for node add menu building
Code was manually building the add menu from all asset libraries, this
should be simpler now.
11abc1be39 Use "All" library for node search menu building
Code was manually building the search menu items from all asset
libraries, this is simpler now.
747a9ea263 Make catalogs from "All" library read-only
Loading the asset library will create a read-only catalog service. The
read-only nature is not dealt with much in the asset catalog code, the
using code (e.g. the UI) is responsible for respecting it.
3cd93ace24 Simple progress reporting for all library
Progress bar display the file reading (and other operations) is actually
broken in master for a while, so this won't actually be reported. Still
calculate it for once it's fixed.
fa817e0c71 Remove asset-shelf region code
This is out of scope of this branch, there's the dedicated `asset-shelf`
branch.
Julian Eisel added 2 commits 2023-02-23 15:50:41 +01:00
Julian Eisel added 2 commits 2023-02-23 19:20:11 +01:00
2bbe699bc1 Use region polling in clip editor
Makes the region management code quite a bit simpler for the clip
editor. A small trade-off is more versioning code.
Julian Eisel added 1 commit 2023-02-23 19:29:38 +01:00
ca7b094bcc Use poll functions for Preferences execution region
Previously we'd hide the "execution" region (containing the Save
Preferences button) when the header is visible, which would contain the
button instead. It was possible to unhide it, which made it behave
glitchy. Now it reliably "removes" is and brings it back when needed
(it's not really removed, only from what the user can tell).
Julian Eisel added this to the User Interface project 2023-02-23 19:31:37 +01:00
Julian Eisel added the
Interest
User Interface
label 2023-02-23 19:31:48 +01:00
Julian Eisel changed title from WIP: UI: Region polling support to UI: Region polling support 2023-02-23 19:32:19 +01:00
Julian Eisel requested review from Campbell Barton 2023-02-24 18:21:28 +01:00
Julian Eisel requested review from Hans Goudey 2023-02-24 18:21:28 +01:00
Hans Goudey approved these changes 2023-03-03 23:18:47 +01:00
Hans Goudey left a comment
Member

The big picture seems like an improvement. The region management in most editors was a bit ugly and this is a more general solution.

The big picture seems like an improvement. The region management in most editors was a bit ugly and this is a more general solution.
@ -164,6 +164,11 @@ typedef struct ARegionType {
void (*init)(struct wmWindowManager *wm, struct ARegion *region);
/* exit is called when the region is hidden or removed */
void (*exit)(struct wmWindowManager *wm, struct ARegion *region);
/** Optional callback to decide whether the region should be treated as existing given the
Member
  /** 
   * Optional callback to decide whether the region should be treated as existing given the
   * current context. When returning false, the region will be kept in storage, but is not
   * available to the user in any way. Callbacks can assume that context has the owning area and
   * space-data set.
   */
``` /** * Optional callback to decide whether the region should be treated as existing given the * current context. When returning false, the region will be kept in storage, but is not * available to the user in any way. Callbacks can assume that context has the owning area and * space-data set. */
JulianEisel marked this conversation as resolved
@ -2081,0 +2090,4 @@
case SPACE_FILE: {
ARegion *new_region;
new_region = do_versions_add_region_if_not_found(
Member

How about something like this?

  if (ARegion *new_region = do_versions_add_region_if_not_found(
          regionbase, RGN_TYPE_EXECUTE, "versioning: execute region for file", RGN_TYPE_UI)) {
    new_region->alignment = RGN_ALIGN_BOTTOM;
    new_region->flag = RGN_FLAG_DYNAMIC_SIZE;
  }
How about something like this? ```c++ if (ARegion *new_region = do_versions_add_region_if_not_found( regionbase, RGN_TYPE_EXECUTE, "versioning: execute region for file", RGN_TYPE_UI)) { new_region->alignment = RGN_ALIGN_BOTTOM; new_region->flag = RGN_FLAG_DYNAMIC_SIZE; } ```
JulianEisel marked this conversation as resolved
@ -49,0 +53,4 @@
ARegion *do_versions_ensure_region(ListBase *regionbase,
int region_type,
const char *allocname,
Member

Do we really need to pass a name for the allocation here? Are we finding memory leaks that aren't easily found with ASAN nowadays?

Do we really need to pass a name for the allocation here? Are we finding memory leaks that aren't easily found with ASAN nowadays?
@ -49,0 +66,4 @@
}
}
ARegion *new_region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), allocname));
Member

MEM_callocN -> MEM_cnew

`MEM_callocN` -> `MEM_cnew`
JulianEisel marked this conversation as resolved
Julian Eisel added 5 commits 2023-03-20 15:06:43 +01:00
Julian Eisel reviewed 2023-03-20 15:32:34 +01:00
@ -49,0 +53,4 @@
ARegion *do_versions_ensure_region(ListBase *regionbase,
int region_type,
const char *allocname,
Author
Member

I think it's useful. I use it fairly often, and not everybody has ASan enabled. But sure, with ASan you don't need it I guess.

I think it's useful. I use it fairly often, and not everybody has ASan enabled. But sure, with ASan you don't need it I guess.
Julian Eisel added 1 commit 2023-03-20 15:33:06 +01:00
Julian Eisel modified the project from User Interface to Brush Assets & Asset Shelf 2023-03-30 13:00:11 +02:00
Campbell Barton requested changes 2023-04-05 12:41:21 +02:00
Campbell Barton left a comment
Owner

Overall this patch seems fine, one request inline.

Overall this patch seems fine, one request inline.
@ -167,0 +170,4 @@
* available to the user in any way. Callbacks can assume that context has the owning area and
* space-data set.
*/
bool (*poll)(const struct bContext *C);

As this function runs a lot I think it would be best to take screen variables directly, e.g. (wm, area, region) arguments and not set the context.


To expand on this, in tests with some basic interaction the region_poll function runs ~19 times on frame change with the default scene, the same on mouse wheel and mouse motion with some modal operators.
Testing some basic interactivity - this function can run 10's of thousands of times in a minute or so
While I don't see this as a problem for simple checks - passing in the necessary arguments ensures slower lookups aren't used. It's also in keeping with other callbacks which take windowing arguments.

Even in this patch the function calls for data-access aren't as directly as they might be: CTX_wm_space_clip(C) calls into CTX_wm_area(..) -> ctx_wm_python_context_get(..), then CTX_py_dict_get(C) & BLI_thread_is_main().

If you anticipate needing access to data besides the area/region in the future, a parameters struct could be used instead of multiple arguments - so the scene or window can be added without having to update the function signature for every poll() function.

As this function runs a _lot_ I think it would be best to take screen variables directly, e.g. `(wm, area, region)` arguments and not set the context. ---- To expand on this, in tests with some basic interaction the `region_poll` function runs ~19 times on frame change with the default scene, the same on mouse wheel and mouse motion with some modal operators. Testing some basic interactivity - this function can run 10's of thousands of times in a minute or so While I don't see this as a problem for simple checks - passing in the necessary arguments ensures slower lookups aren't used. It's also in keeping with other callbacks which take windowing arguments. Even in this patch the function calls for data-access aren't as directly as they might be: `CTX_wm_space_clip(C)` calls into `CTX_wm_area(..)` -> `ctx_wm_python_context_get(..)`, then `CTX_py_dict_get(C)` & `BLI_thread_is_main()`. If you anticipate needing access to data besides the area/region in the future, a parameters struct could be used instead of multiple arguments - so the scene or window can be added without having to update the function signature for every poll() function.
JulianEisel marked this conversation as resolved
Julian Eisel added 2 commits 2023-04-05 13:12:42 +02:00
Julian Eisel added 1 commit 2023-04-05 13:18:04 +02:00
Julian Eisel reviewed 2023-04-05 13:19:22 +02:00
@ -164,6 +172,13 @@ typedef struct ARegionType {
void (*init)(struct wmWindowManager *wm, struct ARegion *region);
/* exit is called when the region is hidden or removed */
Author
Member

Doesn't seem like a real issue, for the majority of regions there is no poll function and so region_poll() early exists before any context access. But sure, easy enough of a change.

Doesn't seem like a real issue, for the majority of regions there is no poll function and so `region_poll()` early exists before any context access. But sure, easy enough of a change.
Julian Eisel requested review from Campbell Barton 2023-04-05 13:19:37 +02:00
Campbell Barton approved these changes 2023-04-05 14:15:22 +02:00
Julian Eisel merged commit fa0f295b53 into main 2023-04-05 15:30:46 +02:00
Julian Eisel deleted branch temp-region-poll 2023-04-05 15:30:47 +02: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 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#105088
No description provided.