Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_outliner / outliner_draw.c
index 0ea6916..57fa935 100644 (file)
@@ -34,6 +34,7 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_group_types.h"
 #include "DNA_lamp_types.h"
+#include "DNA_lightprobe_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_sequence_types.h"
@@ -48,9 +49,9 @@
 
 #include "BKE_context.h"
 #include "BKE_deform.h"
-#include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_layer.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_modifier.h"
@@ -58,6 +59,9 @@
 #include "BKE_scene.h"
 #include "BKE_object.h"
 
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
 #include "ED_armature.h"
 #include "ED_keyframing.h"
 #include "ED_object.h"
@@ -66,8 +70,7 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
 
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
@@ -135,6 +138,20 @@ static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int start
        }
 }
 
+/**
+ * The active object is only needed for reference.
+ */
+static bool is_object_data_in_editmode(const ID *id, const Object *obact)
+{
+       const short id_type = GS(id->name);
+       return (
+               (obact && (obact->mode & OB_MODE_EDIT)) &&
+               (id && OB_DATA_SUPPORT_EDITMODE(id_type)) &&
+               (GS(((ID *)obact->data)->name) == id_type) &&
+               BKE_object_data_is_in_editmode(id)
+       );
+}
+
 /* ****************************************************** */
 
 static void restrictbutton_recursive_ebone(bContext *C, EditBone *ebone_parent, int flag, bool set_flag)
@@ -172,116 +189,6 @@ static void restrictbutton_recursive_bone(Bone *bone_parent, int flag, bool set_
 
 }
 
-static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob_parent, char flag,
-                                           bool state, bool deselect, const char *rnapropname)
-{
-       Main *bmain = CTX_data_main(C);
-       Object *ob;
-
-       for (ob = bmain->object.first; ob; ob = ob->id.next) {
-               if (BKE_object_is_child_recursive(ob_parent, ob)) {
-                       /* only do if child object is selectable */
-                       if ((flag == OB_RESTRICT_SELECT) || (ob->restrictflag & OB_RESTRICT_SELECT) == 0) {
-                               if (state) {
-                                       ob->restrictflag |= flag;
-                                       if (deselect) {
-                                               ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
-                                       }
-                               }
-                               else {
-                                       ob->restrictflag &= ~flag;
-                               }
-                       }
-
-                       if (rnapropname) {
-                               PointerRNA ptr;
-                               PropertyRNA *prop;
-                               ID *id;
-                               bAction *action;
-                               FCurve *fcu;
-                               bool driven, special;
-
-                               RNA_id_pointer_create(&ob->id, &ptr);
-                               prop = RNA_struct_find_property(&ptr, rnapropname);
-                               fcu = rna_get_fcurve_context_ui(C, &ptr, prop, 0, NULL, &action, &driven, &special);
-
-                               if (fcu && !driven) {
-                                       id = ptr.id.data;
-                                       if (autokeyframe_cfra_can_key(scene, id)) {
-                                               ReportList *reports = CTX_wm_reports(C);
-                                               ToolSettings *ts = scene->toolsettings;
-                                               eInsertKeyFlags key_flag = ANIM_get_keyframing_flags(scene, 1);
-
-                                               fcu->flag &= ~FCURVE_SELECTED;
-                                               insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
-                                                               fcu->rna_path, fcu->array_index, CFRA, ts->keyframe_type, key_flag);
-                                               /* Assuming this is not necessary here, since 'ancestor' object button will do it anyway. */
-                                               /* WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); */
-                                       }
-                               }
-                       }
-               }
-       }
-}
-
-static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
-{
-       Scene *scene = (Scene *)poin;
-       Object *ob = (Object *)poin2;
-
-       if (!common_restrict_check(C, ob)) return;
-
-       /* deselect objects that are invisible */
-       if (ob->restrictflag & OB_RESTRICT_VIEW) {
-               /* Ouch! There is no backwards pointer from Object to Base,
-                * so have to do loop to find it. */
-               ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
-       }
-
-       if (CTX_wm_window(C)->eventstate->ctrl) {
-               restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_VIEW,
-                                              (ob->restrictflag & OB_RESTRICT_VIEW) != 0, true, "hide");
-       }
-
-       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
-}
-
-static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
-{
-       Scene *scene = (Scene *)poin;
-       Object *ob = (Object *)poin2;
-
-       if (!common_restrict_check(C, ob)) return;
-
-       /* if select restriction has just been turned on */
-       if (ob->restrictflag & OB_RESTRICT_SELECT) {
-               /* Ouch! There is no backwards pointer from Object to Base,
-                * so have to do loop to find it. */
-               ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
-       }
-
-       if (CTX_wm_window(C)->eventstate->ctrl) {
-               restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_SELECT,
-                                              (ob->restrictflag & OB_RESTRICT_SELECT) != 0, true, NULL);
-       }
-
-       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
-}
-
-static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2)
-{
-       Object *ob = (Object *)poin2;
-
-       if (CTX_wm_window(C)->eventstate->ctrl) {
-               restrictbutton_recursive_child(C, (Scene *)poin, ob, OB_RESTRICT_RENDER,
-                                              (ob->restrictflag & OB_RESTRICT_RENDER) != 0, false, "hide_render");
-       }
-
-       WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, poin);
-}
-
 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
 {
        WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, poin);
@@ -291,7 +198,7 @@ static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *po
 {
        Object *ob = (Object *)poin2;
 
-       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
 }
 
@@ -355,98 +262,6 @@ static void restrictbutton_gp_layer_flag_cb(bContext *C, void *UNUSED(poin), voi
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 }
 
-static int group_restrict_flag(Group *gr, int flag)
-{
-       GroupObject *gob;
-
-#ifdef USE_GROUP_SELECT
-       for (gob = gr->gobject.first; gob; gob = gob->next) {
-               if ((gob->ob->restrictflag & flag) == 0)
-                       return 0;
-       }
-       return 1;
-#else
-       /* weak but fast */
-       if ((gob = gr->gobject.first))
-               if ((gob->ob->restrictflag & flag) == 0)
-                       return 0;
-       return 1;
-#endif
-}
-
-static int group_select_flag(Group *gr)
-{
-       GroupObject *gob;
-
-#ifdef USE_GROUP_SELECT
-       for (gob = gr->gobject.first; gob; gob = gob->next)
-               if ((gob->ob->flag & SELECT))
-                       return 1;
-
-       return 0;
-#else
-       /* weak but fast */
-       if ((gob = gr->gobject.first))
-               if (gob->ob->flag & SELECT)
-                       return 1;
-       return 0;
-#endif
-}
-
-void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
-{
-       Scene *scene = (Scene *)poin;
-       GroupObject *gob;
-       Group *gr = (Group *)poin2;
-
-       if (group_restrict_flag(gr, flag)) {
-               for (gob = gr->gobject.first; gob; gob = gob->next) {
-                       if (ID_IS_LINKED(gob->ob))
-                               continue;
-
-                       gob->ob->restrictflag &= ~flag;
-
-                       if (flag == OB_RESTRICT_VIEW)
-                               if (gob->ob->flag & SELECT)
-                                       ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
-               }
-       }
-       else {
-               for (gob = gr->gobject.first; gob; gob = gob->next) {
-                       if (ID_IS_LINKED(gob->ob))
-                               continue;
-
-                       /* not in editmode */
-                       if (scene->obedit != gob->ob) {
-                               gob->ob->restrictflag |= flag;
-
-                               if (ELEM(flag, OB_RESTRICT_SELECT, OB_RESTRICT_VIEW)) {
-                                       if ((gob->ob->flag & SELECT)) {
-                                               ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
-                                       }
-                               }
-                       }
-               }
-       }
-}
-
-static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
-{
-       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
-       WM_event_add_notifier(C, NC_GROUP, NULL);
-       DAG_id_type_tag(CTX_data_main(C), ID_OB);
-}
-static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
-{
-       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
-       WM_event_add_notifier(C, NC_GROUP, NULL);
-}
-static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
-{
-       restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
-       WM_event_add_notifier(C, NC_GROUP, NULL);
-}
-
 static void restrictbutton_id_user_toggle(bContext *UNUSED(C), void *poin, void *UNUSED(poin2))
 {
        ID *id = (ID *)poin;
@@ -461,12 +276,10 @@ static void restrictbutton_id_user_toggle(bContext *UNUSED(C), void *poin, void
        }
 }
 
