Disable scope updates in texture and image paint modes.

Scope update is very slow for high resolutions, and currently blocks
the UI thread(!). This is especially terrible in paint modes, where
each stroke causes a scope update and unacceptable freezing.

The scopes update method tries to avoid this somewhat by skipping if the
toolbar is disabled, but this doesn't help when painting where brush
tools etc. are frequently needed. It's also a bad-level poll, with the
core system accessing a UI element.

Eventually scope updates should become a low-priority background job,
as well as becoming threaded. Until then this polling provides a usable
workaround to the most outrageous cases.
This commit is contained in:
Lukas Tönne 2015-01-12 14:21:23 +01:00
parent d1246969ed
commit 7f219137cf
5 changed files with 42 additions and 34 deletions

@ -1041,18 +1041,26 @@ class IMAGE_PT_tools_mask(MASK_PT_tools, Panel):
# --- end mask ---
class ImageScopesPanel():
@classmethod
def poll(cls, context):
sima = context.space_data
if not (sima and sima.image):
return False
# scopes are not updated in paint modes, hide
if sima.mode in {'PAINT'}:
return False
ob = context.active_object
if ob and ob.mode in {'TEXTURE_PAINT'}:
return False
return True
class IMAGE_PT_view_histogram(Panel):
class IMAGE_PT_view_histogram(ImageScopesPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_label = "Histogram"
bl_category = "Scopes"
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and sima.image)
def draw(self, context):
layout = self.layout
@ -1065,17 +1073,12 @@ class IMAGE_PT_view_histogram(Panel):
row.prop(hist, "show_line", text="")
class IMAGE_PT_view_waveform(Panel):
class IMAGE_PT_view_waveform(ImageScopesPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_label = "Waveform"
bl_category = "Scopes"
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and sima.image)
def draw(self, context):
layout = self.layout
@ -1087,17 +1090,12 @@ class IMAGE_PT_view_waveform(Panel):
row.prop(sima.scopes, "waveform_mode", text="")
class IMAGE_PT_view_vectorscope(Panel):
class IMAGE_PT_view_vectorscope(ImageScopesPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_label = "Vectorscope"
bl_category = "Scopes"
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and sima.image)
def draw(self, context):
layout = self.layout
@ -1106,17 +1104,12 @@ class IMAGE_PT_view_vectorscope(Panel):
layout.prop(sima.scopes, "vectorscope_alpha")
class IMAGE_PT_sample_line(Panel):
class IMAGE_PT_sample_line(ImageScopesPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_label = "Sample Line"
bl_category = "Scopes"
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and sima.image)
def draw(self, context):
layout = self.layout
@ -1130,17 +1123,12 @@ class IMAGE_PT_sample_line(Panel):
row.prop(hist, "show_line", text="")
class IMAGE_PT_scope_sample(Panel):
class IMAGE_PT_scope_sample(ImageScopesPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'TOOLS'
bl_label = "Scope Samples"
bl_category = "Scopes"
@classmethod
def poll(cls, context):
sima = context.space_data
return sima
def draw(self, context):
layout = self.layout

@ -35,6 +35,7 @@ struct Main;
struct bContext;
struct Image;
struct ImageUser;
struct ImBuf;
struct ToolSettings;
struct uiBlock;
struct wmWindowManager;
@ -58,6 +59,8 @@ void ED_space_image_get_aspect(struct SpaceImage *sima, float *aspx, float *aspy
void ED_space_image_get_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy);
void ED_space_image_get_uv_aspect(struct SpaceImage *sima, float *aspx, float *aspy);
void ED_space_image_scopes_update(const struct bContext *C, struct SpaceImage *sima, struct ImBuf *ibuf, bool use_view_settings);
void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings);
void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings);

@ -35,6 +35,7 @@
#include "BLI_rect.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_image.h"
@ -290,6 +291,20 @@ void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2
r_co[1] = (co[1] * height * zoomy) + (float)sy;
}
void ED_space_image_scopes_update(const struct bContext *C, struct SpaceImage *sima, struct 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) != 0))
return;
scopes_update(&sima->scopes, ibuf, use_view_settings ? &scene->view_settings : NULL, &scene->display_settings);
}
bool ED_space_image_show_render(SpaceImage *sima)
{
return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));

@ -899,9 +899,9 @@ static void image_tools_area_draw(const bContext *C, ARegion *ar)
BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings);
}
if (sima->image->flag & IMA_VIEW_AS_RENDER)
scopes_update(&sima->scopes, ibuf, &scene->view_settings, &scene->display_settings);
ED_space_image_scopes_update(C, sima, ibuf, true);
else
scopes_update(&sima->scopes, ibuf, NULL, &scene->display_settings);
ED_space_image_scopes_update(C, sima, ibuf, false);
}
}
ED_space_image_release_buffer(sima, ibuf, lock);

@ -791,15 +791,16 @@ static void rna_SpaceImageEditor_cursor_location_set(PointerRNA *ptr, const floa
}
}
static void rna_SpaceImageEditor_scopes_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
static void rna_SpaceImageEditor_scopes_update(struct bContext *C, struct PointerRNA *ptr)
{
Scene *scene = CTX_data_scene(C);
SpaceImage *sima = (SpaceImage *)ptr->data;
ImBuf *ibuf;
void *lock;
ibuf = ED_space_image_acquire_buffer(sima, &lock);
if (ibuf) {
scopes_update(&sima->scopes, ibuf, &scene->view_settings, &scene->display_settings);
ED_space_image_scopes_update(C, sima, ibuf, true);
WM_main_add_notifier(NC_IMAGE, sima->image);
}
ED_space_image_release_buffer(sima, ibuf, lock);
@ -2366,6 +2367,7 @@ static void rna_def_space_image(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "scopes");
RNA_def_property_struct_type(prop, "Scopes");
RNA_def_property_ui_text(prop, "Scopes", "Scopes to visualize image statistics");
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_scopes_update");
prop = RNA_def_property(srna, "use_image_pin", PROP_BOOLEAN, PROP_NONE);