Modules/GraphicApplication/tests/PointerPinchConverterTests.cpp
agent 711793ffd7 GraphicApplication: GPU device, window surfaces, window and platform backends
gpu/ replaces the OpenGL path and is split by lifetime:
- GpuDevice is the instance, device, graphics queue, command pool, one-shot
  uploads and render-target registry, shared by every window.
- WindowSurface is one window's surface, swapchain, render pass,
  depth-stencil and frames in flight. beginFrame() returns a GpuFrame
  (command buffer, frame slot, extent), the narrow view renderers record
  into. Render-finished semaphores are per swapchain image, Vulkan results
  are checked and failures throw GpuError.

backends/contract/ is the only thing a backend and the window share.
PlatformWindow is what a backend implements; it knows no coalescer or GPU
object. PlatformWindowHost is all a backend may call back: rawInput(),
onContentResized(), onSurfaceAvailable() and onSurfaceLost(), so the window
drives the GPU surface. Desktop-only manipulation is the optional
DesktopWindowControls interface. A backend also defines its surface
extensions, its resource directory and createPlatformWindow(), which
receives a typed PlatformContext.

- backends/wayland/ keeps xdg configure handling to itself and acknowledges
  it when the frame loop applies it. The seat is split per device
  (keyboard, pointer, tablet, text input, clipboard); clipboard contents are
  read asynchronously on the event loop. evdev key codes and the touchpad
  pinch converter live here. Resources resolve next to the executable.
- backends/android/ runs on native_app_glue and finishes the activity when
  the application returns or fails.

window/ owns the platform window, its WindowSurface, the coalescer and the
input queue, and exposes roles: WindowEventLoop, WindowInput (state,
injection, raw tap, delivery policies, the one place input is muted),
WindowControls (with desktop() for the optional controls) and
WindowServices. Window's public header names no backend.
2026-10-29 05:24:06 +03:00

57 lines
2.1 KiB
C++

#include "UnitTest++/UnitTest++.h"
#include "PointerPinchConverter.hpp"
SUITE(PointerPinchConverter) {
TEST(TotalScaleBecomesIncrementalAndMultipliesBack) {
tp::PointerPinchConverter converter;
const tp::TouchGesture begin = converter.begin({ 10, 20 });
CHECK(begin.phase == tp::GesturePhase::Begin);
CHECK(begin.center == tp::Vec2F(10.0f, 20.0f));
tp::halnf product = 1;
for (tp::halnf total : { 1.2f, 1.5f, 1.5f, 0.9f }) {
const std::optional<tp::TouchGesture> update = converter.update({ 10, 20 }, { 1, 2 }, total, 0);
REQUIRE CHECK(update.has_value());
CHECK(update->pan == tp::Vec2F(1.0f, 2.0f));
product *= update->scale;
CHECK_CLOSE(total, product, 0.0001f);
}
const std::optional<tp::TouchGesture> end = converter.end({ 10, 20 });
REQUIRE CHECK(end.has_value());
CHECK(end->phase == tp::GesturePhase::End);
}
TEST(RotationIsConvertedToRadians) {
tp::PointerPinchConverter converter;
(void) converter.begin({ 0, 0 });
const std::optional<tp::TouchGesture> update = converter.update({ 0, 0 }, { 0, 0 }, 1, 90);
REQUIRE CHECK(update.has_value());
CHECK_CLOSE(1.5707963f, update->rotation, 0.0001f);
}
TEST(UpdatesOutsideAGestureAreIgnoredAndNewGestureRestartsScale) {
tp::PointerPinchConverter converter;
CHECK(!converter.update({ 0, 0 }, { 0, 0 }, 2, 0).has_value());
CHECK(!converter.end({ 0, 0 }).has_value());
(void) converter.begin({ 0, 0 });
(void) converter.update({ 0, 0 }, { 0, 0 }, 2, 0);
(void) converter.end({ 0, 0 });
(void) converter.begin({ 0, 0 });
const std::optional<tp::TouchGesture> fresh = converter.update({ 0, 0 }, { 0, 0 }, 1.25f, 0);
REQUIRE CHECK(fresh.has_value());
CHECK_CLOSE(1.25f, fresh->scale, 0.0001f);
}
TEST(ZeroScaleFromCompositorIsTreatedAsNoChange) {
tp::PointerPinchConverter converter;
(void) converter.begin({ 0, 0 });
const std::optional<tp::TouchGesture> zero = converter.update({ 0, 0 }, { 0, 0 }, 0, 0);
REQUIRE CHECK(zero.has_value());
CHECK_CLOSE(1, zero->scale, 0.0001f);
const std::optional<tp::TouchGesture> next = converter.update({ 0, 0 }, { 0, 0 }, 2, 0);
CHECK_CLOSE(2, next->scale, 0.0001f);
}
}