Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/runtime/js/bindings/lynx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ std::vector<PropNameID> LynxProxy::getPropertyNames(Runtime &rt) {
"createElement",
"fetchDynamicComponent",
"reload",
"startRecording",
"stopRecording",
"QueryComponent",
"addFont",
tasm::kGetTextInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.lynx.tasm.performance.longtasktiming.LynxLongTaskMonitor;
import com.lynx.tasm.performance.timing.TimingConstants;
import com.lynx.tasm.provider.*;
import com.lynx.tasm.recording.LynxFrameRecorder;
import com.lynx.tasm.resourceprovider.LynxResourceCallback;
import com.lynx.tasm.resourceprovider.LynxResourceRequest;
import com.lynx.tasm.resourceprovider.LynxResourceResponse;
Expand Down Expand Up @@ -2362,6 +2363,9 @@ public void destroy() {
// the front end can receive events.
if (mLynxContext != null) {
mLynxContext.clearExposure();
int instanceId = mLynxContext.getInstanceId();
LynxFrameRecorder.inst().stopRecording(instanceId);
LynxFrameRecorder.inst().clearFrameCallback(instanceId);
}
recycleUpdatedDataList();
recycleGlobalPropsSafely();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.lynx.tasm.provider.LynxResourceProvider;
import com.lynx.tasm.provider.LynxResourceRequest;
import com.lynx.tasm.provider.LynxResourceResponse;
import com.lynx.tasm.recording.LynxFrameRecorder;
import com.lynx.tasm.theme.LynxTheme;
import com.lynx.tasm.utils.CallStackUtil;
import com.lynx.tasm.utils.UIThreadUtils;
Expand Down Expand Up @@ -564,10 +565,22 @@ public int getInstanceId() {
}

@CalledByNative
private void startRecording(ReadableMap params) {}
private void startRecording(ReadableMap params) {
int instanceId = getInstanceId();
if (instanceId == LynxContext.INSTANCE_ID_DEFAULT) {
return;
}
LynxFrameRecorder.inst().startRecording(instanceId);
}

@CalledByNative
private void stopRecording(ReadableMap params) {}
private void stopRecording(ReadableMap params) {
int instanceId = getInstanceId();
if (instanceId == LynxContext.INSTANCE_ID_DEFAULT) {
return;
}
LynxFrameRecorder.inst().stopRecording(instanceId);
}

@CalledByNative
private void onTemplateBundleReady(TemplateBundle bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.lynx.tasm.loader.LynxFontFaceLoader;
import com.lynx.tasm.performance.PerformanceController;
import com.lynx.tasm.provider.LynxProviderRegistry;
import com.lynx.tasm.recording.LynxFrameRecorder;
import com.lynx.tasm.resourceprovider.generic.LynxGenericResourceFetcher;
import com.lynx.tasm.resourceprovider.media.LynxMediaResourceFetcher;
import com.lynx.tasm.resourceprovider.template.LynxTemplateResourceFetcher;
Expand Down Expand Up @@ -171,6 +172,7 @@ public abstract class LynxContext extends LynxBaseContext implements ExceptionHa
private String tapSlop = TouchEventDispatcher.mTapSlopDefault;

private LynxFrameViewProvider mLynxFrameViewProvider;
private final LynxFrameRecorder.FrameCallback mFrameCallback = new ContextFrameCallback(this);

public LynxContext(Context base, DisplayMetrics screenMetrics) {
super(base);
Expand Down Expand Up @@ -611,6 +613,22 @@ public void run() {
});
}

private void notifyLynxFrame(@NonNull JSONObject frame) {
final WeakReference<LynxViewClientV2> weakLynxViewClientV2 = mLynxViewClientV2;
if (weakLynxViewClientV2 == null) {
return;
}
LynxEventReporter.runOnReportThread(new Runnable() {
@Override
public void run() {
LynxViewClientV2 lynxViewClientV2 = weakLynxViewClientV2.get();
if (lynxViewClientV2 != null) {
lynxViewClientV2.onLynxFrame(frame);
}
}
});
}

/**
* use {@link #setUIBodyView(UIBodyView)} instead
*/
Expand Down Expand Up @@ -1483,7 +1501,35 @@ public int getInstanceId() {

@RestrictTo(RestrictTo.Scope.LIBRARY)
public void setInstanceId(int instanceId) {
if (mInstanceId != INSTANCE_ID_DEFAULT && mInstanceId != instanceId) {
LynxFrameRecorder.inst().stopRecording(mInstanceId);
LynxFrameRecorder.inst().clearFrameCallback(mInstanceId);
}
this.mInstanceId = instanceId;
syncFrameRecorderCallback();
}

private void syncFrameRecorderCallback() {
if (mInstanceId == INSTANCE_ID_DEFAULT) {
return;
}
LynxFrameRecorder.inst().setFrameCallback(mInstanceId, mFrameCallback);
}

private static final class ContextFrameCallback implements LynxFrameRecorder.FrameCallback {
private final WeakReference<LynxContext> mContextRef;

private ContextFrameCallback(LynxContext context) {
mContextRef = new WeakReference<>(context);
}

@Override
public void onLynxFrame(JSONObject frame) {
LynxContext context = mContextRef.get();
if (context != null) {
context.notifyLynxFrame(frame);
}
}
}

@RestrictTo(RestrictTo.Scope.LIBRARY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.lynx.tasm.event.EventsListener;
import com.lynx.tasm.gesture.detector.GestureDetector;
import com.lynx.tasm.performance.PerformanceController;
import com.lynx.tasm.recording.LynxFrameRecorder;
import com.lynx.tasm.service.ILynxTextService.Page;
import com.lynx.tasm.utils.UIThreadUtils;
import java.util.Iterator;
Expand Down Expand Up @@ -115,6 +116,65 @@ public PaintingContext(LynxUIOwner uiOwner, int threadStrategy) {
this, mTextLayout, mTextra, threadStrategy, mUIOwner.isContextFree());
}

private int getInstanceId() {
LynxContext context = mUIOwner != null ? mUIOwner.getContext() : null;
return context != null ? context.getInstanceId() : LynxContext.INSTANCE_ID_DEFAULT;
}

private boolean isRecordingEnabled() {
return LynxFrameRecorder.inst().isRecordingEnabled(getInstanceId());
}

private void recordCreateNode(int sign, String tagName, PropBundle bundle,
ReadableMapBuffer initialStyles, boolean isFlatten, int nodeIndex) {
if (!isRecordingEnabled()) {
return;
}
LynxFrameRecorder.inst().recordCreateNode(
getInstanceId(), sign, tagName, bundle, initialStyles, isFlatten, nodeIndex);
}

private void recordNodeRelation(int eventType, int parentSign, int childSign, Integer index) {
if (!isRecordingEnabled()) {
return;
}
LynxFrameRecorder.inst().recordNodeRelation(
getInstanceId(), eventType, parentSign, childSign, index);
}

private void recordUpdateProps(
int sign, boolean tendToFlatten, PropBundle bundle, ReadableMapBuffer styles) {
if (!isRecordingEnabled()) {
return;
}
LynxFrameRecorder.inst().recordUpdateProps(
getInstanceId(), sign, tendToFlatten, bundle, styles);
}

private void recordUpdateLayout(int sign, float x, float y, float width, float height,
float paddingLeft, float paddingTop, float paddingRight, float paddingBottom,
float marginLeft, float marginTop, float marginRight, float marginBottom,
float borderLeftWidth, float borderTopWidth, float borderRightWidth, float borderBottomWidth,
Rect bounds, float[] sticky, float maxHeight, int nodeIndex) {
if (!isRecordingEnabled()) {
return;
}
LynxFrameRecorder.inst().recordUpdateLayout(getInstanceId(), sign, x, y, width, height,
new float[] {paddingLeft, paddingTop, paddingRight, paddingBottom},
new float[] {marginLeft, marginTop, marginRight, marginBottom},
new float[] {borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth},
bounds != null ? new float[] {bounds.left, bounds.top, bounds.right, bounds.bottom} : null,
sticky, maxHeight, nodeIndex);
}

private void recordInvoke(
int sign, String method, ReadableMap params, long context, int callback) {
if (!isRecordingEnabled()) {
return;
}
LynxFrameRecorder.inst().recordInvoke(getInstanceId(), sign, method, params, context, callback);
}

// this func will be execed on main thread.
@Override
public void destroy() {
Expand Down Expand Up @@ -192,7 +252,7 @@ public void updateLayout(int sign, float x, float y, float width, float height,
float marginRight, float marginBottom, float borderLeftWidth, float borderTopWidth,
float borderRightWidth, float borderBottomWidth, float[] bounds, float[] sticky,
float maxHeight, int nodeIndex) {
mUIOwner.updateLayout(sign, (int) x, (int) y, (int) width, (int) height, (int) paddingLeft,
setLayoutData(sign, (int) x, (int) y, (int) width, (int) height, (int) paddingLeft,
(int) paddingTop, (int) paddingRight, (int) paddingBottom, (int) marginLeft,
(int) marginTop, (int) marginRight, (int) marginBottom, (int) borderLeftWidth,
(int) borderTopWidth, (int) borderRightWidth, (int) borderBottomWidth,
Expand All @@ -213,6 +273,7 @@ public void updateLayout(int sign, float x, float y, float width, float height,
@CalledByNative
public void updateProps(
int sign, boolean tendToFlatten, PropBundle bundle, ReadableMapBuffer styles) {
recordUpdateProps(sign, tendToFlatten, bundle, styles);
// Convert event listeners and gesture detectors to appropriate data structures.
ReadableMap props = bundle != null ? bundle.getProps() : null;
Map<String, EventsListener> listeners =
Expand All @@ -235,6 +296,7 @@ public Object createNode(final int sign, String tagName, final PropBundle bundle
ReadableMap initialProps = bundle != null ? bundle.getProps() : null;
ReadableArray eventListeners = bundle != null ? bundle.getEventHandlers() : null;
ReadableArray gestureDetectors = bundle != null ? bundle.getGestures() : null;
recordCreateNode(sign, finalTagName, bundle, initialStyles, isFlatten, nodeIndex);
final Future<Runnable> future = createNodeAsync(sign, finalTagName, initialProps,
initialStyles, eventListeners, isFlatten, nodeIndex, gestureDetectors);
return new Runnable() {
Expand Down Expand Up @@ -290,6 +352,7 @@ private boolean needProcessDirection(String tagName) {
@CalledByNative
public void createPaintingNodeSync(int sign, String tagName, PropBundle bundle,
ReadableMapBuffer initialStyles, boolean isFlatten, int nodeIndex) {
recordCreateNode(sign, tagName, bundle, initialStyles, isFlatten, nodeIndex);
ReadableMap initialProps = bundle != null ? bundle.getProps() : null;
ReadableArray eventListeners = bundle != null ? bundle.getEventHandlers() : null;
ReadableArray gestureDetectors = bundle != null ? bundle.getGestures() : null;
Expand Down Expand Up @@ -318,6 +381,7 @@ public Future<Runnable> createNodeAsync(int sign, String tagName, ReadableMap in
@CalledByNative
public Object createPaintingNodeAsync(int sign, String tagName, PropBundle bundle,
ReadableMapBuffer initialStyles, boolean isFlatten, int nodeIndex) {
recordCreateNode(sign, tagName, bundle, initialStyles, isFlatten, nodeIndex);
ReadableMap initialProps = bundle != null ? bundle.getProps() : null;
ReadableArray eventListeners = bundle != null ? bundle.getEventHandlers() : null;
ReadableArray gestureDetectors = bundle != null ? bundle.getGestures() : null;
Expand Down Expand Up @@ -384,16 +448,19 @@ private boolean executeFuture(Future<Runnable> future, int sign, String tagName,

@CalledByNative
public void insertNode(int parentSign, int childSign, int index) {
recordNodeRelation(LynxFrameRecorder.EVENT_LYNX_UI_INSERT_NODE, parentSign, childSign, index);
mUIOwner.insert(parentSign, childSign, index);
}

@CalledByNative
public void removeNode(int parentSign, int childSign) {
recordNodeRelation(LynxFrameRecorder.EVENT_LYNX_UI_REMOVE_NODE, parentSign, childSign, null);
mUIOwner.remove(parentSign, childSign);
}

@CalledByNative
public void destroyNode(int parentSign, int childSign) {
recordNodeRelation(LynxFrameRecorder.EVENT_LYNX_UI_DESTROY_NODE, parentSign, childSign, null);
mUIOwner.destroy(parentSign, childSign);
}

Expand Down Expand Up @@ -697,6 +764,7 @@ private float[] getScrollDefaultResult(float width, float height) {
@CalledByNative
public void invoke(
int sign, String method, ReadableMap params, final long context, final int callback) {
recordInvoke(sign, method, params, context, callback);
UIThreadUtils.runOnUiThreadImmediately(new Runnable() {
private void cb(Object... args) {
if (mDestroyed || mUIOwner.getContext() == null) {
Expand All @@ -723,8 +791,11 @@ public void run() {
private void setLayoutData(int sign, int x, int y, int width, int height, int paddingLeft,
int paddingTop, int paddingRight, int paddingBottom, int marginLeft, int marginTop,
int marginRight, int marginBottom, int borderLeftWidth, int borderTopWidth,
int borderRightWidth, int borderBottomWidth, Rect bounds, float[] sticky, int maxHeight,
int borderRightWidth, int borderBottomWidth, Rect bounds, float[] sticky, float maxHeight,
int nodeIndex) {
recordUpdateLayout(sign, x, y, width, height, paddingLeft, paddingTop, paddingRight,
paddingBottom, marginLeft, marginTop, marginRight, marginBottom, borderLeftWidth,
borderTopWidth, borderRightWidth, borderBottomWidth, bounds, sticky, maxHeight, nodeIndex);
mUIOwner.updateLayout(sign, x, y, width, height, paddingLeft, paddingTop, paddingRight,
paddingBottom, marginLeft, marginTop, marginRight, marginBottom, borderLeftWidth,
borderTopWidth, borderRightWidth, borderBottomWidth, bounds, sticky, maxHeight, nodeIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
import com.lynx.tasm.event.LynxTouchEvent.Point;
import com.lynx.tasm.gesture.arena.GestureArenaManager;
import com.lynx.tasm.gesture.handler.GestureConstants;
import com.lynx.tasm.recording.LynxFrameRecorder;
import com.lynx.tasm.utils.PixelUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -168,6 +170,40 @@ public TouchEventDispatcher(@NonNull LynxUIOwner owner) {
mGestureArenaManager = owner.getGestureArenaManager();
}

private int getInstanceId() {
LynxContext context = mUIOwner != null ? mUIOwner.getContext() : null;
return context != null ? context.getInstanceId() : LynxContext.INSTANCE_ID_DEFAULT;
}

private void recordTouchFrame(String eventName, MotionEvent ev) {
int instanceId = getInstanceId();
if (!LynxFrameRecorder.inst().isRecordingEnabled(instanceId)) {
return;
}
int eventType;
if (EVENT_TOUCH_START.equals(eventName)) {
eventType = LynxFrameRecorder.EVENT_LYNX_TOUCH_START;
} else if (EVENT_TOUCH_MOVE.equals(eventName)) {
eventType = LynxFrameRecorder.EVENT_LYNX_TOUCH_MOVE;
} else if (EVENT_TOUCH_END.equals(eventName)) {
eventType = LynxFrameRecorder.EVENT_LYNX_TOUCH_END;
} else if (EVENT_TOUCH_CANCEL.equals(eventName)) {
eventType = LynxFrameRecorder.EVENT_LYNX_TOUCH_CANCEL;
} else {
return;
}

List<LynxFrameRecorder.TouchPointPayload> points = new ArrayList<>(ev.getPointerCount());
for (int i = 0; i < ev.getPointerCount(); i++) {
EventTargetDetail detail = mActiveUIMap.get(ev.getPointerId(i));
EventTarget target = detail != null ? detail.getUI() : mActiveUI;
Integer targetId = target != null ? target.getSign() : null;
points.add(new LynxFrameRecorder.TouchPointPayload(
ev.getX(i), ev.getY(i), ev.getPointerId(i), targetId));
}
LynxFrameRecorder.inst().recordTouch(instanceId, eventType, points, ev.getEventTime());
}

/**
* Support Context replacement
* @param context
Expand Down Expand Up @@ -710,6 +746,7 @@ private void deactivatePseudoState(int state) {
// dispatch event for touch* .
// TODO(hexionghui): Merge two dispatchEvent interfaces into one.
private void dispatchEvent(String eventName, MotionEvent ev, JavaOnlyMap map) {
recordTouchFrame(eventName, ev);
mFirstLynxTouchEvent = initialFirstLynxTouchEvent(mActiveUI, eventName, ev);
mFirstLynxTouchEvent.setMotionEvent(ev);
LynxTouchEvent event = new LynxTouchEvent(eventName, map);
Expand All @@ -725,6 +762,7 @@ private void dispatchEvent(String eventName, MotionEvent ev, JavaOnlyMap map) {

// dispatch event for tap, click, longpress.
private void dispatchEvent(EventTarget target, String eventName, MotionEvent ev) {
recordTouchFrame(eventName, ev);
mTargetPoint = convertToViewPoint(mActiveUI, new Point(ev.getX(0), ev.getY(0)));
LynxTouchEvent.Point pagePoint = new LynxTouchEvent.Point(ev.getX(0), ev.getY(0));
PointF point = LynxUIHelper.convertPointFromUIToScreen(
Expand Down
Loading
Loading