Blender V5.0
wm_draw.cc File Reference
#include <cstdlib>
#include <cstring>
#include "DNA_camera_types.h"
#include "DNA_color_types.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_view3d_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_rect.h"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "BKE_image.hh"
#include "BKE_layer.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"
#include "IMB_colormanagement.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 (const 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 blender::gpu::TextureFormat 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)
blender::gpu::Texturewm_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_area_offscreen (bContext *C, wmWindow *win, ScrArea *area, bool stereo)
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_t * WM_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_t * WM_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_t * WM_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 float system_scale, const int event_xy[2], const GHOST_CursorBitmapRef *bitmap)
static void wm_software_cursor_draw_crosshair (const float system_scale, 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()

◆ 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 1501 of file wm_draw.cc.

References GHOST_GetPixelAtCursor().

Referenced by eyedropper_color_sample_fl().

◆ wm_draw_area_offscreen()

◆ wm_draw_callbacks()

void wm_draw_callbacks ( wmWindow * win)
static

Definition at line 659 of file wm_draw.cc.

References WindowDrawCB::draw, wmWindow::drawcalls, and LISTBASE_FOREACH_MUTABLE.

Referenced by wm_draw_window_onscreen().

◆ WM_draw_cb_activate()

◆ WM_draw_cb_exit()

◆ wm_draw_offscreen_texture_parameters()

void wm_draw_offscreen_texture_parameters ( GPUOffScreen * offscreen)
static

◆ wm_draw_region_bind()

◆ wm_draw_region_blend()

◆ wm_draw_region_blit()

void wm_draw_region_blit ( ARegion * region,
int view )
static

◆ wm_draw_region_buffer_create()

◆ wm_draw_region_buffer_free()

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 1671 of file wm_draw.cc.

References bScreen::do_draw, and 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()

◆ WM_draw_region_get_viewport()

◆ wm_draw_region_stereo_set()

◆ wm_draw_region_test()

◆ wm_draw_region_texture()

blender::gpu::Texture * wm_draw_region_texture ( ARegion * region,
int view )

◆ wm_draw_region_unbind()

◆ WM_draw_region_viewport_bind()

void WM_draw_region_viewport_bind ( ARegion * region)

Definition at line 1726 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 1731 of file wm_draw.cc.

References wm_draw_region_unbind().

Referenced by ED_view3d_depth_override(), and ui_region_redraw_immediately().

◆ wm_draw_surface()

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

◆ wm_draw_update()

◆ wm_draw_update_clear_window()

◆ 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 (e.g. screen-shot & sample screen color) explicitly redrawing should be avoided, see: #92704, #93950, #97627 & #98462.

Definition at line 1695 of file wm_draw.cc.

References C, 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()

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

◆ 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()

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()

void wm_software_cursor_draw_crosshair ( const float system_scale,
const int event_xy[2] )
static

◆ wm_software_cursor_motion_clear()

void wm_software_cursor_motion_clear ( )
static

Definition at line 233 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()

void wm_software_cursor_motion_clear_with_window ( const wmWindow * win)
static

◆ wm_software_cursor_motion_test()

bool wm_software_cursor_motion_test ( const wmWindow * win)
static

Definition at line 218 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()

void wm_software_cursor_motion_update ( const wmWindow * win)
static

Definition at line 225 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()

bool wm_software_cursor_needed ( )
static

◆ wm_software_cursor_needed_for_window()

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

◆ wm_window_grab_warp_region_is_set()

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 82 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 1484 of file wm_draw.cc.

References C, 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(), and blender::ed::asset::take_screenshot_crop().

◆ 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 1325 of file wm_draw.cc.

References GHOST_ActivateWindowDrawingContext(), wmWindow::ghostwin, GPU_context_active_set(), GPU_DATA_UBYTE, GPU_frontbuffer_read_color(), wmWindow::gpuctx, i, MEM_malloc_arrayN(), wmWindowManager::runtime, 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 1403 of file wm_draw.cc.

References C, 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_malloc_arrayN(), 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 1492 of file wm_draw.cc.

References C, 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()

◆ WM_window_pixels_read_sample_from_offscreen()

Variable Documentation

◆ enabled

int8_t enabled

Definition at line 176 of file wm_draw.cc.

◆ [struct]

struct { ... } g_software_cursor

◆ winid

◆ xy

int xy[2]

Definition at line 178 of file wm_draw.cc.

Referenced by actionzone_area_poll(), annotation_draw_eraser(), annotation_draw_stabilizer(), area_actionzone_refresh_xy(), area_event_inside(), area_move_init(), BKE_area_find_region_xy(), BKE_maskrasterize_handle_sample(), BKE_screen_area_map_find_area_xy(), BKE_screen_area_map_find_area_xy(), BKE_screen_find_area_xy(), BKE_screen_find_area_xy(), BKE_screen_find_main_region_at_xy(), BKE_screen_find_main_region_at_xy(), BKE_screen_find_region_xy(), BKE_screen_find_region_xy(), BLI_rctf_clamp_pt_v(), BLI_rctf_clamp_pt_v(), BLI_rctf_do_minmax_v(), BLI_rctf_init_pt_radius(), BLI_rctf_isect_circle(), BLI_rctf_isect_circle(), BLI_rctf_isect_pt_v(), BLI_rctf_isect_pt_v(), BLI_rcti_clamp_pt_v(), BLI_rcti_clamp_pt_v(), BLI_rcti_do_minmax_v(), BLI_rcti_init_pt_radius(), BLI_rcti_is_valid(), BLI_rcti_isect_circle(), BLI_rcti_isect_circle(), BLI_rcti_isect_pt_v(), BLI_rcti_isect_pt_v(), brush_drawcursor(), btMatrix3x3(), blender::nodes::node_shader_tex_gabor_cc::GaborNoiseFunction::call(), cb_wm_cursor_draw(), blender::ed::vse::check_circle_intersection_in_timeline(), blender::ed::outliner::collection_drop_init(), blender::ed::outliner::collection_drop_tooltip(), CreateMatrix(), data_device_handle_drop(), blender::ed::vse::draw_strip_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_pose_deselect_all_multi_ex(), ED_screen_set_active_region(), blender::nodes::node_composite_map_uv_cc::MapUVOperation::execute_cpu_anisotropic(), blender::nodes::node_composite_map_uv_cc::MapUVOperation::execute_single(), eyedropper_draw_cursor_text_region(), blender::ui::AbstractTreeView::find_hovered(), blender::ed::transform::flushTransNodes(), blender::ed::greasepencil::generate_corner(), GHOST_SystemWayland::getAllDisplayDimensions(), blender::ed::sculpt_paint::image::ops::paint::gradient_draw_line(), 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::ed::sculpt_paint::paint_cursor_context_init(), blender::ed::sculpt_paint::paint_draw_cursor(), blender::ed::sculpt_paint::paint_draw_line_cursor(), blender::ed::sculpt_paint::paint_draw_smooth_cursor(), 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(), blender::ed::vse::sequencer_drop_copy(), KDL::Rotation2::SetRot(), setRotation(), setValue(), blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAALumaEdgeDetectionPS(), blender::eevee::IrradianceBake::surfels_create(), textview_draw(), textview_draw_sel(), blender::ed::transform::transform_draw_cursor_draw(), ui_block_bounds_calc_centered_pie(), ui_block_bounds_calc_popup(), ui_block_bounds_calc_post_centered(), UI_block_end_ex(), ui_block_find_mouse_over_ex(), ui_block_find_mouse_over_ex(), ui_but_contains_point_px(), ui_but_contains_point_px(), ui_but_find_mouse_over_ex(), ui_but_find_mouse_over_ex(), ui_drag_toggle_set(), ui_list_find_mouse_over_ex(), ui_list_find_mouse_over_ex(), ui_list_row_find_mouse_over(), 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_contains_point_px(), UI_region_view_find_at(), UI_region_views_find_item_at(), ui_screen_region_find_mouse_over_ex(), ui_screen_region_find_mouse_over_ex(), ui_searchbox_inside(), ui_searchbox_inside(), UI_view2d_edge_pan_apply(), UI_view2d_edge_pan_apply(), UI_view2d_mouse_in_scrollers(), UI_view2d_mouse_in_scrollers(), UI_view2d_mouse_in_scrollers_ex(), UI_view2d_mouse_in_scrollers_ex(), ui_view_drop_tooltip(), ui_view_item_find_mouse_over(), ui_view_item_find_mouse_over(), v3d_cursor_snap_draw_fn(), blender::ed::transform::view2d_edge_pan_loc_compensate(), view3d_geometry_nodes_drop_tooltip(), view3d_gpu_select_ex(), view3d_mat_drop_tooltip(), 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(), wm_window_update_eventstate(), and blender::ui::AbstractTreeView::~AbstractTreeView().