Skip to content

Commit

Permalink
embedder: merge embedder.h from flutter/engine (#408)
Browse files Browse the repository at this point in the history
Merged from https://github.com/flutter/engine/commits/3.19.0/shell/platform/embedder/embedder.h

Signed-off-by: Hidenori Matsubayashi <Hidenori.Matsubayashi@gmail.com>
  • Loading branch information
HidenoriMatsubayashi authored Feb 16, 2024
1 parent 28de1eb commit 185d73a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
38 changes: 38 additions & 0 deletions src/flutter/common/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_COMMON_CONSTANTS_H_
#define FLUTTER_COMMON_CONSTANTS_H_

namespace flutter {
constexpr double kMegaByteSizeInBytes = (1 << 20);

// The ID for the implicit view if the implicit view is enabled.
//
// The implicit view is a compatibility mechanism to help the transition from
// the older single-view APIs to the newer multi-view APIs. The two sets of APIs
// use different models for view management. The implicit view mechanism allows
// single-view APIs to operate a special view as if other views don't exist.
//
// In the regular multi-view model, all views should be created by
// `Shell::AddView` before being used, and removed by `Shell::RemoveView` to
// signify that they are gone. If a view is added or removed, the framework
// (`PlatformDispatcher`) will be notified. New view IDs are always unique,
// never reused. Operating a non-existing view is an error.
//
// The implicit view is another special view in addition to the "regular views"
// as above. The shell starts up having the implicit view, which has a fixed
// view ID of `kFlutterImplicitViewId` and is available throughout the lifetime
// of the shell. `Shell::AddView` or `RemoveView` must not be called for this
// view. Even when the window that shows the view is closed, the framework is
// unaware and might continue rendering into or operating this view.
//
// The single-view APIs, which are APIs that do not specify view IDs, operate
// the implicit view. The multi-view APIs can operate all views, including the
// implicit view if the target ID is `kFlutterImplicitViewId`, unless specified
// otherwise.
constexpr int64_t kFlutterImplicitViewId = 0;
} // namespace flutter

#endif // FLUTTER_COMMON_CONSTANTS_H_
28 changes: 25 additions & 3 deletions src/flutter/shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_EMBEDDER_H_
#define FLUTTER_EMBEDDER_H_
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_

#include <stdbool.h>
#include <stddef.h>
Expand Down Expand Up @@ -266,6 +266,12 @@ typedef enum {

typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine);

/// Unique identifier for views.
///
/// View IDs are generated by the embedder and are
/// opaque to the engine; the engine does not interpret view IDs in any way.
typedef int64_t FlutterViewId;

typedef struct {
/// horizontal scale factor
double scaleX;
Expand Down Expand Up @@ -961,6 +967,8 @@ typedef struct {
double scale;
/// The rotation of the pan/zoom in radians, where 0.0 is the initial angle.
double rotation;
/// The identifier of the view that received the pointer event.
FlutterViewId view_id;
} FlutterPointerEvent;

typedef enum {
Expand All @@ -969,6 +977,14 @@ typedef enum {
kFlutterKeyEventTypeRepeat,
} FlutterKeyEventType;

typedef enum {
kFlutterKeyEventDeviceTypeKeyboard = 1,
kFlutterKeyEventDeviceTypeDirectionalPad,
kFlutterKeyEventDeviceTypeGamepad,
kFlutterKeyEventDeviceTypeJoystick,
kFlutterKeyEventDeviceTypeHdmi,
} FlutterKeyEventDeviceType;

/// A structure to represent a key event.
///
/// Sending `FlutterKeyEvent` via `FlutterEngineSendKeyEvent` results in a
Expand Down Expand Up @@ -1032,6 +1048,8 @@ typedef struct {
/// An event being synthesized means that the `timestamp` might greatly
/// deviate from the actual time when the event occurs physically.
bool synthesized;
/// The source device for the key event.
FlutterKeyEventDeviceType device_type;
} FlutterKeyEvent;

typedef void (*FlutterKeyEventCallback)(bool /* handled */,
Expand Down Expand Up @@ -2253,6 +2271,8 @@ typedef struct {

#ifndef FLUTTER_ENGINE_NO_PROTOTYPES

// NOLINTBEGIN(google-objc-function-naming)

//------------------------------------------------------------------------------
/// @brief Creates the necessary data structures to launch a Flutter Dart
/// application in AOT mode. The data may only be collected after
Expand Down Expand Up @@ -3124,8 +3144,10 @@ FLUTTER_EXPORT
FlutterEngineResult FlutterEngineGetProcAddresses(
FlutterEngineProcTable* table);

// NOLINTEND(google-objc-function-naming)

#if defined(__cplusplus)
} // extern "C"
#endif

#endif // FLUTTER_EMBEDDER_H_
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_
6 changes: 3 additions & 3 deletions src/flutter/shell/platform/embedder/embedder_struct_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_

#include <type_traits>

Expand All @@ -29,4 +29,4 @@
#define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \
(SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2))

#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
13 changes: 13 additions & 0 deletions src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <chrono>
#include <cmath>

#include "flutter/common/constants.h"
#include "flutter/shell/platform/linux_embedded/logger.h"

namespace flutter {
Expand Down Expand Up @@ -165,6 +166,9 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
.scroll_delta_y = 0,
.device_kind = kFlutterPointerDeviceKindTouch,
.buttons = 0,
// TODO: Use the correct view ID for pointer events once the
// eLinux embedder supports multiple views.
.view_id = flutter::kFlutterImplicitViewId,
};
engine_->SendPointerEvent(event);
}
Expand Down Expand Up @@ -203,6 +207,9 @@ void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) {
.scroll_delta_y = 0,
.device_kind = kFlutterPointerDeviceKindTouch,
.buttons = 0,
// TODO: Use the correct view ID for pointer events once the
// eLinux embedder supports multiple views.
.view_id = flutter::kFlutterImplicitViewId,
};
engine_->SendPointerEvent(event);
}
Expand Down Expand Up @@ -247,6 +254,9 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time,
.scroll_delta_y = 0,
.device_kind = kFlutterPointerDeviceKindTouch,
.buttons = 0,
// TODO: Use the correct view ID for pointer events once the
// eLinux embedder supports multiple views.
.view_id = flutter::kFlutterImplicitViewId,
};
engine_->SendPointerEvent(event);
}
Expand Down Expand Up @@ -424,6 +434,9 @@ void FlutterELinuxView::SendPointerEventWithData(
FlutterPointerEvent event = event_data;
event.device_kind = kFlutterPointerDeviceKindMouse;
event.buttons = mouse_state_.buttons;
// TODO: Use the correct view ID for pointer events once the
// eLinux embedder supports multiple views.
event.view_id = flutter::kFlutterImplicitViewId;

// Set metadata that's always the same regardless of the event.
event.struct_size = sizeof(event);
Expand Down

0 comments on commit 185d73a

Please sign in to comment.