-
 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
 {
        Main *bmain = CTX_data_main(C);
        SpaceOops *soops = CTX_wm_space_outliner(C);
-       Scene *scene = CTX_data_scene(C);
        Object *obedit = CTX_data_edit_object(C);
        BLI_mempool *ts = soops->treestore;
        TreeStoreElem *tselem = tsep;
@@ -528,37 +341,39 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                                BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
                                                BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
                                                ED_armature_bone_rename(obedit->data, oldname, newname);
-                                               WM_event_add_notifier(C, NC_OBJECT | ND_POSE, OBACT);
+                                               WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
                                        }
                                        break;
                                }
 
                                case TSE_BONE:
                                {
+                                       ViewLayer *view_layer = CTX_data_view_layer(C);
+                                       Scene *scene = CTX_data_scene(C);
+                                       bArmature *arm = (bArmature *)tselem->id;
                                        Bone *bone = te->directdata;
-                                       Object *ob;
                                        char newname[sizeof(bone->name)];
 
                                        /* always make current object active */
-                                       tree_element_active(C, scene, soops, te, OL_SETSEL_NORMAL, true);
-                                       ob = OBACT;
+                                       tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
 
                                        /* restore bone name */
                                        BLI_strncpy(newname, bone->name, sizeof(bone->name));
                                        BLI_strncpy(bone->name, oldname, sizeof(bone->name));
-                                       ED_armature_bone_rename(ob->data, oldname, newname);
-                                       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+                                       ED_armature_bone_rename(arm, oldname, newname);
+                                       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
                                        break;
                                }
                                case TSE_POSE_CHANNEL:
                                {
+                                       Scene *scene = CTX_data_scene(C);
+                                       ViewLayer *view_layer = CTX_data_view_layer(C);
+                                       Object *ob = (Object *)tselem->id;
                                        bPoseChannel *pchan = te->directdata;
-                                       Object *ob;
                                        char newname[sizeof(pchan->name)];
 
                                        /* always make current pose-bone active */
-                                       tree_element_active(C, scene, soops, te, OL_SETSEL_NORMAL, true);
-                                       ob = OBACT;
+                                       tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
 
                                        BLI_assert(ob->type == OB_ARMATURE);
 
@@ -566,7 +381,7 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                        BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
                                        BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
                                        ED_armature_bone_rename(ob->data, oldname, newname);
-                                       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+                                       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
                                        break;
                                }
                                case TSE_POSEGRP:
@@ -591,7 +406,26 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                        break;
                                }
                                case TSE_R_LAYER:
+                               {
+                                       Scene *scene = (Scene *)tselem->id;
+                                       ViewLayer *view_layer = te->directdata;
+
+                                       /* Restore old name. */
+                                       char newname[sizeof(view_layer->name)];
+                                       BLI_strncpy(newname, view_layer->name, sizeof(view_layer->name));
+                                       BLI_strncpy(view_layer->name, oldname, sizeof(view_layer->name));
+
+                                       /* Rename, preserving animation and compositing data. */
+                                       BKE_view_layer_rename(bmain, scene, view_layer, newname);
+                                       WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
+                                       break;
+                               }
+                               case TSE_LAYER_COLLECTION:
+                               {
+                                       BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
+                                       WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
                                        break;
+                               }
                        }
                }
                tselem->flag &= ~TSE_TEXTBUT;
@@ -604,121 +438,33 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
        TreeElement *te;
        TreeStoreElem *tselem;
        Object *ob = NULL;
-       Group  *gr = NULL;
-
-       PropertyRNA *object_prop_hide, *object_prop_hide_select, *object_prop_hide_render;
-
-       /* get RNA properties (once) */
-       object_prop_hide = RNA_struct_type_find_property(&RNA_Object, "hide");
-       object_prop_hide_select = RNA_struct_type_find_property(&RNA_Object, "hide_select");
-       object_prop_hide_render = RNA_struct_type_find_property(&RNA_Object, "hide_render");
-       BLI_assert(object_prop_hide && object_prop_hide_select  && object_prop_hide_render);
 
