Commit d77c5029 authored by chaopeng's avatar chaopeng Committed by Commit Bot

Move Viewport reset into DirectManipulationEventHandler

The crash report shows DirectManipulation may call
DirectManipulationEventHandler OnViewportStatusChanged
to READY state after DirectManipulationHelper Destroyed
then crash because we called Reset to invalidate DMHelper.

In this CL, we pass the viewport size to DMEventHandler
and use it to reset viewport at gesture end. Also
DMEventHandler does not need to store pointer of DMHelper.

Bug: 951293
Change-Id: I39a3402659b9ae117ab45288b68dd5d595e58457
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562153
Commit-Queue: Jianpeng Chao <chaopeng@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649712}
parent 059035c6
...@@ -28,19 +28,15 @@ bool FloatEquals(float f1, float f2) { ...@@ -28,19 +28,15 @@ bool FloatEquals(float f1, float f2) {
} // namespace } // namespace
DirectManipulationEventHandler::DirectManipulationEventHandler( DirectManipulationEventHandler::DirectManipulationEventHandler(
DirectManipulationHelper* helper) ui::WindowEventTarget* event_target)
: helper_(helper) {} : event_target_(event_target) {}
void DirectManipulationEventHandler::SetWindowEventTarget( bool DirectManipulationEventHandler::SetViewportSizeInPixels(
ui::WindowEventTarget* event_target) { const gfx::Size& viewport_size_in_pixels) {
if (!event_target && LoggingEnabled()) { if (viewport_size_in_pixels_ == viewport_size_in_pixels)
DebugLogging("Event target is null.", S_OK); return false;
if (event_target_) viewport_size_in_pixels_ = viewport_size_in_pixels;
DebugLogging("Previous event target is not null", S_OK); return true;
else
DebugLogging("Previous event target is null", S_OK);
}
event_target_ = event_target;
} }
void DirectManipulationEventHandler::SetDeviceScaleFactor( void DirectManipulationEventHandler::SetDeviceScaleFactor(
...@@ -181,9 +177,14 @@ HRESULT DirectManipulationEventHandler::OnViewportStatusChanged( ...@@ -181,9 +177,14 @@ HRESULT DirectManipulationEventHandler::OnViewportStatusChanged(
// RUNNING -> READY sequence. // RUNNING -> READY sequence.
if (!FloatEquals(1.0f, last_scale_) || last_x_offset_ != 0 || if (!FloatEquals(1.0f, last_scale_) || last_x_offset_ != 0 ||
last_y_offset_ != 0) { last_y_offset_ != 0) {
HRESULT hr = helper_->Reset(); HRESULT hr = viewport->ZoomToRect(
if (!SUCCEEDED(hr)) static_cast<float>(0), static_cast<float>(0),
static_cast<float>(viewport_size_in_pixels_.width()),
static_cast<float>(viewport_size_in_pixels_.height()), FALSE);
if (!SUCCEEDED(hr)) {
DebugLogging("Viewport zoom to rect failed.", hr);
return hr; return hr;
}
} }
last_scale_ = 1.0f; last_scale_ = 1.0f;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <wrl.h> #include <wrl.h>
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/size.h"
namespace ui { namespace ui {
...@@ -20,7 +21,6 @@ class WindowEventTarget; ...@@ -20,7 +21,6 @@ class WindowEventTarget;
namespace content { namespace content {
class DirectManipulationHelper;
class DirectManipulationUnitTest; class DirectManipulationUnitTest;
// DirectManipulationEventHandler receives status update and gesture events from // DirectManipulationEventHandler receives status update and gesture events from
...@@ -35,11 +35,10 @@ class DirectManipulationEventHandler ...@@ -35,11 +35,10 @@ class DirectManipulationEventHandler
Microsoft::WRL::FtmBase, Microsoft::WRL::FtmBase,
IDirectManipulationViewportEventHandler>> { IDirectManipulationViewportEventHandler>> {
public: public:
explicit DirectManipulationEventHandler(DirectManipulationHelper* helper); explicit DirectManipulationEventHandler(ui::WindowEventTarget* event_target);
// WindowEventTarget updates for every DM_POINTERHITTEST in case window // Return true if viewport_size_in_pixels_ changed.
// hierarchy changed. bool SetViewportSizeInPixels(const gfx::Size& viewport_size_in_pixels);
void SetWindowEventTarget(ui::WindowEventTarget* event_target);
void SetDeviceScaleFactor(float device_scale_factor); void SetDeviceScaleFactor(float device_scale_factor);
...@@ -65,7 +64,6 @@ class DirectManipulationEventHandler ...@@ -65,7 +64,6 @@ class DirectManipulationEventHandler
OnContentUpdated(_In_ IDirectManipulationViewport* viewport, OnContentUpdated(_In_ IDirectManipulationViewport* viewport,
_In_ IDirectManipulationContent* content) override; _In_ IDirectManipulationContent* content) override;
DirectManipulationHelper* helper_ = nullptr;
ui::WindowEventTarget* event_target_ = nullptr; ui::WindowEventTarget* event_target_ = nullptr;
float device_scale_factor_ = 1.0f; float device_scale_factor_ = 1.0f;
float last_scale_ = 1.0f; float last_scale_ = 1.0f;
...@@ -76,6 +74,8 @@ class DirectManipulationEventHandler ...@@ -76,6 +74,8 @@ class DirectManipulationEventHandler
// Current recognized gesture from Direct Manipulation. // Current recognized gesture from Direct Manipulation.
GestureState gesture_state_ = GestureState::kNone; GestureState gesture_state_ = GestureState::kNone;
gfx::Size viewport_size_in_pixels_;
DISALLOW_COPY_AND_ASSIGN(DirectManipulationEventHandler); DISALLOW_COPY_AND_ASSIGN(DirectManipulationEventHandler);
}; };
......
...@@ -77,8 +77,7 @@ DirectManipulationHelper::CreateInstanceForTesting( ...@@ -77,8 +77,7 @@ DirectManipulationHelper::CreateInstanceForTesting(
base::WrapUnique(new DirectManipulationHelper(0, nullptr)); base::WrapUnique(new DirectManipulationHelper(0, nullptr));
instance->event_handler_ = instance->event_handler_ =
Microsoft::WRL::Make<DirectManipulationEventHandler>(instance.get()); Microsoft::WRL::Make<DirectManipulationEventHandler>(event_target);
instance->event_handler_->SetWindowEventTarget(event_target);
instance->viewport_ = viewport; instance->viewport_ = viewport;
...@@ -157,8 +156,8 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) { ...@@ -157,8 +156,8 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) {
return false; return false;
} }
event_handler_ = Microsoft::WRL::Make<DirectManipulationEventHandler>(this); event_handler_ =
event_handler_->SetWindowEventTarget(event_target); Microsoft::WRL::Make<DirectManipulationEventHandler>(event_target);
// We got Direct Manipulation transform from // We got Direct Manipulation transform from
// IDirectManipulationViewportEventHandler. // IDirectManipulationViewportEventHandler.
...@@ -170,8 +169,9 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) { ...@@ -170,8 +169,9 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) {
} }
// Set default rect for viewport before activate. // Set default rect for viewport before activate.
viewport_size_in_pixels_ = {1000, 1000}; gfx::Size viewport_size_in_pixels = {1000, 1000};
RECT rect = gfx::Rect(viewport_size_in_pixels_).ToRECT(); event_handler_->SetViewportSizeInPixels(viewport_size_in_pixels);
RECT rect = gfx::Rect(viewport_size_in_pixels).ToRECT();
hr = viewport_->SetViewportRect(&rect); hr = viewport_->SetViewportRect(&rect);
if (!SUCCEEDED(hr)) { if (!SUCCEEDED(hr)) {
DebugLogging("Viewport set rect failed.", hr); DebugLogging("Viewport set rect failed.", hr);
...@@ -205,7 +205,7 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) { ...@@ -205,7 +205,7 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) {
void DirectManipulationHelper::SetSizeInPixels( void DirectManipulationHelper::SetSizeInPixels(
const gfx::Size& size_in_pixels) { const gfx::Size& size_in_pixels) {
if (viewport_size_in_pixels_ == size_in_pixels) if (!event_handler_->SetViewportSizeInPixels(size_in_pixels))
return; return;
HRESULT hr = viewport_->Stop(); HRESULT hr = viewport_->Stop();
...@@ -214,8 +214,7 @@ void DirectManipulationHelper::SetSizeInPixels( ...@@ -214,8 +214,7 @@ void DirectManipulationHelper::SetSizeInPixels(
return; return;
} }
viewport_size_in_pixels_ = size_in_pixels; RECT rect = gfx::Rect(size_in_pixels).ToRECT();
RECT rect = gfx::Rect(viewport_size_in_pixels_).ToRECT();
hr = viewport_->SetViewportRect(&rect); hr = viewport_->SetViewportRect(&rect);
if (!SUCCEEDED(hr)) if (!SUCCEEDED(hr))
DebugLogging("Viewport set rect failed.", hr); DebugLogging("Viewport set rect failed.", hr);
...@@ -245,21 +244,6 @@ void DirectManipulationHelper::OnPointerHitTest(WPARAM w_param) { ...@@ -245,21 +244,6 @@ void DirectManipulationHelper::OnPointerHitTest(WPARAM w_param) {
} }
} }
HRESULT DirectManipulationHelper::Reset() {
// By zooming the primary content to a rect that match the viewport rect, we
// reset the content's transform to identity.
HRESULT hr = viewport_->ZoomToRect(
static_cast<float>(0), static_cast<float>(0),
static_cast<float>(viewport_size_in_pixels_.width()),
static_cast<float>(viewport_size_in_pixels_.height()), FALSE);
if (!SUCCEEDED(hr)) {
DebugLogging("Viewport zoom to rect failed.", hr);
return hr;
}
return S_OK;
}
void DirectManipulationHelper::SetDeviceScaleFactorForTesting(float factor) { void DirectManipulationHelper::SetDeviceScaleFactorForTesting(float factor) {
event_handler_->SetDeviceScaleFactor(factor); event_handler_->SetDeviceScaleFactor(factor);
} }
......
...@@ -73,9 +73,6 @@ class CONTENT_EXPORT DirectManipulationHelper ...@@ -73,9 +73,6 @@ class CONTENT_EXPORT DirectManipulationHelper
// Updates viewport size. Call it when window bounds updated. // Updates viewport size. Call it when window bounds updated.
void SetSizeInPixels(const gfx::Size& size_in_pixels); void SetSizeInPixels(const gfx::Size& size_in_pixels);
// Reset for gesture end.
HRESULT Reset();
// Pass the pointer hit test to Direct Manipulation. // Pass the pointer hit test to Direct Manipulation.
void OnPointerHitTest(WPARAM w_param); void OnPointerHitTest(WPARAM w_param);
...@@ -100,7 +97,6 @@ class CONTENT_EXPORT DirectManipulationHelper ...@@ -100,7 +97,6 @@ class CONTENT_EXPORT DirectManipulationHelper
HWND window_; HWND window_;
ui::Compositor* compositor_ = nullptr; ui::Compositor* compositor_ = nullptr;
DWORD view_port_handler_cookie_; DWORD view_port_handler_cookie_;
gfx::Size viewport_size_in_pixels_;
DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper); DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment