Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / screen / area.c
index caae803100b5996af1d17b114d83d25871f7f4e3..390098b3ea38017bb1f0395d89b4953253ae424b 100644 (file)
 #include "BLI_utildefines.h"
 #include "BLI_linklist_stack.h"
 
-
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
+#include "BKE_workspace.h"
 
 #include "RNA_access.h"
 #include "RNA_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
-#include "wm_subwindow.h"
+#include "WM_message.h"
 
 #include "ED_screen.h"
 #include "ED_screen_types.h"
 #include "ED_space_api.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_draw.h"
+
 #include "BLF_api.h"
 
 #include "IMB_imbuf.h"
@@ -72,7 +75,7 @@
 
 #include "screen_intern.h"
 
-extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
+extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3, const float color[4]); /* xxx temp */
 
 /* general area and region code */
 
@@ -88,23 +91,35 @@ static void region_draw_emboss(const ARegion *ar, const rcti *scirct)
        
        /* set transp line */
        glEnable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+       
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+       unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+       immBegin(GWN_PRIM_LINE_STRIP, 5);
        
        /* right  */
-       glColor4ub(0, 0, 0, 30);
-       sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
+       immAttrib4ub(color, 0, 0, 0, 30);
+       immVertex2f(pos, rect.xmax, rect.ymax);
+       immAttrib4ub(color, 0, 0, 0, 30);
+       immVertex2f(pos, rect.xmax, rect.ymin);
        
        /* bottom  */
-       glColor4ub(0, 0, 0, 30);
-       sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
+       immAttrib4ub(color, 0, 0, 0, 30);
+       immVertex2f(pos, rect.xmin, rect.ymin);
        
-       /* top  */
-       glColor4ub(255, 255, 255, 30);
-       sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
-
        /* left  */
-       glColor4ub(255, 255, 255, 30);
-       sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
+       immAttrib4ub(color, 255, 255, 255, 30);
+       immVertex2f(pos, rect.xmin, rect.ymax);
+
+       /* top  */
+       immAttrib4ub(color, 255, 255, 255, 30);
+       immVertex2f(pos, rect.xmax, rect.ymax);
+       
+       immEnd();
+       immUnbindProgram();
        
        glDisable(GL_BLEND);
 }
@@ -112,11 +127,11 @@ static void region_draw_emboss(const ARegion *ar, const rcti *scirct)
 void ED_region_pixelspace(ARegion *ar)
 {
        wmOrtho2_region_pixelspace(ar);
-       glLoadIdentity();
+       gpuLoadIdentity();
 }
 
 /* only exported for WM */
-void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note)
+void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note, const Scene *scene)
 {
        /* generic notes first */
        switch (note->category) {
@@ -130,15 +145,15 @@ void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note
        }
 
        if (ar->type && ar->type->listener)
-               ar->type->listener(sc, sa, ar, note);
+               ar->type->listener(sc, sa, ar, note, scene);
 }
 
 /* only exported for WM */
-void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note)
+void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note, Scene *scene, WorkSpace *workspace)
 {
        /* no generic notes? */
        if (sa->type && sa->type->listener) {
-               sa->type->listener(sc, sa, note);
+               sa->type->listener(sc, sa, note, scene, workspace);
        }
 }
 