+       /* get RNA properties (once for speed) */
+       PropertyRNA *collection_prop_hide_viewport;
+       PropertyRNA *collection_prop_hide_select;
+       PropertyRNA *collection_prop_hide_render;
+       collection_prop_hide_select = RNA_struct_type_find_property(&RNA_Collection, "hide_select");
+       collection_prop_hide_viewport = RNA_struct_type_find_property(&RNA_Collection, "hide_viewport");
+       collection_prop_hide_render = RNA_struct_type_find_property(&RNA_Collection, "hide_render");
+       BLI_assert(collection_prop_hide_viewport &&
+                  collection_prop_hide_select &&
+                  collection_prop_hide_render);
 
        for (te = lb->first; te; te = te->next) {
                tselem = TREESTORE(te);
                if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
-                       /* objects have toggle-able restriction flags */
-                       if (tselem->type == 0 && te->idcode == ID_OB) {
-                               PointerRNA ptr;
-
-                               ob = (Object *)tselem->id;
-                               RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ptr);
-
-                               UI_block_emboss_set(block, UI_EMBOSS_NONE);
-                               bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_VIEW_OFF,
-                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                       &ptr, object_prop_hide, -1, 0, 0, -1, -1,
-                                                       TIP_("Restrict viewport visibility (Ctrl - Recursive)"));
-                               UI_but_func_set(bt, restrictbutton_view_cb, scene, ob);
-                               UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
-                               bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_SELECT_OFF,
-                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                       &ptr, object_prop_hide_select, -1, 0, 0, -1, -1,
-                                                       TIP_("Restrict viewport selection (Ctrl - Recursive)"));
-                               UI_but_func_set(bt, restrictbutton_sel_cb, scene, ob);
-                               UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
-                               bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_RENDER_OFF,
-                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                       &ptr, object_prop_hide_render, -1, 0, 0, -1, -1,
-                                                       TIP_("Restrict rendering (Ctrl - Recursive)"));
-                               UI_but_func_set(bt, restrictbutton_rend_cb, scene, ob);
-                               UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
-                               UI_block_emboss_set(block, UI_EMBOSS);
-
-                       }
-                       if (tselem->type == 0 && te->idcode == ID_GR) {
-                               int restrict_bool;
-                               int but_flag = UI_BUT_DRAG_LOCK;
-                               gr = (Group *)tselem->id;
-
-                               if (ID_IS_LINKED(gr))
-                                       but_flag |= UI_BUT_DISABLED;
-
-                               UI_block_emboss_set(block, UI_EMBOSS_NONE);
-
-                               restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW);
-                               bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                 NULL, 0, 0, 0, 0, TIP_("Restrict/Allow visibility in the 3D View"));
-                               UI_but_func_set(bt, restrictbutton_gr_restrict_view, scene, gr);
-                               UI_but_flag_enable(bt, but_flag);
-
-                               restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT);
-                               bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                 NULL, 0, 0, 0, 0, TIP_("Restrict/Allow selection in the 3D View"));
-                               UI_but_func_set(bt, restrictbutton_gr_restrict_select, scene, gr);
-                               UI_but_flag_enable(bt, but_flag);
-
-                               restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER);
-                               bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF,
-                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-                                                 NULL, 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
-                               UI_but_func_set(bt, restrictbutton_gr_restrict_render, scene, gr);
-                               UI_but_flag_enable(bt, but_flag);
-
-                               UI_block_emboss_set(block, UI_EMBOSS);
-                       }
-                       /* scene render layers and passes have toggle-able flags too! */
-                       else if (tselem->type == TSE_R_LAYER) {
-                               UI_block_emboss_set(block, UI_EMBOSS_NONE);
-
-                               bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT - 1,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
-                                                     UI_UNIT_Y, te->directdata, 0, 0, 0, 0, TIP_("Render this RenderLayer"));
-                               UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
-                               UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
-                               UI_block_emboss_set(block, UI_EMBOSS);
-                       }
-                       else if (tselem->type == TSE_R_PASS) {
-                               int *layflag = te->directdata;
-                               int passflag = 1 << tselem->nr;
+                       if (tselem->type == TSE_R_LAYER && (soops->outlinevis == SO_SCENES)) {
+                               /* View layer render toggle. */
+                               ViewLayer *view_layer = te->directdata;
 
                                UI_block_emboss_set(block, UI_EMBOSS_NONE);
 
-
-                               bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, passflag, 0, ICON_CHECKBOX_HLT - 1,
-                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
-                                                     UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Render this Pass"));
+                               bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, VIEW_LAYER_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
+                                                     (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
+                                                     UI_UNIT_Y, &view_layer->flag, 0, 0, 0, 0, TIP_("Use view layer for rendering"));
                                UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
 
-                               layflag++;  /* is lay_xor */
-                               if (ELEM(passflag, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT,
-                                         SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT))
-                               {
-                                       bt = uiDefIconButBitI(block, UI_BTYPE_TOGGLE, passflag, 0, (*layflag & passflag) ? ICON_DOT : ICON_BLANK1,
-                                                             (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
-                                                             UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Exclude this Pass from Combined"));
-                                       UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
-                                       UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-                               }
-
                                UI_block_emboss_set(block, UI_EMBOSS);
                        }
                        else if (tselem->type == TSE_MODIFIER) {
@@ -804,6 +550,36 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
 
                                /* TODO: visibility in renders */
 
+                               UI_block_emboss_set(block, UI_EMBOSS);
+                       }
+                       else if (outliner_is_collection_tree_element(te)) {
+                               LayerCollection *lc = (tselem->type == TSE_LAYER_COLLECTION) ? te->directdata : NULL;
+                               Collection *collection = outliner_collection_from_tree_element(te);
+
+                               UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+                               if ((!lc || !(lc->flag & LAYER_COLLECTION_EXCLUDE)) &&
+                                   !(collection->flag & COLLECTION_IS_MASTER))
+                               {
+                                       PointerRNA collection_ptr;
+                                       RNA_id_pointer_create(&collection->id, &collection_ptr);
+
+                                       bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_VIEW_OFF,
+                                                               (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
+                                                               UI_UNIT_Y, &collection_ptr, collection_prop_hide_viewport, -1, 0, 0, 0, 0, NULL);
+                                       UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+
+                                       bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_RENDER_OFF,
+                                                               (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
+                                                               UI_UNIT_Y, &collection_ptr, collection_prop_hide_render, -1, 0, 0, 0, 0, NULL);
+                                       UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+
+                                       bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_SELECT_OFF,
+                                                               (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
+                                                               UI_UNIT_Y, &collection_ptr, collection_prop_hide_select, -1, 0, 0, 0, 0, NULL);
+                                       UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+                               }
+
                                UI_block_emboss_set(block, UI_EMBOSS);
                        }
                }
@@ -879,18 +655,23 @@ static void outliner_draw_rnacols(ARegion *ar, int sizex)
        float miny = v2d->cur.ymin;
        if (miny < v2d->tot.ymin) miny = v2d->tot.ymin;
 
-       UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
+       glLineWidth(1.0f);
 
-       /* draw column separator lines */
-       fdrawline((float)sizex,
-                 v2d->cur.ymax,
-                 (float)sizex,
-                 miny);
+       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
 
-       fdrawline((float)sizex + OL_RNA_COL_SIZEX,
-                 v2d->cur.ymax,
-                 (float)sizex + OL_RNA_COL_SIZEX,
-                 miny);
+       immBegin(GWN_PRIM_LINES, 4);
+
+       immVertex2f(pos, sizex, v2d->cur.ymax);
+       immVertex2f(pos, sizex, miny);
+
+       immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, v2d->cur.ymax);
+       immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, miny);
+
+       immEnd();
+
+       immUnbindProgram();
 }
 
 static void outliner_draw_rnabuts(uiBlock *block, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
@@ -988,7 +769,7 @@ static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
        /* restrict column clip... it has been coded by simply overdrawing, doesnt work for buttons */
        if (arg->x >= arg->xmax) {
                glEnable(GL_BLEND);
-               UI_icon_draw_aspect(arg->x, arg->y, icon, 1.0f / UI_DPI_FAC, arg->alpha);
+               UI_icon_draw_alpha(arg->x, arg->y, icon, arg->alpha);
                glDisable(GL_BLEND);
        }
        else {
@@ -1056,184 +837,261 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
        arg.x = x;
        arg.y = y;
 
+#define ICON_DRAW(_icon) UI_icon_draw_alpha(x, y, _icon, alpha)
+
        if (tselem->type) {
                switch (tselem->type) {
                        case TSE_ANIM_DATA:
-                               UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
+                               ICON_DRAW(ICON_ANIM_DATA); /* XXX */
+                               break;
                        case TSE_NLA:
-                               UI_icon_draw(x, y, ICON_NLA); break;
+                               ICON_DRAW(ICON_NLA);
+                               break;
                        case TSE_NLA_TRACK:
-                               UI_icon_draw(x, y, ICON_NLA); break; // XXX
+                               ICON_DRAW(ICON_NLA); /* XXX */
+                               break;
                        case TSE_NLA_ACTION:
-                               UI_icon_draw(x, y, ICON_ACTION); break;
+                               ICON_DRAW(ICON_ACTION);
+                               break;
                        case TSE_DRIVER_BASE:
-                               UI_icon_draw(x, y, ICON_DRIVER); break;
+                               ICON_DRAW(ICON_DRIVER);
+                               break;
                        case TSE_DEFGROUP_BASE:
-                               UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
+                               ICON_DRAW(ICON_GROUP_VERTEX);
+                               break;
                        case TSE_BONE:
                        case TSE_EBONE:
-                               UI_icon_draw(x, y, ICON_BONE_DATA); break;
+                               ICON_DRAW(ICON_BONE_DATA);
+                               break;
                        case TSE_CONSTRAINT_BASE:
-                               UI_icon_draw(x, y, ICON_CONSTRAINT); break;
+                               ICON_DRAW(ICON_CONSTRAINT);
+                               break;
                        case TSE_MODIFIER_BASE:
-                               UI_icon_draw(x, y, ICON_MODIFIER); break;
+                               ICON_DRAW(ICON_MODIFIER);
+                               break;
                        case TSE_LINKED_OB:
-                               UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
+                               ICON_DRAW(ICON_OBJECT_DATA);
+                               break;
                        case TSE_LINKED_PSYS:
-                               UI_icon_draw(x, y, ICON_PARTICLES); break;
+                               ICON_DRAW(ICON_PARTICLES);
+                               break;
                        case TSE_MODIFIER:
                        {
                                Object *ob = (Object *)tselem->id;
                                ModifierData *md = BLI_findlink(&ob->modifiers, tselem->nr);
                                switch ((ModifierType)md->type) {
                                        case eModifierType_Subsurf:
-                                               UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
+                                               ICON_DRAW(ICON_MOD_SUBSURF);
+                                               break;
                                        case eModifierType_Armature:
-                                               UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
+                                               ICON_DRAW(ICON_MOD_ARMATURE);
+                                               break;
                                        case eModifierType_Lattice:
-                                               UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
+                                               ICON_DRAW(ICON_MOD_LATTICE);
+                                               break;
                                        case eModifierType_Curve:
-                                               UI_icon_draw(x, y, ICON_MOD_CURVE); break;
+                                               ICON_DRAW(ICON_MOD_CURVE);
+                                               break;
                                        case eModifierType_Build:
-                                               UI_icon_draw(x, y, ICON_MOD_BUILD); break;
+                                               ICON_DRAW(ICON_MOD_BUILD);
+                                               break;
                                        case eModifierType_Mirror:
-                                               UI_icon_draw(x, y, ICON_MOD_MIRROR); break;
+                                               ICON_DRAW(ICON_MOD_MIRROR);
+                                               break;
                                        case eModifierType_Decimate:
-                                               UI_icon_draw(x, y, ICON_MOD_DECIM); break;
+                                               ICON_DRAW(ICON_MOD_DECIM);
+                                               break;
                                        case eModifierType_Wave:
-                                               UI_icon_draw(x, y, ICON_MOD_WAVE); break;
+                                               ICON_DRAW(ICON_MOD_WAVE);
+                                               break;
                                        case eModifierType_Hook:
-                                               UI_icon_draw(x, y, ICON_HOOK); break;
+                                               ICON_DRAW(ICON_HOOK);
+                                               break;
                                        case eModifierType_Softbody:
-                                               UI_icon_draw(x, y, ICON_MOD_SOFT); break;
+                                               ICON_DRAW(ICON_MOD_SOFT);
+                                               break;
                                        case eModifierType_Boolean:
-                                               UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
+                                               ICON_DRAW(ICON_MOD_BOOLEAN);
+                                               break;
                                        case eModifierType_ParticleSystem:
-                                               UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
+                                               ICON_DRAW(ICON_MOD_PARTICLES);
+                                               break;
                                        case eModifierType_ParticleInstance:
-                                               UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
+                                               ICON_DRAW(ICON_MOD_PARTICLES);
+                                               break;
                                        case eModifierType_EdgeSplit:
-                                               UI_icon_draw(x, y, ICON_MOD_EDGESPLIT); break;
+                                               ICON_DRAW(ICON_MOD_EDGESPLIT);
+                                               break;
                                        case eModifierType_Array:
-                                               UI_icon_draw(x, y, ICON_MOD_ARRAY); break;
+                                               ICON_DRAW(ICON_MOD_ARRAY);
+                                               break;
                                        case eModifierType_UVProject:
                                        case eModifierType_UVWarp:  /* TODO, get own icon */
-                                               UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
+                                               ICON_DRAW(ICON_MOD_UVPROJECT);
+                                               break;
                                        case eModifierType_Displace:
-                                               UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
+                                               ICON_DRAW(ICON_MOD_DISPLACE);
+                                               break;
                                        case eModifierType_Shrinkwrap:
-                                               UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
+                                               ICON_DRAW(ICON_MOD_SHRINKWRAP);
+                                               break;
                                        case eModifierType_Cast:
-                                               UI_icon_draw(x, y, ICON_MOD_CAST); break;
+                                               ICON_DRAW(ICON_MOD_CAST);
+                                               break;
                                        case eModifierType_MeshDeform:
                                        case eModifierType_SurfaceDeform:
-                                               UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
+                                               ICON_DRAW(ICON_MOD_MESHDEFORM);
+                                               break;
                                        case eModifierType_Bevel:
-                                               UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
+                                               ICON_DRAW(ICON_MOD_BEVEL);
+                                               break;
                                        case eModifierType_Smooth:
                                        case eModifierType_LaplacianSmooth:
                                        case eModifierType_CorrectiveSmooth:
-                                               UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
+                                               ICON_DRAW(ICON_MOD_SMOOTH);
+                                               break;
                                        case eModifierType_SimpleDeform:
-                                               UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
+                                               ICON_DRAW(ICON_MOD_SIMPLEDEFORM);
+                                               break;
                                        case eModifierType_Mask:
-                                               UI_icon_draw(x, y, ICON_MOD_MASK); break;
+                                               ICON_DRAW(ICON_MOD_MASK);
+                                               break;
                                        case eModifierType_Cloth:
-                                               UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
+                                               ICON_DRAW(ICON_MOD_CLOTH);
+                                               break;
                                        case eModifierType_Explode:
-                                               UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
+                                               ICON_DRAW(ICON_MOD_EXPLODE);
+                                               break;
                                        case eModifierType_Collision:
                                        case eModifierType_Surface:
-                                               UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
+                                               ICON_DRAW(ICON_MOD_PHYSICS);
+                                               break;
                                        case eModifierType_Fluidsim:
-                                               UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
+                                               ICON_DRAW(ICON_MOD_FLUIDSIM);
+                                               break;
                                        case eModifierType_Multires:
-                                               UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
+                                               ICON_DRAW(ICON_MOD_MULTIRES);
+                                               break;
                                        case eModifierType_Smoke:
-                                               UI_icon_draw(x, y, ICON_MOD_SMOKE); break;
+                                               ICON_DRAW(ICON_MOD_SMOKE);
+                                               break;
                                        case eModifierType_Solidify:
-                                               UI_icon_draw(x, y, ICON_MOD_SOLIDIFY); break;
+                                               ICON_DRAW(ICON_MOD_SOLIDIFY);
+                                               break;
                                        case eModifierType_Screw:
-                                               UI_icon_draw(x, y, ICON_MOD_SCREW); break;
+                                               ICON_DRAW(ICON_MOD_SCREW);
+                                               break;
                                        case eModifierType_Remesh:
-                                               UI_icon_draw(x, y, ICON_MOD_REMESH); break;
+                                               ICON_DRAW(ICON_MOD_REMESH);
+                                               break;
                                        case eModifierType_WeightVGEdit:
                                        case eModifierType_WeightVGMix:
                                        case eModifierType_WeightVGProximity:
-                                               UI_icon_draw(x, y, ICON_MOD_VERTEX_WEIGHT); break;
+                                               ICON_DRAW(ICON_MOD_VERTEX_WEIGHT);
+                                               break;
                                        case eModifierType_DynamicPaint:
-                                               UI_icon_draw(x, y, ICON_MOD_DYNAMICPAINT); break;
+                                               ICON_DRAW(ICON_MOD_DYNAMICPAINT);
+                                               break;
                                        case eModifierType_Ocean:
-                                               UI_icon_draw(x, y, ICON_MOD_OCEAN); break;
+                                               ICON_DRAW(ICON_MOD_OCEAN);
+                                               break;
                                        case eModifierType_Warp:
-                                               UI_icon_draw(x, y, ICON_MOD_WARP); break;
+                                               ICON_DRAW(ICON_MOD_WARP);
+                                               break;
                                        case eModifierType_Skin:
-                                               UI_icon_draw(x, y, ICON_MOD_SKIN); break;
+                                               ICON_DRAW(ICON_MOD_SKIN);
+                                               break;
                                        case eModifierType_Triangulate:
-                                               UI_icon_draw(x, y, ICON_MOD_TRIANGULATE); break;
+                                               ICON_DRAW(ICON_MOD_TRIANGULATE);
+                                               break;
                                        case eModifierType_MeshCache:
-                                               UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
+                                               ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+                                               break;
                                        case eModifierType_MeshSequenceCache:
-                                               UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
+                                               ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+                                               break;
                                        case eModifierType_Wireframe:
-                                               UI_icon_draw(x, y, ICON_MOD_WIREFRAME); break;
+                                               ICON_DRAW(ICON_MOD_WIREFRAME);
+                                               break;
                                        case eModifierType_LaplacianDeform:
-                                               UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
+                                               ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+                                               break;
                                        case eModifierType_DataTransfer:
-                                               UI_icon_draw(x, y, ICON_MOD_DATA_TRANSFER); break;
+                                               ICON_DRAW(ICON_MOD_DATA_TRANSFER);
+                                               break;
                                        case eModifierType_NormalEdit:
-                                               UI_icon_draw(x, y, ICON_MOD_NORMALEDIT); break;
+                                               ICON_DRAW(ICON_MOD_NORMALEDIT);
+                                               break;
                                        /* Default */
                                        case eModifierType_None:
                                        case eModifierType_ShapeKey:
                                        case NUM_MODIFIER_TYPES:
-                                               UI_icon_draw(x, y, ICON_DOT); break;
+                                               ICON_DRAW(ICON_DOT);
+                                               break;
                                }
                                break;
                        }
                        case TSE_POSE_BASE:
-                               UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
+                               ICON_DRAW(ICON_ARMATURE_DATA);
+                               break;
                        case TSE_POSE_CHANNEL:
-                               UI_icon_draw(x, y, ICON_BONE_DATA); break;
+                               ICON_DRAW(ICON_BONE_DATA);
+                               break;
                        case TSE_PROXY:
-                               UI_icon_draw(x, y, ICON_GHOST); break;
+                               ICON_DRAW(ICON_GHOST);
+                               break;
                        case TSE_R_LAYER_BASE:
-                               UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
+                               ICON_DRAW(ICON_RENDERLAYERS);
+                               break;
+                       case TSE_SCENE_OBJECTS_BASE:
+                               ICON_DRAW(ICON_OUTLINER_OB_GROUP_INSTANCE);
+                               break;
                        case TSE_R_LAYER:
-                               UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
+                               ICON_DRAW(ICON_RENDER_RESULT);
+                               break;
                        case TSE_LINKED_LAMP:
-                               UI_icon_draw(x, y, ICON_LAMP_DATA); break;
+                               ICON_DRAW(ICON_LAMP_DATA);
+                               break;
                        case TSE_LINKED_MAT:
-                               UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
+                               ICON_DRAW(ICON_MATERIAL_DATA);
+                               break;
                        case TSE_POSEGRP_BASE:
-                               UI_icon_draw(x, y, ICON_GROUP_BONE); break;
+                               ICON_DRAW(ICON_GROUP_BONE);
+                               break;
                        case TSE_SEQUENCE:
                                if (te->idcode == SEQ_TYPE_MOVIE)
-                                       UI_icon_draw(x, y, ICON_SEQUENCE);
+                                       ICON_DRAW(ICON_SEQUENCE);
                                else if (te->idcode == SEQ_TYPE_META)
-                                       UI_icon_draw(x, y, ICON_DOT);
+                                       ICON_DRAW(ICON_DOT);
                                else if (te->idcode == SEQ_TYPE_SCENE)
-                                       UI_icon_draw(x, y, ICON_SCENE);
+                                       ICON_DRAW(ICON_SCENE);
                                else if (te->idcode == SEQ_TYPE_SOUND_RAM)
-                                       UI_icon_draw(x, y, ICON_SOUND);
+                                       ICON_DRAW(ICON_SOUND);
                                else if (te->idcode == SEQ_TYPE_IMAGE)
-                                       UI_icon_draw(x, y, ICON_IMAGE_COL);
+                                       ICON_DRAW(ICON_IMAGE_COL);
                                else
-                                       UI_icon_draw(x, y, ICON_PARTICLES);
+                                       ICON_DRAW(ICON_PARTICLES);
                                break;
                        case TSE_SEQ_STRIP:
-                               UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
+                               ICON_DRAW(ICON_LIBRARY_DATA_DIRECT);
                                break;
                        case TSE_SEQUENCE_DUP:
-                               UI_icon_draw(x, y, ICON_OBJECT_DATA);
+                               ICON_DRAW(ICON_OBJECT_DATA);
                                break;
                        case TSE_RNA_STRUCT:
                                if (RNA_struct_is_ID(te->rnaptr.type)) {
                                        arg.id = (ID *)te->rnaptr.data;
                                        tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
                                }
-                               else
-                                       UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
+                               else {
+                                       int icon = RNA_struct_ui_icon(te->rnaptr.type);
+                                       ICON_DRAW(icon);
+                               }
+                               break;
+                       case TSE_LAYER_COLLECTION:
+                       case TSE_SCENE_COLLECTION_BASE:
+                       case TSE_VIEW_COLLECTION_BASE:
+                               ICON_DRAW(ICON_GROUP);
                                break;
                        /* Removed the icons from outliner. Need a better structure with Layers, Palettes and Colors */
 #if 0
@@ -1242,7 +1100,8 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
                                break;
 #endif
                        default:
-                               UI_icon_draw(x, y, ICON_DOT); break;
+                               ICON_DRAW(ICON_DOT);
+                               break;
                }
        }
        else if (tselem->id) {
@@ -1269,8 +1128,16 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
                                        tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
                                case OB_SPEAKER:
                                        tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
+                               case OB_LIGHTPROBE:
+                                       tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LIGHTPROBE); break;
                                case OB_EMPTY:
-                                       tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY); break;
+                                       if (ob->dup_group) {
+                                               tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_GROUP_INSTANCE);
+                                       }
+                                       else {
+                                               tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY);
+                                       }
+                                       break;
                        }
                }
                else {
@@ -1347,22 +1214,45 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
                                        tselem_draw_icon_uibut(&arg, ICON_LINE_DATA); break;
                                case ID_GD:
                                        tselem_draw_icon_uibut(&arg, ICON_GREASEPENCIL); break;
+                               case ID_LP:
+                               {
+                                       LightProbe * lp = (LightProbe *)tselem->id;
+                                       switch (lp->type) {
+                                               case LIGHTPROBE_TYPE_CUBE:
+                                                       tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
+                                               case LIGHTPROBE_TYPE_PLANAR:
+                                                       tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_PLANAR); break;
+                                               case LIGHTPROBE_TYPE_GRID:
+                                                       tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_GRID); break;
+                                               default:
+                                                       tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
+                                       }
+                                       break;
+                               }
+                               case ID_BR:
+                                       tselem_draw_icon_uibut(&arg, ICON_BRUSH_DATA); break;
+                               case ID_SCR:
+                               case ID_WS:
+                                       tselem_draw_icon_uibut(&arg, ICON_SPLITSCREEN); break;
                                default:
                                        break;
                        }
                }
        }
