graphics_SanAngeles: support null platform

Freon boards now support only EGL_PLATFORM_NULL and minigbm so use
WAFFLE_PLATFORM_NULL.

Platform arg parsing is moved to the SanAngeles executable, since that
is where we ultimately want it, and the attempt to factor it out to
graphics_utils.py was cumbersome and not used by anything else.

The waffle_window_show() call was moved because in WAFFLE_PLATFORM_NULL
it must happen before waffle_make_current().

Restored the depth buffer configuration that was accidentally removed
during porting to waffle.

On freon, stop ui in order to mode set.

BUG=chromium:468328
TEST=test_that -b samus -i trybot-samus-paladin/... :lab: graphics_SanAngeles
TEST=test_that -b lumpy -i trybot-lumpy-paladin/... :lab: graphics_SanAngeles
TEST=test_that -b daisy -i trybot-daisy-paladin/... :lab: graphics_SanAngeles
CQ-DEPEND=CL:260993

Change-Id: Idb3aa5a8024f920beec2364a9701bc5455acb602
Reviewed-on: https://chromium-review.googlesource.com/260995
Reviewed-by: Ilja Friedel <ihf@chromium.org>
Commit-Queue: Frank Henigman <fjhenigman@chromium.org>
Tested-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/client/cros/graphics/graphics_utils.py b/client/cros/graphics/graphics_utils.py
index 18e22cc..c12cf43 100644
--- a/client/cros/graphics/graphics_utils.py
+++ b/client/cros/graphics/graphics_utils.py
@@ -26,24 +26,6 @@
 from autotest_lib.client.cros.graphics import drm
 
 
-def waffle_platform(platform):
-    """ Return waffle enum string and value for the given platform. """
-    # these should match what's in waffle.h in the media-libs/waffle package
-    name, value = dict(
-        android=('ANDROID', 0x0011),
-        cgl=('CGL', 0x0012),
-        glx=('GLX', 0x0013),
-        wayland=('WAYLAND', 0x0014),
-        x11_egl=('X11_EGL', 0x0015),
-        gbm=('GBM', 0x0016),
-    ).get(platform, ('', 0))
-    if name:
-        name = 'WAFFLE_PLATFORM_' + name
-    else:
-        raise error.TestFail('Unknown waffle_platform "%s"' % platform)
-    return name, value
-
-
 # TODO(ihf): Remove xcommand for non-freon builds.
 def xcommand(cmd, user=None):
     """
diff --git a/client/site_tests/graphics_SanAngeles/graphics_SanAngeles.py b/client/site_tests/graphics_SanAngeles/graphics_SanAngeles.py
index 4394b3e..efbdff9 100644
--- a/client/site_tests/graphics_SanAngeles/graphics_SanAngeles.py
+++ b/client/site_tests/graphics_SanAngeles/graphics_SanAngeles.py
@@ -6,6 +6,7 @@
 
 from autotest_lib.client.bin import test, utils
 from autotest_lib.client.common_lib import error
+from autotest_lib.client.cros import service_stopper
 from autotest_lib.client.cros.graphics import graphics_utils
 
 class graphics_SanAngeles(test.test):
@@ -23,8 +24,14 @@
 
     def initialize(self):
         self.GSC = graphics_utils.GraphicsStateChecker()
+        if utils.is_freon():
+            # If UI is running, we must stop it and restore later.
+            self._services = service_stopper.ServiceStopper(['ui'])
+            self._services.stop_services()
 
     def cleanup(self):
+        if utils.is_freon() and self._services:
+            self._services.restore_services()
         if self.GSC:
             keyvals = self.GSC.get_memory_keyvals()
             for key, val in keyvals.iteritems():
@@ -48,8 +55,7 @@
                                  '%s, %s or %s.  Test setup error.'
                                  % (cmd_gl, cmd_gles, cmd_gles_s))
 
-        cmd += ' %s %d' % graphics_utils.waffle_platform(
-                              utils.graphics_platform())
+        cmd += ' ' + utils.graphics_platform()
         cmd = graphics_utils.xcommand(cmd)
         result = utils.run(cmd,
                            stderr_is_expected = False,
diff --git a/client/site_tests/graphics_SanAngeles/src/app-linux.c b/client/site_tests/graphics_SanAngeles/src/app-linux.c
index 6d8c848..c6a55d4 100644
--- a/client/site_tests/graphics_SanAngeles/src/app-linux.c
+++ b/client/site_tests/graphics_SanAngeles/src/app-linux.c
@@ -110,6 +110,7 @@
         WAFFLE_GREEN_SIZE,      5,
         WAFFLE_BLUE_SIZE,       5,
         WAFFLE_ALPHA_SIZE,      0,
+        WAFFLE_DEPTH_SIZE,      16,
         WAFFLE_DOUBLE_BUFFERED, true,
         0
     };
@@ -140,6 +141,9 @@
     if (!sWindow)
         return waffleError();
 
+    if (!waffle_window_show(sWindow))
+        return waffleError();
+
     ok = waffle_make_current(sDisplay, sWindow, sContext);
     if (!ok)
         return waffleError();
@@ -176,29 +180,38 @@
         waffleError();
 }
 
+#define PLATFORM(x) { #x, WAFFLE_PLATFORM_##x }
+
+static struct platform_item {
+    const char *name;
+    int32_t value;
+} platform_list[] = {
+    PLATFORM(GLX),
+    PLATFORM(X11_EGL),
+    PLATFORM(GBM),
+    PLATFORM(NULL),
+    { NULL, 0 }
+};
+
 int main(int argc, char *argv[])
 {
-    int32_t platform = WAFFLE_NONE;
-    if (argc == 3)
-    {
-        // TODO(fjhenigman): add waffle_to_string_to_enum to waffle
-        // then only pass in platform string here.
-        platform = atoi(argv[2]);
-        if (strcmp(waffle_enum_to_string(platform), argv[1]))
-        {
-            // check if waffle changed platform names/values so that
-            // they no longer match those in the test driver
-            fprintf(stderr, "Error: %s != %d\n", argv[1], platform);
-            return EXIT_FAILURE;
-        }
+    // TODO(fjhenigman): add waffle_to_string_to_enum to waffle then use it
+    // to parse the platform arg.
+    int32_t platform_value = WAFFLE_NONE;
+    struct platform_item *p = platform_list;
+    while (argc == 2 && p->name && platform_value == WAFFLE_NONE) {
+        if (!strcasecmp(argv[1], p->name))
+            platform_value = p->value;
+        ++p;
     }
-    if (platform == WAFFLE_NONE )
+
+    if (platform_value == WAFFLE_NONE)
     {
-        fprintf(stderr, "Usage: SanOGLES <platform name> <platform value>\n");
+        fprintf(stderr, "Usage: SanOGLES <platform>\n");
         return EXIT_FAILURE;
     }
 
-    if (!initGraphics(platform))
+    if (!initGraphics(platform_value))
     {
         fprintf(stderr, "Error: Graphics initialization failed.\n");
         return EXIT_FAILURE;
@@ -222,9 +235,6 @@
                                   timeNow.tv_usec / 1000),
                   sWindowWidth, sWindowHeight);
         gettimeofday(&timeAfter, NULL);
-        if (num_frames == 0)
-            if (!waffle_window_show(sWindow))
-                waffleError();
 
 #ifdef SAN_ANGELES_OBSERVATION_GLES
         checkGLErrors();