Blender V4.3
wm_draw.cc File Reference
#include <cstdlib>
#include <cstring>
#include "DNA_camera_types.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "DNA_view3d_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector_types.hh"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "BKE_image.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "GHOST_C-api.h"
#include "ED_node.hh"
#include "ED_screen.hh"
#include "ED_view3d.hh"
#include "GPU_batch_presets.hh"
#include "GPU_capabilities.hh"
#include "GPU_context.hh"
#include "GPU_debug.hh"
#include "GPU_framebuffer.hh"
#include "GPU_immediate.hh"
#include "GPU_matrix.hh"
#include "GPU_state.hh"
#include "GPU_texture.hh"
#include "GPU_viewport.hh"
#include "RE_engine.h"
#include "WM_api.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "wm.hh"
#include "wm_draw.hh"
#include "wm_event_system.hh"
#include "wm_surface.hh"
#include "wm_window.hh"
#include "UI_resources.hh"

Go to the source code of this file.

Classes

struct  GrabState
 
struct  WindowDrawCB
 

Macros

#define SPACE_NAME(space)
 

Functions

Internal Utilities
static bool wm_window_grab_warp_region_is_set (const wmWindow *win)
 
static bool wm_draw_region_stereo_set (Main *bmain, ScrArea *area, ARegion *region, eStereoViews sview)
 
static void wm_region_test_gizmo_do_draw (bContext *C, ScrArea *area, ARegion *region, bool tag_redraw)
 
static void wm_region_test_render_do_draw (const Scene *scene, Depsgraph *depsgraph, ScrArea *area, ARegion *region)
 
static bool wm_region_use_viewport_by_type (short space_type, short region_type)
 
bool WM_region_use_viewport (ScrArea *area, ARegion *region)
 
static const char * wm_area_name (ScrArea *area)
 
Draw Paint Cursor
static void wm_paintcursor_draw (bContext *C, ScrArea *area, ARegion *region)
 
Post Draw Region on display handlers
static void wm_region_draw_overlay (bContext *C, const ScrArea *area, ARegion *region)
 
Window Drawing (Draw All)

Reference method, draw all each time.

void * WM_draw_cb_activate (wmWindow *win, void(*draw)(const wmWindow *win, void *customdata), void *customdata)
 
void WM_draw_cb_exit (wmWindow *win, void *handle)
 
static void wm_draw_callbacks (wmWindow *win)
 
Region Drawing

Each region draws into its own frame-buffer, which is then blit on the window draw buffer. This helps with fast redrawing if only some regions change. It also means we can share a single context for multiple windows, so that for example VAOs can be shared between windows.

static void wm_draw_region_buffer_free (ARegion *region)
 
static void wm_draw_offscreen_texture_parameters (GPUOffScreen *offscreen)
 
static eGPUTextureFormat get_hdr_framebuffer_format (const Scene *scene)
 
static void wm_draw_region_buffer_create (Scene *scene, ARegion *region, bool stereo, bool use_viewport)
 
static void wm_draw_region_bind (ARegion *region, int view)
 
static void wm_draw_region_unbind (ARegion *region)
 
static void wm_draw_region_blit (ARegion *region, int view)
 
GPUTexture * wm_draw_region_texture (ARegion *region, int view)
 
void wm_draw_region_blend (ARegion *region, int view, bool blend)
 
GPUViewportWM_draw_region_get_viewport (ARegion *region)
 
GPUViewportWM_draw_region_get_bound_viewport (ARegion *region)
 
static void wm_draw_window_offscreen (bContext *C, wmWindow *win, bool stereo)
 
static void wm_draw_window_onscreen (bContext *C, wmWindow *win, int view)
 
static void wm_draw_window (bContext *C, wmWindow *win)
 
static void wm_draw_surface (bContext *C, wmSurface *surface)
 
Window Screen Shot Utility (Front-Buffer & Off-Screen)

Include here since it can involve low level buffer switching.