@@ -207,15 +222,27 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
        if (G.debug_value == 1) {
                rcti click_rect;
                float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
-               char alpha_debug = 255 * alpha;
+               unsigned char alpha_debug = 255 * alpha;
 
                BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
 
-               glColor4ub(255, 0, 0, alpha_debug);
-               fdrawbox(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
-               glColor4ub(0, 255, 255, alpha_debug);
-               fdrawline(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
-               fdrawline(click_rect.xmin, click_rect.ymax, click_rect.xmax, click_rect.ymin);
+               Gwn_VertFormat *format = immVertexFormat();
+               unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+               unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+               immAttrib4ub(color, 255, 0, 0, alpha_debug);
+               immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+               imm_draw_box_wire_2d(pos, click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
+
+               immAttrib4ub(color, 0, 255, 255, alpha_debug);
+               immBegin(GWN_PRIM_LINES, 4);
+               immVertex2f(pos, click_rect.xmin, click_rect.ymin);
+               immVertex2f(pos, click_rect.xmax, click_rect.ymax);
+               immVertex2f(pos, click_rect.xmin, click_rect.ymax);
+               immVertex2f(pos, click_rect.xmax, click_rect.ymin);
+               immEnd();
+
+               immUnbindProgram();
        }
 }
 
@@ -230,69 +257,102 @@ static void area_draw_azone(short x1, short y1, short x2, short y2)
        dx = copysign(ceilf(0.3f * abs(dx)), dx);
        dy = copysign(ceilf(0.3f * abs(dy)), dy);
 
-       glEnable(GL_BLEND);
        glEnable(GL_LINE_SMOOTH);
+
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+       unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+       immBegin(GWN_PRIM_LINES, 12);
+
+       immAttrib4ub(col, 255, 255, 255, 180);
+       immVertex2f(pos, x1, y2);
+       immAttrib4ub(col, 255, 255, 255, 180);
+       immVertex2f(pos, x2, y1);
+
+       immAttrib4ub(col, 255, 255, 255, 130);
+       immVertex2f(pos, x1, y2 - dy);
+       immAttrib4ub(col, 255, 255, 255, 130);
+       immVertex2f(pos, x2 - dx, y1);
+
+       immAttrib4ub(col, 255, 255, 255, 80);
+       immVertex2f(pos, x1, y2 - 2 * dy);
+       immAttrib4ub(col, 255, 255, 255, 80);
+       immVertex2f(pos, x2 - 2 * dx, y1);
        
-       glColor4ub(255, 255, 255, 180);
-       fdrawline(x1, y2, x2, y1);
-       glColor4ub(255, 255, 255, 130);
-       fdrawline(x1, y2 - dy, x2 - dx, y1);
-       glColor4ub(255, 255, 255, 80);
-       fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
-       
-       glColor4ub(0, 0, 0, 210);
-       fdrawline(x1, y2 + 1, x2 + 1, y1);
-       glColor4ub(0, 0, 0, 180);
-       fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
-       glColor4ub(0, 0, 0, 150);
-       fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
+       immAttrib4ub(col, 0, 0, 0, 210);
+       immVertex2f(pos, x1, y2 + 1);
+       immAttrib4ub(col, 0, 0, 0, 210);
+       immVertex2f(pos, x2 + 1, y1);
+
+       immAttrib4ub(col, 0, 0, 0, 180);
+       immVertex2f(pos, x1, y2 - dy + 1);
+       immAttrib4ub(col, 0, 0, 0, 180);
+       immVertex2f(pos, x2 - dx + 1, y1);
+
+       immAttrib4ub(col, 0, 0, 0, 150);
+       immVertex2f(pos, x1, y2 - 2 * dy + 1);
+       immAttrib4ub(col, 0, 0, 0, 150);
+       immVertex2f(pos, x2 - 2 * dx + 1, y1);
+
+       immEnd();
+       immUnbindProgram();
 
        glDisable(GL_LINE_SMOOTH);
-       glDisable(GL_BLEND);
 }
 
 static void region_draw_azone_icon(AZone *az)
 {
-       GLUquadricObj *qobj = NULL; 
-       short midx = az->x1 + (az->x2 - az->x1) / 2;
-       short midy = az->y1 + (az->y2 - az->y1) / 2;
-               
-       qobj = gluNewQuadric();
-       
-       glPushMatrix();
-       glTranslatef(midx, midy, 0.0);
-       
-       /* outlined circle */
-       glEnable(GL_LINE_SMOOTH);
+       float midx = az->x1 + (az->x2 - az->x1) * 0.5f;
+       float midy = az->y1 + (az->y2 - az->y1) * 0.5f;
 
-       glColor4f(1.f, 1.f, 1.f, 0.8f);
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
 
-       gluQuadricDrawStyle(qobj, GLU_FILL); 
-       gluDisk(qobj, 0.0,  4.25f, 16, 1);
+       /* outlined circle */
+       GPU_enable_program_point_size(); /* TODO: make a fixed-size shader to avoid this */
+       immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
+       immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f);
+       immUniform4f("outlineColor", 0.2f, 0.2f, 0.2f, 0.9f);
+       immUniform1f("outlineWidth", 1.0f);
+       immUniform1f("size", 9.5f);
+       immBegin(GWN_PRIM_POINTS, 1);
+       immVertex2f(pos, midx, midy);
+       immEnd();
+       immUnbindProgram();
+       GPU_disable_program_point_size();
 
-       glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
-       
-       gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
-       gluDisk(qobj, 0.0,  4.25f, 16, 1);
-       
-       glDisable(GL_LINE_SMOOTH);
-       
-       glPopMatrix();
-       gluDeleteQuadric(qobj);
-       
        /* + */
-       sdrawline(midx, midy - 2, midx, midy + 3);
-       sdrawline(midx - 2, midy, midx + 3, midy);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor4f(0.2f, 0.2f, 0.2f, 0.9f);
+       immBegin(GWN_PRIM_LINES, 4);
+       immVertex2f(pos, midx, midy - 2);
+       immVertex2f(pos, midx, midy + 3);
+       immVertex2f(pos, midx - 2, midy);
+       immVertex2f(pos, midx + 3, midy);
+       immEnd();
+       immUnbindProgram();
 }
 
 static void draw_azone_plus(float x1, float y1, float x2, float y2)
 {
        float width = 0.1f * U.widget_unit;
        float pad = 0.2f * U.widget_unit;
-       
-       glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
-       glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
-       glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
+
+       Gwn_VertFormat *format = immVertexFormat();
+       unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+       glEnable(GL_BLEND);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor4f(0.8f, 0.8f, 0.8f, 0.4f);
+
+       immRectf(pos, (x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
+       immRectf(pos, x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
+       immRectf(pos, (x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
+
+       immUnbindProgram();
+       glDisable(GL_BLEND);
 }
 
 static void region_draw_azone_tab_plus(AZone *az)
@@ -315,54 +375,41 @@ static void region_draw_azone_tab_plus(AZone *az)
                        break;
        }
 
-       glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
-       UI_draw_roundbox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
-
-       glEnable(GL_BLEND);
+       float color[4] = {0.05f, 0.05f, 0.05f, 0.4f};
+       UI_draw_roundbox_aa(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, color);
 
-       glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
        draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
-
-       glDisable(GL_BLEND);
 }
 
 static void region_draw_azone_tab(AZone *az)
 {
-       float col[3];
+       float col[4], black[4] = {0.0f, 0.0f, 0.0f, 0.5f};
        
        glEnable(GL_BLEND);
        UI_GetThemeColor3fv(TH_HEADER, col);
-       glColor4f(col[0], col[1], col[2], 0.5f);
-       
+       col[3] = 0.5f;
+
        /* add code to draw region hidden as 'too small' */
        switch (az->edge) {
                case AE_TOP_TO_BOTTOMRIGHT:
-                       UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
-                       
-                       UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
-                       glColor4ub(0, 0, 0, 255);
-                       UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
+                       UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
+                       UI_draw_roundbox_shade_x(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f, col);
+                       UI_draw_roundbox_aa(false, (float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f, black);
                        break;
                case AE_BOTTOM_TO_TOPLEFT:
-                       UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
-                       
-                       UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
-                       glColor4ub(0, 0, 0, 255);
-                       UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
+                       UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
+                       UI_draw_roundbox_shade_x(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f, col);
+                       UI_draw_roundbox_aa(false, (float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f, black);
                        break;
                case AE_LEFT_TO_TOPRIGHT:
-                       UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
-                       
-                       UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
-                       glColor4ub(0, 0, 0, 255);
-                       UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
+                       UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
+                       UI_draw_roundbox_shade_x(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f, col);
+                       UI_draw_roundbox_aa(false, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, black);
                        break;
                case AE_RIGHT_TO_TOPLEFT:
-                       UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
-                       
-                       UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
-                       glColor4ub(0, 0, 0, 255);
-                       UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
+                       UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
+                       UI_draw_roundbox_shade_x(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f, col);
+                       UI_draw_roundbox_aa(false, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, black);
                        break;
        }
        
@@ -373,24 +420,24 @@ static void region_draw_azone_tria(AZone *az)
 {
        glEnable(GL_BLEND);
        //UI_GetThemeColor3fv(TH_HEADER, col);
-       glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
+       float color[4] = {0.0f, 0.0f, 0.0f, 0.35f};
        
        /* add code to draw region hidden as 'too small' */
        switch (az->edge) {
                case AE_TOP_TO_BOTTOMRIGHT:
-                       ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y1, (float)(az->x1 + az->x2) / 2, (float)az->y2);
+                       ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y1, (float)(az->x1 + az->x2) / 2, (float)az->y2, color);
                        break;
                        
                case AE_BOTTOM_TO_TOPLEFT:
-                       ui_draw_anti_tria((float)az->x1, (float)az->y2, (float)az->x2, (float)az->y2, (float)(az->x1 + az->x2) / 2, (float)az->y1);
+                       ui_draw_anti_tria((float)az->x1, (float)az->y2, (float)az->x2, (float)az->y2, (float)(az->x1 + az->x2) / 2, (float)az->y1, color);
                        break;
 
                case AE_LEFT_TO_TOPRIGHT:
-                       ui_draw_anti_tria((float)az->x2, (float)az->y1, (float)az->x2, (float)az->y2, (float)az->x1, (float)(az->y1 + az->y2) / 2);
+                       ui_draw_anti_tria((float)az->x2, (float)az->y1, (float)az->x2, (float)az->y2, (float)az->x1, (float)(az->y1 + az->y2) / 2, color);
                        break;
                        
                case AE_RIGHT_TO_TOPLEFT:
-                       ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x1, (float)az->y2, (float)az->x2, (float)(az->y1 + az->y2) / 2);
+                       ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x1, (float)az->y2, (float)az->x2, (float)(az->y1 + az->y2) / 2, color);
                        break;
                        
        }
@@ -412,10 +459,10 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
 
        glLineWidth(1.0f);
        glEnable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
-       glPushMatrix();
-       glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f);
+       gpuPushMatrix();
+       gpuTranslate2f(-ar->winrct.xmin, -ar->winrct.ymin);
        
        for (az = sa->actionzones.first; az; az = az->next) {
                /* test if action zone is over this region */
@@ -452,28 +499,38 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
                }
        }
 
-       glPopMatrix();
+       gpuPopMatrix();
 
        glDisable(GL_BLEND);
 }
 
