Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_internal.c
| Show All 23 Lines | |||||
| #include <math.h> | #include <math.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rect.h" | |||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BLI_timecode.h" | #include "BLI_timecode.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "PIL_time.h" | #include "PIL_time.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | typedef struct RenderJob { | ||||
| ScrArea *area; | ScrArea *area; | ||||
| ColorManagedViewSettings view_settings; | ColorManagedViewSettings view_settings; | ||||
| ColorManagedDisplaySettings display_settings; | ColorManagedDisplaySettings display_settings; | ||||
| bool supports_glsl_draw; | bool supports_glsl_draw; | ||||
| bool interface_locked; | bool interface_locked; | ||||
| } RenderJob; | } RenderJob; | ||||
| /* called inside thread! */ | /* called inside thread! */ | ||||
| static void image_buffer_rect_update(RenderJob *rj, | static bool image_buffer_calc_imbuf_rect(const RenderResult *rr, | ||||
| RenderResult *rr, | const ImBuf *ibuf, | ||||
| ImBuf *ibuf, | |||||
| ImageUser *iuser, | |||||
| volatile rcti *renrect, | volatile rcti *renrect, | ||||
| const char *viewname) | rcti *r_ibuf_rect, | ||||
| int *r_offset_x, | |||||
| int *r_offset_y) | |||||
| { | { | ||||
| Scene *scene = rj->scene; | |||||
| const float *rectf = NULL; | |||||
| int ymin, ymax, xmin, xmax; | int ymin, ymax, xmin, xmax; | ||||
| int rymin, rxmin; | |||||
| int linear_stride, linear_offset_x, linear_offset_y; | |||||
| ColorManagedViewSettings *view_settings; | |||||
| ColorManagedDisplaySettings *display_settings; | |||||
| if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) { | |||||
| /* The whole image buffer it so be color managed again anyway. */ | |||||
| return; | |||||
| } | |||||
| /* if renrect argument, we only refresh scanlines */ | /* if renrect argument, we only refresh scanlines */ | ||||
| if (renrect) { | if (renrect) { | ||||
| /* if (ymax == recty), rendering of layer is ready, | /* if (ymax == recty), rendering of layer is ready, | ||||
| * we should not draw, other things happen... */ | * we should not draw, other things happen... */ | ||||
| if (rr->renlay == NULL || renrect->ymax >= rr->recty) { | if (rr->renlay == NULL || renrect->ymax >= rr->recty) { | ||||
| return; | return false; | ||||
| } | } | ||||
| /* xmin here is first subrect x coord, xmax defines subrect width */ | /* xmin here is first subrect x coord, xmax defines subrect width */ | ||||
| xmin = renrect->xmin + rr->crop; | xmin = renrect->xmin + rr->crop; | ||||
| xmax = renrect->xmax - xmin + rr->crop; | xmax = renrect->xmax - xmin + rr->crop; | ||||
| if (xmax < 2) { | if (xmax < 2) { | ||||
| return; | return false; | ||||
| } | } | ||||
| ymin = renrect->ymin + rr->crop; | ymin = renrect->ymin + rr->crop; | ||||
| ymax = renrect->ymax - ymin + rr->crop; | ymax = renrect->ymax - ymin + rr->crop; | ||||
| if (ymax < 2) { | if (ymax < 2) { | ||||
| return; | return false; | ||||
| } | } | ||||
| renrect->ymin = renrect->ymax; | renrect->ymin = renrect->ymax; | ||||
| } | } | ||||
| else { | else { | ||||
| xmin = ymin = rr->crop; | xmin = ymin = rr->crop; | ||||
| xmax = rr->rectx - 2 * rr->crop; | xmax = rr->rectx - 2 * rr->crop; | ||||
| ymax = rr->recty - 2 * rr->crop; | ymax = rr->recty - 2 * rr->crop; | ||||
| } | } | ||||
| /* xmin ymin is in tile coords. transform to ibuf */ | /* xmin ymin is in tile coords. transform to ibuf */ | ||||
| rxmin = rr->tilerect.xmin + xmin; | int rxmin = rr->tilerect.xmin + xmin; | ||||
| if (rxmin >= ibuf->x) { | if (rxmin >= ibuf->x) { | ||||
| return; | return false; | ||||
| } | } | ||||
| rymin = rr->tilerect.ymin + ymin; | int rymin = rr->tilerect.ymin + ymin; | ||||
| if (rymin >= ibuf->y) { | if (rymin >= ibuf->y) { | ||||
| return; | return false; | ||||
| } | } | ||||
| if (rxmin + xmax > ibuf->x) { | if (rxmin + xmax > ibuf->x) { | ||||
| xmax = ibuf->x - rxmin; | xmax = ibuf->x - rxmin; | ||||
| } | } | ||||
| if (rymin + ymax > ibuf->y) { | if (rymin + ymax > ibuf->y) { | ||||
| ymax = ibuf->y - rymin; | ymax = ibuf->y - rymin; | ||||
| } | } | ||||
| if (xmax < 1 || ymax < 1) { | if (xmax < 1 || ymax < 1) { | ||||
| return false; | |||||
| } | |||||
| r_ibuf_rect->xmax = xmax; | |||||
| r_ibuf_rect->ymax = ymax; | |||||
| r_ibuf_rect->xmin = xmin; | |||||
| r_ibuf_rect->ymin = ymin; | |||||
| *r_offset_x = rxmin; | |||||
| *r_offset_y = rymin; | |||||
| return true; | |||||
| } | |||||
| static void image_buffer_rect_update(RenderJob *rj, | |||||
| RenderResult *rr, | |||||
| ImBuf *ibuf, | |||||
| ImageUser *iuser, | |||||
| const rcti *imbuf_rect, | |||||
| int offset_x, | |||||
| int offset_y, | |||||
| const char *viewname) | |||||
| { | |||||
| Scene *scene = rj->scene; | |||||
| const float *rectf = NULL; | |||||
| int linear_stride, linear_offset_x, linear_offset_y; | |||||
| ColorManagedViewSettings *view_settings; | |||||
| ColorManagedDisplaySettings *display_settings; | |||||
| if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) { | |||||
| /* The whole image buffer is to be color managed again anyway. */ | |||||
fclem: typo; `it so` instead of `is to` | |||||
| return; | return; | ||||
| } | } | ||||
| /* The thing here is, the logic below (which was default behavior | /* The thing here is, the logic below (which was default behavior | ||||
| * of how rectf is acquiring since forever) gives float buffer for | * of how rectf is acquiring since forever) gives float buffer for | ||||
| * composite output only. This buffer can not be used for other | * composite output only. This buffer can not be used for other | ||||
| * passes obviously. | * passes obviously. | ||||
| * | * | ||||
| Show All 27 Lines | else { | ||||
| return; | return; | ||||
| } | } | ||||
| rectf = RE_RenderLayerGetPass(rr->renlay, RE_PASSNAME_COMBINED, viewname); | rectf = RE_RenderLayerGetPass(rr->renlay, RE_PASSNAME_COMBINED, viewname); | ||||
| } | } | ||||
| if (rectf == NULL) { | if (rectf == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| rectf += 4 * (rr->rectx * ymin + xmin); | rectf += 4 * (rr->rectx * imbuf_rect->ymin + imbuf_rect->xmin); | ||||
| linear_stride = rr->rectx; | linear_stride = rr->rectx; | ||||
| linear_offset_x = rxmin; | linear_offset_x = offset_x; | ||||
| linear_offset_y = rymin; | linear_offset_y = offset_y; | ||||
| } | } | ||||
| else { | else { | ||||
| rectf = ibuf->rect_float; | rectf = ibuf->rect_float; | ||||
| linear_stride = ibuf->x; | linear_stride = ibuf->x; | ||||
| linear_offset_x = 0; | linear_offset_x = 0; | ||||
| linear_offset_y = 0; | linear_offset_y = 0; | ||||
| } | } | ||||
| view_settings = &scene->view_settings; | view_settings = &scene->view_settings; | ||||
| display_settings = &scene->display_settings; | display_settings = &scene->display_settings; | ||||
| IMB_partial_display_buffer_update(ibuf, | IMB_partial_display_buffer_update(ibuf, | ||||
| rectf, | rectf, | ||||
| NULL, | NULL, | ||||
| linear_stride, | linear_stride, | ||||
| linear_offset_x, | linear_offset_x, | ||||
| linear_offset_y, | linear_offset_y, | ||||
| view_settings, | view_settings, | ||||
| display_settings, | display_settings, | ||||
| rxmin, | offset_x, | ||||
| rymin, | offset_y, | ||||
| rxmin + xmax, | offset_x + imbuf_rect->xmax, | ||||
| rymin + ymax); | offset_y + imbuf_rect->ymax); | ||||
| } | } | ||||
| /* ****************************** render invoking ***************** */ | /* ****************************** render invoking ***************** */ | ||||
| /* set callbacks, exported to sequence render too. | /* set callbacks, exported to sequence render too. | ||||
| * Only call in foreground (UI) renders. */ | * Only call in foreground (UI) renders. */ | ||||
| static void screen_render_single_layer_set( | static void screen_render_single_layer_set( | ||||
| ▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect) | ||||
| } | } | ||||
| if (rr == NULL) { | if (rr == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* update part of render */ | /* update part of render */ | ||||
| render_image_update_pass_and_layer(rj, rr, &rj->iuser); | render_image_update_pass_and_layer(rj, rr, &rj->iuser); | ||||
| rcti imbuf_rect; | |||||
| int offset_x; | |||||
| int offset_y; | |||||
| ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock); | ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock); | ||||
| if (ibuf) { | if (ibuf) { | ||||
| if (!image_buffer_calc_imbuf_rect(rr, ibuf, renrect, &imbuf_rect, &offset_x, &offset_y)) { | |||||
| BKE_image_release_ibuf(ima, ibuf, lock); | |||||
| return; | |||||
| } | |||||
| /* Don't waste time on CPU side color management if | /* Don't waste time on CPU side color management if | ||||
| * image will be displayed using GLSL. | * image will be displayed using GLSL. | ||||
| * | * | ||||
| * Need to update rect if Save Buffers enabled because in | * Need to update rect if Save Buffers enabled because in | ||||
| * this case GLSL doesn't have original float buffer to | * this case GLSL doesn't have original float buffer to | ||||
| * operate with. | * operate with. | ||||
| */ | */ | ||||
| if (!rj->supports_glsl_draw || ibuf->channels == 1 || | if (!rj->supports_glsl_draw || ibuf->channels == 1 || | ||||
| ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) { | ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) { | ||||
| image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect, viewname); | image_buffer_rect_update( | ||||
| rj, rr, ibuf, &rj->iuser, &imbuf_rect, offset_x, offset_y, viewname); | |||||
| } | } | ||||
| ima->gpuflag |= IMA_GPU_REFRESH; | BKE_image_update_gputexture_delayed( | ||||
| ima, ibuf, offset_x, offset_y, imbuf_rect.xmax, imbuf_rect.ymax); | |||||
| /* make jobs timer to send notifier */ | /* make jobs timer to send notifier */ | ||||
| *(rj->do_update) = true; | *(rj->do_update) = true; | ||||
| } | } | ||||
| BKE_image_release_ibuf(ima, ibuf, lock); | BKE_image_release_ibuf(ima, ibuf, lock); | ||||
| } | } | ||||
| static void current_scene_update(void *rjv, Scene *scene) | static void current_scene_update(void *rjv, Scene *scene) | ||||
| ▲ Show 20 Lines • Show All 571 Lines • Show Last 20 Lines | |||||
typo; it so instead of is to