Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
f5bdf9b0
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f5bdf9b0
编写于
11月 09, 2017
作者:
Z
Zachary Anderson
提交者:
GitHub
11月 09, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Android] Pulls the native platform view out of FlutterView (#4338)
上级
a9319a10
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
293 addition
and
190 deletion
+293
-190
shell/platform/android/BUILD.gn
shell/platform/android/BUILD.gn
+1
-0
shell/platform/android/io/flutter/view/FlutterNativeView.java
...l/platform/android/io/flutter/view/FlutterNativeView.java
+200
-0
shell/platform/android/io/flutter/view/FlutterView.java
shell/platform/android/io/flutter/view/FlutterView.java
+24
-141
shell/platform/android/platform_view_android_jni.cc
shell/platform/android/platform_view_android_jni.cc
+67
-49
travis/licenses_golden/licenses_flutter
travis/licenses_golden/licenses_flutter
+1
-0
未找到文件。
shell/platform/android/BUILD.gn
浏览文件 @
f5bdf9b0
...
...
@@ -113,6 +113,7 @@ java_library("flutter_shell_java") {
"io/flutter/util/Preconditions.java",
"io/flutter/view/AccessibilityBridge.java",
"io/flutter/view/FlutterMain.java",
"io/flutter/view/FlutterNativeView.java",
"io/flutter/view/FlutterView.java",
"io/flutter/view/ResourceCleaner.java",
"io/flutter/view/ResourceExtractor.java",
...
...
shell/platform/android/io/flutter/view/FlutterNativeView.java
0 → 100644
浏览文件 @
f5bdf9b0
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package
io.flutter.view
;
import
android.util.Log
;
import
io.flutter.plugin.common.*
;
import
java.nio.ByteBuffer
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.HashMap
;
import
java.util.Map
;
class
FlutterNativeView
implements
BinaryMessenger
{
private
static
final
String
TAG
=
"FlutterNativeView"
;
private
final
Map
<
String
,
BinaryMessageHandler
>
mMessageHandlers
;
private
int
mNextReplyId
=
1
;
private
final
Map
<
Integer
,
BinaryReply
>
mPendingReplies
=
new
HashMap
<>();
private
long
mNativePlatformView
;
private
FlutterView
mFlutterView
;
FlutterNativeView
(
FlutterView
flutterView
)
{
mFlutterView
=
flutterView
;
attach
(
this
);
assertAttached
();
mMessageHandlers
=
new
HashMap
<>();
}
FlutterNativeView
()
{
this
(
null
);
}
public
void
destroy
()
{
mFlutterView
=
null
;
nativeDestroy
(
mNativePlatformView
);
mNativePlatformView
=
0
;
}
public
boolean
isAttached
()
{
return
mNativePlatformView
!=
0
;
}
public
long
get
()
{
return
mNativePlatformView
;
}
public
void
assertAttached
()
{
if
(!
isAttached
())
throw
new
AssertionError
(
"Platform view is not attached"
);
}
public
void
runFromBundle
(
String
bundlePath
,
String
snapshotOverride
,
String
entrypoint
,
boolean
reuseRuntimeController
)
{
assertAttached
();
nativeRunBundleAndSnapshot
(
mNativePlatformView
,
bundlePath
,
snapshotOverride
,
entrypoint
,
reuseRuntimeController
);
}
public
void
runFromSource
(
final
String
assetsDirectory
,
final
String
main
,
final
String
packages
)
{
assertAttached
();
nativeRunBundleAndSource
(
mNativePlatformView
,
assetsDirectory
,
main
,
packages
);
}
public
static
String
getObservatoryUri
()
{
return
nativeGetObservatoryUri
();
}
@Override
public
void
send
(
String
channel
,
ByteBuffer
message
)
{
send
(
channel
,
message
,
null
);
}
@Override
public
void
send
(
String
channel
,
ByteBuffer
message
,
BinaryReply
callback
)
{
if
(!
isAttached
())
{
Log
.
d
(
TAG
,
"FlutterView.send called on a detached view, channel="
+
channel
);
return
;
}
int
replyId
=
0
;
if
(
callback
!=
null
)
{
replyId
=
mNextReplyId
++;
mPendingReplies
.
put
(
replyId
,
callback
);
}
if
(
message
==
null
)
{
nativeDispatchEmptyPlatformMessage
(
mNativePlatformView
,
channel
,
replyId
);
}
else
{
nativeDispatchPlatformMessage
(
mNativePlatformView
,
channel
,
message
,
message
.
position
(),
replyId
);
}
}
@Override
public
void
setMessageHandler
(
String
channel
,
BinaryMessageHandler
handler
)
{
if
(
handler
==
null
)
{
mMessageHandlers
.
remove
(
channel
);
}
else
{
mMessageHandlers
.
put
(
channel
,
handler
);
}
}
private
void
attach
(
FlutterNativeView
view
)
{
mNativePlatformView
=
nativeAttach
(
view
);
}
// Called by native to send us a platform message.
private
void
handlePlatformMessage
(
final
String
channel
,
byte
[]
message
,
final
int
replyId
)
{
assertAttached
();
BinaryMessageHandler
handler
=
mMessageHandlers
.
get
(
channel
);
if
(
handler
!=
null
)
{
try
{
final
ByteBuffer
buffer
=
(
message
==
null
?
null
:
ByteBuffer
.
wrap
(
message
));
handler
.
onMessage
(
buffer
,
new
BinaryReply
()
{
private
final
AtomicBoolean
done
=
new
AtomicBoolean
(
false
);
@Override
public
void
reply
(
ByteBuffer
reply
)
{
if
(!
isAttached
())
{
Log
.
d
(
TAG
,
"handlePlatformMessage replying to a detached view, channel="
+
channel
);
return
;
}
if
(
done
.
getAndSet
(
true
))
{
throw
new
IllegalStateException
(
"Reply already submitted"
);
}
if
(
reply
==
null
)
{
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
else
{
nativeInvokePlatformMessageResponseCallback
(
mNativePlatformView
,
replyId
,
reply
,
reply
.
position
());
}
}
});
}
catch
(
Exception
ex
)
{
Log
.
e
(
TAG
,
"Uncaught exception in binary message listener"
,
ex
);
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
return
;
}
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
// Called by native to respond to a platform message that we sent.
private
void
handlePlatformMessageResponse
(
int
replyId
,
byte
[]
reply
)
{
BinaryReply
callback
=
mPendingReplies
.
remove
(
replyId
);
if
(
callback
!=
null
)
{
try
{
callback
.
reply
(
reply
==
null
?
null
:
ByteBuffer
.
wrap
(
reply
));
}
catch
(
Exception
ex
)
{
Log
.
e
(
TAG
,
"Uncaught exception in binary message reply handler"
,
ex
);
}
}
}
// Called by native to update the semantics/accessibility tree.
private
void
updateSemantics
(
ByteBuffer
buffer
,
String
[]
strings
)
{
if
(
mFlutterView
==
null
)
return
;
mFlutterView
.
updateSemantics
(
buffer
,
strings
);
}
// Called by native to notify first Flutter frame rendered.
private
void
onFirstFrame
()
{
if
(
mFlutterView
==
null
)
return
;
mFlutterView
.
onFirstFrame
();
}
private
static
native
long
nativeAttach
(
FlutterNativeView
view
);
private
static
native
void
nativeDestroy
(
long
nativePlatformViewAndroid
);
private
static
native
void
nativeRunBundleAndSnapshot
(
long
nativePlatformViewAndroid
,
String
bundlePath
,
String
snapshotOverride
,
String
entrypoint
,
boolean
reuseRuntimeController
);
private
static
native
void
nativeRunBundleAndSource
(
long
nativePlatformViewAndroid
,
String
bundlePath
,
String
main
,
String
packages
);
private
static
native
String
nativeGetObservatoryUri
();
// Send an empty platform message to Dart.
private
static
native
void
nativeDispatchEmptyPlatformMessage
(
long
nativePlatformViewAndroid
,
String
channel
,
int
responseId
);
// Send a data-carrying platform message to Dart.
private
static
native
void
nativeDispatchPlatformMessage
(
long
nativePlatformViewAndroid
,
String
channel
,
ByteBuffer
message
,
int
position
,
int
responseId
);
// Send an empty response to a platform message received from Dart.
private
static
native
void
nativeInvokePlatformMessageEmptyResponseCallback
(
long
nativePlatformViewAndroid
,
int
responseId
);
// Send a data-carrying response to a platform message received from Dart.
private
static
native
void
nativeInvokePlatformMessageResponseCallback
(
long
nativePlatformViewAndroid
,
int
responseId
,
ByteBuffer
message
,
int
position
);
}
shell/platform/android/io/flutter/view/FlutterView.java
浏览文件 @
f5bdf9b0
...
...
@@ -84,7 +84,6 @@ public class FlutterView extends SurfaceView
private
static
final
String
ACTION_DISCOVER
=
"io.flutter.view.DISCOVER"
;
static
final
class
ViewportMetrics
{
float
devicePixelRatio
=
1.0f
;
int
physicalWidth
=
0
;
int
physicalHeight
=
0
;
...
...
@@ -95,7 +94,6 @@ public class FlutterView extends SurfaceView
}
private
final
TextInputPlugin
mTextInputPlugin
;
private
final
Map
<
String
,
BinaryMessageHandler
>
mMessageHandlers
;
private
final
SurfaceHolder
.
Callback
mSurfaceCallback
;
private
final
ViewportMetrics
mMetrics
;
private
final
AccessibilityManager
mAccessibilityManager
;
...
...
@@ -109,7 +107,7 @@ public class FlutterView extends SurfaceView
private
final
List
<
ActivityLifecycleListener
>
mActivityLifecycleListeners
;
private
final
List
<
FirstFrameListener
>
mFirstFrameListeners
;
private
final
AtomicLong
nextTextureId
=
new
AtomicLong
(
0L
);
private
long
mNativePlatform
View
;
private
FlutterNativeView
mNative
View
;
private
boolean
mIsSoftwareRenderingEnabled
=
false
;
// using the software renderer or not
public
FlutterView
(
Context
context
)
{
...
...
@@ -126,8 +124,7 @@ public class FlutterView extends SurfaceView
setFocusable
(
true
);
setFocusableInTouchMode
(
true
);
attach
();
assertAttached
();
mNativeView
=
new
FlutterNativeView
(
this
);
int
color
=
0xFF000000
;
TypedValue
typedValue
=
new
TypedValue
();
...
...
@@ -143,19 +140,19 @@ public class FlutterView extends SurfaceView
@Override
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
assertAttached
();
nativeSurfaceCreated
(
mNative
PlatformView
,
holder
.
getSurface
(),
backgroundColor
);
nativeSurfaceCreated
(
mNative
View
.
get
()
,
holder
.
getSurface
(),
backgroundColor
);
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
assertAttached
();
nativeSurfaceChanged
(
mNative
PlatformView
,
width
,
height
);
nativeSurfaceChanged
(
mNative
View
.
get
()
,
width
,
height
);
}
@Override
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
assertAttached
();
nativeSurfaceDestroyed
(
mNative
PlatformView
);
nativeSurfaceDestroyed
(
mNative
View
.
get
()
);
}
};
getHolder
().
addCallback
(
mSurfaceCallback
);
...
...
@@ -163,7 +160,6 @@ public class FlutterView extends SurfaceView
mAccessibilityManager
=
(
AccessibilityManager
)
getContext
()
.
getSystemService
(
Context
.
ACCESSIBILITY_SERVICE
);
mMessageHandlers
=
new
HashMap
<>();
mActivityLifecycleListeners
=
new
ArrayList
<>();
mFirstFrameListeners
=
new
ArrayList
<>();
...
...
@@ -323,8 +319,6 @@ public class FlutterView extends SurfaceView
}
getHolder
().
removeCallback
(
mSurfaceCallback
);
nativeDetach
(
mNativePlatformView
);
mNativePlatformView
=
0
;
}
@Override
...
...
@@ -496,7 +490,7 @@ public class FlutterView extends SurfaceView
}
assert
packet
.
position
()
%
(
kPointerDataFieldCount
*
kBytePerField
)
==
0
;
nativeDispatchPointerDataPacket
(
mNative
PlatformView
,
packet
,
packet
.
position
());
nativeDispatchPointerDataPacket
(
mNative
View
.
get
()
,
packet
,
packet
.
position
());
return
true
;
}
...
...
@@ -547,17 +541,12 @@ public class FlutterView extends SurfaceView
}
}
private
void
attach
()
{
mNativePlatformView
=
nativeAttach
(
this
);
}
private
boolean
isAttached
()
{
return
mNative
PlatformView
!=
0
;
return
mNative
View
.
isAttached
()
;
}
void
assertAttached
()
{
if
(!
isAttached
())
throw
new
AssertionError
(
"Platform view is not attached"
);
mNativeView
.
assertAttached
();
}
private
void
preRun
()
{
...
...
@@ -578,18 +567,16 @@ public class FlutterView extends SurfaceView
public
void
runFromBundle
(
String
bundlePath
,
String
snapshotOverride
,
String
entrypoint
,
boolean
reuseRuntimeController
)
{
assertAttached
();
preRun
();
nativeRunBundleAndSnapshot
(
mNativePlatformView
,
bundlePath
,
snapshotOverride
,
entrypoint
,
reuseRuntimeController
);
mNativeView
.
runFromBundle
(
bundlePath
,
snapshotOverride
,
entrypoint
,
reuseRuntimeController
);
postRun
();
}
private
void
runFromSource
(
final
String
assetsDirectory
,
final
String
main
,
final
String
packages
)
{
private
void
runFromSource
(
final
String
assetsDirectory
,
final
String
main
,
final
String
packages
)
{
Runnable
runnable
=
new
Runnable
()
{
public
void
run
()
{
assertAttached
();
preRun
();
nativeRunBundleAndSource
(
mNativePlatformView
,
assetsDirectory
,
main
,
packages
);
mNativeView
.
runFromSource
(
assetsDirectory
,
main
,
packages
);
postRun
();
synchronized
(
this
)
{
notify
();
...
...
@@ -616,15 +603,9 @@ public class FlutterView extends SurfaceView
*/
public
Bitmap
getBitmap
()
{
assertAttached
();
return
nativeGetBitmap
(
mNative
PlatformView
);
return
nativeGetBitmap
(
mNative
View
.
get
()
);
}
private
static
native
long
nativeAttach
(
FlutterView
view
);
private
static
native
String
nativeGetObservatoryUri
();
private
static
native
void
nativeDetach
(
long
nativePlatformViewAndroid
);
private
static
native
void
nativeSurfaceCreated
(
long
nativePlatformViewAndroid
,
Surface
surface
,
int
backgroundColor
);
...
...
@@ -635,17 +616,6 @@ public class FlutterView extends SurfaceView
private
static
native
void
nativeSurfaceDestroyed
(
long
nativePlatformViewAndroid
);
private
static
native
void
nativeRunBundleAndSnapshot
(
long
nativePlatformViewAndroid
,
String
bundlePath
,
String
snapshotOverride
,
String
entrypoint
,
boolean
reuseRuntimeController
);
private
static
native
void
nativeRunBundleAndSource
(
long
nativePlatformViewAndroid
,
String
bundlePath
,
String
main
,
String
packages
);
private
static
native
void
nativeSetViewportMetrics
(
long
nativePlatformViewAndroid
,
float
devicePixelRatio
,
int
physicalWidth
,
...
...
@@ -657,14 +627,6 @@ public class FlutterView extends SurfaceView
private
static
native
Bitmap
nativeGetBitmap
(
long
nativePlatformViewAndroid
);
// Send a data-carrying platform message to Dart.
private
static
native
void
nativeDispatchPlatformMessage
(
long
nativePlatformViewAndroid
,
String
channel
,
ByteBuffer
message
,
int
position
,
int
responseId
);
// Send an empty platform message to Dart.
private
static
native
void
nativeDispatchEmptyPlatformMessage
(
long
nativePlatformViewAndroid
,
String
channel
,
int
responseId
);
private
static
native
void
nativeDispatchPointerDataPacket
(
long
nativePlatformViewAndroid
,
ByteBuffer
buffer
,
int
position
);
...
...
@@ -674,14 +636,6 @@ public class FlutterView extends SurfaceView
private
static
native
void
nativeSetSemanticsEnabled
(
long
nativePlatformViewAndroid
,
boolean
enabled
);
// Send a data-carrying response to a platform message received from Dart.
private
static
native
void
nativeInvokePlatformMessageResponseCallback
(
long
nativePlatformViewAndroid
,
int
responseId
,
ByteBuffer
message
,
int
position
);
// Send an empty response to a platform message received from Dart.
private
static
native
void
nativeInvokePlatformMessageEmptyResponseCallback
(
long
nativePlatformViewAndroid
,
int
responseId
);
private
static
native
boolean
nativeGetIsSoftwareRenderingEnabled
();
private
static
native
void
nativeRegisterTexture
(
long
nativePlatformViewAndroid
,
long
textureId
,
SurfaceTexture
surfaceTexture
);
...
...
@@ -693,7 +647,7 @@ public class FlutterView extends SurfaceView
private
void
updateViewportMetrics
()
{
if
(!
isAttached
())
return
;
nativeSetViewportMetrics
(
mNative
PlatformView
,
nativeSetViewportMetrics
(
mNative
View
.
get
()
,
mMetrics
.
devicePixelRatio
,
mMetrics
.
physicalWidth
,
mMetrics
.
physicalHeight
,
...
...
@@ -708,60 +662,8 @@ public class FlutterView extends SurfaceView
VsyncWaiter
.
refreshPeriodNanos
=
(
long
)(
1000000000.0
/
fps
);
}
// Called by native to send us a platform message.
private
void
handlePlatformMessage
(
final
String
channel
,
byte
[]
message
,
final
int
replyId
)
{
assertAttached
();
BinaryMessageHandler
handler
=
mMessageHandlers
.
get
(
channel
);
if
(
handler
!=
null
)
{
try
{
final
ByteBuffer
buffer
=
(
message
==
null
?
null
:
ByteBuffer
.
wrap
(
message
));
handler
.
onMessage
(
buffer
,
new
BinaryReply
()
{
private
final
AtomicBoolean
done
=
new
AtomicBoolean
(
false
);
@Override
public
void
reply
(
ByteBuffer
reply
)
{
if
(!
isAttached
())
{
Log
.
d
(
TAG
,
"handlePlatformMessage replying to a detached view, channel="
+
channel
);
return
;
}
if
(
done
.
getAndSet
(
true
))
{
throw
new
IllegalStateException
(
"Reply already submitted"
);
}
if
(
reply
==
null
)
{
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
else
{
nativeInvokePlatformMessageResponseCallback
(
mNativePlatformView
,
replyId
,
reply
,
reply
.
position
());
}
}
});
}
catch
(
Exception
ex
)
{
Log
.
e
(
TAG
,
"Uncaught exception in binary message listener"
,
ex
);
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
return
;
}
nativeInvokePlatformMessageEmptyResponseCallback
(
mNativePlatformView
,
replyId
);
}
private
int
mNextReplyId
=
1
;
private
final
Map
<
Integer
,
BinaryReply
>
mPendingReplies
=
new
HashMap
<>();
// Called by native to respond to a platform message that we sent.
private
void
handlePlatformMessageResponse
(
int
replyId
,
byte
[]
reply
)
{
BinaryReply
callback
=
mPendingReplies
.
remove
(
replyId
);
if
(
callback
!=
null
)
{
try
{
callback
.
reply
(
reply
==
null
?
null
:
ByteBuffer
.
wrap
(
reply
));
}
catch
(
Exception
ex
)
{
Log
.
e
(
TAG
,
"Uncaught exception in binary message reply handler"
,
ex
);
}
}
}
// Called by native to update the semantics/accessibility tree.
p
rivate
void
updateSemantics
(
ByteBuffer
buffer
,
String
[]
strings
)
{
p
ublic
void
updateSemantics
(
ByteBuffer
buffer
,
String
[]
strings
)
{
try
{
if
(
mAccessibilityNodeProvider
!=
null
)
{
buffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
...
...
@@ -773,7 +675,7 @@ public class FlutterView extends SurfaceView
}
// Called by native to notify first Flutter frame rendered.
p
rivate
void
onFirstFrame
()
{
p
ublic
void
onFirstFrame
()
{
for
(
FirstFrameListener
listener
:
mFirstFrameListeners
)
{
listener
.
onFirstFrame
();
}
...
...
@@ -788,7 +690,7 @@ public class FlutterView extends SurfaceView
protected
void
dispatchSemanticsAction
(
int
id
,
int
action
)
{
if
(!
isAttached
())
return
;
nativeDispatchSemanticsAction
(
mNative
PlatformView
,
id
,
action
);
nativeDispatchSemanticsAction
(
mNative
View
.
get
()
,
id
,
action
);
}
@Override
...
...
@@ -872,7 +774,7 @@ public class FlutterView extends SurfaceView
mAccessibilityEnabled
=
true
;
if
(
mAccessibilityNodeProvider
==
null
)
{
mAccessibilityNodeProvider
=
new
AccessibilityBridge
(
this
);
nativeSetSemanticsEnabled
(
mNative
PlatformView
,
true
);
nativeSetSemanticsEnabled
(
mNative
View
.
get
()
,
true
);
}
mAccessibilityNodeProvider
.
setAccessibilityEnabled
(
true
);
}
...
...
@@ -901,36 +803,17 @@ public class FlutterView extends SurfaceView
@Override
public
void
send
(
String
channel
,
ByteBuffer
message
)
{
send
(
channel
,
message
,
null
);
mNativeView
.
send
(
channel
,
message
);
}
@Override
public
void
send
(
String
channel
,
ByteBuffer
message
,
BinaryReply
callback
)
{
if
(!
isAttached
())
{
Log
.
d
(
TAG
,
"FlutterView.send called on a detached view, channel="
+
channel
);
return
;
}
int
replyId
=
0
;
if
(
callback
!=
null
)
{
replyId
=
mNextReplyId
++;
mPendingReplies
.
put
(
replyId
,
callback
);
}
if
(
message
==
null
)
{
nativeDispatchEmptyPlatformMessage
(
mNativePlatformView
,
channel
,
replyId
);
}
else
{
nativeDispatchPlatformMessage
(
mNativePlatformView
,
channel
,
message
,
message
.
position
(),
replyId
);
}
mNativeView
.
send
(
channel
,
message
,
callback
);
}
@Override
public
void
setMessageHandler
(
String
channel
,
BinaryMessageHandler
handler
)
{
if
(
handler
==
null
)
{
mMessageHandlers
.
remove
(
channel
);
}
else
{
mMessageHandlers
.
put
(
channel
,
handler
);
}
mNativeView
.
setMessageHandler
(
channel
,
handler
);
}
/**
...
...
@@ -944,7 +827,7 @@ public class FlutterView extends SurfaceView
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
URI
observatoryUri
=
URI
.
create
(
nativeG
etObservatoryUri
());
URI
observatoryUri
=
URI
.
create
(
FlutterNativeView
.
g
etObservatoryUri
());
JSONObject
discover
=
new
JSONObject
();
try
{
discover
.
put
(
"id"
,
getContext
().
getPackageName
());
...
...
@@ -968,7 +851,7 @@ public class FlutterView extends SurfaceView
surfaceTexture
.
detachFromGLContext
();
final
SurfaceTextureRegistryEntry
entry
=
new
SurfaceTextureRegistryEntry
(
nextTextureId
.
getAndIncrement
(),
surfaceTexture
);
nativeRegisterTexture
(
mNative
PlatformView
,
entry
.
id
(),
surfaceTexture
);
nativeRegisterTexture
(
mNative
View
.
get
()
,
entry
.
id
(),
surfaceTexture
);
return
entry
;
}
...
...
@@ -983,7 +866,7 @@ public class FlutterView extends SurfaceView
this
.
surfaceTexture
.
setOnFrameAvailableListener
(
new
SurfaceTexture
.
OnFrameAvailableListener
()
{
@Override
public
void
onFrameAvailable
(
SurfaceTexture
texture
)
{
nativeMarkTextureFrameAvailable
(
mNative
PlatformView
,
SurfaceTextureRegistryEntry
.
this
.
id
);
nativeMarkTextureFrameAvailable
(
mNative
View
.
get
()
,
SurfaceTextureRegistryEntry
.
this
.
id
);
}
});
}
...
...
@@ -1004,7 +887,7 @@ public class FlutterView extends SurfaceView
return
;
}
released
=
true
;
nativeUnregisterTexture
(
mNative
PlatformView
,
id
);
nativeUnregisterTexture
(
mNative
View
.
get
()
,
id
);
surfaceTexture
.
release
();
}
}
...
...
shell/platform/android/platform_view_android_jni.cc
浏览文件 @
f5bdf9b0
...
...
@@ -19,6 +19,8 @@
namespace
shell
{
static
fml
::
jni
::
ScopedJavaGlobalRef
<
jclass
>*
g_flutter_view_class
=
nullptr
;
static
fml
::
jni
::
ScopedJavaGlobalRef
<
jclass
>*
g_flutter_native_view_class
=
nullptr
;
static
fml
::
jni
::
ScopedJavaGlobalRef
<
jclass
>*
g_surface_texture_class
=
nullptr
;
// Called By Native
...
...
@@ -92,7 +94,7 @@ static jlong Attach(JNIEnv* env, jclass clazz, jobject flutterView) {
return
reinterpret_cast
<
jlong
>
(
storage
);
}
static
void
De
tach
(
JNIEnv
*
env
,
jobject
jcaller
,
jlong
platform_view
)
{
static
void
De
stroy
(
JNIEnv
*
env
,
jobject
jcaller
,
jlong
platform_view
)
{
PLATFORM_VIEW
->
Detach
();
delete
&
PLATFORM_VIEW
;
}
...
...
@@ -276,28 +278,72 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return
false
;
}
g_flutter_native_view_class
=
new
fml
::
jni
::
ScopedJavaGlobalRef
<
jclass
>
(
env
,
env
->
FindClass
(
"io/flutter/view/FlutterNativeView"
));
if
(
g_flutter_native_view_class
->
is_null
())
{
return
false
;
}
g_surface_texture_class
=
new
fml
::
jni
::
ScopedJavaGlobalRef
<
jclass
>
(
env
,
env
->
FindClass
(
"android/graphics/SurfaceTexture"
));
if
(
g_surface_texture_class
->
is_null
())
{
return
false
;
}
static
const
JNINativeMethod
methods
[]
=
{
static
const
JNINativeMethod
native_view_
methods
[]
=
{
{
.
name
=
"nativeAttach"
,
.
signature
=
"(Lio/flutter/view/FlutterView;)J"
,
.
signature
=
"(Lio/flutter/view/Flutter
Native
View;)J"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
Attach
),
},
{
.
name
=
"nativeDe
tach
"
,
.
name
=
"nativeDe
stroy
"
,
.
signature
=
"(J)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
Detach
),
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
Destroy
),
},
{
.
name
=
"nativeRunBundleAndSnapshot"
,
.
signature
=
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
RunBundleAndSnapshot
),
},
{
.
name
=
"nativeRunBundleAndSource"
,
.
signature
=
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
RunBundleAndSource
),
},
{
.
name
=
"nativeGetObservatoryUri"
,
.
signature
=
"()Ljava/lang/String;"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
GetObservatoryUri
),
},
{
.
name
=
"nativeDispatchEmptyPlatformMessage"
,
.
signature
=
"(JLjava/lang/String;I)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
DispatchEmptyPlatformMessage
),
},
{
.
name
=
"nativeDispatchPlatformMessage"
,
.
signature
=
"(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
DispatchPlatformMessage
),
},
{
.
name
=
"nativeInvokePlatformMessageResponseCallback"
,
.
signature
=
"(JILjava/nio/ByteBuffer;I)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
InvokePlatformMessageResponseCallback
),
},
{
.
name
=
"nativeInvokePlatformMessageEmptyResponseCallback"
,
.
signature
=
"(JI)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
InvokePlatformMessageEmptyResponseCallback
),
},
};
static
const
JNINativeMethod
view_methods
[]
=
{
{
.
name
=
"nativeSurfaceCreated"
,
.
signature
=
"(JLandroid/view/Surface;I)V"
,
...
...
@@ -313,18 +359,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.
signature
=
"(J)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
SurfaceDestroyed
),
},
{
.
name
=
"nativeRunBundleAndSnapshot"
,
.
signature
=
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
RunBundleAndSnapshot
),
},
{
.
name
=
"nativeRunBundleAndSource"
,
.
signature
=
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
RunBundleAndSource
),
},
{
.
name
=
"nativeSetViewportMetrics"
,
.
signature
=
"(JFIIIIII)V"
,
...
...
@@ -335,17 +369,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.
signature
=
"(J)Landroid/graphics/Bitmap;"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
GetBitmap
),
},
{
.
name
=
"nativeDispatchPlatformMessage"
,
.
signature
=
"(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
DispatchPlatformMessage
),
},
{
.
name
=
"nativeDispatchEmptyPlatformMessage"
,
.
signature
=
"(JLjava/lang/String;I)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
DispatchEmptyPlatformMessage
),
},
{
.
name
=
"nativeDispatchPointerDataPacket"
,
.
signature
=
"(JLjava/nio/ByteBuffer;I)V"
,
...
...
@@ -361,18 +384,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
.
signature
=
"(JZ)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
SetSemanticsEnabled
),
},
{
.
name
=
"nativeInvokePlatformMessageResponseCallback"
,
.
signature
=
"(JILjava/nio/ByteBuffer;I)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
InvokePlatformMessageResponseCallback
),
},
{
.
name
=
"nativeInvokePlatformMessageEmptyResponseCallback"
,
.
signature
=
"(JI)V"
,
.
fnPtr
=
reinterpret_cast
<
void
*>
(
&
shell
::
InvokePlatformMessageEmptyResponseCallback
),
},
{
.
name
=
"nativeGetIsSoftwareRenderingEnabled"
,
.
signature
=
"()Z"
,
...
...
@@ -395,36 +406,43 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
},
};
if
(
env
->
RegisterNatives
(
g_flutter_view_class
->
obj
(),
methods
,
arraysize
(
methods
))
!=
0
)
{
if
(
env
->
RegisterNatives
(
g_flutter_native_view_class
->
obj
(),
native_view_methods
,
arraysize
(
native_view_methods
))
!=
0
)
{
return
false
;
}
if
(
env
->
RegisterNatives
(
g_flutter_view_class
->
obj
(),
view_methods
,
arraysize
(
view_methods
))
!=
0
)
{
return
false
;
}
g_handle_platform_message_method
=
env
->
GetMethodID
(
g_flutter_
view_class
->
obj
(),
"handlePlatformMessage"
,
"(Ljava/lang/String;[BI)V"
);
env
->
GetMethodID
(
g_flutter_
native_view_class
->
obj
()
,
"
handlePlatformMessage"
,
"
(Ljava/lang/String;[BI)V"
);
if
(
g_handle_platform_message_method
==
nullptr
)
{
return
false
;
}
g_handle_platform_message_response_method
=
env
->
GetMethodID
(
g_flutter_view_class
->
obj
(),
"handlePlatformMessageResponse"
,
"(I[B)V"
);
g_handle_platform_message_response_method
=
env
->
GetMethodID
(
g_flutter_native_view_class
->
obj
(),
"handlePlatformMessageResponse"
,
"(I[B)V"
);
if
(
g_handle_platform_message_response_method
==
nullptr
)
{
return
false
;
}
g_update_semantics_method
=
env
->
GetMethodID
(
g_flutter_view_class
->
obj
(),
"updateSemantics"
,
env
->
GetMethodID
(
g_flutter_
native_
view_class
->
obj
(),
"updateSemantics"
,
"(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V"
);
if
(
g_update_semantics_method
==
nullptr
)
{
return
false
;
}
g_on_first_frame_method
=
env
->
GetMethodID
(
g_flutter_view_class
->
obj
(),
"onFirstFrame"
,
"()V"
);
g_on_first_frame_method
=
env
->
GetMethodID
(
g_flutter_native_view_class
->
obj
(),
"onFirstFrame"
,
"()V"
);
if
(
g_on_first_frame_method
==
nullptr
)
{
return
false
;
...
...
travis/licenses_golden/licenses_flutter
浏览文件 @
f5bdf9b0
...
...
@@ -1174,6 +1174,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/StandardM
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/StringCodec.java
FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/view/TextureRegistry.java
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.cc
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.h
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录