-/* only exported for WM */
-/* makes region ready for drawing, sets pixelspace */
-void ED_region_set(const bContext *C, ARegion *ar)
+/* Follow wmMsgNotifyFn spec */
+void ED_region_do_msg_notify_tag_redraw(
+        bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
 {
-       wmWindow *win = CTX_wm_window(C);
-       ScrArea *sa = CTX_wm_area(C);
-       
-       ar->drawrct = ar->winrct;
-       
-       /* note; this sets state, so we can use wmOrtho and friends */
-       wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, true);
-       
-       UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
-       
-       ED_region_pixelspace(ar);
-}
+       ARegion *ar = msg_val->owner;
+       ED_region_tag_redraw(ar);
 
+       /* This avoids _many_ situations where header/properties control display settings.
+        * the common case is space properties in the header */
+       if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_UI)) {
+               while (ar && ar->prev) {
+                       ar = ar->prev;
+               }
+               for (; ar; ar = ar->next) {
+                       if (ELEM(ar->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS)) {
+                               ED_region_tag_redraw(ar);
+                       }
+               }
+       }
+}
+/* Follow wmMsgNotifyFn spec */
+void ED_area_do_msg_notify_tag_refresh(
+        bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
+{
+       ScrArea *sa = msg_val->user_data;
+       ED_area_tag_refresh(sa);
+}
 
 /* only exported for WM */
 void ED_region_do_draw(bContext *C, ARegion *ar)
@@ -481,27 +538,15 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        wmWindow *win = CTX_wm_window(C);
        ScrArea *sa = CTX_wm_area(C);
        ARegionType *at = ar->type;
-       bool scissor_pad;
 
        /* see BKE_spacedata_draw_locks() */
        if (at->do_lock)
                return;
 
-       /* if no partial draw rect set, full rect */
-       if (ar->drawrct.xmin == ar->drawrct.xmax) {
-               ar->drawrct = ar->winrct;
-               scissor_pad = true;
-       }
-       else {
-               /* extra clip for safety */
-               BLI_rcti_isect(&ar->winrct, &ar->drawrct, &ar->drawrct);
-               scissor_pad = false;
-       }
-
        ar->do_draw |= RGN_DRAWING;
        
-       /* note; this sets state, so we can use wmOrtho and friends */
-       wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, scissor_pad);
+       /* Set viewport, scissor, ortho and ar->drawrct. */
+       wmPartialViewport(&ar->drawrct, &ar->winrct, &ar->drawrct);
 
        wmOrtho2_region_pixelspace(ar);
        
