Files
test/source/blender/editors/space_image/image_edit.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

560 lines
14 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2008 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spimage
*/
#include "DNA_brush_types.h"
#include "DNA_mask_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_scene.h"
#include "IMB_imbuf_types.h"
#include "DEG_depsgraph.hh"
#include "ED_image.hh" /* own include */
#include "ED_mesh.hh"
#include "ED_screen.hh"
#include "ED_uvedit.hh"
#include "UI_view2d.hh"
#include "WM_api.hh"
#include "WM_types.hh"
/* NOTE: image_panel_properties() uses pointer to sima->image directly. */
Image *ED_space_image(const SpaceImage *sima)
{
return sima->image;
}
void ED_space_image_set(Main *bmain, SpaceImage *sima, Image *ima, bool automatic)
{
/* Automatically pin image when manually assigned, otherwise it follows object. */
if (!automatic && sima->image != ima && sima->mode == SI_MODE_UV) {
sima->pin = true;
}
sima->image = ima;
if (ima == nullptr || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) {
if (sima->mode == SI_MODE_PAINT) {
sima->mode = SI_MODE_VIEW;
}
}
if (sima->image) {
BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
}
id_us_ensure_real((ID *)sima->image);
WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, nullptr);
}
void ED_space_image_sync(Main *bmain, Image *image, bool ignore_render_viewer)
{
wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
const bScreen *screen = WM_window_get_active_screen(win);
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype != SPACE_IMAGE) {
continue;
}
SpaceImage *sima = (SpaceImage *)sl;
if (sima->pin) {
continue;
}
if (ignore_render_viewer && sima->image &&
ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE))
{
continue;
}
ED_space_image_set(bmain, sima, image, true);
}
}
}
}
void ED_space_image_auto_set(const bContext *C, SpaceImage *sima)
{
if (sima->mode != SI_MODE_UV || sima->pin) {
return;
}
/* Track image assigned to active face in edit mode. */
Object *ob = CTX_data_active_object(C);
if (!(ob && (ob->mode & OB_MODE_EDIT) && ED_space_image_show_uvedit(sima, ob))) {
return;
}
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
BMFace *efa = BM_mesh_active_face_get(bm, true, false);
if (efa == nullptr) {
return;
}
Image *ima = nullptr;
ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, nullptr, nullptr, nullptr);
if (ima != sima->image) {
sima->image = ima;
if (sima->image) {
Main *bmain = CTX_data_main(C);
BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
}
}
}
Mask *ED_space_image_get_mask(const SpaceImage *sima)
{
return sima->mask_info.mask;
}
void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
{
sima->mask_info.mask = mask;
/* weak, but same as image/space */
id_us_ensure_real((ID *)sima->mask_info.mask);
if (C) {
WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
}
}
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile)
{
ImBuf *ibuf;
if (sima && sima->image) {
const Image *image = sima->image;
#if 0
if (image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) {
return BIF_render_spare_imbuf();
}
else
#endif
{
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
sima->iuser.tile = tile;
ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, r_lock);
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
sima->iuser.tile = 0;
}
if (ibuf) {
if (image->type == IMA_TYPE_R_RESULT && ibuf->x != 0 && ibuf->y != 0) {
/* Render result might be lazily allocated. Return ibuf without buffers to indicate that
* there is image buffer but it has no data yet. */
return ibuf;
}
if (ibuf->byte_buffer.data || ibuf->float_buffer.data) {
return ibuf;
}
BKE_image_release_ibuf(sima->image, ibuf, *r_lock);
*r_lock = nullptr;
}
}
else {
*r_lock = nullptr;
}
return nullptr;
}
void ED_space_image_release_buffer(SpaceImage *sima, ImBuf *ibuf, void *lock)
{
if (sima && sima->image) {
BKE_image_release_ibuf(sima->image, ibuf, lock);
}
}
int ED_space_image_get_display_channel_mask(ImBuf *ibuf)
{
int result = (SI_USE_ALPHA | SI_SHOW_ALPHA | SI_SHOW_ZBUF | SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
if (!ibuf) {
return result;
}
const bool color = ibuf->channels >= 3;
const bool alpha = ibuf->channels == 4;
const bool zbuf = ibuf->channels == 1;
if (!alpha) {
result &= ~(SI_USE_ALPHA | SI_SHOW_ALPHA);
}
if (!zbuf) {
2020-06-18 12:21:38 +10:00
result &= ~SI_SHOW_ZBUF;
}
if (!color) {
result &= ~(SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
}
return result;
}
bool ED_space_image_has_buffer(SpaceImage *sima)
{
ImBuf *ibuf;
void *lock;
bool has_buffer;
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
has_buffer = (ibuf != nullptr);
ED_space_image_release_buffer(sima, ibuf, lock);
return has_buffer;
}
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
{
Scene *scene = sima->iuser.scene;
ImBuf *ibuf;
void *lock;
Add support for tiled images and the UDIM naming scheme This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
/* TODO(lukas): Support tiled images with different sizes */
ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
*r_width = ibuf->x;
*r_height = ibuf->y;
}
else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
/* not very important, just nice */
BKE_render_resolution(&scene->r, true, r_width, r_height);
}
/* I know a bit weak... but preview uses not actual image size */
// XXX else if (image_preview_active(sima, r_width, r_height));
else {
*r_width = IMG_SIZE_FALLBACK;
*r_height = IMG_SIZE_FALLBACK;
}
ED_space_image_release_buffer(sima, ibuf, lock);
}
void ED_space_image_get_size_fl(SpaceImage *sima, float r_size[2])
{
int size_i[2];
ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
r_size[0] = size_i[0];
r_size[1] = size_i[1];
}
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
{
Image *ima = sima->image;
if ((ima == nullptr) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) {
*r_aspx = *r_aspy = 1.0;
}
else {
BKE_image_get_aspect(ima, r_aspx, r_aspy);
}
}
2020-05-04 19:32:59 +10:00
void ED_space_image_get_zoom(SpaceImage *sima,
const ARegion *region,
float *r_zoomx,
float *r_zoomy)
{
int width, height;
ED_space_image_get_size(sima, &width, &height);
*r_zoomx = float(BLI_rcti_size_x(&region->winrct) + 1) /
float(BLI_rctf_size_x(&region->v2d.cur) * width);
*r_zoomy = float(BLI_rcti_size_y(&region->winrct) + 1) /
float(BLI_rctf_size_y(&region->v2d.cur) * height);
}
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
{
int w, h;
ED_space_image_get_aspect(sima, r_aspx, r_aspy);
ED_space_image_get_size(sima, &w, &h);
*r_aspx *= float(w);
*r_aspy *= float(h);
if (*r_aspx < *r_aspy) {
*r_aspy = *r_aspy / *r_aspx;
*r_aspx = 1.0f;
}
else {
*r_aspx = *r_aspx / *r_aspy;
*r_aspy = 1.0f;
}
}
void ED_image_get_uv_aspect(Image *ima, ImageUser *iuser, float *r_aspx, float *r_aspy)
{
if (ima) {
int w, h;
BKE_image_get_aspect(ima, r_aspx, r_aspy);
BKE_image_get_size(ima, iuser, &w, &h);
*r_aspx *= float(w);
*r_aspy *= float(h);
}
else {
*r_aspx = 1.0f;
*r_aspy = 1.0f;
}
}
2020-05-04 19:32:59 +10:00
void ED_image_mouse_pos(SpaceImage *sima, const ARegion *region, const int mval[2], float co[2])
{
int sx, sy, width, height;
float zoomx, zoomy;
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
ED_space_image_get_size(sima, &width, &height);
UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &sx, &sy);
co[0] = ((mval[0] - sx) / zoomx) / width;
co[1] = ((mval[1] - sy) / zoomy) / height;
}
void ED_image_view_center_to_point(SpaceImage *sima, float x, float y)
{
int width, height;
float aspx, aspy;
ED_space_image_get_size(sima, &width, &height);
ED_space_image_get_aspect(sima, &aspx, &aspy);
sima->xof = (x - 0.5f) * width * aspx;
sima->yof = (y - 0.5f) * height * aspy;
}
void ED_image_point_pos(
2020-05-04 19:32:59 +10:00
SpaceImage *sima, const ARegion *region, float x, float y, float *r_x, float *r_y)
{
int sx, sy, width, height;
float zoomx, zoomy;
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
ED_space_image_get_size(sima, &width, &height);
UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &sx, &sy);
*r_x = ((x - sx) / zoomx) / width;
*r_y = ((y - sy) / zoomy) / height;
}
void ED_image_point_pos__reverse(SpaceImage *sima,
2020-05-04 19:32:59 +10:00
const ARegion *region,
const float co[2],
float r_co[2])
{
float zoomx, zoomy;
int width, height;
int sx, sy;
UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &sx, &sy);
ED_space_image_get_size(sima, &width, &height);
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
r_co[0] = (co[0] * width * zoomx) + float(sx);
r_co[1] = (co[1] * height * zoomy) + float(sy);
}
bool ED_image_slot_cycle(Image *image, int direction)
{
const int cur = image->render_slot;
int i, slot;
BLI_assert(ELEM(direction, -1, 1));
int num_slots = BLI_listbase_count(&image->renderslots);
for (i = 1; i < num_slots; i++) {
slot = (cur + ((direction == -1) ? -i : i)) % num_slots;
if (slot < 0) {
slot += num_slots;
}
RenderSlot *render_slot = BKE_image_get_renderslot(image, slot);
if ((render_slot && render_slot->render) || slot == image->last_render_slot) {
image->render_slot = slot;
break;
}
}
if (num_slots == 1) {
image->render_slot = 0;
}
else if (i == num_slots) {
image->render_slot = ((cur == 1) ? 0 : 1);
}
if (cur != image->render_slot) {
BKE_image_partial_update_mark_full_update(image);
}
return (cur != image->render_slot);
}
void ED_space_image_scopes_update(const bContext *C,
SpaceImage *sima,
ImBuf *ibuf,
bool use_view_settings)
{
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
/* scope update can be expensive, don't update during paint modes */
if (sima->mode == SI_MODE_PAINT) {
return;
}
if (ob && ((ob->mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) {
return;
}
/* We also don't update scopes of render result during render. */
if (G.is_rendering) {
const Image *image = sima->image;
if (image != nullptr && ELEM(image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
return;
}
}
BKE_scopes_update(&sima->scopes,
ibuf,
use_view_settings ? &scene->view_settings : nullptr,
&scene->display_settings);
}
bool ED_space_image_show_render(const SpaceImage *sima)
{
return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
}
bool ED_space_image_show_paint(const SpaceImage *sima)
{
if (ED_space_image_show_render(sima)) {
return false;
}
return (sima->mode == SI_MODE_PAINT);
}
bool ED_space_image_show_uvedit(const SpaceImage *sima, Object *obedit)
{
if (sima) {
if (ED_space_image_show_render(sima)) {
return false;
}
if (sima->mode != SI_MODE_UV) {
return false;
}
}
if (obedit && obedit->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool ret;
ret = EDBM_uv_check(em);
return ret;
}
return false;
}
bool ED_space_image_check_show_maskedit(SpaceImage *sima, Object *obedit)
{
/* check editmode - this is reserved for UV editing */
if (obedit && ED_space_image_show_uvedit(sima, obedit)) {
return false;
}
2012-07-25 12:15:22 +00:00
return (sima->mode == SI_MODE_MASK);
}
2018-07-02 11:47:00 +02:00
bool ED_space_image_maskedit_poll(bContext *C)
{
SpaceImage *sima = CTX_wm_space_image(C);
if (sima) {
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
BKE_view_layer_synced_ensure(scene, view_layer);
Object *obedit = BKE_view_layer_edit_object_get(view_layer);
return ED_space_image_check_show_maskedit(sima, obedit);
}
return false;
}
bool ED_space_image_maskedit_visible_splines_poll(bContext *C)
{
if (!ED_space_image_maskedit_poll(C)) {
return false;
}
const SpaceImage *space_image = CTX_wm_space_image(C);
return space_image->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
bool ED_space_image_paint_curve(const bContext *C)
{
SpaceImage *sima = CTX_wm_space_image(C);
if (sima && sima->mode == SI_MODE_PAINT) {
Brush *br = CTX_data_tool_settings(C)->imapaint.paint.brush;
if (br && (br->flag & BRUSH_CURVE)) {
return true;
}
}
return false;
}
2018-07-02 11:47:00 +02:00
bool ED_space_image_maskedit_mask_poll(bContext *C)
{
if (ED_space_image_maskedit_poll(C)) {
SpaceImage *sima = CTX_wm_space_image(C);
return sima->mask_info.mask != nullptr;
}
return false;
}
bool ED_space_image_maskedit_mask_visible_splines_poll(bContext *C)
{
if (!ED_space_image_maskedit_mask_poll(C)) {
return false;
}
const SpaceImage *space_image = CTX_wm_space_image(C);
return space_image->mask_info.draw_flag & MASK_DRAWFLAG_SPLINE;
}
bool ED_space_image_cursor_poll(bContext *C)
{
return ED_operator_uvedit_space_image(C) || ED_space_image_maskedit_poll(C) ||
ED_space_image_paint_curve(C);
}