+
+#undef ICON_DRAW
 }
 
-static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level,
-                                  int xmax, int *offsx, int ys)
+static void outliner_draw_iconrow(
+        bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
+        ListBase *lb, int level, int xmax, int *offsx, int ys, float alpha_fac)
 {
        TreeElement *te;
        TreeStoreElem *tselem;
        eOLDrawState active;
+       const Object *obact = OBACT(view_layer);
 
        for (te = lb->first; te; te = te->next) {
-
                /* exit drawing early */
                if ((*offsx) - UI_UNIT_X > xmax)
                        break;
@@ -1371,38 +1261,41 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
 
                /* object hierarchy always, further constrained on level */
                if (level < 1 || (tselem->type == 0 && te->idcode == ID_OB)) {
-
                        /* active blocks get white circle */
                        if (tselem->type == 0) {
                                if (te->idcode == ID_OB) {
-                                       active = (OBACT == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
+                                       active = (OBACT(view_layer) == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
                                }
-                               else if (scene->obedit && scene->obedit->data == tselem->id) {
+                               else if (is_object_data_in_editmode(tselem->id, obact)) {
                                        active = OL_DRAWSEL_NORMAL;
                                }
                                else {
-                                       active = tree_element_active(C, scene, soops, te, OL_SETSEL_NONE, false);
+                                       active = tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false);
                                }
                        }
                        else {
-                               active = tree_element_type_active(NULL, scene, soops, te, tselem, OL_SETSEL_NONE, false);
+                               active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
                        }
 
                        if (active != OL_DRAWSEL_NONE) {
                                float ufac = UI_UNIT_X / 20.0f;
+                               float color[4] = {1.0f, 1.0f, 1.0f, 0.4f};
 
                                UI_draw_roundbox_corner_set(UI_CNR_ALL);
-                               glColor4ub(255, 255, 255, 100);
-                               UI_draw_roundbox(
+                               color[3] *= alpha_fac;
+
+                               UI_draw_roundbox_aa(
+                                       true,
                                        (float) *offsx + 1.0f * ufac,
                                        (float)ys + 1.0f * ufac,
                                        (float)*offsx + UI_UNIT_X - 1.0f * ufac,
                                        (float)ys + UI_UNIT_Y - ufac,
-                                       (float)UI_UNIT_Y / 2.0f - ufac);
+                                       (float)UI_UNIT_Y / 2.0f - ufac,
+                                       color);
                                glEnable(GL_BLEND); /* roundbox disables */
                        }
 
-                       tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
+                       tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f * alpha_fac);
                        te->xs = *offsx;
                        te->ys = ys;
                        te->xend = (short)*offsx + UI_UNIT_X;
@@ -1412,8 +1305,11 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
                }
 
                /* this tree element always has same amount of branches, so don't draw */
-               if (tselem->type != TSE_R_LAYER)
-                       outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level + 1, xmax, offsx, ys);
+               if (tselem->type != TSE_R_LAYER) {
+                       outliner_draw_iconrow(
+                               C, block, scene, view_layer, soops,
+                               &te->subtree, level + 1, xmax, offsx, ys, alpha_fac);
+               }
        }
 
 }
