Skip to content

Commit

Permalink
[content_handler] Make RuntimeHolder convey its viewport metrics to t…
Browse files Browse the repository at this point in the history
…he direct input instance. (flutter#3367)
  • Loading branch information
chinmaygarde authored Jan 26, 2017
1 parent a042f57 commit d45638f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions content_handler/direct_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ void DirectInput::PerformRead() {
pointer_data.kind = blink::PointerData::DeviceKind::kTouch;
pointer_data.device = touch_identifier;

pointer_data.physical_x = finger.x / 2.0;
pointer_data.physical_y = finger.y / 2.0;
pointer_data.physical_x = ((static_cast<float>(finger.x) / ACER12_X_MAX) *
viewport_metrics_.physical_width);
pointer_data.physical_y = ((static_cast<float>(finger.y) / ACER12_Y_MAX) *
viewport_metrics_.physical_height);

bool down = !!acer12_finger_id_tswitch(finger.finger_id);

Expand Down Expand Up @@ -231,4 +233,8 @@ ftl::UniqueFD DirectInput::GetTouchFileDescriptor() {
return {};
}

void DirectInput::SetViewportMetrics(blink::ViewportMetrics metrics) {
viewport_metrics_ = metrics;
}

} // namespace flutter_runner
4 changes: 4 additions & 0 deletions content_handler/direct_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
#include "lib/fidl/c/waiter/async_waiter.h"
#include "lib/ftl/files/unique_fd.h"
#include "lib/ftl/macros.h"
Expand All @@ -31,6 +32,8 @@ class DirectInput {

void CancelWaitForReadAvailability();

void SetViewportMetrics(blink::ViewportMetrics metrics);

private:
DirectInputCallback callback_;
bool valid_;
Expand All @@ -39,6 +42,7 @@ class DirectInput {
std::vector<uint8_t> read_buffer_;
FidlAsyncWaitID last_wait_;
std::set<int64_t> touch_ids_;
blink::ViewportMetrics viewport_metrics_;

static ftl::UniqueFD GetTouchFileDescriptor();

Expand Down
8 changes: 8 additions & 0 deletions content_handler/runtime_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ void RuntimeHolder::CreateView(
runtime_ = blink::RuntimeController::Create(this);
runtime_->CreateDartController(script_uri);
runtime_->SetViewportMetrics(viewport_metrics_);
#if FLUTTER_ENABLE_VULKAN
direct_input_->SetViewportMetrics(viewport_metrics_);
#endif // FLUTTER_ENABLE_VULKAN
runtime_->dart_controller()->RunFromSnapshot(snapshot.data(),
snapshot.size());
}
Expand Down Expand Up @@ -341,6 +344,11 @@ void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation,
// TODO(abarth): Use view_properties_->display_metrics->device_pixel_ratio
// once that's reasonable.
runtime_->SetViewportMetrics(viewport_metrics_);
#if FLUTTER_ENABLE_VULKAN
if (direct_input_) {
direct_input_->SetViewportMetrics(viewport_metrics_);
}
#endif // FLUTTER_ENABLE_VULKAN
}

// Remember the scene version for rendering.
Expand Down

0 comments on commit d45638f

Please sign in to comment.