Skip to content

Commit 185d73a

Browse files
embedder: merge embedder.h from flutter/engine (#408)
Merged from https://github.com/flutter/engine/commits/3.19.0/shell/platform/embedder/embedder.h Signed-off-by: Hidenori Matsubayashi <[email protected]>
1 parent 28de1eb commit 185d73a

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

src/flutter/common/constants.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_COMMON_CONSTANTS_H_
6+
#define FLUTTER_COMMON_CONSTANTS_H_
7+
8+
namespace flutter {
9+
constexpr double kMegaByteSizeInBytes = (1 << 20);
10+
11+
// The ID for the implicit view if the implicit view is enabled.
12+
//
13+
// The implicit view is a compatibility mechanism to help the transition from
14+
// the older single-view APIs to the newer multi-view APIs. The two sets of APIs
15+
// use different models for view management. The implicit view mechanism allows
16+
// single-view APIs to operate a special view as if other views don't exist.
17+
//
18+
// In the regular multi-view model, all views should be created by
19+
// `Shell::AddView` before being used, and removed by `Shell::RemoveView` to
20+
// signify that they are gone. If a view is added or removed, the framework
21+
// (`PlatformDispatcher`) will be notified. New view IDs are always unique,
22+
// never reused. Operating a non-existing view is an error.
23+
//
24+
// The implicit view is another special view in addition to the "regular views"
25+
// as above. The shell starts up having the implicit view, which has a fixed
26+
// view ID of `kFlutterImplicitViewId` and is available throughout the lifetime
27+
// of the shell. `Shell::AddView` or `RemoveView` must not be called for this
28+
// view. Even when the window that shows the view is closed, the framework is
29+
// unaware and might continue rendering into or operating this view.
30+
//
31+
// The single-view APIs, which are APIs that do not specify view IDs, operate
32+
// the implicit view. The multi-view APIs can operate all views, including the
33+
// implicit view if the target ID is `kFlutterImplicitViewId`, unless specified
34+
// otherwise.
35+
constexpr int64_t kFlutterImplicitViewId = 0;
36+
} // namespace flutter
37+
38+
#endif // FLUTTER_COMMON_CONSTANTS_H_

src/flutter/shell/platform/embedder/embedder.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef FLUTTER_EMBEDDER_H_
6-
#define FLUTTER_EMBEDDER_H_
5+
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_
6+
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_
77

88
#include <stdbool.h>
99
#include <stddef.h>
@@ -266,6 +266,12 @@ typedef enum {
266266

267267
typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine);
268268

269+
/// Unique identifier for views.
270+
///
271+
/// View IDs are generated by the embedder and are
272+
/// opaque to the engine; the engine does not interpret view IDs in any way.
273+
typedef int64_t FlutterViewId;
274+
269275
typedef struct {
270276
/// horizontal scale factor
271277
double scaleX;
@@ -961,6 +967,8 @@ typedef struct {
961967
double scale;
962968
/// The rotation of the pan/zoom in radians, where 0.0 is the initial angle.
963969
double rotation;
970+
/// The identifier of the view that received the pointer event.
971+
FlutterViewId view_id;
964972
} FlutterPointerEvent;
965973

966974
typedef enum {
@@ -969,6 +977,14 @@ typedef enum {
969977
kFlutterKeyEventTypeRepeat,
970978
} FlutterKeyEventType;
971979

980+
typedef enum {
981+
kFlutterKeyEventDeviceTypeKeyboard = 1,
982+
kFlutterKeyEventDeviceTypeDirectionalPad,
983+
kFlutterKeyEventDeviceTypeGamepad,
984+
kFlutterKeyEventDeviceTypeJoystick,
985+
kFlutterKeyEventDeviceTypeHdmi,
986+
} FlutterKeyEventDeviceType;
987+
972988
/// A structure to represent a key event.
973989
///
974990
/// Sending `FlutterKeyEvent` via `FlutterEngineSendKeyEvent` results in a
@@ -1032,6 +1048,8 @@ typedef struct {
10321048
/// An event being synthesized means that the `timestamp` might greatly
10331049
/// deviate from the actual time when the event occurs physically.
10341050
bool synthesized;
1051+
/// The source device for the key event.
1052+
FlutterKeyEventDeviceType device_type;
10351053
} FlutterKeyEvent;
10361054

10371055
typedef void (*FlutterKeyEventCallback)(bool /* handled */,
@@ -2253,6 +2271,8 @@ typedef struct {
22532271

22542272
#ifndef FLUTTER_ENGINE_NO_PROTOTYPES
22552273

2274+
// NOLINTBEGIN(google-objc-function-naming)
2275+
22562276
//------------------------------------------------------------------------------
22572277
/// @brief Creates the necessary data structures to launch a Flutter Dart
22582278
/// application in AOT mode. The data may only be collected after
@@ -3124,8 +3144,10 @@ FLUTTER_EXPORT
31243144
FlutterEngineResult FlutterEngineGetProcAddresses(
31253145
FlutterEngineProcTable* table);
31263146

3147+
// NOLINTEND(google-objc-function-naming)
3148+
31273149
#if defined(__cplusplus)
31283150
} // extern "C"
31293151
#endif
31303152

3131-
#endif // FLUTTER_EMBEDDER_H_
3153+
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_

src/flutter/shell/platform/embedder/embedder_struct_macros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
6-
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
5+
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
6+
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_
77

88
#include <type_traits>
99

@@ -29,4 +29,4 @@
2929
#define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \
3030
(SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2))
3131

32-
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_
32+
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_

src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <chrono>
88
#include <cmath>
99

10+
#include "flutter/common/constants.h"
1011
#include "flutter/shell/platform/linux_embedded/logger.h"
1112

1213
namespace flutter {
@@ -165,6 +166,9 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
165166
.scroll_delta_y = 0,
166167
.device_kind = kFlutterPointerDeviceKindTouch,
167168
.buttons = 0,
169+
// TODO: Use the correct view ID for pointer events once the
170+
// eLinux embedder supports multiple views.
171+
.view_id = flutter::kFlutterImplicitViewId,
168172
};
169173
engine_->SendPointerEvent(event);
170174
}
@@ -203,6 +207,9 @@ void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) {
203207
.scroll_delta_y = 0,
204208
.device_kind = kFlutterPointerDeviceKindTouch,
205209
.buttons = 0,
210+
// TODO: Use the correct view ID for pointer events once the
211+
// eLinux embedder supports multiple views.
212+
.view_id = flutter::kFlutterImplicitViewId,
206213
};
207214
engine_->SendPointerEvent(event);
208215
}
@@ -247,6 +254,9 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time,
247254
.scroll_delta_y = 0,
248255
.device_kind = kFlutterPointerDeviceKindTouch,
249256
.buttons = 0,
257+
// TODO: Use the correct view ID for pointer events once the
258+
// eLinux embedder supports multiple views.
259+
.view_id = flutter::kFlutterImplicitViewId,
250260
};
251261
engine_->SendPointerEvent(event);
252262
}
@@ -424,6 +434,9 @@ void FlutterELinuxView::SendPointerEventWithData(
424434
FlutterPointerEvent event = event_data;
425435
event.device_kind = kFlutterPointerDeviceKindMouse;
426436
event.buttons = mouse_state_.buttons;
437+
// TODO: Use the correct view ID for pointer events once the
438+
// eLinux embedder supports multiple views.
439+
event.view_id = flutter::kFlutterImplicitViewId;
427440

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

0 commit comments

Comments
 (0)