@@ -512,7 +557,7 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
                UI_ThemeClearColor(TH_HEADER);
                glClear(GL_COLOR_BUFFER_BIT);
                
-               UI_ThemeColor(TH_TEXT);
+               UI_FontThemeColor(BLF_default(), TH_TEXT);
                BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
        }
        else if (at->draw) {
@@ -529,9 +574,13 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        /* for debugging unneeded area redraws and partial redraw */
 #if 0
        glEnable(GL_BLEND);
-       glColor4f(drand48(), drand48(), drand48(), 0.1f);
-       glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
+       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);
+       immUniformColor4f(drand48(), drand48(), drand48(), 0.1f);
+       immRectf(pos, ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
                ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
+       immUnbindProgram();
        glDisable(GL_BLEND);
 #endif
 
@@ -540,12 +589,45 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        UI_blocklist_free_inactive(C, &ar->uiblocks);
 
        if (sa) {
+               const bScreen *screen = WM_window_get_active_screen(win);
+
                /* disable emboss when the area is full,
                 * unless we need to see division between regions (quad-split for eg) */
-               if (((win->screen->state == SCREENFULL) && (ar->alignment == RGN_ALIGN_NONE)) == 0) {
+               if (((screen->state == SCREENFULL) && (ar->alignment == RGN_ALIGN_NONE)) == 0) {
                        region_draw_emboss(ar, &ar->winrct);
                }
        }
+
+       /* We may want to detach message-subscriptions from drawing. */
+       {
+               WorkSpace *workspace = CTX_wm_workspace(C);
+               wmWindowManager *wm = CTX_wm_manager(C);
+               bScreen *screen = WM_window_get_active_screen(win);
+               Scene *scene = CTX_data_scene(C);
+               struct wmMsgBus *mbus = wm->message_bus;
+               WM_msgbus_clear_by_owner(mbus, ar);
+
+               /* Cheat, always subscribe to this space type properties.
+                *
+                * This covers most cases and avoids copy-paste similar code for each space type.
+                */
+               if (ELEM(ar->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS, RGN_TYPE_UI, RGN_TYPE_TOOLS)) {
+                       SpaceLink *sl = sa->spacedata.first;
+
+                       PointerRNA ptr;
+                       RNA_pointer_create(&screen->id, &RNA_Space, sl, &ptr);
+
+                       wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+                               .owner = ar,
+                               .user_data = ar,
+                               .notify = ED_region_do_msg_notify_tag_redraw,
+                       };
+                       /* All properties for this space type. */
+                       WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_region_tag_redraw, __func__);
+               }
+
+               ED_region_message_subscribe(C, workspace, scene, screen, sa, ar, mbus);
+       }
 }
 
 /* **********************************
@@ -656,7 +738,7 @@ void ED_area_headerprint(ScrArea *sa, const char *str)
 /* ************************************************************ */
 
 
