diff options
author | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-13 23:56:49 +0000 |
---|---|---|
committer | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-13 23:56:49 +0000 |
commit | 03122891a47d0ba0207904aa4aa74474ea741343 (patch) | |
tree | 6cc97c0e032869831dbf7cb4d8d7c15c4a167672 /ui/display/chromeos | |
parent | 81d2b9ced182a57bdbe1a8f5be012e2416954ae0 (diff) | |
download | chromium_src-03122891a47d0ba0207904aa4aa74474ea741343.zip chromium_src-03122891a47d0ba0207904aa4aa74474ea741343.tar.gz chromium_src-03122891a47d0ba0207904aa4aa74474ea741343.tar.bz2 |
Re-land "Move touch CTM from X into Chrome"
Currently we compute the touch CTM in OutputConfigurator
and push that into X. This CL makes computing the touch CTM
in DisplayController, and pushing it
into WindowTreeHostX11. This moves the functionality of
touch CTM from X into Chrome.
Basically, when there is output configuration change, we
compute the TouchCTM for each touch device, and push the
TouchCTM into the WindowTreeHostX11 that is associated
with the touchscreen. Then when X events reaching root
window, we use the CTM to map the events coordinate in
framebuffer space into the root window's coordinate space.
BUG=351019, chrome-os-partner:25788
TEST=tested on Pixel/Clapper with external touch/non-touch displays
on both extended/mirror mode. Touch events are correctly mapped to
chrome window or discarded if it is from blank region from letterboxing/pillarboxing mirror mode.
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=269371
TBR=sadrul@chromium.org
Review URL: https://codereview.chromium.org/280833002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270252 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/display/chromeos')
-rw-r--r-- | ui/display/chromeos/display_configurator.cc | 99 | ||||
-rw-r--r-- | ui/display/chromeos/display_configurator.h | 39 | ||||
-rw-r--r-- | ui/display/chromeos/display_configurator_unittest.cc | 61 | ||||
-rw-r--r-- | ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc | 6 | ||||
-rw-r--r-- | ui/display/chromeos/ozone/touchscreen_delegate_ozone.h | 3 | ||||
-rw-r--r-- | ui/display/chromeos/x11/touchscreen_delegate_x11.cc | 50 | ||||
-rw-r--r-- | ui/display/chromeos/x11/touchscreen_delegate_x11.h | 3 |
7 files changed, 6 insertions, 255 deletions
diff --git a/ui/display/chromeos/display_configurator.cc b/ui/display/chromeos/display_configurator.cc index 1283b58..a2281a8 100644 --- a/ui/display/chromeos/display_configurator.cc +++ b/ui/display/chromeos/display_configurator.cc @@ -89,12 +89,6 @@ int GetDisplayPower( } // namespace -DisplayConfigurator::CoordinateTransformation::CoordinateTransformation() - : x_scale(1.0), - x_offset(0.0), - y_scale(1.0), - y_offset(0.0) {} - DisplayConfigurator::DisplayState::DisplayState() : display(NULL), touch_device_id(0), @@ -796,11 +790,8 @@ bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, DisplayState* state = &cached_displays_[i]; new_mode[i] = display_power[i] ? state->mirror_mode : NULL; if (state->touch_device_id) { - // CTM needs to be calculated if aspect preserving scaling is used. - // Otherwise, assume it is full screen, and use identity CTM. if (state->mirror_mode != state->display->native_mode() && state->display->is_aspect_preserving_scaling()) { - state->transform = GetMirrorModeCTM(*state); mirrored_display_area_ratio_map_[state->touch_device_id] = GetMirroredDisplayAreaRatio(*state); } @@ -833,12 +824,6 @@ bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, size.set_height(size.height() + (size.height() ? kVerticalGap : 0) + mode_info->size().height()); } - - for (size_t i = 0; i < cached_displays_.size(); ++i) { - DisplayState* state = &cached_displays_[i]; - if (state->touch_device_id) - state->transform = GetExtendedModeCTM(*state, new_origins[i], size); - } break; } } @@ -886,13 +871,8 @@ bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, break; } - if (configure_succeeded) { - if (state.touch_device_id) - touchscreen_delegate_->ConfigureCTM(state.touch_device_id, - state.transform); - } else { + if (!configure_succeeded) all_succeeded = false; - } // If we are trying to set mirror mode and one of the modesets fails, // then the two monitors will be mis-matched. In this case, return @@ -907,6 +887,7 @@ bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, if (all_succeeded) { display_state_ = display_state; power_state_ = power_state; + framebuffer_size_ = size; } return all_succeeded; } @@ -945,82 +926,6 @@ MultipleDisplayState DisplayConfigurator::ChooseDisplayState( return MULTIPLE_DISPLAY_STATE_INVALID; } -DisplayConfigurator::CoordinateTransformation -DisplayConfigurator::GetMirrorModeCTM(const DisplayState& display_state) { - CoordinateTransformation ctm; // Default to identity - const DisplayMode* native_mode_info = display_state.display->native_mode(); - const DisplayMode* mirror_mode_info = display_state.mirror_mode; - - if (!native_mode_info || !mirror_mode_info || - native_mode_info->size().height() == 0 || - mirror_mode_info->size().height() == 0 || - native_mode_info->size().width() == 0 || - mirror_mode_info->size().width() == 0) - return ctm; - - float native_mode_ar = static_cast<float>(native_mode_info->size().width()) / - static_cast<float>(native_mode_info->size().height()); - float mirror_mode_ar = static_cast<float>(mirror_mode_info->size().width()) / - static_cast<float>(mirror_mode_info->size().height()); - - if (mirror_mode_ar > native_mode_ar) { // Letterboxing - ctm.x_scale = 1.0; - ctm.x_offset = 0.0; - ctm.y_scale = mirror_mode_ar / native_mode_ar; - ctm.y_offset = (native_mode_ar / mirror_mode_ar - 1.0) * 0.5; - return ctm; - } - if (native_mode_ar > mirror_mode_ar) { // Pillarboxing - ctm.y_scale = 1.0; - ctm.y_offset = 0.0; - ctm.x_scale = native_mode_ar / mirror_mode_ar; - ctm.x_offset = (mirror_mode_ar / native_mode_ar - 1.0) * 0.5; - return ctm; - } - - return ctm; // Same aspect ratio - return identity -} - -DisplayConfigurator::CoordinateTransformation -DisplayConfigurator::GetExtendedModeCTM(const DisplayState& display_state, - const gfx::Point& new_origin, - const gfx::Size& framebuffer_size) { - CoordinateTransformation ctm; // Default to identity - const DisplayMode* mode_info = display_state.selected_mode; - DCHECK(mode_info); - if (!mode_info) - return ctm; - // An example of how to calculate the CTM. - // Suppose we have 2 monitors, the first one has size 1366 x 768. - // The second one has size 2560 x 1600 - // The total size of framebuffer is 2560 x 2428 - // where 2428 = 768 + 60 (hidden gap) + 1600 - // and the sceond monitor is translated to Point (0, 828) in the - // framebuffer. - // X will first map input event location to [0, 2560) x [0, 2428), - // then apply CTM on it. - // So to compute CTM, for monitor1, we have - // x_scale = (1366 - 1) / (2560 - 1) - // x_offset = 0 / (2560 - 1) - // y_scale = (768 - 1) / (2428 - 1) - // y_offset = 0 / (2428 -1) - // For Monitor 2, we have - // x_scale = (2560 - 1) / (2560 - 1) - // x_offset = 0 / (2560 - 1) - // y_scale = (1600 - 1) / (2428 - 1) - // y_offset = 828 / (2428 -1) - // See the unittest DisplayConfiguratorTest.CTMForMultiScreens. - ctm.x_scale = static_cast<float>(mode_info->size().width() - 1) / - (framebuffer_size.width() - 1); - ctm.x_offset = - static_cast<float>(new_origin.x()) / (framebuffer_size.width() - 1); - ctm.y_scale = static_cast<float>(mode_info->size().height() - 1) / - (framebuffer_size.height() - 1); - ctm.y_offset = - static_cast<float>(new_origin.y()) / (framebuffer_size.height() - 1); - return ctm; -} - float DisplayConfigurator::GetMirroredDisplayAreaRatio( const DisplayState& display_state) { float area_ratio = 1.0f; diff --git a/ui/display/chromeos/display_configurator.h b/ui/display/chromeos/display_configurator.h index 028a902..d0c9235 100644 --- a/ui/display/chromeos/display_configurator.h +++ b/ui/display/chromeos/display_configurator.h @@ -19,6 +19,7 @@ #include "ui/display/display_export.h" #include "ui/display/types/chromeos/native_display_observer.h" #include "ui/display/types/display_constants.h" +#include "ui/gfx/geometry/size.h" namespace gfx { class Point; @@ -36,16 +37,6 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { typedef uint64_t ContentProtectionClientId; static const ContentProtectionClientId kInvalidClientId = 0; - struct CoordinateTransformation { - // Initialized to the identity transformation. - CoordinateTransformation(); - - float x_scale; - float x_offset; - float y_scale; - float y_offset; - }; - struct DisplayState { DisplayState(); @@ -54,8 +45,6 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { // XInput device ID or 0 if this display isn't a touchscreen. int touch_device_id; - CoordinateTransformation transform; - // User-selected mode for the display. const DisplayMode* selected_mode; @@ -117,14 +106,6 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { // If a touchscreen with same resolution as a display's native mode // is detected, its id will be stored in this display. virtual void AssociateTouchscreens(std::vector<DisplayState>* displays) = 0; - - // Configures XInput's Coordinate Transformation Matrix property. - // |touch_device_id| the ID of the touchscreen device to configure. - // |ctm| contains the desired transformation parameters. The offsets - // in it should be normalized so that 1 corresponds to the X or Y axis - // size for the corresponding offset. - virtual void ConfigureCTM(int touch_device_id, - const CoordinateTransformation& ctm) = 0; }; // Helper class used by tests. @@ -171,6 +152,7 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { MultipleDisplayState display_state() const { return display_state_; } chromeos::DisplayPowerState power_state() const { return power_state_; } + const gfx::Size framebuffer_size() const { return framebuffer_size_; } const std::vector<DisplayState>& cached_displays() const { return cached_displays_; } @@ -335,21 +317,6 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { MultipleDisplayState ChooseDisplayState( chromeos::DisplayPowerState power_state) const; - // Computes the relevant transformation for mirror mode. - // |display| is the display on which mirror mode is being applied. - // Returns the transformation or identity if computations fail. - CoordinateTransformation GetMirrorModeCTM(const DisplayState& display); - - // Computes the relevant transformation for extended mode. |display| is the - // display on which extended mode is being applied. |new_origin| is the - // position of the display on the framebuffer. |framebuffer_size| is the - // size of the combined framebuffer. - // Returns the transformation or identity if computations fail. - CoordinateTransformation GetExtendedModeCTM( - const DisplayState& display, - const gfx::Point& new_origin, - const gfx::Size& framebuffer_size); - // Returns the ratio between mirrored mode area and native mode area: // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) float GetMirroredDisplayAreaRatio(const DisplayState& display); @@ -383,6 +350,8 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { // The current display state. MultipleDisplayState display_state_; + gfx::Size framebuffer_size_; + // The current power state. chromeos::DisplayPowerState power_state_; diff --git a/ui/display/chromeos/display_configurator_unittest.cc b/ui/display/chromeos/display_configurator_unittest.cc index 1790d66..1835d75 100644 --- a/ui/display/chromeos/display_configurator_unittest.cc +++ b/ui/display/chromeos/display_configurator_unittest.cc @@ -82,18 +82,6 @@ std::string GetFramebufferAction(const gfx::Size& size, out2 ? DisplaySnapshotToString(*out2).c_str() : "NULL"); } -// Returns a string describing a TestNativeDisplayDelegate::ConfigureCTM() call. -std::string GetCTMAction( - int device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) { - return base::StringPrintf("ctm(id=%d,transform=(%f,%f,%f,%f))", - device_id, - ctm.x_scale, - ctm.x_offset, - ctm.y_scale, - ctm.y_offset); -} - // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call. std::string GetSetHDCPStateAction(const DisplaySnapshot& output, HDCPState state) { @@ -154,11 +142,6 @@ class TestTouchscreenDelegate configure_touchscreens_(false) {} virtual ~TestTouchscreenDelegate() {} - const DisplayConfigurator::CoordinateTransformation& GetCTM( - int touch_device_id) { - return ctms_[touch_device_id]; - } - void set_configure_touchscreens(bool state) { configure_touchscreens_ = state; } @@ -171,21 +154,12 @@ class TestTouchscreenDelegate (*outputs)[i].touch_device_id = i + 1; } } - virtual void ConfigureCTM( - int touch_device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) OVERRIDE { - log_->AppendAction(GetCTMAction(touch_device_id, ctm)); - ctms_[touch_device_id] = ctm; - } private: ActionLogger* log_; // Not owned. bool configure_touchscreens_; - // Most-recently-configured transformation matrices, keyed by touch device ID. - std::map<int, DisplayConfigurator::CoordinateTransformation> ctms_; - DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate); }; @@ -1242,41 +1216,6 @@ TEST_F(DisplayConfiguratorTest, ContentProtectionTwoClients) { log_->GetActionsAndClear()); } -TEST_F(DisplayConfiguratorTest, CTMForMultiScreens) { - touchscreen_delegate_->set_configure_touchscreens(true); - UpdateOutputs(2, false); - configurator_.Init(false); - state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); - configurator_.ForceInitialConfigure(0); - - const int kDualHeight = small_mode_.size().height() + - DisplayConfigurator::kVerticalGap + - big_mode_.size().height(); - const int kDualWidth = big_mode_.size().width(); - - DisplayConfigurator::CoordinateTransformation ctm1 = - touchscreen_delegate_->GetCTM(1); - DisplayConfigurator::CoordinateTransformation ctm2 = - touchscreen_delegate_->GetCTM(2); - - EXPECT_EQ(small_mode_.size().height() - 1, - round((kDualHeight - 1) * ctm1.y_scale)); - EXPECT_EQ(0, round((kDualHeight - 1) * ctm1.y_offset)); - - EXPECT_EQ(big_mode_.size().height() - 1, - round((kDualHeight - 1) * ctm2.y_scale)); - EXPECT_EQ(small_mode_.size().height() + DisplayConfigurator::kVerticalGap, - round((kDualHeight - 1) * ctm2.y_offset)); - - EXPECT_EQ(small_mode_.size().width() - 1, - round((kDualWidth - 1) * ctm1.x_scale)); - EXPECT_EQ(0, round((kDualWidth - 1) * ctm1.x_offset)); - - EXPECT_EQ(big_mode_.size().width() - 1, - round((kDualWidth - 1) * ctm2.x_scale)); - EXPECT_EQ(0, round((kDualWidth - 1) * ctm2.x_offset)); -} - TEST_F(DisplayConfiguratorTest, HandleConfigureCrtcFailure) { InitWithSingleOutput(); diff --git a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc index 1705f8b..c302e2d 100644 --- a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc +++ b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc @@ -15,10 +15,4 @@ void TouchscreenDelegateOzone::AssociateTouchscreens( NOTIMPLEMENTED(); } -void TouchscreenDelegateOzone::ConfigureCTM( - int touch_device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) { - NOTIMPLEMENTED(); -} - } // namespace ui diff --git a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h index 729b3cb..7f33a03 100644 --- a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h +++ b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h @@ -18,9 +18,6 @@ class TouchscreenDelegateOzone // DisplayConfigurator::TouchscreenDelegate overrides: virtual void AssociateTouchscreens( std::vector<DisplayConfigurator::DisplayState>* outputs) OVERRIDE; - virtual void ConfigureCTM( - int touch_device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateOzone); diff --git a/ui/display/chromeos/x11/touchscreen_delegate_x11.cc b/ui/display/chromeos/x11/touchscreen_delegate_x11.cc index 3b69d3a..b76d62e 100644 --- a/ui/display/chromeos/x11/touchscreen_delegate_x11.cc +++ b/ui/display/chromeos/x11/touchscreen_delegate_x11.cc @@ -129,54 +129,4 @@ void TouchscreenDelegateX11::AssociateTouchscreens( XIFreeDeviceInfo(info); } -void TouchscreenDelegateX11::ConfigureCTM( - int touch_device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) { - VLOG(1) << "ConfigureCTM: id=" << touch_device_id << " scale=" << ctm.x_scale - << "x" << ctm.y_scale << " offset=(" << ctm.x_offset << ", " - << ctm.y_offset << ")"; - int ndevices = 0; - XIDeviceInfo* info = XIQueryDevice(display_, touch_device_id, &ndevices); - Atom prop = XInternAtom(display_, "Coordinate Transformation Matrix", False); - Atom float_atom = XInternAtom(display_, "FLOAT", False); - if (ndevices == 1 && prop != None && float_atom != None) { - Atom type; - int format; - unsigned long num_items; - unsigned long bytes_after; - unsigned char* data = NULL; - // Verify that the property exists with correct format, type, etc. - int status = XIGetProperty(display_, - info->deviceid, - prop, - 0, - 0, - False, - AnyPropertyType, - &type, - &format, - &num_items, - &bytes_after, - &data); - if (data) - XFree(data); - if (status == Success && type == float_atom && format == 32) { - float value[3][3] = { - { ctm.x_scale, 0.0, ctm.x_offset }, - { 0.0, ctm.y_scale, ctm.y_offset }, - { 0.0, 0.0, 1.0 } - }; - XIChangeProperty(display_, - info->deviceid, - prop, - type, - format, - PropModeReplace, - reinterpret_cast<unsigned char*>(value), - 9); - } - } - XIFreeDeviceInfo(info); -} - } // namespace ui diff --git a/ui/display/chromeos/x11/touchscreen_delegate_x11.h b/ui/display/chromeos/x11/touchscreen_delegate_x11.h index 434f55f..7966ddf 100644 --- a/ui/display/chromeos/x11/touchscreen_delegate_x11.h +++ b/ui/display/chromeos/x11/touchscreen_delegate_x11.h @@ -20,9 +20,6 @@ class TouchscreenDelegateX11 : public DisplayConfigurator::TouchscreenDelegate { // DisplayConfigurator::TouchscreenDelegate implementation: virtual void AssociateTouchscreens( DisplayConfigurator::DisplayStateList* outputs) OVERRIDE; - virtual void ConfigureCTM( - int touch_device_id, - const DisplayConfigurator::CoordinateTransformation& ctm) OVERRIDE; private: Display* display_; |