uint8_tWM_window_pixels_read_from_frontbuffer (const wmWindowManager *wm, const wmWindow *win, int r_size[2])
 
void WM_window_pixels_read_sample_from_frontbuffer (const wmWindowManager *wm, const wmWindow *win, const int pos[2], float r_col[3])
 
uint8_tWM_window_pixels_read_from_offscreen (bContext *C, wmWindow *win, int r_size[2])
 
bool WM_window_pixels_read_sample_from_offscreen (bContext *C, wmWindow *win, const int pos[2], float r_col[3])
 
uint8_tWM_window_pixels_read (bContext *C, wmWindow *win, int r_size[2])
 
bool WM_window_pixels_read_sample (bContext *C, wmWindow *win, const int pos[2], float r_col[3])
 
bool WM_desktop_cursor_sample_read (float r_col[3])
 
Main Update Call
static bool wm_draw_update_test_window (Main *bmain, bContext *C, wmWindow *win)
 
static void wm_draw_update_clear_window (bContext *C, wmWindow *win)
 
void WM_paint_cursor_tag_redraw (wmWindow *win, ARegion *)
 
void wm_draw_update (bContext *C)
 
void wm_draw_region_clear (wmWindow *win, ARegion *)
 
void WM_draw_region_free (ARegion *region)
 
void wm_draw_region_test (bContext *C, ScrArea *area, ARegion *region)
 
void WM_redraw_windows (bContext *C)
 
Region Viewport Drawing

This is needed for viewport drawing for operator use (where the viewport may not have drawn yet).

Otherwise avoid using these since they're exposing low level logic externally.

void WM_draw_region_viewport_ensure (Scene *scene, ARegion *region, short space_type)
 
void WM_draw_region_viewport_bind (ARegion *region)
 
void WM_draw_region_viewport_unbind (ARegion *region)
 

Draw Software Cursor

Draw the cursor instead of relying on the graphical environment. Needed when setting the cursor position (warping) isn't supported (GHOST/WAYLAND).

struct { 
 
   int8_t   enabled 
 
   int   winid 
 