@@ -1423,9 +1319,12 @@ static void outliner_set_coord_tree_element(TreeElement *te, int startx, int sta
 {
        TreeElement *ten;
 
-       /* store coord and continue, we need coordinates for elements outside view too */
-       te->xs = startx;
-       te->ys = starty;
+       /* closed items may be displayed in row of parent, don't change their coordinate! */
+       if ((te->flag & TE_ICONROW) == 0) {
+               /* store coord and continue, we need coordinates for elements outside view too */
+               te->xs = startx;
+               te->ys = starty;
+       }
 
        for (ten = te->subtree.first; ten; ten = ten->next) {
                outliner_set_coord_tree_element(ten, startx + UI_UNIT_X, starty);
@@ -1434,24 +1333,28 @@ static void outliner_set_coord_tree_element(TreeElement *te, int startx, int sta
 
 
 static void outliner_draw_tree_element(
-        bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ARegion *ar, SpaceOops *soops,
-        TreeElement *te, int startx, int *starty, TreeElement **te_edit)
+        bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ViewLayer *view_layer,
+        ARegion *ar, SpaceOops *soops, TreeElement *te, bool draw_grayed_out,
+        int startx, int *starty, TreeElement **te_edit, TreeElement **te_floating)
 {
-       TreeElement *ten;
        TreeStoreElem *tselem;
        float ufac = UI_UNIT_X / 20.0f;
        int offsx = 0;
        eOLDrawState active = OL_DRAWSEL_NONE;
-
+       float color[4];
        tselem = TREESTORE(te);
 
        if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) {
+               const float alpha_fac = ((te->flag & TE_DISABLED) || draw_grayed_out) ? 0.5f : 1.0f;
+               const float alpha = 0.5f * alpha_fac;
                int xmax = ar->v2d.cur.xmax;
-               unsigned char alpha = 128;
 
                if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) {
                        *te_edit = te;
                }
+               if ((te->drag_data != NULL) && (*te_floating == NULL)) {
+                       *te_floating = te;
+               }
 
                /* icons can be ui buts, we don't want it to overlap with restrict */
                if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
@@ -1459,151 +1362,137 @@ static void outliner_draw_tree_element(
 
                glEnable(GL_BLEND);
 
-               /* start by highlighting search matches
-                *      we don't expand items when searching in the datablocks but we
-                *      still want to highlight any filter matches.
-                */
-               if ((SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) &&
-                   (tselem->flag & TSE_SEARCHMATCH))
-               {
-                       char col[4];
-                       UI_GetThemeColorType4ubv(TH_MATCH, SPACE_OUTLINER, col);
-                       col[3] = alpha;
-                       glColor4ubv((GLubyte *)col);
-                       glRecti(startx, *starty + 1, ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
-               }
-
                /* colors for active/selected data */
                if (tselem->type == 0) {
-
+                       const Object *obact = OBACT(view_layer);
                        if (te->idcode == ID_SCE) {
                                if (tselem->id == (ID *)scene) {
-                                       glColor4ub(255, 255, 255, alpha);
-                                       active = OL_DRAWSEL_ACTIVE;
-                               }
-                       }
-                       else if (te->idcode == ID_GR) {
-                               Group *gr = (Group *)tselem->id;
-                               if (group_select_flag(gr)) {
-                                       char col[4];
-                                       UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
-                                       col[3] = alpha;
-                                       glColor4ubv((GLubyte *)col);
-
+                                       rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
                                        active = OL_DRAWSEL_ACTIVE;
                                }
                        }
                        else if (te->idcode == ID_OB) {
                                Object *ob = (Object *)tselem->id;
+                               Base *base = (Base *)te->directdata;
+                               const bool is_selected = (base != NULL) && ((base->flag & BASE_SELECTED) != 0);
 
-                               if (ob == OBACT || (ob->flag & SELECT)) {
+                               if (ob == obact || is_selected) {
                                        char col[4] = {0, 0, 0, 0};
 
                                        /* outliner active ob: always white text, circle color now similar to view3d */
 
                                        active = OL_DRAWSEL_ACTIVE;
-                                       if (ob == OBACT) {
-                                               if (ob->flag & SELECT) {
+                                       if (ob == obact) {
+                                               if (is_selected) {
                                                        UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
                                                        col[3] = alpha;
                                                }
 
                                                active = OL_DRAWSEL_NORMAL;
                                        }
-                                       else if (ob->flag & SELECT) {
+                                       else if (is_selected) {
                                                UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
                                                col[3] = alpha;
                                        }
-
-                                       glColor4ubv((GLubyte *)col);
+                                       rgba_float_args_set(color, (float)col[0] / 255, (float)col[1] / 255, (float)col[2] / 255, alpha);
                                }
-
                        }
-                       else if (scene->obedit && scene->obedit->data == tselem->id) {
-                               glColor4ub(255, 255, 255, alpha);
+                       else if (is_object_data_in_editmode(tselem->id, obact)) {
+                               rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
                                active = OL_DRAWSEL_ACTIVE;
                        }
                        else {
-                               if (tree_element_active(C, scene, soops, te, OL_SETSEL_NONE, false)) {
-                                       glColor4ub(220, 220, 255, alpha);
+                               if (tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false)) {
+                                       rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
                                        active = OL_DRAWSEL_ACTIVE;
                                }
                        }
                }
                else {
-                       if (tree_element_type_active(NULL, scene, soops, te, tselem, OL_SETSEL_NONE, false) != OL_DRAWSEL_NONE) {
-                               active = OL_DRAWSEL_ACTIVE;
-                       }
-                       glColor4ub(220, 220, 255, alpha);
+                       active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
+                       rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
                }
 
                /* active circle */
                if (active != OL_DRAWSEL_NONE) {
                        UI_draw_roundbox_corner_set(UI_CNR_ALL);
-                       UI_draw_roundbox(
+                       UI_draw_roundbox_aa(
+                               true,
                                (float)startx + UI_UNIT_X + 1.0f * ufac,
                                (float)*starty + 1.0f * ufac,
                                (float)startx + 2.0f * UI_UNIT_X - 1.0f * ufac,
                                (float)*starty + UI_UNIT_Y - 1.0f * ufac,
-                               UI_UNIT_Y / 2.0f - 1.0f * ufac);
+                               UI_UNIT_Y / 2.0f - 1.0f * ufac, color);
                        glEnable(GL_BLEND); /* roundbox disables it */
 
                        te->flag |= TE_ACTIVE; // for lookup in display hierarchies
                }
 
-               /* open/close icon, only when sublevels, except for scene */
-               if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
-                       int icon_x;
-                       icon_x = startx;
+               if (tselem->type == TSE_VIEW_COLLECTION_BASE) {
+                       /* Scene collection in view layer can't expand/collapse. */
+               }
+               else if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
+                       /* open/close icon, only when sublevels, except for scene */
+                       int icon_x = startx;
 
                        // icons a bit higher
                        if (TSELEM_OPEN(tselem, soops))
-                               UI_icon_draw((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN);
+                               UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN,
+                                                  alpha_fac);
                        else
-                               UI_icon_draw((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT);
+                               UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT,
+                                                  alpha_fac);
                }
                offsx += UI_UNIT_X;
 
                /* datatype icon */
 
-               if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
-
-                       tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, 1.0f);
-
+               if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE))) {
+                       tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, alpha_fac);
                        offsx += UI_UNIT_X + 2 * ufac;
                }
                else
                        offsx += 2 * ufac;
 
-               if (tselem->type == 0 && ID_IS_LINKED(tselem->id)) {
-                       glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
+               if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_LINKED(tselem->id)) {
                        if (tselem->id->tag & LIB_TAG_MISSING) {
-                               UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN);
+                               UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN,
+                                                  alpha_fac);
                        }
                        else if (tselem->id->tag & LIB_TAG_INDIRECT) {
-                               UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT);
+                               UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT,
+                                                  alpha_fac);
                        }
                        else {
-                               UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT);
+                               UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT,
+                                                  alpha_fac);
                        }
