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 """Classes to do comparison for mirrored mode."""
      6 
      7 import logging
      8 
      9 from autotest_lib.client.cros.chameleon import screen_capture
     10 from autotest_lib.client.cros.chameleon import screen_comparison
     11 
     12 
     13 class MirrorComparer(object):
     14     """A class to compare the resolutions and screens for mirrored mode.
     15 
     16     Calling its member method compare() does the comparison.
     17 
     18     """
     19 
     20     def __init__(self, display_facade, output_dir):
     21         """Initializes the MirrorComparer objects.
     22 
     23         @param display_facade: A display facade object
     24         @param output_dir: The directory for output images.
     25         """
     26         self._display_facade = display_facade
     27         int_capturer = screen_capture.CrosInternalScreenCapturer(display_facade)
     28         ext_capturer = screen_capture.CrosExternalScreenCapturer(display_facade)
     29         # The frame buffers of screens should be perfectly matched.
     30         # Skip if the image sizes are different.
     31         self._screen_comparer = screen_comparison.ScreenComparer(
     32                 int_capturer, ext_capturer, output_dir, 0, 0, True)
     33 
     34 
     35     def compare(self):
     36         """Compares the resolutions and screens on all CrOS screens.
     37 
     38         This method first checks if CrOS is under mirrored mode or not. Skip
     39         the following tests if not in mirrored mode.
     40 
     41         Then it checks all the resolutions identical and also all the screens
     42         identical.
     43 
     44         @return: None if the check passes; otherwise, a string of error message.
     45         """
     46         if not self._display_facade.is_mirrored_enabled():
     47             message = 'Do mirror comparison but not in mirrored mode.'
     48             logging.error(message)
     49             return message
     50 
     51         logging.info('Checking the resolutions of all screens identical...')
     52         # TODO(waihong): Support the case without internal screen.
     53         internal_resolution = self._display_facade.get_internal_resolution()
     54         # TODO(waihong): Support multiple external screens.
     55         external_resolution = self._display_facade.get_external_resolution()
     56 
     57         if internal_resolution != external_resolution:
     58             logging.info('Sofware-based mirroring, skip the screen comparison. '
     59                          'Resolutions: Internal %r; External %r',
     60                          internal_resolution, external_resolution)
     61             return None
     62         else:
     63             logging.info('Resolutions across all CrOS screens match: %dx%d',
     64                          *internal_resolution)
     65 
     66         logging.info('Checking all the screens mirrored...')
     67         return self._screen_comparer.compare()
     68