Home | History | Annotate | Download | only in helper
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include <signal.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <windows.h>
      9 
     10 static BOOL font_smoothing_enabled = FALSE;
     11 
     12 static void SaveInitialSettings() {
     13   ::SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing_enabled, 0);
     14 }
     15 
     16 // Technically, all we need to do is disable ClearType. However,
     17 // for some reason, the call to SPI_SETFONTSMOOTHINGTYPE doesn't
     18 // seem to work, so we just disable font smoothing all together
     19 // (which works reliably).
     20 static void InstallLayoutTestSettings() {
     21   ::SystemParametersInfo(SPI_SETFONTSMOOTHING, FALSE, 0, 0);
     22 }
     23 
     24 static void RestoreInitialSettings() {
     25   ::SystemParametersInfo(
     26       SPI_SETFONTSMOOTHING, static_cast<UINT>(font_smoothing_enabled), 0, 0);
     27 }
     28 
     29 static void SimpleSignalHandler(int signalNumber) {
     30   // Try to restore the settings and then go down cleanly.
     31   RestoreInitialSettings();
     32   exit(128 + signalNumber);
     33 }
     34 
     35 int main(int, char**) {
     36   // Hooks the ways we might get told to clean up...
     37   signal(SIGINT, SimpleSignalHandler);
     38   signal(SIGTERM, SimpleSignalHandler);
     39 
     40   SaveInitialSettings();
     41 
     42   InstallLayoutTestSettings();
     43 
     44   // Let the script know we're ready.
     45   printf("ready\n");
     46   fflush(stdout);
     47 
     48   // Wait for any key (or signal).
     49   getchar();
     50 
     51   RestoreInitialSettings();
     52 
     53   return EXIT_SUCCESS;
     54 }
     55