[scenic] Switch compositor lookup to use global ids
TEST=CQ, load system ui
Change-Id: I3fb222113dc80a5480c0e5c68b4a5e890557c47e
diff --git a/lib/ui/gfx/engine/engine.cc b/lib/ui/gfx/engine/engine.cc
index 5762741..dbadd1d 100644
--- a/lib/ui/gfx/engine/engine.cc
+++ b/lib/ui/gfx/engine/engine.cc
@@ -311,9 +311,9 @@
return compositors_.empty() ? nullptr : *compositors_.begin();
}
-Compositor* Engine::GetCompositor(scenic_impl::ResourceId compositor_id) const {
+Compositor* Engine::GetCompositor(scenic_impl::GlobalId compositor_id) const {
for (Compositor* compositor : compositors_) {
- if (compositor->id() == compositor_id) {
+ if (compositor->global_id() == compositor_id) {
return compositor;
}
}
diff --git a/lib/ui/gfx/engine/engine.h b/lib/ui/gfx/engine/engine.h
index 620d8e6..5955daf 100644
--- a/lib/ui/gfx/engine/engine.h
+++ b/lib/ui/gfx/engine/engine.h
@@ -125,7 +125,7 @@
Compositor* GetFirstCompositor() const;
// Returns the compositor requested, or nullptr if it does not exist.
- Compositor* GetCompositor(scenic_impl::ResourceId compositor_id) const;
+ Compositor* GetCompositor(scenic_impl::GlobalId compositor_id) const;
// Dumps the contents of all scene graphs.
std::string DumpScenes() const;
diff --git a/lib/ui/gfx/gfx_system.cc b/lib/ui/gfx/gfx_system.cc
index 4182d18..97083c4 100644
--- a/lib/ui/gfx/gfx_system.cc
+++ b/lib/ui/gfx/gfx_system.cc
@@ -318,7 +318,7 @@
return false;
}
-Compositor* GfxSystem::GetCompositor(ResourceId compositor_id) const {
+Compositor* GfxSystem::GetCompositor(GlobalId compositor_id) const {
return engine_->GetCompositor(compositor_id);
}
diff --git a/lib/ui/gfx/gfx_system.h b/lib/ui/gfx/gfx_system.h
index dcba9d2..90dbad3 100644
--- a/lib/ui/gfx/gfx_system.h
+++ b/lib/ui/gfx/gfx_system.h
@@ -39,7 +39,7 @@
override;
// TODO(SCN-906): Break out Engine, instead of coupling it to GfxSystem.
- Compositor* GetCompositor(ResourceId compositor_id) const;
+ Compositor* GetCompositor(GlobalId compositor_id) const;
gfx::Session* GetSession(SessionId session_id) const;
// TODO(SCN-906): Remove this in favor of unified initialization.
diff --git a/lib/ui/input/input_system.cc b/lib/ui/input/input_system.cc
index fd96811..9b909e8 100644
--- a/lib/ui/input/input_system.cc
+++ b/lib/ui/input/input_system.cc
@@ -20,6 +20,7 @@
#include "garnet/lib/ui/gfx/resources/view_holder.h"
#include "garnet/lib/ui/gfx/util/unwrap.h"
#include "garnet/lib/ui/scenic/event_reporter.h"
+#include "garnet/lib/ui/scenic/session.h"
#include "lib/component/cpp/startup_context.h"
#include "lib/escher/geometry/types.h"
#include "lib/escher/util/type_utils.h"
@@ -121,8 +122,13 @@
// - must not retain it, or extends its lifetime via Refptr,
// - must not write into it,
// - may call const functions against it.
+//
+// Only the root presenter creates compositors and sends input commands.
+// This invariant means this dispatcher context's session, handling an input
+// command, also originally created the compositor.
+//
std::vector<gfx::Hit> PerformGlobalHitTest(gfx::GfxSystem* gfx_system,
- uint32_t compositor_id, float x,
+ GlobalId compositor_id, float x,
float y) {
FXL_DCHECK(gfx_system);
@@ -255,8 +261,9 @@
DispatchCommand(std::move(input.send_keyboard_input()));
} else if (input.is_send_pointer_input()) {
// Compositor and layer stack required for dispatch.
- gfx::Compositor* compositor =
- gfx_system_->GetCompositor(input.send_pointer_input().compositor_id);
+ GlobalId compositor_id(context()->session_id(),
+ input.send_pointer_input().compositor_id);
+ gfx::Compositor* compositor = gfx_system_->GetCompositor(compositor_id);
if (!compositor)
return; // It's legal to race against GFX's compositor setup.
@@ -306,8 +313,9 @@
<< "Oops, touch device had unexpected HOVER event.";
if (pointer_phase == Phase::ADD) {
- const std::vector<gfx::Hit> hits = PerformGlobalHitTest(
- gfx_system_, command.compositor_id, pointer_x, pointer_y);
+ GlobalId compositor_id(context()->session_id(), command.compositor_id);
+ const std::vector<gfx::Hit> hits =
+ PerformGlobalHitTest(gfx_system_, compositor_id, pointer_x, pointer_y);
// Find input targets. Honor the "input masking" view property.
ViewStack hit_views;
@@ -406,8 +414,9 @@
// gestures, so there is no parallel dispatch.
// - Mouse DOWN triggers a focus change, but honors the no-focus property.
// - Mouse UP drops the association between event stream and client.
-// - For an unassociated MOVE event, we perform a hit test, and send the top-most
-// client this MOVE event. Focus does not change for unassociated MOVEs.
+// - For an unassociated MOVE event, we perform a hit test, and send the
+// top-most client this MOVE event. Focus does not change for unassociated
+// MOVEs.
// - The hit test must account for the mouse cursor itself, which today is
// owned by the root presenter. The nodes associated with visible mouse
// cursors(!) do not roll up to any View (as expected), but may appear in the
@@ -427,8 +436,9 @@
<< ") had an unexpected event: " << pointer_phase;
if (pointer_phase == Phase::DOWN) {
- const std::vector<gfx::Hit> hits = PerformGlobalHitTest(
- gfx_system_, command.compositor_id, pointer_x, pointer_y);
+ GlobalId compositor_id(context()->session_id(), command.compositor_id);
+ const std::vector<gfx::Hit> hits =
+ PerformGlobalHitTest(gfx_system_, compositor_id, pointer_x, pointer_y);
// Find top-hit target and associated properties.
// NOTE: We may hit various mouse cursors (owned by root presenter), so keep
@@ -500,8 +510,9 @@
// Deal with unassociated MOVE events.
if (pointer_phase == Phase::MOVE && mouse_targets_.count(device_id) == 0) {
- const std::vector<gfx::Hit> hits = PerformGlobalHitTest(
- gfx_system_, command.compositor_id, pointer_x, pointer_y);
+ GlobalId compositor_id(context()->session_id(), command.compositor_id);
+ const std::vector<gfx::Hit> hits =
+ PerformGlobalHitTest(gfx_system_, compositor_id, pointer_x, pointer_y);
// Find top-hit target and send it this move event.
// NOTE: We may hit various mouse cursors (owned by root presenter), so keep
// going until we find a hit with a valid owning View.