   int   xy [2] 
 
g_software_cursor 
 
static bool wm_software_cursor_needed ()
 
static bool wm_software_cursor_needed_for_window (const wmWindow *win, GrabState *grab_state)
 
static bool wm_software_cursor_motion_test (const wmWindow *win)
 
static void wm_software_cursor_motion_update (const wmWindow *win)
 
static void wm_software_cursor_motion_clear ()
 
static void wm_software_cursor_motion_clear_with_window (const wmWindow *win)
 
static void wm_software_cursor_draw_bitmap (const int event_xy[2], const GHOST_CursorBitmapRef *bitmap)
 
static void wm_software_cursor_draw_crosshair (const int event_xy[2])
 
static void wm_software_cursor_draw (wmWindow *win, const GrabState *grab_state)
 

Detailed Description

Handle OpenGL buffers for windowing, also paint cursor.

Definition in file wm_draw.cc.

Macro Definition Documentation

◆ SPACE_NAME

#define SPACE_NAME ( space)
Value:
case space: \
return #space;

Referenced by wm_area_name().

Function Documentation

◆ get_hdr_framebuffer_format()

static eGPUTextureFormat get_hdr_framebuffer_format ( const Scene * scene)
static

◆ wm_area_name()

◆ WM_desktop_cursor_sample_read()

bool WM_desktop_cursor_sample_read ( float r_col[3])

Return the color of the pixel at the current mouse cursor position on the desktop, whether in a Blender window or not. Returns false on failure or if not supported by the platform.

Definition at line 1428 of file wm_draw.cc.

References GHOST_GetPixelAtCursor().

Referenced by eyedropper_color_sample_fl().

◆ wm_draw_callbacks()

static void wm_draw_callbacks ( wmWindow * win)
static

Definition at line 631 of file wm_draw.cc.

References wmWindow::drawcalls, and LISTBASE_FOREACH.

Referenced by wm_draw_window_onscreen().

◆ WM_draw_cb_activate()

void * WM_draw_cb_activate ( wmWindow * win,
void(* draw )(const wmWindow *win, void *customdata),
void * customdata )

◆ WM_draw_cb_exit()

◆ wm_draw_offscreen_texture_parameters()

static void wm_draw_offscreen_texture_parameters ( GPUOffScreen * offscreen)
static

◆ wm_draw_region_bind()

static void wm_draw_region_bind ( ARegion * region,
int view )
static

◆ wm_draw_region_blend()

◆ wm_draw_region_blit()

static void wm_draw_region_blit ( ARegion * region,
int view )
static

Definition at line 782 of file wm_draw.cc.

References GPU_offscreen_draw_to_screen(), and GPU_viewport_draw_to_screen().

Referenced by wm_draw_window_onscreen().

◆ wm_draw_region_buffer_create()

◆ wm_draw_region_buffer_free()

static void wm_draw_region_buffer_free ( ARegion * region)
static

◆ wm_draw_region_clear()

void wm_draw_region_clear ( wmWindow * win,
ARegion * region )

Definition at line 1597 of file wm_draw.cc.

References WM_window_get_active_screen().

Referenced by ui_region_temp_remove().

◆ WM_draw_region_free()

void WM_draw_region_free ( ARegion * region)

◆ WM_draw_region_get_bound_viewport()

GPUViewport * WM_draw_region_get_bound_viewport ( ARegion * region)

◆ WM_draw_region_get_viewport()

◆ wm_draw_region_stereo_set()

◆ wm_draw_region_test()

◆ wm_draw_region_texture()

GPUTexture * wm_draw_region_texture ( ARegion * region,
int view )

Definition at line 808 of file wm_draw.cc.

References GPU_offscreen_color_texture(), and GPU_viewport_color_texture().

Referenced by wm_draw_region_blend().

◆ wm_draw_region_unbind()

static void wm_draw_region_unbind ( ARegion * region)
static

◆ WM_draw_region_viewport_bind()

void WM_draw_region_viewport_bind ( ARegion * region)

Definition at line 1652 of file wm_draw.cc.

References wm_draw_region_bind().

Referenced by ED_view3d_depth_override(), and ui_region_redraw_immediately().

◆ WM_draw_region_viewport_ensure()

void WM_draw_region_viewport_ensure ( Scene * scene,
ARegion * region,
short space_type )

◆ WM_draw_region_viewport_unbind()

void WM_draw_region_viewport_unbind ( ARegion * region)

Definition at line 1657 of file wm_draw.cc.

References wm_draw_region_unbind().

Referenced by ED_view3d_depth_override(), and ui_region_redraw_immediately().

◆ wm_draw_surface()

static void wm_draw_surface ( bContext * C,
wmSurface * surface )
static

Draw offscreen contexts not bound to a specific window.

Definition at line 1248 of file wm_draw.cc.

References CTX_wm_manager(), GPU_context_begin_frame(), GPU_context_end_frame(), wm_surface_clear_drawable(), wm_surface_make_drawable(), and wm_window_clear_drawable().

Referenced by wm_draw_update().

◆ wm_draw_update()

◆ wm_draw_update_clear_window()

static void wm_draw_update_clear_window ( bContext * C,
wmWindow * win )
static

◆ wm_draw_update_test_window()

◆ wm_draw_window()

◆ wm_draw_window_offscreen()

◆ wm_draw_window_onscreen()

◆ WM_paint_cursor_tag_redraw()

◆ wm_paintcursor_draw()

◆ WM_redraw_windows()

void WM_redraw_windows ( bContext * C)

High level function to redraw windows.

Warning
this should be avoided by operators and low-level IO functionality because drawing relies on the event system & depsgraph preparing data for display. An explicit call to draw is error prone since it may attempt to show stale data.

With some rare exceptions which require a redraw (screen-shot & sample screen color for e.g.) explicitly redrawing should be avoided, see: #92704, #93950, #97627 & #98462.

Definition at line 1621 of file wm_draw.cc.

References CTX_wm_area(), CTX_wm_area_set(), CTX_wm_region(), CTX_wm_region_set(), CTX_wm_window(), CTX_wm_window_set(), and wm_draw_update().

Referenced by sample_color_exec(), sample_color_invoke(), and screenshot_data_create().

◆ wm_region_draw_overlay()

static void wm_region_draw_overlay ( bContext * C,
const ScrArea * area,
ARegion * region )
static

Definition at line 380 of file wm_draw.cc.

References CTX_wm_window(), UI_SetTheme(), wmViewport(), and wmWindowViewport().

Referenced by wm_draw_window_onscreen().

◆ wm_region_test_gizmo_do_draw()

◆ wm_region_test_render_do_draw()

◆ WM_region_use_viewport()

bool WM_region_use_viewport ( ScrArea * area,
ARegion * region )

◆ wm_region_use_viewport_by_type()

static bool wm_region_use_viewport_by_type ( short space_type,
short region_type )
static

◆ wm_software_cursor_draw()

◆ wm_software_cursor_draw_bitmap()

◆ wm_software_cursor_draw_crosshair()

static void wm_software_cursor_draw_crosshair ( const int event_xy[2])
static

◆ wm_software_cursor_motion_clear()

static void wm_software_cursor_motion_clear ( )
static

Definition at line 225 of file wm_draw.cc.

References g_software_cursor.

Referenced by wm_software_cursor_motion_clear_with_window().

◆ wm_software_cursor_motion_clear_with_window()

static void wm_software_cursor_motion_clear_with_window ( const wmWindow * win)
static

◆ wm_software_cursor_motion_test()

static bool wm_software_cursor_motion_test ( const wmWindow * win)
static

Definition at line 210 of file wm_draw.cc.

References wmWindow::eventstate, g_software_cursor, wmWindow::winid, and wmEvent::xy.

Referenced by wm_draw_update_test_window().

◆ wm_software_cursor_motion_update()

static void wm_software_cursor_motion_update ( const wmWindow * win)
static

Definition at line 217 of file wm_draw.cc.

References wmWindow::eventstate, g_software_cursor, wmWindow::winid, and wmEvent::xy.

Referenced by wm_draw_window_onscreen().

◆ wm_software_cursor_needed()

static bool wm_software_cursor_needed ( )
static

◆ wm_software_cursor_needed_for_window()

static bool wm_software_cursor_needed_for_window ( const wmWindow * win,
GrabState * grab_state )
static

◆ wm_window_grab_warp_region_is_set()

static bool wm_window_grab_warp_region_is_set ( const wmWindow * win)
static

Return true when the cursor is grabbed and wrapped within a region.

Definition at line 74 of file wm_draw.cc.

References bounds(), ELEM, GHOST_GetCursorGrabState(), GHOST_kGrabHide, GHOST_kGrabWrap, wmWindow::ghostwin, and wmWindow::grabcursor.

Referenced by wm_paintcursor_draw().

◆ WM_window_pixels_read()

uint8_t * WM_window_pixels_read ( bContext * C,
wmWindow * win,
int r_size[2] )

Read from the screen.

Note
Use off-screen drawing when front-buffer reading is not supported.

Definition at line 1411 of file wm_draw.cc.

References CTX_wm_manager(), WM_capabilities_flag(), WM_CAPABILITY_GPU_FRONT_BUFFER_READ, WM_window_pixels_read_from_frontbuffer(), and WM_window_pixels_read_from_offscreen().

Referenced by screenshot_data_create().

◆ WM_window_pixels_read_from_frontbuffer()

uint8_t * WM_window_pixels_read_from_frontbuffer ( const wmWindowManager * wm,
const wmWindow * win,
int r_size[2] )

Read pixels from the front-buffer (fast).

Note
Internally this depends on the front-buffer state, for a slower but more reliable method of reading pixels, use WM_window_pixels_read_from_offscreen. Fast pixel access may be preferred for file-save thumbnails.
Warning
Drawing (swap-buffers) immediately before calling this function causes the front-buffer state to be invalid under some EGL configurations.

Definition at line 1271 of file wm_draw.cc.

References GHOST_ActivateWindowDrawingContext(), wmWindow::ghostwin, GPU_context_active_set(), GPU_DATA_UBYTE, GPU_frontbuffer_read_color(), wmWindow::gpuctx, MEM_mallocN, wmWindowManager::windrawable, and WM_window_native_pixel_size().

Referenced by blend_file_thumb_from_screenshot(), and WM_window_pixels_read().

◆ WM_window_pixels_read_from_offscreen()

uint8_t * WM_window_pixels_read_from_offscreen ( bContext * C,
wmWindow * win,
int r_size[2] )

Draw the window & read pixels from an off-screen buffer (slower than WM_window_pixels_read_from_frontbuffer).

Note
This is needed because the state of the front-buffer may be damaged (see in-line code comments for details).

Definition at line 1341 of file wm_draw.cc.

References get_hdr_framebuffer_format(), GPU_DATA_UBYTE, GPU_offscreen_bind(), GPU_offscreen_create(), GPU_offscreen_free(), GPU_offscreen_read_color(), GPU_offscreen_unbind(), GPU_TEXTURE_USAGE_SHADER_READ, MEM_mallocN, UNLIKELY, wm_draw_window_onscreen(), WM_window_get_active_scene(), and WM_window_native_pixel_size().

Referenced by WM_window_pixels_read().

◆ WM_window_pixels_read_sample()

bool WM_window_pixels_read_sample ( bContext * C,
wmWindow * win,
const int pos[2],
float r_col[3] )

Read a single pixel from the screen.

Note
Use off-screen drawing when front-buffer reading is not supported.

Definition at line 1419 of file wm_draw.cc.

References CTX_wm_manager(), pos, WM_capabilities_flag(), WM_CAPABILITY_GPU_FRONT_BUFFER_READ, WM_window_pixels_read_sample_from_frontbuffer(), and WM_window_pixels_read_sample_from_offscreen().

Referenced by eyedropper_color_sample_fl(), and paint_sample_color().

◆ WM_window_pixels_read_sample_from_frontbuffer()

void WM_window_pixels_read_sample_from_frontbuffer ( const wmWindowManager * wm,
const wmWindow * win,
const int pos[2],
float r_col[3] )

◆ WM_window_pixels_read_sample_from_offscreen()

Variable Documentation

◆ enabled

int8_t enabled

Definition at line 168 of file wm_draw.cc.

◆ [struct]

struct { ... } g_software_cursor

◆ winid

◆ xy

int xy[2]

Definition at line 170 of file wm_draw.cc.

Referenced by actionzone_area_poll(), area_actionzone_refresh_xy(), area_event_inside(), BKE_area_find_region_xy(), BKE_maskrasterize_handle_sample(), BKE_screen_area_map_find_area_xy(), BKE_screen_find_area_xy(), BKE_screen_find_main_region_at_xy(), BKE_screen_find_region_xy(), BLI_rctf_clamp_pt_v(), BLI_rctf_do_minmax_v(), BLI_rctf_init_pt_radius(), BLI_rctf_isect_circle(), BLI_rctf_isect_pt_v(), BLI_rcti_clamp_pt_v(), BLI_rcti_do_minmax_v(), BLI_rcti_init_pt_radius(), BLI_rcti_isect_circle(), BLI_rcti_isect_pt_v(), btMatrix3x3(), blender::nodes::node_shader_tex_gabor_cc::GaborNoiseFunction::call(), blender::ed::outliner::collection_drop_init(), blender::ed::outliner::collection_drop_tooltip(), CreateMatrix(), data_device_handle_drop(), draw_seq_in_view(), dropbox_tooltip(), ED_area_actionzone_find_xy(), ED_area_azones_update(), ED_armature_pick_bone(), ed_armature_pick_bone_impl(), ED_armature_pick_ebone(), ED_armature_pick_pchan(), ED_screen_set_active_region(), eyedropper_draw_cursor_text_ex(), eyedropper_draw_cursor_text_region(), blender::ui::AbstractTreeView::find_hovered(), blender::ed::transform::flushTransNodes(), blender::ed::greasepencil::generate_corner(), GHOST_SystemWayland::getAllDisplayDimensions(), KDL::Vector2::GetValue(), blender::compositor::FastGaussianBlurOperation::IIR_gauss(), keyframe_region_circle_test(), keyframe_region_lasso_test(), layer_bucket_depth_from_xy(), layer_bucket_index_from_xy(), maskrasterize_buffer_cb(), maskrasterize_layer_isect(), blender::ed::outliner::outliner_drop_insert_collection_find(), blender::ed::outliner::outliner_drop_insert_find(), blender::compositor::DisplaceOperation::pixel_transform(), blender::compositor::MapUVOperation::pixel_transform(), region_event_inside(), blender::ui::region_views_find_drop_target_at(), relative_pointer_handle_relative_motion_impl(), sample_uniform_cone(), sample_uniform_hemisphere(), ScaleAlongAxis(), screen_actionzone_find_xy(), screen_cursor_set(), sequencer_drop_copy(), setRotation(), setValue(), blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAALumaEdgeDetectionPS(), blender::eevee::IrradianceBake::surfels_create(), textview_draw(), textview_draw_sel(), ui_block_bounds_calc_centered_pie(), ui_block_bounds_calc_popup(), UI_block_end_ex(), ui_block_find_mouse_over_ex(), ui_but_contains_point_px(), ui_but_find_mouse_over_ex(), ui_drag_toggle_set(), ui_list_find_mouse_over_ex(), ui_list_row_find_mouse_over(), ui_mouse_motion_towards_check(), ui_mouse_motion_towards_init(), ui_mouse_motion_towards_init_ex(), ui_mouse_motion_towards_reinit(), UI_region_block_find_mouse_over(), ui_region_contains_point_px(), UI_region_view_find_at(), UI_region_views_find_item_at(), ui_screen_region_find_mouse_over_ex(), ui_searchbox_inside(), UI_view2d_edge_pan_apply(), UI_view2d_mouse_in_scrollers(), UI_view2d_mouse_in_scrollers_ex(), ui_view_drop_tooltip(), ui_view_item_find_mouse_over(), blender::compositor::DisplaceOperation::update_memory_buffer_partial(), blender::compositor::MapUVOperation::update_memory_buffer_partial(), blender::compositor::MaskOperation::update_memory_buffer_partial(), blender::compositor::MovieDistortionOperation::update_memory_buffer_partial(), blender::compositor::ScreenLensDistortionOperation::update_memory_buffer_partial(), v3d_cursor_snap_draw_fn(), view2d_edge_pan_loc_compensate(), view3d_geometry_nodes_drop_tooltip(), view3d_mat_drop_tooltip(), view3d_opengl_select_ex(), view3d_ruler_item_project(), viewdolly_apply(), viewmove_modal_impl(), viewrotate_modal_impl(), viewzoom_apply(), viewzoom_apply_3d(), viewzoom_apply_camera(), viewzoom_invoke_impl(), viewzoom_modal_impl(), wm_drag_draw_default(), WM_drag_draw_default_fn(), wm_drag_draw_icon(), WM_drag_draw_item_name_fn(), wm_drag_draw_tooltip(), wm_drags_draw(), WM_event_drag_start_mval(), WM_event_drag_start_mval_fl(), WM_gesture_new(), wm_handler_fileselect_do(), wm_handlers_do(), wm_paintcursor_draw(), and wm_window_update_eventstate().