Home | History | Annotate | Download | only in chameleon
      1 # Copyright 2014 The Chromium OS 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 from autotest_lib.client.cros.chameleon import mirror_comparison
      6 from autotest_lib.client.cros.chameleon import resolution_comparison
      7 from autotest_lib.client.cros.chameleon import screen_capture
      8 from autotest_lib.client.cros.chameleon import screen_comparison
      9 
     10 
     11 class ScreenUtilityFactory(object):
     12     """A factory to generate utilities for screen comparison test.
     13 
     14     This factory creates the utilities, according to the properties of
     15     the CrOS. For example, a CrOS connected to VGA can use a VGA specific
     16     algorithm for screen comparison.
     17 
     18     """
     19 
     20     _PIXEL_DIFF_MARGIN_FOR_ANALOG = 30
     21     _PIXEL_DIFF_MARGIN_FOR_DIGITAL = 3
     22 
     23     _WRONG_PIXELS_MARGIN_FOR_ANALOG = 0.04  # 4%
     24     _WRONG_PIXELS_MARGIN_FOR_DIGITAL = 0
     25 
     26 
     27     def __init__(self, chameleon_port, display_facade):
     28         """Initializes the ScreenUtilityFactory objects."""
     29         self._chameleon_port = chameleon_port
     30         self._display_facade = display_facade
     31         self._is_vga = chameleon_port.get_connector_type() == 'VGA'
     32 
     33 
     34     def create_resolution_comparer(self):
     35         """Creates a resolution comparer object."""
     36         if self._is_vga:
     37             return resolution_comparison.VgaResolutionComparer(
     38                     self._chameleon_port, self._display_facade)
     39         else:
     40             return resolution_comparison.ExactMatchResolutionComparer(
     41                     self._chameleon_port, self._display_facade)
     42 
     43 
     44     def create_chameleon_screen_capturer(self):
     45         """Creates a Chameleon screen capturer."""
     46         if self._is_vga:
     47             return screen_capture.VgaChameleonScreenCapturer(
     48                     self._chameleon_port)
     49         else:
     50             return screen_capture.CommonChameleonScreenCapturer(
     51                     self._chameleon_port)
     52 
     53 
     54     def create_cros_screen_capturer(self, internal_screen=False):
     55         """Creates an Chrome OS screen capturer.
     56 
     57         @param internal_screen: True to compare the internal screen on CrOS.
     58         """
     59         if internal_screen:
     60             return screen_capture.CrosInternalScreenCapturer(
     61                     self._display_facade)
     62         else:
     63             return screen_capture.CrosExternalScreenCapturer(
     64                     self._display_facade)
     65 
     66 
     67     def create_screen_comparer(self, output_dir):
     68         """Creates a screen comparer.
     69 
     70         @param output_dir: The directory the image files output to.
     71         """
     72         if self._is_vga:
     73             pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_ANALOG
     74             wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_ANALOG
     75         else:
     76             pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_DIGITAL
     77             wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_DIGITAL
     78 
     79         capturer1 = self.create_chameleon_screen_capturer()
     80         capturer2 = self.create_cros_screen_capturer()
     81 
     82         return screen_comparison.ScreenComparer(
     83                 capturer1, capturer2, output_dir,
     84                 pixel_diff_margin, wrong_pixels_margin)
     85 
     86 
     87     def create_mirror_comparer(self, output_dir):
     88         """Creates a comparer for mirrored mode.
     89 
     90         @param output_dir: The directory the image files output to.
     91         """
     92         return mirror_comparison.MirrorComparer(self._display_facade, output_dir)
     93