mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-29 14:10:47 +08:00
feat(renderer): modify the creation TDFEngine process to synchronous
This commit is contained in:
committed by
hippy-actions[bot]
parent
b14679f5b2
commit
bf33624494
@@ -18,41 +18,121 @@ package com.tencent.renderer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Application.ActivityLifecycleCallbacks;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.tencent.tdf.TDFEngine;
|
||||
import com.tencent.tdf.TDFEngineConfig;
|
||||
import com.tencent.tdf.filepicker.FilePickerDelegate;
|
||||
import com.tencent.tdf.view.TDFViewWrapper;
|
||||
import com.tencent.tdf.view.TDFOutputView;
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
public class TDFHippyRootView extends TDFViewWrapper {
|
||||
IEngineCallback mEngineCallback;
|
||||
public class TDFHippyRootView extends FrameLayout {
|
||||
|
||||
public TDFHippyRootView(Activity attachActivity) {
|
||||
super(attachActivity);
|
||||
private final Context mContext;
|
||||
private Activity mAttachActivity;
|
||||
private ActivityLifecycleCallbacks mActivityLifecycleCallbacks;
|
||||
private TDFRenderEngine mTDFEngine;
|
||||
private TDFOutputView mTDFView;
|
||||
|
||||
public TDFHippyRootView(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mTDFEngine = setupTDFEngine();
|
||||
mTDFView = createTDFView(mTDFEngine);
|
||||
if (mContext instanceof Activity) {
|
||||
addActivityLifecycleObserver((Activity) mContext);
|
||||
}
|
||||
}
|
||||
|
||||
public void setEngineCallback(IEngineCallback engineCallback) {
|
||||
mEngineCallback = engineCallback;
|
||||
public TDFRenderEngine getTDFEngine() {
|
||||
return mTDFEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TDFEngine createEngine() {
|
||||
@Override protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (mTDFEngine != null) {
|
||||
mTDFEngine.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
destroy();
|
||||
}
|
||||
|
||||
private TDFRenderEngine setupTDFEngine() {
|
||||
TDFEngineConfig tdfEngineConfig = new TDFEngineConfig();
|
||||
tdfEngineConfig.setViewMode(TDFEngineConfig.TDFViewMode.TextureView);
|
||||
TDFRenderEngine engine = new TDFRenderEngine(getActivity(), tdfEngineConfig);
|
||||
if (mEngineCallback != null) {
|
||||
mEngineCallback.onCreated(engine);
|
||||
}
|
||||
return engine;
|
||||
return new TDFRenderEngine(mContext, tdfEngineConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify TDF Render
|
||||
*/
|
||||
public interface IEngineCallback {
|
||||
void onCreated(TDFRenderEngine engine);
|
||||
private TDFOutputView createTDFView(TDFEngine engine) {
|
||||
TDFOutputView tdfView = null;
|
||||
if (engine != null) {
|
||||
tdfView = engine.getTDFView();
|
||||
LayoutParams layoutParams = new LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT);
|
||||
addView(tdfView, layoutParams);
|
||||
}
|
||||
return tdfView;
|
||||
}
|
||||
|
||||
private void destroy() {
|
||||
if (mTDFEngine != null) {
|
||||
mTDFEngine.onDestroy();
|
||||
}
|
||||
mTDFEngine = null;
|
||||
if (mAttachActivity != null) {
|
||||
mAttachActivity.getApplication()
|
||||
.unregisterActivityLifecycleCallbacks(mActivityLifecycleCallbacks);
|
||||
}
|
||||
}
|
||||
|
||||
private void addActivityLifecycleObserver(Activity activity) {
|
||||
mAttachActivity = activity;
|
||||
mActivityLifecycleCallbacks = new ActivityLifecycleCallbacks() {
|
||||
@Override public void onActivityCreated(@NonNull Activity activity,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onActivityStarted(@NonNull Activity activity) {
|
||||
}
|
||||
|
||||
@Override public void onActivityResumed(@NonNull Activity activity) {
|
||||
if (activity == mAttachActivity && mTDFEngine != null) {
|
||||
mTDFEngine.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onActivityPaused(@NonNull Activity activity) {
|
||||
if (activity == mAttachActivity && mTDFEngine != null) {
|
||||
mTDFEngine.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onActivityStopped(@NonNull Activity activity) {
|
||||
if (activity == mAttachActivity && mTDFEngine != null) {
|
||||
mTDFEngine.onStop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onActivitySaveInstanceState(@NonNull Activity activity,
|
||||
@NonNull Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
if (activity == mAttachActivity) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
mAttachActivity.getApplication()
|
||||
.registerActivityLifecycleCallbacks(mActivityLifecycleCallbacks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,17 +85,12 @@ public class TDFRenderer extends Renderer implements RenderProxy, TDFRenderEngin
|
||||
if (!(context instanceof Activity)) {
|
||||
throw new RuntimeException("Unsupported Host");
|
||||
}
|
||||
|
||||
mRootView = new TDFHippyRootView((Activity) context);
|
||||
// When TDFHippyRootView's onAttachedToWindow is called, com.tencent.tdf.TDFEngine will be created.
|
||||
// So, set the creation callback here.
|
||||
mRootView.setEngineCallback(engine -> {
|
||||
// Notify TDF Render in Native(C++) size to bind with TDF Shell, this is the key process for TDF Render.
|
||||
// At this time point, TDF Core's Shell is created but not started.
|
||||
registerTDFEngine(mInstanceId, engine.getJNI().getnativeEngine(), mRootViewId);
|
||||
engine.registerLifecycleListener(TDFRenderer.this);
|
||||
registerControllers(mRootViewId, mControllers, mRootView, TDFRenderer.this, engine);
|
||||
});
|
||||
mRootView = new TDFHippyRootView(context);
|
||||
TDFRenderEngine engine = mRootView.getTDFEngine();
|
||||
registerTDFEngine(mInstanceId, engine.getJNI().getnativeEngine(), mRootViewId);
|
||||
LogUtils.d(TAG, "onTDFEngineCreate: " + engine.getJNI().getnativeEngine());
|
||||
engine.registerLifecycleListener(TDFRenderer.this);
|
||||
registerControllers(mRootViewId, mControllers, mRootView, TDFRenderer.this, engine);
|
||||
mRootView.setId(mRootViewId);
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user