diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-08-05 02:15:38 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-08-05 12:55:29 +0300 |
commit | f5c023dfd77f213b849bc4f30624a8d771723bed (patch) | |
tree | 535f9f57192a2ff0aff1867254112019fae4fb16 /source/blender | |
parent | 47335b4e61db11e1ee2e38f421dc86fa3c3dd375 (diff) |
Avoid change to global theme state in draw-manager
Changing the global state would obviously cause issues for async
execution. This is the simplest solution for a simple problem.
Reviewers: fclem, brecht
Differential Revision: https://developer.blender.org/D5413
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 143 | ||||
-rw-r--r-- | source/blender/editors/include/UI_resources.h | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 46 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 13 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 7 |
5 files changed, 135 insertions, 80 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index ac3e7e4ce67..5a27158bbc0 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -25,6 +25,8 @@ #include "GPU_shader.h" #include "GPU_texture.h" +#include "DNA_space_types.h" + #include "UI_resources.h" #include "BKE_object.h" @@ -53,37 +55,51 @@ static struct GPUTexture *DRW_create_weight_colorramp_texture(void); void DRW_globals_update(void) { GlobalsUboStorage *gb = &G_draw.block; - - UI_GetThemeColor4fv(TH_WIRE, gb->colorWire); - UI_GetThemeColor4fv(TH_WIRE_EDIT, gb->colorWireEdit); - UI_GetThemeColor4fv(TH_ACTIVE, gb->colorActive); - UI_GetThemeColor4fv(TH_SELECT, gb->colorSelect); + float tmp1[4], tmp2[4]; + + /* Explicitly access values of SPACE_VIEW3D here, don't use UI_SetTheme() to change global - + * thread-unsafe - theme state. */ + +#define DRW_GetThemeValuef(_id) UI_GetThemeValueTypef(_id, SPACE_VIEW3D) +#define DRW_GetThemeColor4fv(_id, _col) UI_GetThemeColorType4fv(_id, SPACE_VIEW3D, _col) +#define DRW_GetThemeColorBlendShade4fv(_id1, _id2, _col, _fac, _ofs) \ + DRW_GetThemeColor4fv(_id1, tmp1); \ + DRW_GetThemeColor4fv(_id2, tmp2); \ + UI_GetColorPtrBlendShade4fv(tmp1, tmp2, _col, _fac, _ofs) +#define DRW_GetThemeColorShadeAlpha4fv(_id, _col, _ofs, _alphaofs) \ + DRW_GetThemeColor4fv(_id, _col); \ + UI_GetColorPtrShadeAlpha4fv(_col, _col, _ofs, _alphaofs) + + DRW_GetThemeColor4fv(TH_WIRE, gb->colorWire); + DRW_GetThemeColor4fv(TH_WIRE_EDIT, gb->colorWireEdit); + DRW_GetThemeColor4fv(TH_ACTIVE, gb->colorActive); + DRW_GetThemeColor4fv(TH_SELECT, gb->colorSelect); UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, gb->colorLibrarySelect); UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, gb->colorLibrary); - UI_GetThemeColor4fv(TH_TRANSFORM, gb->colorTransform); - UI_GetThemeColor4fv(TH_LIGHT, gb->colorLight); - UI_GetThemeColor4fv(TH_SPEAKER, gb->colorSpeaker); - UI_GetThemeColor4fv(TH_CAMERA, gb->colorCamera); - UI_GetThemeColor4fv(TH_EMPTY, gb->colorEmpty); - UI_GetThemeColor4fv(TH_VERTEX, gb->colorVertex); - UI_GetThemeColor4fv(TH_VERTEX_SELECT, gb->colorVertexSelect); - UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, gb->colorVertexUnreferenced); + DRW_GetThemeColor4fv(TH_TRANSFORM, gb->colorTransform); + DRW_GetThemeColor4fv(TH_LIGHT, gb->colorLight); + DRW_GetThemeColor4fv(TH_SPEAKER, gb->colorSpeaker); + DRW_GetThemeColor4fv(TH_CAMERA, gb->colorCamera); + DRW_GetThemeColor4fv(TH_EMPTY, gb->colorEmpty); + DRW_GetThemeColor4fv(TH_VERTEX, gb->colorVertex); + DRW_GetThemeColor4fv(TH_VERTEX_SELECT, gb->colorVertexSelect); + DRW_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, gb->colorVertexUnreferenced); UI_COLOR_RGBA_FROM_U8(0xB0, 0x00, 0xB0, 0xFF, gb->colorVertexMissingData); - UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, gb->colorEditMeshActive); - UI_GetThemeColor4fv(TH_EDGE_SELECT, gb->colorEdgeSelect); - - UI_GetThemeColor4fv(TH_EDGE_SEAM, gb->colorEdgeSeam); - UI_GetThemeColor4fv(TH_EDGE_SHARP, gb->colorEdgeSharp); - UI_GetThemeColor4fv(TH_EDGE_CREASE, gb->colorEdgeCrease); - UI_GetThemeColor4fv(TH_EDGE_BEVEL, gb->colorEdgeBWeight); - UI_GetThemeColor4fv(TH_EDGE_FACESEL, gb->colorEdgeFaceSelect); - UI_GetThemeColor4fv(TH_FACE, gb->colorFace); - UI_GetThemeColor4fv(TH_FACE_SELECT, gb->colorFaceSelect); - UI_GetThemeColor4fv(TH_NORMAL, gb->colorNormal); - UI_GetThemeColor4fv(TH_VNORMAL, gb->colorVNormal); - UI_GetThemeColor4fv(TH_LNORMAL, gb->colorLNormal); - UI_GetThemeColor4fv(TH_FACE_DOT, gb->colorFaceDot); - UI_GetThemeColor4fv(TH_BACK, gb->colorBackground); + DRW_GetThemeColor4fv(TH_EDITMESH_ACTIVE, gb->colorEditMeshActive); + DRW_GetThemeColor4fv(TH_EDGE_SELECT, gb->colorEdgeSelect); + + DRW_GetThemeColor4fv(TH_EDGE_SEAM, gb->colorEdgeSeam); + DRW_GetThemeColor4fv(TH_EDGE_SHARP, gb->colorEdgeSharp); + DRW_GetThemeColor4fv(TH_EDGE_CREASE, gb->colorEdgeCrease); + DRW_GetThemeColor4fv(TH_EDGE_BEVEL, gb->colorEdgeBWeight); + DRW_GetThemeColor4fv(TH_EDGE_FACESEL, gb->colorEdgeFaceSelect); + DRW_GetThemeColor4fv(TH_FACE, gb->colorFace); + DRW_GetThemeColor4fv(TH_FACE_SELECT, gb->colorFaceSelect); + DRW_GetThemeColor4fv(TH_NORMAL, gb->colorNormal); + DRW_GetThemeColor4fv(TH_VNORMAL, gb->colorVNormal); + DRW_GetThemeColor4fv(TH_LNORMAL, gb->colorLNormal); + DRW_GetThemeColor4fv(TH_FACE_DOT, gb->colorFaceDot); + DRW_GetThemeColor4fv(TH_BACK, gb->colorBackground); /* Custom median color to slightly affect the edit mesh colors. */ interp_v4_v4v4(gb->colorEditMeshMiddle, gb->colorVertexSelect, gb->colorWireEdit, 0.35f); @@ -105,53 +121,55 @@ void DRW_globals_update(void) #endif /* Curve */ - UI_GetThemeColor4fv(TH_HANDLE_FREE, gb->colorHandleFree); - UI_GetThemeColor4fv(TH_HANDLE_AUTO, gb->colorHandleAuto); - UI_GetThemeColor4fv(TH_HANDLE_VECT, gb->colorHandleVect); - UI_GetThemeColor4fv(TH_HANDLE_ALIGN, gb->colorHandleAlign); - UI_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, gb->colorHandleAutoclamp); - UI_GetThemeColor4fv(TH_HANDLE_SEL_FREE, gb->colorHandleSelFree); - UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, gb->colorHandleSelAuto); - UI_GetThemeColor4fv(TH_HANDLE_SEL_VECT, gb->colorHandleSelVect); - UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, gb->colorHandleSelAlign); - UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, gb->colorHandleSelAutoclamp); - UI_GetThemeColor4fv(TH_NURB_ULINE, gb->colorNurbUline); - UI_GetThemeColor4fv(TH_NURB_VLINE, gb->colorNurbVline); - UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, gb->colorNurbSelUline); - UI_GetThemeColor4fv(TH_NURB_SEL_VLINE, gb->colorNurbSelVline); - UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, gb->colorActiveSpline); - - UI_GetThemeColor4fv(TH_BONE_POSE, gb->colorBonePose); - - UI_GetThemeColor4fv(TH_CFRAME, gb->colorCurrentFrame); + DRW_GetThemeColor4fv(TH_HANDLE_FREE, gb->colorHandleFree); + DRW_GetThemeColor4fv(TH_HANDLE_AUTO, gb->colorHandleAuto); + DRW_GetThemeColor4fv(TH_HANDLE_VECT, gb->colorHandleVect); + DRW_GetThemeColor4fv(TH_HANDLE_ALIGN, gb->colorHandleAlign); + DRW_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, gb->colorHandleAutoclamp); + DRW_GetThemeColor4fv(TH_HANDLE_SEL_FREE, gb->colorHandleSelFree); + DRW_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, gb->colorHandleSelAuto); + DRW_GetThemeColor4fv(TH_HANDLE_SEL_VECT, gb->colorHandleSelVect); + DRW_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, gb->colorHandleSelAlign); + DRW_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, gb->colorHandleSelAutoclamp); + DRW_GetThemeColor4fv(TH_NURB_ULINE, gb->colorNurbUline); + DRW_GetThemeColor4fv(TH_NURB_VLINE, gb->colorNurbVline); + DRW_GetThemeColor4fv(TH_NURB_SEL_ULINE, gb->colorNurbSelUline); + DRW_GetThemeColor4fv(TH_NURB_SEL_VLINE, gb->colorNurbSelVline); + DRW_GetThemeColor4fv(TH_ACTIVE_SPLINE, gb->colorActiveSpline); + + DRW_GetThemeColor4fv(TH_BONE_POSE, gb->colorBonePose); + + DRW_GetThemeColor4fv(TH_CFRAME, gb->colorCurrentFrame); /* Grid */ - UI_GetThemeColorShade4fv(TH_GRID, 10, gb->colorGrid); + DRW_GetThemeColor4fv(TH_GRID, tmp1); + UI_GetColorPtrShadeAlpha4fv(tmp1, gb->colorGrid, 10, 0); /* emphasise division lines lighter instead of darker, if background is darker than grid */ - UI_GetThemeColorShade4fv( - TH_GRID, + UI_GetColorPtrShadeAlpha4fv( + tmp1, + gb->colorGridEmphasise, (gb->colorGrid[0] + gb->colorGrid[1] + gb->colorGrid[2] + 0.12f > gb->colorBackground[0] + gb->colorBackground[1] + gb->colorBackground[2]) ? 20 : -10, - gb->colorGridEmphasise); + 0); /* Grid Axis */ - UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, gb->colorGridAxisX); - UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, gb->colorGridAxisY); - UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, gb->colorGridAxisZ); + DRW_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, gb->colorGridAxisX, 0.5f, -10); + DRW_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, gb->colorGridAxisY, 0.5f, -10); + DRW_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, gb->colorGridAxisZ, 0.5f, -10); - UI_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, 0, -80, gb->colorDeselect); - UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, gb->colorOutline); - UI_GetThemeColorShadeAlpha4fv(TH_LIGHT, 0, 255, gb->colorLightNoAlpha); + DRW_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, gb->colorDeselect, 0, -80); + DRW_GetThemeColorShadeAlpha4fv(TH_WIRE, gb->colorOutline, 0, -30); + DRW_GetThemeColorShadeAlpha4fv(TH_LIGHT, gb->colorLightNoAlpha, 0, 255); - gb->sizeLightCenter = (UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.5f) * U.pixelsize; + gb->sizeLightCenter = (DRW_GetThemeValuef(TH_OBCENTER_DIA) + 1.5f) * U.pixelsize; gb->sizeLightCircle = U.pixelsize * 9.0f; gb->sizeLightCircleShadow = gb->sizeLightCircle + U.pixelsize * 3.0f; /* M_SQRT2 to be at least the same size of the old square */ gb->sizeVertex = U.pixelsize * - (max_ff(1.0f, UI_GetThemeValuef(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f)); - gb->sizeFaceDot = U.pixelsize * UI_GetThemeValuef(TH_FACEDOT_SIZE); + (max_ff(1.0f, DRW_GetThemeValuef(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f)); + gb->sizeFaceDot = U.pixelsize * DRW_GetThemeValuef(TH_FACEDOT_SIZE); gb->sizeEdge = U.pixelsize * (1.0f / 2.0f); /* TODO Theme */ gb->sizeEdgeFix = U.pixelsize * (0.5f + 2.0f * (2.0f * (gb->sizeEdge * (float)M_SQRT1_2))); @@ -208,6 +226,11 @@ void DRW_globals_update(void) G_draw.weight_ramp = DRW_create_weight_colorramp_texture(); } + +#undef DRW_GetThemeValuef +#undef DRW_GetThemeColor4fv +#undef DRW_GetThemeColorBlendShade4fv +#undef DRW_GetThemeColorShadeAlpha4fv } /* ********************************* SHGROUP ************************************* */ diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index 3b080b6df95..17bd1ff0c22 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -394,6 +394,8 @@ bool UI_GetIconThemeColor4ubv(int colorid, unsigned char col[4]); // shade a 3 byte color (same as UI_GetColorPtrBlendShade3ubv with 0.0 factor) void UI_GetColorPtrShade3ubv(const unsigned char cp1[3], unsigned char col[3], int offset); +void UI_GetColorPtrShadeAlpha4fv(const float cp[4], float col[4], int offset, int alphaoffset); + // get a 3 byte color, blended and shaded between two other char color pointers void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], @@ -401,6 +403,10 @@ void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], float fac, int offset); +// get a 3 byte color, blended and shaded between two other char color pointers +void UI_GetColorPtrBlendShade4fv( + const float cp1[4], const float cp2[4], float col[4], float fac, int offset); + // sets the font color // (for anything fancy use UI_GetThemeColor[Fancy] then BLF_color) void UI_FontThemeColor(int fontid, int colorid); diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 25116934b06..2a940bc5ce0 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1420,6 +1420,28 @@ void UI_GetColorPtrShade3ubv(const uchar cp[3], uchar col[3], int offset) col[2] = b; } +void UI_GetColorPtrShadeAlpha4fv(const float cp[4], float col[4], int offset, int alphaoffset) +{ + const float ofs = offset / 255.0f; + const float alphaofs = alphaoffset / 255.0f; + float r, g, b, a; + + r = ofs + cp[0]; + g = ofs + cp[1]; + b = ofs + cp[2]; + a = alphaofs + cp[3]; + + CLAMP(r, 0.0f, 1.0f); + CLAMP(g, 0.0f, 1.0f); + CLAMP(b, 0.0f, 1.0f); + CLAMP(a, 0.0f, 1.0f); + + col[0] = r; + col[1] = g; + col[2] = b; + col[3] = a; +} + /* get a 3 byte color, blended and shaded between two other char color pointers */ void UI_GetColorPtrBlendShade3ubv( const uchar cp1[3], const uchar cp2[3], uchar col[3], float fac, int offset) @@ -1440,6 +1462,30 @@ void UI_GetColorPtrBlendShade3ubv( col[2] = b; } +void UI_GetColorPtrBlendShade4fv( + const float cp1[4], const float cp2[4], float col[4], float fac, int offset) +{ + const float ofs = (float)offset / 255.0f; + float r, g, b, a; + + CLAMP(fac, 0.0f, 1.0f); + + r = ofs + (1.0f - fac) * cp1[0] + fac * cp2[0]; + g = ofs + (1.0f - fac) * cp1[1] + fac * cp2[1]; + b = ofs + (1.0f - fac) * cp1[2] + fac * cp2[2]; + a = ofs + (1.0f - fac) * cp1[3] + fac * cp2[3]; + + CLAMP(r, 0.0f, 1.0f); + CLAMP(g, 0.0f, 1.0f); + CLAMP(b, 0.0f, 1.0f); + CLAMP(a, 0.0f, 1.0f); + + col[0] = r; + col[1] = g; + col[2] = b; + col[3] = a; +} + void UI_ThemeClearColor(int colorid) { float col[3]; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 8844428b1bf..6ea4e832b58 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -774,7 +774,6 @@ static void drawrenderborder(ARegion *ar, View3D *v3d) void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool alphaoverride) { - struct bThemeState theme_state; Scene *scene = DEG_get_evaluated_scene(depsgraph); RegionView3D *rv3d = ar->regiondata; @@ -787,10 +786,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a /* not that nice but means we wont zoom into billboards */ U.glalphaclip = alphaoverride ? 0.5f : glalphaclip; - /* Tools may request depth outside of regular drawing code. */ - UI_Theme_Store(&theme_state); - UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); - ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL); GPU_clear(GPU_DEPTH_BIT); @@ -826,8 +821,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a U.glalphaclip = glalphaclip; v3d->flag = flag; - - UI_Theme_Restore(&theme_state); } /* ******************** other elements ***************** */ @@ -1563,10 +1556,6 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, ar->winrct.xmax = winx; ar->winrct.ymax = winy; - struct bThemeState theme_state; - UI_Theme_Store(&theme_state); - UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); - /* set flags */ G.f |= G_FLAG_RENDER_VIEWPORT; @@ -1601,8 +1590,6 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, GPU_matrix_pop_projection(); GPU_matrix_pop(); - UI_Theme_Restore(&theme_state); - G.f &= ~G_FLAG_RENDER_VIEWPORT; } diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 2515ee6e482..2c003383549 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -984,7 +984,6 @@ int view3d_opengl_select(ViewContext *vc, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter) { - struct bThemeState theme_state; Depsgraph *depsgraph = vc->depsgraph; Scene *scene = vc->scene; View3D *v3d = vc->v3d; @@ -1070,10 +1069,6 @@ int view3d_opengl_select(ViewContext *vc, break; } - /* Tools may request depth outside of regular drawing code. */ - UI_Theme_Store(&theme_state); - UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); - /* Re-use cache (rect must be smaller then the cached) * other context is assumed to be unchanged */ if (GPU_select_is_cached()) { @@ -1176,8 +1171,6 @@ finally: printf("Too many objects in select buffer\n"); /* XXX make error message */ } - UI_Theme_Restore(&theme_state); - return hits; } |