-                       glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
+                       offsx += UI_UNIT_X + 2 * ufac;
+               }
+               else if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_STATIC_OVERRIDE(tselem->id)) {
+                       UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_OVERRIDE,
+                                          alpha_fac);
                        offsx += UI_UNIT_X + 2 * ufac;
                }
                glDisable(GL_BLEND);
 
                /* name */
                if ((tselem->flag & TSE_TEXTBUT) == 0) {
+                       unsigned char text_col[4];
+
                        if (active == OL_DRAWSEL_NORMAL) {
-                               UI_ThemeColor(TH_TEXT_HI);
+                               UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
                        }
                        else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
-                               UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
+                               UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.75f, text_col);
+                               text_col[3] = 255;
                        }
                        else {
-                               UI_ThemeColor(TH_TEXT);
+                               UI_GetThemeColor4ubv(TH_TEXT, text_col);
                        }
+                       text_col[3] *= alpha_fac;
 
-                       UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name);
+                       UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name, text_col);
                }
 
                offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(fstyle, te->name));
@@ -1614,24 +1503,34 @@ static void outliner_draw_tree_element(
                                if (tselem->type == 0 && te->idcode == ID_SCE) {
                                        /* pass */
                                }
+                               /* this tree element always has same amount of branches, so don't draw */
                                else if (tselem->type != TSE_R_LAYER) {
-                                       /* this tree element always has same amount of branches, so don't draw */
-
                                        int tempx = startx + offsx;
 
-                                       /* divider */
-                                       UI_ThemeColorShade(TH_BACK, -40);
-                                       glRecti(tempx   - 10.0f * ufac,
-                                               *starty +  4.0f * ufac,
-                                               tempx   -  8.0f * ufac,
-                                               *starty + UI_UNIT_Y - 4.0f * ufac);
-
                                        glEnable(GL_BLEND);
-                                       glPixelTransferf(GL_ALPHA_SCALE, 0.5);
 
-                                       outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty);
+                                       /* divider */
+                                       {
+                                               Gwn_VertFormat *format = immVertexFormat();
+                                               unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+                                               unsigned char col[4];
+
+                                               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+                                               UI_GetThemeColorShade4ubv(TH_BACK, -40, col);
+                                               col[3] *= alpha_fac;
+
+                                               immUniformColor4ubv(col);
+                                               immRecti(pos, tempx   - 10.0f * ufac,
+                                                        *starty +  4.0f * ufac,
+                                                        tempx   -  8.0f * ufac,
+                                                        *starty + UI_UNIT_Y - 4.0f * ufac);
+                                               immUnbindProgram();
+                                       }
+
+                                       outliner_draw_iconrow(
+                                               C, block, scene, view_layer, soops, &te->subtree, 0, xmax, &tempx,
+                                               *starty, alpha_fac);
 
-                                       glPixelTransferf(GL_ALPHA_SCALE, 1.0);
                                        glDisable(GL_BLEND);
                                }
                        }
@@ -1645,12 +1544,18 @@ static void outliner_draw_tree_element(
        if (TSELEM_OPEN(tselem, soops)) {
                *starty -= UI_UNIT_Y;
 
-               for (ten = te->subtree.first; ten; ten = ten->next) {
-                       outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, ten, startx + UI_UNIT_X, starty, te_edit);
+               for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
+                       /* check if element needs to be drawn grayed out, but also gray out
+                        * childs of a grayed out parent (pass on draw_grayed_out to childs) */
+                       bool draw_childs_grayed_out = draw_grayed_out || (ten->drag_data != NULL);
+                       outliner_draw_tree_element(
+                               C, block, fstyle, scene, view_layer,
+                               ar, soops, ten, draw_childs_grayed_out,
+                               startx + UI_UNIT_X, starty, te_edit, te_floating);
                }
        }
        else {
-               for (ten = te->subtree.first; ten; ten = ten->next) {
+               for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
                        outliner_set_coord_tree_element(ten, startx, *starty);
                }
 
@@ -1658,40 +1563,130 @@ static void outliner_draw_tree_element(
        }
 }
 
