Fix TTY switching after failed failed repaint with legacy mode set.

Reported in !179 adding weston_output_repaint_failed resets the output

Co-authored-by: Daniel Stone
Co-authored-by: Julius Krah
Signed-off-by: n3rdopolis <bluescreen_avenger@verizon.net>
diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c
index 2a6b0d1..780d007 100644
--- a/libweston/backend-drm/kms.c
+++ b/libweston/backend-drm/kms.c
@@ -1271,6 +1271,14 @@
 		if (ret != 0) {
 			weston_log("Couldn't apply state for output %s\n",
 				   output->base.name);
+			weston_output_repaint_failed(&output->base);
+			drm_output_state_free(output->state_cur);
+			output->state_cur = drm_output_state_alloc(output, NULL);
+			b->state_invalid = true;
+			if (!b->use_pixman) {
+				drm_output_fini_egl(output);
+				drm_output_init_egl(output, b);
+			}
 		}
 	}
 
diff --git a/libweston/backend.h b/libweston/backend.h
index b9afb2c..3ae59a6 100644
--- a/libweston/backend.h
+++ b/libweston/backend.h
@@ -161,6 +161,10 @@
 weston_output_finish_frame(struct weston_output *output,
 			   const struct timespec *stamp,
 			   uint32_t presented_flags);
+
+void
+weston_output_repaint_failed(struct weston_output *output);
+
 int
 weston_output_mode_set_native(struct weston_output *output,
 			      struct weston_mode *mode,
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 3fa1b8d..26ef54b 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -3215,6 +3215,15 @@
 	output_repaint_timer_arm(compositor);
 }
 
+
+WL_EXPORT void
+weston_output_repaint_failed(struct weston_output *output)
+{
+	weston_log("Clearing repaint status.\n");
+	assert(output->repaint_status == REPAINT_AWAITING_COMPLETION);
+	output->repaint_status = REPAINT_NOT_SCHEDULED;
+}
+
 static void
 idle_repaint(void *data)
 {