1// Copyright (c) 2013 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 CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_ 6#define CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "chromeos/display/output_configurator.h" 13 14typedef XID Window; 15 16struct _XDisplay; 17typedef struct _XDisplay Display; 18struct _XRROutputInfo; 19typedef _XRROutputInfo XRROutputInfo; 20struct _XRRScreenResources; 21typedef _XRRScreenResources XRRScreenResources; 22 23namespace chromeos { 24 25class RealOutputConfiguratorDelegate : public OutputConfigurator::Delegate { 26 public: 27 RealOutputConfiguratorDelegate(); 28 virtual ~RealOutputConfiguratorDelegate(); 29 30 // OutputConfigurator::Delegate overrides: 31 virtual void SetPanelFittingEnabled(bool enabled) OVERRIDE; 32 virtual void InitXRandRExtension(int* event_base) OVERRIDE; 33 virtual void UpdateXRandRConfiguration( 34 const base::NativeEvent& event) OVERRIDE; 35 virtual void GrabServer() OVERRIDE; 36 virtual void UngrabServer() OVERRIDE; 37 virtual void SyncWithServer() OVERRIDE; 38 virtual void SetBackgroundColor(uint32 color_argb) OVERRIDE; 39 virtual void ForceDPMSOn() OVERRIDE; 40 virtual std::vector<OutputConfigurator::OutputSnapshot> GetOutputs( 41 const OutputConfigurator::StateController* state_controller) OVERRIDE; 42 virtual bool GetModeDetails( 43 RRMode mode, 44 int* width, 45 int* height, 46 bool* interlaced) OVERRIDE; 47 virtual bool ConfigureCrtc( 48 RRCrtc crtc, 49 RRMode mode, 50 RROutput output, 51 int x, 52 int y) OVERRIDE; 53 virtual void CreateFrameBuffer( 54 int width, 55 int height, 56 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) OVERRIDE; 57 virtual void ConfigureCTM( 58 int touch_device_id, 59 const OutputConfigurator::CoordinateTransformation& ctm) OVERRIDE; 60 virtual void SendProjectingStateToPowerManager(bool projecting) OVERRIDE; 61 62 private: 63 // Destroys unused CRTCs and parks used CRTCs in a way which allows a 64 // framebuffer resize. This is faster than turning them off, resizing, 65 // then turning them back on. 66 void DestroyUnusedCrtcs( 67 const std::vector<OutputConfigurator::OutputSnapshot>& outputs); 68 69 // Returns whether |id| is configured to preserve aspect when scaling. 70 bool IsOutputAspectPreservingScaling(RROutput id); 71 72 // Looks for a mode on internal and external outputs having same 73 // resolution. |internal_info| and |external_info| are used to search 74 // for the modes. |internal_output_id| is used to create a new mode, if 75 // applicable. |try_creating|=true will enable creating panel-fitting 76 // mode on the |internal_info| output instead of only searching for a 77 // matching mode. Note: it may lead to a crash, if |internal_info| is 78 // not capable of panel fitting. |preserve_aspect|=true will limit the 79 // search / creation only to the modes having the native aspect ratio of 80 // |external_info|. |internal_mirror_mode| and |external_mirror_mode| 81 // are the out-parameters for the modes on the two outputs which will 82 // have the same resolution. Returns false if no mode appropriate for 83 // mirroring has been found/created. 84 bool FindOrCreateMirrorMode(XRROutputInfo* internal_info, 85 XRROutputInfo* external_info, 86 RROutput internal_output_id, 87 bool try_creating, 88 bool preserve_aspect, 89 RRMode* internal_mirror_mode, 90 RRMode* external_mirror_mode); 91 92 // Searches for touchscreens among input devices, 93 // and tries to match them up to screens in |outputs|. 94 // |outputs| is an array of detected screens. 95 // If a touchscreen with same resolution as an output's native mode 96 // is detected, its id will be stored in this output. 97 void GetTouchscreens( 98 std::vector<OutputConfigurator::OutputSnapshot>* outputs); 99 100 Display* display_; 101 Window window_; 102 103 // Initialized when the server is grabbed and freed when it's ungrabbed. 104 XRRScreenResources* screen_; 105 106 // Used to enable modes which rely on panel fitting. 107 bool is_panel_fitting_enabled_; 108 109 DISALLOW_COPY_AND_ASSIGN(RealOutputConfiguratorDelegate); 110}; 111 112} // namespace chromeos 113 114#endif // CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_ 115