-static void area_azone_initialize(wmWindow *win, bScreen *screen, ScrArea *sa)
+static void area_azone_initialize(wmWindow *win, const bScreen *screen, ScrArea *sa)
 {
        AZone *az;
        
@@ -1316,7 +1398,9 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
                 * must be minimum '4' */
        }
        else {
-               if (ELEM(win->screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
+               const bScreen *screen = WM_window_get_active_screen(win);
+
+               if (ELEM(screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
                        region_azone_add(sa, ar, alignment, false);
                }
                else {
@@ -1349,24 +1433,14 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
 
 
 /* used for area initialize below */
-static void region_subwindow(wmWindow *win, ARegion *ar, bool activate)
+static void region_subwindow(ARegion *ar)
 {
        bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
 
        if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev)
                hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
 
-       if (hidden) {
-               if (ar->swinid)
-                       wm_subwindow_close(win, ar->swinid);
-               ar->swinid = 0;
-       }
-       else if (ar->swinid == 0) {
-               ar->swinid = wm_subwindow_open(win, &ar->winrct, activate);
-       }
-       else {
-               wm_subwindow_position(win, ar->swinid, &ar->winrct, activate);
-       }
+       ar->visible = !hidden;
 }
 
 static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
@@ -1440,6 +1514,7 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
 /* called in screen_refresh, or screens_init, also area size changes */
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 {
+       const bScreen *screen = WM_window_get_active_screen(win);
        ARegion *ar;
        rcti rect;
        
@@ -1458,7 +1533,7 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        area_calc_totrct(sa, WM_window_pixels_x(win), WM_window_pixels_y(win));
        
        /* clear all azones, add the area triange widgets */
-       area_azone_initialize(win, win->screen, sa);
+       area_azone_initialize(win, screen, sa);
 
        /* region rect sizes */
        rect = sa->totrct;
@@ -1472,14 +1547,15 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        
        /* region windows, default and own handlers */
        for (ar = sa->regionbase.first; ar; ar = ar->next) {
-               region_subwindow(win, ar, false);
+               region_subwindow(ar);
                
-               if (ar->swinid) {
+               if (ar->visible) {
                        /* default region handlers */
                        ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
                        /* own handlers */
-                       if (ar->type->init)
+                       if (ar->type->init) {
                                ar->type->init(wm, ar);
+                       }
                }
                else {
                        /* prevent uiblocks to run */
@@ -1500,22 +1576,16 @@ static void region_update_rect(ARegion *ar)
 /**
  * Call to move a popup window (keep OpenGL context free!)
  */
-void ED_region_update_rect(bContext *C, ARegion *ar)
+void ED_region_update_rect(bContext *UNUSED(C), ARegion *ar)
 {
-       wmWindow *win = CTX_wm_window(C);
-
-       wm_subwindow_rect_set(win, ar->swinid, &ar->winrct);
-
        region_update_rect(ar);
 }
 
 /* externally called for floating regions like menus */
-void ED_region_init(bContext *C, ARegion *ar)
+void ED_region_init(bContext *UNUSED(C), ARegion *ar)
 {
-//     ARegionType *at = ar->type;
-
        /* refresh can be called before window opened */
-       region_subwindow(CTX_wm_window(C), ar, false);
+       region_subwindow(ar);
 
        region_update_rect(ar);
 }
@@ -1764,6 +1834,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
 
 void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int contextnr, const bool vertical)
 {
+       const WorkSpace *workspace = CTX_wm_workspace(C);
        ScrArea *sa = CTX_wm_area(C);
        uiStyle *style = UI_style_get_dpi();
        uiBlock *block;
@@ -1814,6 +1885,11 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
                        continue;
                }
 
+               /* If we're tagged, only use compatible. */
+               if (pt->owner_id[0] && BKE_workspace_owner_id_check(workspace, pt->owner_id) == false) {
+                       continue;
+               }
+
                /* draw panel */
                if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
                        BLI_SMALLSTACK_PUSH(pt_stack, pt);
@@ -1973,8 +2049,12 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
                /* view should be in pixelspace */
                UI_view2d_view_restore(C);
                glEnable(GL_BLEND);
-               UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
-               glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
+               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);
+               immUniformThemeColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
+               immRecti(pos, 0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
+               immUnbindProgram();
                glDisable(GL_BLEND);
        }
        else {
@@ -2078,22 +2158,37 @@ int ED_area_headersize(void)
        return (int)(HEADERY * UI_DPI_FAC);
 }
 
-void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
+void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw)
 {
        const int header_height = UI_UNIT_Y;
        uiStyle *style = UI_style_get_dpi();
        int fontid = style->widget.uifont_id;
        GLint scissor[4];
        rcti rect;
+       int num_lines = 0;
 
        /* background box */
        ED_region_visible_rect(ar, &rect);
-       rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
 
-       /* box fill entire width or just around text */
-       if (!full_redraw)
-               rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
+       /* Box fill entire width or just around text. */
+       if (!full_redraw) {
+               const char **text = &text_array[0];
+               while (*text) {
+                       rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, *text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
+                       text++;
+                       num_lines++;
+               }
+       }
+       /* Just count the line number. */
+       else {
+               const char **text = &text_array[0];
+               while (*text) {
+                       text++;
+                       num_lines++;
+               }
+       }
 
+       rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height * num_lines;
        rect.ymax = BLI_rcti_size_y(&ar->winrct);
 
        /* setup scissor */
@@ -2102,18 +2197,29 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
                  BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
 
        glEnable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glColor4fv(fill_color);
-       glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+       glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+       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);
+       immUniformColor4fv(fill_color);
+       immRecti(pos, rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+       immUnbindProgram();
        glDisable(GL_BLEND);
 
        /* text */
-       UI_ThemeColor(TH_TEXT_HI);
+       UI_FontThemeColor(fontid, TH_TEXT_HI);
        BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        BLF_enable(fontid, BLF_CLIPPING);
-       BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
-
-       BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
+       int offset = num_lines - 1;
+       {
+               const char **text = &text_array[0];
+               while (*text) {
+                       BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit + offset * header_height, 0.0f);
+                       BLF_draw(fontid, *text, BLF_DRAW_STR_DUMMY_MAX);
+                       text++;
+                       offset--;
+               }
+       }
 
        BLF_disable(fontid, BLF_CLIPPING);
 
@@ -2121,6 +2227,11 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
        glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
 }
 
+void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
+{
+       ED_region_info_draw_multiline(ar, (const char *[2]){text, NULL}, fill_color, full_redraw);
+}
+
 #define MAX_METADATA_STR    1024
 
 static const char *meta_data_list[] =
@@ -2289,11 +2400,11 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
                return;
 
        /* find window pixel coordinates of origin */
-       glPushMatrix();
+       gpuPushMatrix();
 
        /* offset and zoom using ogl */
-       glTranslatef(x, y, 0.0f);
-       glScalef(zoomx, zoomy, 1.0f);
+       gpuTranslate2f(x, y);
+       gpuScale2f(zoomx, zoomy);
 
        BLF_size(blf_mono_font, style->widgetlabel.points * 1.5f * U.pixelsize, U.dpi);
 
@@ -2303,17 +2414,20 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
        box_y = metadata_box_height_get(ibuf, blf_mono_font, true);
 
        if (box_y) {
-               UI_ThemeColor(TH_METADATA_BG);
-
                /* set up rect */
                BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymax, frame->ymax + box_y);
                /* draw top box */
-               glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+               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);
+               immUniformThemeColor(TH_METADATA_BG);
+               immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+               immUnbindProgram();
 
                BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
                BLF_enable(blf_mono_font, BLF_CLIPPING);
 
-               UI_ThemeColor(TH_METADATA_TEXT);
+               UI_FontThemeColor(blf_mono_font, TH_METADATA_TEXT);
                metadata_draw_imbuf(ibuf, &rect, blf_mono_font, true);
 
                BLF_disable(blf_mono_font, BLF_CLIPPING);
@@ -2325,23 +2439,26 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
        box_y = metadata_box_height_get(ibuf, blf_mono_font, false);
 
        if (box_y) {
-               UI_ThemeColor(TH_METADATA_BG);
-
                /* set up box rect */
                BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymin - box_y, frame->ymin);
                /* draw top box */
-               glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+               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);
+               immUniformThemeColor(TH_METADATA_BG);
+               immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+               immUnbindProgram();
 
                BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
                BLF_enable(blf_mono_font, BLF_CLIPPING);
 
-               UI_ThemeColor(TH_METADATA_TEXT);
+               UI_FontThemeColor(blf_mono_font, TH_METADATA_TEXT);
                metadata_draw_imbuf(ibuf, &rect, blf_mono_font, false);
 
                BLF_disable(blf_mono_font, BLF_CLIPPING);
        }
 
-       glPopMatrix();
+       gpuPopMatrix();
 }
 
 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
