1 // Copyright (c) 2012 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 #ifndef ASH_DISPLAY_OVERSCAN_CALIBRATOR_H_ 6 #define ASH_DISPLAY_OVERSCAN_CALIBRATOR_H_ 7 8 #include <memory> 9 10 #include "ash/ash_export.h" 11 #include "base/macros.h" 12 #include "ui/compositor/layer_delegate.h" 13 #include "ui/display/display.h" 14 #include "ui/display/display_observer.h" 15 #include "ui/gfx/geometry/insets.h" 16 #include "ui/gfx/geometry/rect.h" 17 18 namespace ui { 19 class Layer; 20 } 21 22 namespace ash { 23 24 // This is used to show the visible feedback to the user's operations for 25 // calibrating display overscan settings. 26 class ASH_EXPORT OverscanCalibrator : public ui::LayerDelegate, 27 public display::DisplayObserver { 28 public: 29 OverscanCalibrator(const display::Display& target_display, 30 const gfx::Insets& initial_insets); 31 ~OverscanCalibrator() override; 32 33 // Commits the current insets data to the system. 34 void Commit(); 35 36 // Reset the overscan insets to default value. If the display has 37 // overscan, the default value is the display's default overscan 38 // value. Otherwise, the default value is the old |initial_insets_|. 39 void Reset(); 40 41 // Updates the insets and redraw the visual feedback. 42 void UpdateInsets(const gfx::Insets& insets); 43 insets()44 const gfx::Insets& insets() const { return insets_; } 45 46 // ui::LayerDelegate overrides: 47 void OnPaintLayer(const ui::PaintContext& context) override; 48 void OnDeviceScaleFactorChanged(float old_device_scale_factor, 49 float new_device_scale_factor) override; 50 51 // DisplayObserver: 52 void OnDisplayMetricsChanged(const display::Display& display, 53 uint32_t changed_metrics) override; 54 55 private: 56 void UpdateUILayer(); 57 58 // The target display. 59 display::Display display_; 60 61 // The current insets. 62 gfx::Insets insets_; 63 64 // The insets initially given. Stored so we can undo the insets later. 65 gfx::Insets initial_insets_; 66 67 // Whether the current insets are committed to the system or not. 68 bool committed_; 69 70 // The visualization layer for the current calibration region. 71 std::unique_ptr<ui::Layer> calibration_layer_; 72 73 DISALLOW_COPY_AND_ASSIGN(OverscanCalibrator); 74 }; 75 76 } // namespace ash 77 78 #endif // ASH_DISPLAY_OVERSCAN_CALIBRATOR_H_ 79