[PATCH 1/3] d2d1/tests: Enable developers to export generated images.

Giovanni Mascellani gio at debian.org
Tue Jan 21 06:02:05 CST 2020


By flipping the export_surfaces flag a developer can easily access the
generated bitmaps to inspect them visually. By default the flag is
disabled, so that no files are generated or overwritten and no
performance penalty is paid.

Signed-off-by: Giovanni Mascellani <gio at debian.org>
---

Is this kind of developer-oriented patch acceptable in Wine? Or is
there already an easy way to export the bitmaps generated during the
test? I could not find one.

---
 dlls/d2d1/tests/d2d1.c | 45 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c
index 5377c4ea34..801334f2ad 100644
--- a/dlls/d2d1/tests/d2d1.c
+++ b/dlls/d2d1/tests/d2d1.c
@@ -28,6 +28,7 @@
 #include "wine/heap.h"
 
 static BOOL use_mt = TRUE;
+static const BOOL export_surfaces = FALSE;
 
 static struct test_entry
 {
@@ -613,6 +614,30 @@ static void read_figure(struct figure *figure, BYTE *data, unsigned int pitch,
         figure_add_span(figure, span);
 }
 
+static void export_surface_to_ppm(IDXGISurface *surface, const char *filename,
+                                  unsigned int x, unsigned int y,
+                                  unsigned int w, unsigned int h) {
+    unsigned int i, j, pitch;
+    struct resource_readback rb;
+    const BYTE *data;
+    FILE *fout;
+
+    get_surface_readback(surface, &rb);
+    data = rb.map_desc.pData;
+    pitch = rb.map_desc.RowPitch;
+
+    fout = fopen(filename, "w");
+    fprintf(fout, "P3\n%d %d\n%d\n", w, h, 255);
+    for (i = 0; i < h; i++) {
+        const BYTE *row = &data[(y+i) * pitch + x * 4];
+        for (j = 0; j < w; j++) {
+            fprintf(fout, "%d %d %d\n", row[j * 4 + 2], row[j * 4 + 1], row[j * 4]);
+        }
+    }
+    fflush(fout);
+    fclose(fout);
+}
+
 static BOOL compare_figure(IDXGISurface *surface, unsigned int x, unsigned int y,
         unsigned int w, unsigned int h, DWORD prev, unsigned int max_diff, const char *ref)
 {
@@ -5841,6 +5866,10 @@ static void test_draw_geometry(void)
     hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
     ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
 
+    if (export_surfaces) {
+        export_surface_to_ppm(surface, "surface1.ppm", 0, 0, 640, 480);
+    }
+
     match = compare_figure(surface,   0,   0, 160, 160, 0xff652e89, 0, "");
     ok(match, "Figure does not match.\n");
     match = compare_figure(surface, 160,   0, 160, 160, 0xff652e89, 0, "yGBQUFBQUFBQUFDoYQAA");
@@ -5983,6 +6012,10 @@ static void test_draw_geometry(void)
     ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
     ID2D1PathGeometry_Release(geometry);
 
+    if (export_surfaces) {
+        export_surface_to_ppm(surface, "surface2.ppm", 0, 0, 640, 480);
+    }
+
     match = compare_figure(surface,   0,   0, 160, 160, 0xff652e89, 0, "");
     ok(match, "Figure does not match.\n");
     match = compare_figure(surface, 160,   0, 160, 160, 0xff652e89, 0, "");
@@ -6095,6 +6128,10 @@ static void test_draw_geometry(void)
     ID2D1RectangleGeometry_Release(rect_geometry[1]);
     ID2D1RectangleGeometry_Release(rect_geometry[0]);
 
+    if (export_surfaces) {
+        export_surface_to_ppm(surface, "surface3.ppm", 0, 0, 640, 480);
+    }
+
     match = compare_figure(surface,   0,   0, 160, 160, 0xff652e89, 0,
             "vi5kPGQ8ZDxkPGQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwU"
             "PBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8"
@@ -6266,6 +6303,10 @@ static void test_draw_geometry(void)
     ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
     ID2D1PathGeometry_Release(geometry);
 
+    if (export_surfaces) {
+        export_surface_to_ppm(surface, "surface4.ppm", 0, 0, 640, 480);
+    }
+
     match = compare_figure(surface,   0,   0, 160, 160, 0xff652e89, 0,
             "vi5kPGQ8ZDxkPGQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwU"
             "PBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8FDwUPBQ8"
@@ -6446,6 +6487,10 @@ static void test_draw_geometry(void)
     ID2D1TransformedGeometry_Release(transformed_geometry[1]);
     ID2D1TransformedGeometry_Release(transformed_geometry[0]);
 
+    if (export_surfaces) {
+        export_surface_to_ppm(surface, "surface5.ppm", 0, 0, 640, 480);
+    }
+
     match = compare_figure(surface,   0,   0, 160, 160, 0xff652e89, 128,
             "yjIJkQEHBwaIAQUSBYMBBBYEggEEFgSCAQQWBIIBBBYEggEEFgSCAQQWBIIBBBYEggEEFgSCAQQW"
             "BIIBBBYEggEEFgSDAQQVBIMBBBUEgwEEFQSDAQQVBIMBBBUEgwEEFQSDAQQVBIMBBBUEgwEEFQSD"
-- 
2.25.0




More information about the wine-devel mailing list