@@ -2351,11 +2468,16 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
        int x1, y1, x2, y2;
 
        /* the image is located inside (0, 0), (1, 1) as set by view2d */
-       UI_ThemeColorShade(TH_BACK, 20);
-
        UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
        UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
-       glRectf(x1, y1, x2, y2);
+
+       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, 20);
+       immRectf(pos, x1, y1, x2, y2);
+       immUnbindProgram();
 
        /* gridsize adapted to zoom level */
        gridsize = 0.5f * (zoomx + zoomy);
@@ -2375,33 +2497,58 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
                }
        }
 
-       /* the fine resolution level */
        blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
        CLAMP(blendfac, 0.0f, 1.0f);
-       UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
 
-       fac = 0.0f;
-       glBegin(GL_LINES);
-       while (fac < 1.0f) {
-               glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
-               glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
-               glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
-               glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
-               fac += gridstep;
-       }
+       int count_fine = 1.0f / gridstep;
+       int count_large = 1.0f / (4.0f * gridstep);
+
+       if (count_fine > 0) {
+               GWN_vertformat_clear(format);
+               pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+               unsigned color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+               
+               immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+               immBegin(GWN_PRIM_LINES, 4 * count_fine + 4 * count_large);
+               
+               float theme_color[3];
+               UI_GetThemeColorShade3fv(TH_BACK, (int)(20.0f * (1.0f - blendfac)), theme_color);
+               fac = 0.0f;
+               
+               /* the fine resolution level */
+               for (int i = 0; i < count_fine; i++) {
+                       immAttrib3fv(color, theme_color);
+                       immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
+                       immAttrib3fv(color, theme_color);
+                       immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
+                       immAttrib3fv(color, theme_color);
+                       immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
+                       immAttrib3fv(color, theme_color);
+                       immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
+                       fac += gridstep;
+               }
 
-       /* the large resolution level */
-       UI_ThemeColor(TH_BACK);
+               if (count_large > 0) {
+                       UI_GetThemeColor3fv(TH_BACK, theme_color);
+                       fac = 0.0f;
+                       
+                       /* the large resolution level */
+                       for (int i = 0; i < count_large; i++) {
+                               immAttrib3fv(color, theme_color);
+                               immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
+                               immAttrib3fv(color, theme_color);
+                               immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
+                               immAttrib3fv(color, theme_color);
+                               immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
+                               immAttrib3fv(color, theme_color);
+                               immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
+                               fac += 4.0f * gridstep;
+                       }
+               }
 
-       fac = 0.0f;
-       while (fac < 1.0f) {
-               glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
-               glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
-               glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
-               glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
-               fac += 4.0f * gridstep;
+               immEnd();
+               immUnbindProgram();
        }
-       glEnd();
 }
 
 /* If the area has overlapping regions, it returns visible rect for Region *ar */