-static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
+static void outliner_draw_tree_element_floating(
+        const ARegion *ar, const TreeElement *te_floating)
 {
-       TreeElement *te;
+       const TreeElement *te_insert = te_floating->drag_data->insert_handle;
+       const int line_width = 2;
+
+       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+       int coord_y = te_insert->ys;
+       int coord_x = te_insert->xs;
+       float col[4];
+
+       if (te_insert == te_floating) {
+               /* don't draw anything */
+               return;
+       }
+
+       UI_GetThemeColorShade4fv(TH_BACK, -40, col);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       glEnable(GL_BLEND);
+
+       if (ELEM(te_floating->drag_data->insert_type, TE_INSERT_BEFORE, TE_INSERT_AFTER)) {
+               if (te_floating->drag_data->insert_type == TE_INSERT_BEFORE) {
+                       coord_y += UI_UNIT_Y;
+               }
+               immUniformColor4fv(col);
+               glLineWidth(line_width);
+
+               immBegin(GWN_PRIM_LINE_STRIP, 2);
+               immVertex2f(pos, coord_x, coord_y);
+               immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
+               immEnd();
+       }
+       else {
+               BLI_assert(te_floating->drag_data->insert_type == TE_INSERT_INTO);
+               immUniformColor3fvAlpha(col, col[3] * 0.5f);
+
+               immBegin(GWN_PRIM_TRI_STRIP, 4);
+               immVertex2f(pos, coord_x, coord_y + UI_UNIT_Y);
+               immVertex2f(pos, coord_x, coord_y);
+               immVertex2f(pos, ar->v2d.cur.xmax, coord_y + UI_UNIT_Y);
+               immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
+               immEnd();
+       }
+
+       glDisable(GL_BLEND);
+       immUnbindProgram();
+}
+
+static void outliner_draw_hierarchy_lines_recursive(unsigned pos, SpaceOops *soops, ListBase *lb, int startx,
+                                                    const unsigned char col[4], bool draw_grayed_out,
+                                                    int *starty)
+{
+       TreeElement *te, *te_vertical_line_last = NULL;
        TreeStoreElem *tselem;
        int y1, y2;
 
-       if (BLI_listbase_is_empty(lb)) return;
+       if (BLI_listbase_is_empty(lb)) {
+               return;
+       }
+
+       const unsigned char grayed_alpha = col[3] / 2;
 
-       y1 = y2 = *starty; /* for vertical lines between objects */
+       /* For vertical lines between objects. */
+       y1 = y2 = *starty;
        for (te = lb->first; te; te = te->next) {
-               y2 = *starty;
+               bool draw_childs_grayed_out = draw_grayed_out || (te->drag_data != NULL);
                tselem = TREESTORE(te);
 
-               /* horizontal line? */
-               if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE))
-                       glRecti(startx, *starty, startx + UI_UNIT_X, *starty - 1);
+               if (draw_childs_grayed_out) {
+                       immUniformColor3ubvAlpha(col, grayed_alpha);
+               }
+               else {
+                       immUniformColor4ubv(col);
+               }
+
+               /* Horizontal Line? */
+               if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) {
+                       immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - 1);
+
+                       /* Vertical Line? */
+                       if (te->idcode == ID_OB) {
+                               te_vertical_line_last = te;
+                               y2 = *starty;
+                       }
+               }
 
                *starty -= UI_UNIT_Y;
 
                if (TSELEM_OPEN(tselem, soops))
-                       outliner_draw_hierarchy(soops, &te->subtree, startx + UI_UNIT_X, starty);
+                       outliner_draw_hierarchy_lines_recursive(pos, soops, &te->subtree, startx + UI_UNIT_X,
+                                                               col, draw_childs_grayed_out, starty);
        }
 
-       /* vertical line */
-       te = lb->last;
-       if (te->parent || lb->first != lb->last) {
-               tselem = TREESTORE(te);
-               if (tselem->type == 0 && te->idcode == ID_OB) {
+       if (draw_grayed_out) {
+               immUniformColor3ubvAlpha(col, grayed_alpha);
+       }
+       else {
+               immUniformColor4ubv(col);
+       }
 
-                       glRecti(startx, y1 + UI_UNIT_Y, startx + 1, y2);
-               }
+       /* Vertical line. */
+       te = te_vertical_line_last;
+       if ((te != NULL) && (te->parent || lb->first != lb->last)) {
+               immRecti(pos, startx, y1 + UI_UNIT_Y, startx + 1, y2);
        }
 }
 
