• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5from autotest_lib.client.cros.chameleon import mirror_comparison
6from autotest_lib.client.cros.chameleon import resolution_comparison
7from autotest_lib.client.cros.chameleon import screen_capture
8from autotest_lib.client.cros.chameleon import screen_comparison
9
10
11class 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    _WRONG_PIXELS_MARGIN_FOR_ANALOG = 0.04  # 4%
22
23    _PIXEL_DIFF_MARGIN_FOR_DIGITAL = 3
24    _WRONG_PIXELS_MARGIN_FOR_DIGITAL = 0
25
26    # Comparing to the calibration image directly allows more margin due to
27    # anti-aliasing.
28    _PIXEL_DIFF_MARGIN_FOR_CALIBRATION = 30
29    _WRONG_PIXELS_MARGIN_FOR_CALIBRATION = 0.03  # 3% due to crbug/937346
30
31
32    def __init__(self, chameleon_port, display_facade):
33        """Initializes the ScreenUtilityFactory objects."""
34        self._chameleon_port = chameleon_port
35        self._display_facade = display_facade
36        self._is_vga = chameleon_port.get_connector_type() == 'VGA'
37
38
39    def create_resolution_comparer(self):
40        """Creates a resolution comparer object."""
41        if self._is_vga:
42            return resolution_comparison.VgaResolutionComparer(
43                    self._chameleon_port, self._display_facade)
44        else:
45            return resolution_comparison.ExactMatchResolutionComparer(
46                    self._chameleon_port, self._display_facade)
47
48
49    def create_chameleon_screen_capturer(self):
50        """Creates a Chameleon screen capturer."""
51        if self._is_vga:
52            return screen_capture.VgaChameleonScreenCapturer(
53                    self._chameleon_port)
54        else:
55            return screen_capture.CommonChameleonScreenCapturer(
56                    self._chameleon_port)
57
58
59    def create_cros_screen_capturer(self, internal_screen=False):
60        """Creates an Chrome OS screen capturer.
61
62        @param internal_screen: True to compare the internal screen on CrOS.
63        """
64        if internal_screen:
65            return screen_capture.CrosInternalScreenCapturer(
66                    self._display_facade)
67        else:
68            return screen_capture.CrosExternalScreenCapturer(
69                    self._display_facade)
70
71
72    def create_calibration_image_capturer(self):
73        """Creates a calibration image capturer."""
74        return screen_capture.CrosCalibrationImageCapturer(self._display_facade)
75
76
77    def create_screen_comparer(self, output_dir):
78        """Creates a screen comparer.
79
80        @param output_dir: The directory the image files output to.
81        """
82        if self._is_vga:
83            pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_ANALOG
84            wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_ANALOG
85        else:
86            pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_DIGITAL
87            wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_DIGITAL
88
89        capturer1 = self.create_chameleon_screen_capturer()
90        capturer2 = self.create_cros_screen_capturer()
91
92        return screen_comparison.ScreenComparer(
93                capturer1, capturer2, output_dir,
94                pixel_diff_margin, wrong_pixels_margin)
95
96
97    def create_mirror_comparer(self, output_dir):
98        """Creates a comparer for mirrored mode.
99
100        @param output_dir: The directory the image files output to.
101        """
102        return mirror_comparison.MirrorComparer(self._display_facade,
103                                                output_dir)
104
105
106    def create_calibration_comparer(self, output_dir):
107        """Creates a comparer to check between Chameleon and calibration image.
108
109        @param output_dir: The directory the image files output to.
110        """
111        if self._is_vga:
112            pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_ANALOG
113            wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_ANALOG
114        else:
115            pixel_diff_margin = self._PIXEL_DIFF_MARGIN_FOR_CALIBRATION
116            wrong_pixels_margin = self._WRONG_PIXELS_MARGIN_FOR_CALIBRATION
117
118        capturer1 = self.create_chameleon_screen_capturer()
119        capturer2 = self.create_calibration_image_capturer()
120
121        return screen_comparison.ScreenComparer(
122                capturer1, capturer2, output_dir,
123                pixel_diff_margin, wrong_pixels_margin)
124