@@ -2438,8 +2585,11 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect)
 
 void ED_region_cache_draw_background(const ARegion *ar)
 {
-       glColor4ub(128, 128, 255, 64);
-       glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
+       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor4ub(128, 128, 255, 64);
+       immRecti(pos, 0, 0, ar->winx, 8 * UI_DPI_FAC);
+       immUnbindProgram();
 }
 
 void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
@@ -2455,9 +2605,13 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
 
        BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
 
-       glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
+       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformThemeColor(TH_CFRAME);
+       immRecti(pos, x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
+       immUnbindProgram();
 
-       UI_ThemeColor(TH_TEXT);
+       UI_FontThemeColor(fontid, TH_TEXT);
        BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
        BLF_draw(fontid, numstr, sizeof(numstr));
 }
@@ -2465,17 +2619,40 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
 void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
 {
        if (num_segments) {
-               int a;
+               unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+               immUniformColor4ub(128, 128, 255, 128);
 
-               glColor4ub(128, 128, 255, 128);
+               for (int a = 0; a < num_segments; a++) {
+                       float x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
+                       float x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
 
-               for (a = 0; a < num_segments; a++) {
-                       float x1, x2;
+                       immRecti(pos, x1, 0, x2, 8 * UI_DPI_FAC);
+                       /* TODO(merwin): use primitive restart to draw multiple rects more efficiently */
+               }
 
-                       x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
-                       x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
+               immUnbindProgram();
+       }
+}
 
-                       glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
-               }
+/**
+ * Generate subscriptions for this region.
+ */
+void ED_region_message_subscribe(
+        bContext *C,
+        struct WorkSpace *workspace, struct Scene *scene,
+        struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+        struct wmMsgBus *mbus)
+{
+       if (ar->manipulator_map != NULL) {
+               WM_manipulatormap_message_subscribe(C, ar->manipulator_map, ar, mbus);
+       }
+
+       if (BLI_listbase_is_empty(&ar->uiblocks)) {
+               UI_region_message_subscribe(ar, mbus);
+       }
+
+       if (ar->type->message_subscribe != NULL) {
+               ar->type->message_subscribe(C, workspace, scene, screen, sa, ar, mbus);
        }
 }