Add an option to downscale hi-res views
[pcsx_rearmed.git] / plugins / gpulib / vout_pl.c
index 11307e2..075e3c3 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <string.h>
 #include "gpu.h"
-#include "cspace.h"
 #include "../../frontend/plugin_lib.h"
 
 static const struct rearmed_cbs *cbs;
@@ -32,14 +31,25 @@ static void check_mode_change(int force)
   static int old_h;
   int w = gpu.screen.hres;
   int h = gpu.screen.h;
+  int w_out = w;
+  int h_out = h;
 
   gpu.state.enhancement_active =
     gpu.get_enhancement_bufer != NULL && gpu.state.enhancement_enable
     && w <= 512 && h <= 256 && !gpu.status.rgb24;
 
   if (gpu.state.enhancement_active) {
-    w *= 2;
-    h *= 2;
+    w_out *= 2;
+    h_out *= 2;
+  }
+
+  gpu.state.downscale_active =
+    gpu.get_downscale_buffer != NULL && gpu.state.downscale_enable
+    && (w >= 512 || h >= 256);
+
+  if (gpu.state.downscale_active) {
+    w_out = w < 512 ? w : 320;
+    h_out = h < 256 ? h : h / 2;
   }
 
   // width|rgb24 change?
@@ -48,8 +58,7 @@ static void check_mode_change(int force)
     old_status = gpu.status.reg;
     old_h = h;
 
-    cbs->pl_vout_set_mode(w, h,
-      (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
+    cbs->pl_vout_set_mode(w_out, h_out, w, h, gpu.status.rgb24 ? 24 : 16);
   }
 }
 
@@ -69,11 +78,14 @@ void vout_update(void)
   if (gpu.state.enhancement_active)
     vram = gpu.get_enhancement_bufer(&x, &y, &w, &h, &vram_h);
 
+  if (gpu.state.downscale_active)
+    vram = gpu.get_downscale_buffer(&x, &y, &w, &h, &vram_h);
+
   if (y + h > vram_h) {
     if (y + h - vram_h > h / 2) {
       // wrap
-      y = 0;
       h -= vram_h - y;
+      y = 0;
     }
     else
       // clip
@@ -89,6 +101,8 @@ void vout_blank(void)
 {
   int w = gpu.screen.hres;
   int h = gpu.screen.h;
+
+  check_mode_change(0);
   if (gpu.state.enhancement_active) {
     w *= 2;
     h *= 2;
@@ -103,6 +117,7 @@ long GPUopen(void **unused)
 
   cbs->pl_vout_open();
   check_mode_change(1);
+  vout_update();
   return 0;
 }