Merge RP1A.191212.001

Change-Id: I68340f956662148363459d8ccd428b57a18e9ccc
diff --git a/Android.bp b/Android.bp
index e970a85..8247b84 100644
--- a/Android.bp
+++ b/Android.bp
@@ -22,6 +22,7 @@
         "lib/gem.c",
         "lib/gem_msm.c",
         "lib/igt_aux.c",
+        "lib/igt_color_encoding.c",
         "lib/igt_core.c",
         "lib/igt_debugfs.c",
         "lib/igt_device.c",
@@ -33,6 +34,7 @@
         "lib/igt_sysfs.c",
         "lib/ion.c",
         "lib/ioctl_wrappers.c",
+        "lib/sw_sync.c",
         "lib/i915/gem_mman.c",
         "lib/uwildmat/uwildmat.c",
     ],
@@ -63,6 +65,12 @@
 }
 
 cc_test {
+    name: "kms_atomic",
+    defaults: ["igt-gpu-tools-test-defaults"],
+    srcs: ["tests/kms_atomic.c"],
+}
+
+cc_test {
     name: "ion_fb",
     defaults: ["igt-gpu-tools-test-defaults"],
     srcs: ["tests/ion_fb.c"],
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index f5a4e5f..879211f 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1635,9 +1635,11 @@
 	fb_id = igt_create_fb(fd, width, height, format, modifier, fb);
 	igt_assert(fb_id);
 
+#if defined(USE_CAIRO_PIXMAN)
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_color(cr, 0, 0, width, height, r, g, b);
 	igt_put_cairo_ctx(fd, fb, cr);
+#endif
 
 	return fb_id;
 }
@@ -1672,9 +1674,11 @@
 	fb_id = igt_create_fb(fd, width, height, format, modifier, fb);
 	igt_assert(fb_id);
 
+#if defined(USE_CAIRO_PIXMAN)
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_test_pattern(cr, width, height);
 	igt_put_cairo_ctx(fd, fb, cr);
+#endif
 
 	return fb_id;
 }
@@ -1714,10 +1718,12 @@
 	fb_id = igt_create_fb(fd, width, height, format, modifier, fb);
 	igt_assert(fb_id);
 
+#if defined(USE_CAIRO_PIXMAN)
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_color(cr, 0, 0, width, height, r, g, b);
 	igt_paint_test_pattern(cr, width, height);
 	igt_put_cairo_ctx(fd, fb, cr);
+#endif
 
 	return fb_id;
 }
@@ -3576,8 +3582,12 @@
 		if (f->drm_id == drm_format)
 			return (f->cairo_id != CAIRO_FORMAT_INVALID) ||
 				(f->pixman_id != PIXMAN_invalid);
-#endif
+
 	return false;
+#else
+	/* If we don't use Cairo/Pixman, all formats are equally good */
+	return true;
+#endif
 }
 
 /**
diff --git a/lib/sw_sync.c b/lib/sw_sync.c
index d671923..9a3bd6c 100644
--- a/lib/sw_sync.c
+++ b/lib/sw_sync.c
@@ -33,7 +33,7 @@
 #include <stdint.h>
 #include <sys/ioctl.h>
 
-#include "sync_file.h"
+#include <linux/sync_file.h>
 
 #include "igt_debugfs.h"
 #include "igt_kmod.h"
diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c
index 8462d12..e34bee6 100644
--- a/tests/kms_atomic.c
+++ b/tests/kms_atomic.c
@@ -302,6 +302,7 @@
 				    format_overlay, I915_TILING_NONE,
 				    0.2, 0.2, 0.2, &fb_overlay);
 
+#if defined(USE_CAIRO_PIXMAN)
 	/* Draw a hole in the overlay */
 	cr = igt_get_cairo_ctx(pipe->display->drm_fd, &fb_overlay);
 	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
@@ -310,6 +311,7 @@
 			      0.0, 0.0, 0.0, 0.0);
 	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
 	igt_put_cairo_ctx(pipe->display->drm_fd, &fb_overlay, cr);
+#endif
 
 	igt_plane_set_fb(primary, &fb_primary);
 	igt_plane_set_fb(overlay, &fb_overlay);
@@ -337,6 +339,7 @@
 	igt_assert_eq_u64(igt_plane_get_prop(overlay, IGT_PLANE_ZPOS), 0);
 
 	/* Draw a hole in the primary exactly on top of the overlay plane */
+#if defined(USE_CAIRO_PIXMAN)
 	cr = igt_get_cairo_ctx(pipe->display->drm_fd, &fb_primary);
 	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
 	igt_paint_color_alpha(cr, w_overlay / 2, h_overlay / 2,
@@ -344,6 +347,7 @@
 			      0.0, 0.0, 0.0, 0.5);
 	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
 	igt_put_cairo_ctx(pipe->display->drm_fd, &fb_primary, cr);
+#endif
 
 	igt_info("Committing with a hole in the primary through "\
 		  "which the underlay should be seen\n");
@@ -683,7 +687,8 @@
 {
 	int timeline, fence_fd;
 	void *map;
-	const ptrdiff_t PAGE_SIZE = sysconf(_SC_PAGE_SIZE);
+	const ptrdiff_t page_size = sysconf(_SC_PAGE_SIZE);
+
 	uint64_t old_mode_id = pipe->values[IGT_CRTC_MODE_ID];
 
 	igt_require_sw_sync();
@@ -691,28 +696,28 @@
 	timeline = sw_sync_timeline_create();
 
 	/* invalid out_fence_ptr */
-	map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+	map = mmap(NULL, page_size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 	igt_assert(map != MAP_FAILED);
 
 	igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_OUT_FENCE_PTR, (ptrdiff_t)map);
 	crtc_commit_atomic_err(pipe, plane, ATOMIC_RELAX_NONE, EFAULT);
-	munmap(map, PAGE_SIZE);
+	munmap(map, page_size);
 
 	/* invalid out_fence_ptr */
-	map = mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+	map = mmap(NULL, page_size, PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 	igt_assert(map != MAP_FAILED);
 
 	igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_OUT_FENCE_PTR, (ptrdiff_t)map);
 	crtc_commit_atomic_err(pipe, plane, ATOMIC_RELAX_NONE, EFAULT);
-	munmap(map, PAGE_SIZE);
+	munmap(map, page_size);
 
 	/* invalid out_fence_ptr */
-	map = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+	map = mmap(NULL, page_size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 	igt_assert(map != MAP_FAILED);
 
 	igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_OUT_FENCE_PTR, (ptrdiff_t)map);
 	crtc_commit_atomic_err(pipe, plane, ATOMIC_RELAX_NONE, EFAULT);
-	munmap(map, PAGE_SIZE);
+	munmap(map, page_size);
 
 	/* valid in fence but not allowed prop on crtc */
 	fence_fd = sw_sync_timeline_create_fence(timeline, 1);