Blender  V3.3
render_view.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #include <cstddef>
9 #include <cstring>
10 
11 #include "BLI_listbase.h"
12 #include "BLI_utildefines.h"
13 
14 #include "DNA_scene_types.h"
15 #include "DNA_userdef_types.h"
16 
17 #include "BKE_context.h"
18 #include "BKE_global.h"
19 #include "BKE_image.h"
20 #include "BKE_main.h"
21 #include "BKE_report.h"
22 #include "BKE_scene.h"
23 #include "BKE_screen.h"
24 
25 #include "BLT_translation.h"
26 
27 #include "WM_api.h"
28 #include "WM_types.h"
29 
30 #include "ED_screen.h"
31 #include "UI_interface.h"
32 
33 #include "wm_window.h"
34 
35 #include "render_intern.hh"
36 
37 /*********************** utilities for finding areas *************************/
38 
45 {
46  bScreen *screen = CTX_wm_screen(C);
47  ScrArea *area, *big = nullptr;
48  int size, maxsize = 0, bwmaxsize = 0;
49  short foundwin = 0;
50 
51  for (area = static_cast<ScrArea *>(screen->areabase.first); area; area = area->next) {
52  if (area->winx > 30 && area->winy > 30) {
53  size = area->winx * area->winy;
54  if (!area->full && area->spacetype == SPACE_PROPERTIES) {
55  if (foundwin == 0 && size > bwmaxsize) {
56  bwmaxsize = size;
57  big = area;
58  }
59  }
60  else if (area->spacetype != SPACE_IMAGE && size > maxsize) {
61  maxsize = size;
62  big = area;
63  foundwin = 1;
64  }
65  }
66  }
67 
68  return big;
69 }
70 
72 {
74  ScrArea *area = nullptr;
75  SpaceImage *sima;
76 
77  /* find an imagewindow showing render result */
78  for (*win = static_cast<wmWindow *>(wm->windows.first); *win; *win = (*win)->next) {
79  if (WM_window_get_active_scene(*win) == scene) {
80  const bScreen *screen = WM_window_get_active_screen(*win);
81 
82  for (area = static_cast<ScrArea *>(screen->areabase.first); area; area = area->next) {
83  if (area->spacetype == SPACE_IMAGE) {
84  sima = static_cast<SpaceImage *>(area->spacedata.first);
85  if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
86  break;
87  }
88  }
89  }
90  if (area) {
91  break;
92  }
93  }
94  }
95 
96  return area;
97 }
98 
100 {
101  bScreen *screen = CTX_wm_screen(C);
102  ScrArea *area;
103  SpaceImage *sima;
104 
105  /* find an imagewindow showing render result */
106  for (area = static_cast<ScrArea *>(screen->areabase.first); area; area = area->next) {
107  if (area->spacetype == SPACE_IMAGE) {
108  sima = static_cast<SpaceImage *>(area->spacedata.first);
109  if ((sima->mode == SI_MODE_VIEW) && !sima->image) {
110  break;
111  }
112  }
113  }
114 
115  return area;
116 }
117 
118 /********************** open image editor for render *************************/
119 
120 ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
121 {
122  Main *bmain = CTX_data_main(C);
124  wmWindow *win = nullptr;
125  ScrArea *area = nullptr;
126  SpaceImage *sima;
127  bool area_was_image = false;
128 
129  if (U.render_display_type == USER_RENDER_DISPLAY_NONE) {
130  return nullptr;
131  }
132 
133  if (U.render_display_type == USER_RENDER_DISPLAY_WINDOW) {
134  int sizex, sizey;
135  BKE_render_resolution(&scene->r, false, &sizex, &sizey);
136 
137  sizex += 30 * UI_DPI_FAC;
138  sizey += 60 * UI_DPI_FAC;
139 
140  /* arbitrary... miniature image window views don't make much sense */
141  if (sizex < 320) {
142  sizex = 320;
143  }
144  if (sizey < 256) {
145  sizey = 256;
146  }
147 
148  /* changes context! */
149  if (WM_window_open(C,
150  IFACE_("Blender Render"),
151  mx,
152  my,
153  sizex,
154  sizey,
155  SPACE_IMAGE,
156  true,
157  false,
158  true,
159  WIN_ALIGN_LOCATION_CENTER) == nullptr) {
160  BKE_report(reports, RPT_ERROR, "Failed to open window!");
161  return nullptr;
162  }
163 
164  area = CTX_wm_area(C);
165  if (BLI_listbase_is_single(&area->spacedata) == false) {
166  sima = static_cast<SpaceImage *>(area->spacedata.first);
167  sima->flag |= SI_PREVSPACE;
168  }
169  }
170  else if (U.render_display_type == USER_RENDER_DISPLAY_SCREEN) {
171  area = CTX_wm_area(C);
172 
173  /* If the active screen is already in full-screen mode, skip this and
174  * unset the area, so that the full-screen area is just changed later. */
175  if (area && area->full) {
176  area = nullptr;
177  }
178  else {
179  if (area && area->spacetype == SPACE_IMAGE) {
180  area_was_image = true;
181  }
182 
183  /* this function returns with changed context */
185  }
186  }
187 
188  if (!area) {
190  if (area == nullptr) {
192  }
193 
194  /* if area found in other window, we make that one show in front */
195  if (win && win != CTX_wm_window(C)) {
196  wm_window_raise(win);
197  }
198 
199  if (area == nullptr) {
200  /* find largest open non-image area */
202  if (area) {
204  sima = static_cast<SpaceImage *>(area->spacedata.first);
205 
206  /* Makes "Escape" go back to previous space. */
207  sima->flag |= SI_PREVSPACE;
208 
209  /* We already had a full-screen here -> mark new space as a stacked full-screen. */
210  if (area->full) {
212  }
213  }
214  else {
215  /* use any area of decent size */
217  if (area->spacetype != SPACE_IMAGE) {
218  // XXX newspace(area, SPACE_IMAGE);
219  sima = static_cast<SpaceImage *>(area->spacedata.first);
220 
221  /* Makes "Escape" go back to previous space. */
222  sima->flag |= SI_PREVSPACE;
223  }
224  }
225  }
226  }
227  sima = static_cast<SpaceImage *>(area->spacedata.first);
229 
230  /* get the correct image, and scale it */
231  sima->image = BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
232 
233  /* If we're rendering to full screen, set appropriate hints on image editor
234  * so it can restore properly on pressing escape. */
235  if (area->full) {
236  sima->flag |= SI_FULLWINDOW;
237 
238  /* Tell the image editor to revert to previous space in space list on close
239  * _only_ if it wasn't already an image editor when the render was invoked */
240  if (area_was_image == 0) {
241  sima->flag |= SI_PREVSPACE;
242  }
243  else {
244  /* Leave it alone so the image editor will just go back from
245  * full screen to the original tiled setup */
246  }
247  }
248 
249  if ((sima->flag & SI_PREVSPACE) && sima->next) {
250  SpaceLink *old_sl = sima->next;
252  }
253 
254  return area;
255 }
256 
257 /*************************** cancel render viewer **********************/
258 
260 {
261  wmWindow *win = CTX_wm_window(C);
263  SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
264 
265  /* ensure image editor full-screen and area full-screen states are in sync */
266  if ((sima->flag & SI_FULLWINDOW) && !area->full) {
267  sima->flag &= ~SI_FULLWINDOW;
268  }
269 
270  /* determine if render already shows */
271  if (sima->flag & SI_PREVSPACE) {
272  sima->flag &= ~SI_PREVSPACE;
273 
274  if (sima->flag & SI_FULLWINDOW) {
275  sima->flag &= ~SI_FULLWINDOW;
277  }
278  else {
280  }
281 
282  return OPERATOR_FINISHED;
283  }
284  if (sima->flag & SI_FULLWINDOW) {
285  sima->flag &= ~SI_FULLWINDOW;
287  return OPERATOR_FINISHED;
288  }
289  if (WM_window_is_temp_screen(win)) {
291  return OPERATOR_FINISHED;
292  }
293 
294  return OPERATOR_PASS_THROUGH;
295 }
296 
298 {
299  /* identifiers */
300  ot->name = "Cancel Render View";
301  ot->description = "Cancel show render view";
302  ot->idname = "RENDER_OT_view_cancel";
303 
304  /* api callbacks */
307 }
308 
309 /************************* show render viewer *****************/
310 
311 static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
312 {
313  wmWindow *wincur = CTX_wm_window(C);
314 
315  /* test if we have currently a temp screen active */
316  if (WM_window_is_temp_screen(wincur)) {
317  wm_window_lower(wincur);
318  }
319  else {
320  wmWindow *win, *winshow;
322 
323  /* is there another window on current scene showing result? */
324  for (win = static_cast<wmWindow *>(CTX_wm_manager(C)->windows.first); win; win = win->next) {
325  const bScreen *screen = WM_window_get_active_screen(win);
326 
327  if ((WM_window_is_temp_screen(win) &&
328  ((ScrArea *)screen->areabase.first)->spacetype == SPACE_IMAGE) ||
329  (win == winshow && winshow != wincur)) {
330  wm_window_raise(win);
331  return OPERATOR_FINISHED;
332  }
333  }
334 
335  /* determine if render already shows */
336  if (area) {
337  /* but don't close it when rendering */
338  if (G.is_rendering == false) {
339  SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
340 
341  if (sima->flag & SI_PREVSPACE) {
342  sima->flag &= ~SI_PREVSPACE;
343 
344  if (sima->flag & SI_FULLWINDOW) {
345  sima->flag &= ~SI_FULLWINDOW;
347  }
348  else {
350  }
351  }
352  }
353  }
354  else {
355  render_view_open(C, event->xy[0], event->xy[1], op->reports);
356  }
357  }
358 
359  return OPERATOR_FINISHED;
360 }
361 
363 {
364  /* identifiers */
365  ot->name = "Show/Hide Render View";
366  ot->description = "Toggle show render view";
367  ot->idname = "RENDER_OT_view_show";
368 
369  /* api callbacks */
372 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
struct Image * BKE_image_ensure_viewer(struct Main *bmain, int type, const char *name)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
void BKE_render_resolution(const struct RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition: scene.cc:2960
struct ARegion struct ARegion struct ScrArea struct ScrArea * BKE_screen_find_big_area(struct bScreen *screen, int spacetype, short min)
Definition: screen.c:937
void void BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
Definition: BLI_listbase.h:265
#define UNUSED(x)
#define IFACE_(msgid)
@ IMA_TYPE_R_RESULT
@ AREA_FLAG_STACKED_FULLSCREEN
@ SCREENMAXIMIZED
@ SI_FULLWINDOW
@ SI_PREVSPACE
@ SPACE_PROPERTIES
@ SPACE_IMAGE
@ SPACE_FLAG_TYPE_WAS_ACTIVE
@ SPACE_FLAG_TYPE_TEMPORARY
@ SI_MODE_VIEW
#define SPACE_TYPE_ANY
@ USER_RENDER_DISPLAY_NONE
@ USER_RENDER_DISPLAY_SCREEN
@ USER_RENDER_DISPLAY_WINDOW
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void ED_screen_full_prevspace(struct bContext *C, ScrArea *area)
Definition: screen_edit.c:1275
bool ED_operator_image_active(struct bContext *C)
Definition: screen_ops.c:344
bool ED_operator_screenactive(struct bContext *C)
Definition: screen_ops.c:119
void ED_area_prevspace(struct bContext *C, ScrArea *area)
Definition: area.c:2567
ScrArea * ED_screen_full_newspace(struct bContext *C, ScrArea *area, int type)
Definition: screen_edit.c:1242
struct ScrArea * ED_screen_state_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *area, short state)
Definition: screen_edit.c:1415
void ED_area_newspace(struct bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition: area.c:2427
#define C
Definition: RandGen.cpp:25
#define UI_DPI_FAC
Definition: UI_interface.h:305
@ WIN_ALIGN_LOCATION_CENTER
Definition: WM_api.h:218
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
short type
Scene scene
#define G(x, y, z)
static void area(int d1, int d2, int e1, int e2, float weights[2])
ScrArea * render_view_open(bContext *C, int mx, int my, ReportList *reports)
Definition: render_view.cc:120
void RENDER_OT_view_cancel(struct wmOperatorType *ot)
Definition: render_view.cc:297
static ScrArea * find_area_image_empty(bContext *C)
Definition: render_view.cc:99
void RENDER_OT_view_show(struct wmOperatorType *ot)
Definition: render_view.cc:362
static ScrArea * find_area_showing_r_result(bContext *C, Scene *scene, wmWindow **win)
Definition: render_view.cc:71
static ScrArea * biggest_non_image_area(bContext *C)
Definition: render_view.cc:44
static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(op))
Definition: render_view.cc:259
static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: render_view.cc:311
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
struct RenderData r
SpaceLink * next
struct Image * image
ListBase areabase
int xy[2]
Definition: WM_types.h:682
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct wmWindow * next
wmOperatorType * ot
Definition: wm_files.c:3479
void wm_window_raise(wmWindow *win)
Definition: wm_window.c:1868
void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition: wm_window.c:366
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2300
bool WM_window_is_temp_screen(const wmWindow *win)
Definition: wm_window.c:2311
wmWindow * WM_window_open(bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type, bool toplevel, bool dialog, bool temp, eWindowAlignment alignment)
Definition: wm_window.c:721
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2183
void wm_window_lower(wmWindow *win)
Definition: wm_window.c:1863