+static void outliner_draw_hierarchy_lines(SpaceOops *soops, ListBase *lb, int startx, int *starty)
+{
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       unsigned char col[4];
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.4f, col);
+       col[3] = 255;
+
+       glEnable(GL_BLEND);
+       outliner_draw_hierarchy_lines_recursive(pos, soops, lb, startx, col, false, starty);
+       glDisable(GL_BLEND);
+
+       immUnbindProgram();
+}
+
 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
 {
        TreeElement *te;
@@ -1702,71 +1697,152 @@ static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *
 
                /* selection status */
                if (TSELEM_OPEN(tselem, soops))
-                       if (tselem->type == TSE_RNA_STRUCT)
-                               glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+                       if (tselem->type == TSE_RNA_STRUCT) {
+                               Gwn_VertFormat *format = immVertexFormat();
+                               unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+                               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+                               immThemeColorShadeAlpha(TH_BACK, -15, -200);
+                               immRecti(pos, 0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+                               immUnbindProgram();
+                       }
 
                *starty -= UI_UNIT_Y;
                if (TSELEM_OPEN(tselem, soops)) {
                        outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
-                       if (tselem->type == TSE_RNA_STRUCT)
-                               fdrawline(0, (float)*starty + UI_UNIT_Y, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
+                       if (tselem->type == TSE_RNA_STRUCT) {
+                               Gwn_VertFormat *format = immVertexFormat();
+                               unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+                               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+                               immThemeColorShadeAlpha(TH_BACK, -15, -200);
+
+                               immBegin(GWN_PRIM_LINES, 2);
+                               immVertex2f(pos, 0, (float)*starty + UI_UNIT_Y);
+                               immVertex2f(pos, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
+                               immEnd();
+
+                               immUnbindProgram();
+                       }
                }
        }
 }
 
-static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
+static void outliner_draw_highlights_recursive(
+        unsigned pos, const ARegion *ar, const SpaceOops *soops, const ListBase *lb,
+        const float col_selection[4], const float col_highlight[4], const float col_searchmatch[4],
+        int start_x, int *io_start_y)
 {
-       TreeElement *te;
-       TreeStoreElem *tselem;
+       const bool is_searching = SEARCHING_OUTLINER(soops) ||
+                                 (soops->outlinevis == SO_DATA_API &&
+                                  (soops->filter & SO_FILTER_SEARCH) &&
+                                  soops->search_string[0] != 0);
 
-       for (te = lb->first; te; te = te->next) {
-               tselem = TREESTORE(te);
+       for (TreeElement *te = lb->first; te; te = te->next) {
+               const TreeStoreElem *tselem = TREESTORE(te);
+               const int start_y = *io_start_y;
 
                /* selection status */
                if (tselem->flag & TSE_SELECTED) {
-                       glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+                       immUniformColor4fv(col_selection);
+                       immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+               }
+
+               /* search match highlights
+                *   we don't expand items when searching in the datablocks but we
+                *   still want to highlight any filter matches. */
+               if (is_searching && (tselem->flag & TSE_SEARCHMATCH)) {
+                       immUniformColor4fv(col_searchmatch);
+                       immRecti(pos, start_x, start_y + 1, ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+               }
+
+               /* mouse hover highlights */
+               if ((tselem->flag & TSE_HIGHLIGHTED) || (te->drag_data != NULL)) {
+                       immUniformColor4fv(col_highlight);
+                       immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+               }
+
+               *io_start_y -= UI_UNIT_Y;
+               if (TSELEM_OPEN(tselem, soops)) {
+                       outliner_draw_highlights_recursive(
+                               pos, ar, soops, &te->subtree, col_selection, col_highlight, col_searchmatch,
+                               start_x + UI_UNIT_X, io_start_y);
                }
-               *starty -= UI_UNIT_Y;
-               if (TSELEM_OPEN(tselem, soops)) outliner_draw_selection(ar, soops, &te->subtree, starty);
        }
 }
 
+static void outliner_draw_highlights(ARegion *ar, SpaceOops *soops, int startx, int *starty)
+{
+       const float col_highlight[4] = {1.0f, 1.0f, 1.0f, 0.13f};
+       float col_selection[4], col_searchmatch[4];
+
+       UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col_selection);
+       col_selection[3] = 1.0f; /* no alpha */
+       UI_GetThemeColor4fv(TH_MATCH, col_searchmatch);
+       col_searchmatch[3] = 0.5f;
+
+       glEnable(GL_BLEND);
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       outliner_draw_highlights_recursive(pos, ar, soops, &soops->tree, col_selection, col_highlight, col_searchmatch,
+                                          startx, starty);
+       immUnbindProgram();
+       glDisable(GL_BLEND);
+}
 
-static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar,
-                               SpaceOops *soops, TreeElement **te_edit)
+static void outliner_draw_tree(
+        bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer,
+        ARegion *ar, SpaceOops *soops, const bool has_restrict_icons,
+        TreeElement **te_edit)
 {
        const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
-       TreeElement *te;
+       TreeElement *te_floating = NULL;
        int starty, startx;
-       float col[3];
 
-       glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
+       glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // only once
 
-       if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+       if (soops->outlinevis == SO_DATA_API) {
                /* struct marks */
-               UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
-               //UI_ThemeColorShade(TH_BACK, -20);
                starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
                outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
        }
 
-       /* always draw selection fill before hierarchy */
-       UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col);
-       glColor3fv(col);
+       /* draw highlights before hierarchy */
        starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
-       outliner_draw_selection(ar, soops, &soops->tree, &starty);
+       startx = 0;
+       outliner_draw_highlights(ar, soops, startx, &starty);
+
+       /* set scissor so tree elements or lines can't overlap restriction icons */
+       GLfloat scissor[4] = {0};
+       if (has_restrict_icons) {
+               int mask_x = BLI_rcti_size_x(&ar->v2d.mask) - (int)OL_TOGW + 1;
+               CLAMP_MIN(mask_x, 0);
+
+               glGetFloatv(GL_SCISSOR_BOX, scissor);
+               glScissor(0, 0, mask_x, ar->winy);
+       }
 
        // gray hierarchy lines
-       UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
+
        starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
        startx = UI_UNIT_X / 2 - 1.0f;
-       outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
+       outliner_draw_hierarchy_lines(soops, &soops->tree, startx, &starty);
 
        // items themselves
        starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
        startx = 0;
-       for (te = soops->tree.first; te; te = te->next) {
-               outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, te, startx, &starty, te_edit);
+       for (TreeElement *te = soops->tree.first; te; te = te->next) {
+               outliner_draw_tree_element(
+                       C, block, fstyle, scene, view_layer,
+                       ar, soops, te, te->drag_data != NULL,
+                       startx, &starty, te_edit, &te_floating);
+       }
+       if (te_floating && te_floating->drag_data->insert_handle) {
+               outliner_draw_tree_element_floating(ar, te_floating);
+       }
+
+       if (has_restrict_icons) {
+               /* reset scissor */
+               glScissor(UNPACK4(scissor));
        }
 }
 
@@ -1775,53 +1851,57 @@ static void outliner_back(ARegion *ar)
 {
        int ystart;
 
-       UI_ThemeColorShade(TH_BACK, 6);
        ystart = (int)ar->v2d.tot.ymax;
        ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
 
-       while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
-               glRecti(0, ystart, (int)ar->v2d.cur.xmax, ystart + UI_UNIT_Y);
-               ystart -= 2 * UI_UNIT_Y;
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformThemeColorShade(TH_BACK, 6);
+
+       const float x1 = 0.0f, x2 = ar->v2d.cur.xmax;
+       float y1 = ystart, y2;
+       int tot = (int)floor(ystart - ar->v2d.cur.ymin + 2 * UI_UNIT_Y) / (2 * UI_UNIT_Y);
+
+       if (tot > 0) {
+               immBegin(GWN_PRIM_TRIS, 6 * tot);
+               while (tot--) {
+                       y1 -= 2 * UI_UNIT_Y;
+                       y2 = y1 + UI_UNIT_Y;
+                       immVertex2f(pos, x1, y1);
+                       immVertex2f(pos, x2, y1);
+                       immVertex2f(pos, x2, y2);
+
+                       immVertex2f(pos, x1, y1);
+                       immVertex2f(pos, x2, y2);
+                       immVertex2f(pos, x1, y2);
+               }
+               immEnd();
        }
+       immUnbindProgram();
 }
 
 static void outliner_draw_restrictcols(ARegion *ar)
 {
-       int ystart;
+       glLineWidth(1.0f);
 
-       /* background underneath */
-       UI_ThemeColor(TH_BACK);
-       glRecti((int)(ar->v2d.cur.xmax - OL_TOGW),
-               (int)(ar->v2d.cur.ymin - 1), (int)ar->v2d.cur.xmax, (int)ar->v2d.cur.ymax);
+       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
+       immBegin(GWN_PRIM_LINES, 6);
 
-       UI_ThemeColorShade(TH_BACK, 6);
-       ystart = (int)ar->v2d.tot.ymax;
-       ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax);
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin);
 
-       while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
-               glRecti((int)ar->v2d.cur.xmax - OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart + UI_UNIT_Y);
-               ystart -= 2 * UI_UNIT_Y;
-       }
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymax);
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymin);
 
-       UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
-
-       /* view */
-       sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX),
-                 (int)ar->v2d.cur.ymax,
-                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX),
-                 (int)ar->v2d.cur.ymin);
-
-       /* render */
-       sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX),
-                 (int)ar->v2d.cur.ymax,
-                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX),
-                 (int)ar->v2d.cur.ymin);
-
-       /* render */
-       sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX),
-                 (int)ar->v2d.cur.ymax,
-                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX),
-                 (int)ar->v2d.cur.ymin);
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymax);
+       immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymin);
+
+       immEnd();
+       immUnbindProgram();
 }
 
 /* ****************************************************** */
@@ -1831,19 +1911,21 @@ void draw_outliner(const bContext *C)
 {
        Main *mainvar = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        ARegion *ar = CTX_wm_region(C);
        View2D *v2d = &ar->v2d;
        SpaceOops *soops = CTX_wm_space_outliner(C);
        uiBlock *block;
        int sizey = 0, sizex = 0, sizex_rna = 0;
        TreeElement *te_edit = NULL;
+       bool has_restrict_icons;
 
-       outliner_build_tree(mainvar, scene, soops); // always
+       outliner_build_tree(mainvar, scene, view_layer, soops, ar); // always
 
        /* get extents of data */
        outliner_height(soops, &soops->tree, &sizey);
 
-       if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+       if (soops->outlinevis == SO_DATA_API) {
                /* RNA has two columns:
                 *  - column 1 is (max_width + OL_RNA_COL_SPACEX) or
                 *                               (OL_RNA_COL_X), whichever is wider...
@@ -1858,6 +1940,7 @@ void draw_outliner(const bContext *C)
 
                /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
                sizex = sizex_rna + OL_RNA_COL_SIZEX + 50;
+               has_restrict_icons = false;
        }
        else {
                /* width must take into account restriction columns (if visible) so that entries will still be visible */
@@ -1867,9 +1950,11 @@ void draw_outliner(const bContext *C)
 
                /* constant offset for restriction columns */
                // XXX this isn't that great yet...
-               if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
+               if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0) {
                        sizex += OL_TOGW * 3;
+               }
 
+               has_restrict_icons = !(soops->flag & SO_HIDE_RESTRICTCOLS);
        }
 
        /* adds vertical offset */
@@ -1886,19 +1971,21 @@ void draw_outliner(const bContext *C)
        /* draw outliner stuff (background, hierarchy lines and names) */
        outliner_back(ar);
        block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
-       outliner_draw_tree((bContext *)C, block, scene, ar, soops, &te_edit);
+       outliner_draw_tree(
+               (bContext *)C, block, scene, view_layer,
+               ar, soops, has_restrict_icons, &te_edit);
 
-       if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+       if (soops->outlinevis == SO_DATA_API) {
                /* draw rna buttons */
                outliner_draw_rnacols(ar, sizex_rna);
                outliner_draw_rnabuts(block, ar, soops, sizex_rna, &soops->tree);
        }
-       else if ((soops->outlinevis == SO_ID_ORPHANS) && !(soops->flag & SO_HIDE_RESTRICTCOLS)) {
+       else if ((soops->outlinevis == SO_ID_ORPHANS) && has_restrict_icons) {
                /* draw user toggle columns */
                outliner_draw_restrictcols(ar);
                outliner_draw_userbuts(block, ar, soops, &soops->tree);
        }
-       else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
+       else if (has_restrict_icons) {
                /* draw restriction columns */
                outliner_draw_restrictcols(ar);
                outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
@@ -1911,7 +1998,4 @@ void draw_outliner(const bContext *C)
 
        UI_block_end(C, block);
        UI_block_draw(C, block);
-
-       /* clear flag that allows quick redraws */
-       soops->storeflag &= ~SO_TREESTORE_REDRAW;
 }