Java Code Examples for android.view.Choreographer#FrameCallback

The following examples show how to use android.view.Choreographer#FrameCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLManager.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 未実行のChoreographer.FrameCallbackがあれば取り除く
 * @param callback
 * @throws IllegalStateException
 */
public synchronized void removeFrameCallback(
	@NonNull final Choreographer.FrameCallback callback)
		throws IllegalStateException {

	if (DEBUG) Log.v(TAG, "removeFrameCallback:");
	checkValid();
	if (isGLThread()) {
		// すでにGLスレッド上であれば直接実行
		Choreographer.getInstance().removeFrameCallback(callback);
	} else {
		// 別スレッド上にいるならGLスレッド上へ投げる
		mGLHandler.post(new Runnable() {
			@Override
			public void run() {
				Choreographer.getInstance().removeFrameCallback(callback);
			}
		});
	}
}
 
Example 2
Source File: GLManager.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * GLコンテキスト上で実行されるChoreographer.FrameCallbackをpostする
 * @param callback
 * @param delayMs
 * @throws IllegalStateException
 */
public synchronized void postFrameCallbackDelayed(
	@NonNull final Choreographer.FrameCallback callback,
	final long delayMs) throws IllegalStateException {

	if (DEBUG) Log.v(TAG, "postFrameCallbackDelayed:");
	checkValid();
	if (isGLThread()) {
		// すでにGLスレッド上であれば直接実行
		Choreographer.getInstance().postFrameCallbackDelayed(callback, delayMs);
	} else {
		// 別スレッド上にいるならGLスレッド上へ投げる
		mGLHandler.post(new Runnable() {
			@Override
			public void run() {
				Choreographer.getInstance().postFrameCallbackDelayed(callback, delayMs);
			}
		});
	}
}
 
Example 3
Source File: AndroidSpringLooperFactory.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
  mChoreographer = choreographer;
  mFrameCallback = new Choreographer.FrameCallback() {
    @Override
    public void doFrame(long frameTimeNanos) {
      if (!mStarted || mSpringSystem == null) {
        return;
      }
      long currentTime = SystemClock.uptimeMillis();
      mSpringSystem.loop(currentTime - mLastTime);
      mLastTime = currentTime;
      mChoreographer.postFrameCallback(mFrameCallback);
    }
  };
}
 
Example 4
Source File: VSyncMonitor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a VSyncMonitor
 * @param context The application context.
 * @param listener The listener receiving VSync notifications.
 */
public VSyncMonitor(Context context, VSyncMonitor.Listener listener) {
    mListener = listener;
    float refreshRate = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay().getRefreshRate();
    final boolean useEstimatedRefreshPeriod = refreshRate < 30;

    if (refreshRate <= 0) refreshRate = 60;
    mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate);

    mChoreographer = Choreographer.getInstance();
    mVSyncFrameCallback = new Choreographer.FrameCallback() {
        @Override
        public void doFrame(long frameTimeNanos) {
            TraceEvent.begin("VSync");
            if (useEstimatedRefreshPeriod && mConsecutiveVSync) {
                // Display.getRefreshRate() is unreliable on some platforms.
                // Adjust refresh period- initial value is based on Display.getRefreshRate()
                // after that it asymptotically approaches the real value.
                long lastRefreshDurationNano = frameTimeNanos - mGoodStartingPointNano;
                float lastRefreshDurationWeight = 0.1f;
                mRefreshPeriodNano += (long) (lastRefreshDurationWeight
                        * (lastRefreshDurationNano - mRefreshPeriodNano));
            }
            mGoodStartingPointNano = frameTimeNanos;
            onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
            TraceEvent.end("VSync");
        }
    };
    mGoodStartingPointNano = getCurrentNanoTime();
}
 
Example 5
Source File: ChoreographerCompat.java    From react-native-GPay with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Choreographer.FrameCallback getFrameCallback() {
  if (mFrameCallback == null) {
    mFrameCallback = new Choreographer.FrameCallback() {
      @Override
      public void doFrame(long frameTimeNanos) {
        FrameCallback.this.doFrame(frameTimeNanos);
      }
    };
  }
  return mFrameCallback;
}
 
Example 6
Source File: AndroidSpringLooperFactory.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
  mChoreographer = choreographer;
  mFrameCallback = new Choreographer.FrameCallback() {
    @Override
    public void doFrame(long frameTimeNanos) {
      if (!mStarted || mSpringSystem == null) {
        return;
      }
      mSpringSystem.loop();
      mChoreographer.postFrameCallback(mFrameCallback);
    }
  };
}
 
Example 7
Source File: AndroidSpringLooperFactory.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
  mChoreographer = choreographer;
  mFrameCallback = new Choreographer.FrameCallback() {
    @Override
    public void doFrame(long frameTimeNanos) {
      if (!mStarted || mSpringSystem == null) {
        return;
      }
      mSpringSystem.loop();
      mChoreographer.postFrameCallback(mFrameCallback);
    }
  };
}
 
Example 8
Source File: ChoreographerCompat.java    From litho with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Choreographer.FrameCallback getFrameCallback() {
  if (mFrameCallback == null) {
    mFrameCallback =
        new Choreographer.FrameCallback() {
          @Override
          public void doFrame(long frameTimeNanos) {
            ChoreographerCompat.FrameCallback.this.doFrameInternal(frameTimeNanos);
          }
        };
  }
  return mFrameCallback;
}
 
Example 9
Source File: AndroidSpringLooperFactory.java    From StackCardsView with Apache License 2.0 5 votes vote down vote up
public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
  mChoreographer = choreographer;
  mFrameCallback = new Choreographer.FrameCallback() {
    @Override
    public void doFrame(long frameTimeNanos) {
      if (!mStarted || mSpringSystem == null) {
        return;
      }
      long currentTime = SystemClock.uptimeMillis();
      mSpringSystem.loop(currentTime - mLastTime);
      mLastTime = currentTime;
      mChoreographer.postFrameCallback(mFrameCallback);
    }
  };
}
 
Example 10
Source File: AndroidSpringLooperFactory.java    From Conquer with Apache License 2.0 5 votes vote down vote up
public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
	mChoreographer = choreographer;
	mFrameCallback = new Choreographer.FrameCallback() {
		@Override
		public void doFrame(long frameTimeNanos) {
			if (!mStarted || mSpringSystem == null) {
				return;
			}
			long currentTime = SystemClock.uptimeMillis();
			mSpringSystem.loop(currentTime - mLastTime);
			mLastTime = currentTime;
			mChoreographer.postFrameCallback(mFrameCallback);
		}
	};
}
 
Example 11
Source File: AnimationHandler.java    From CircularReveal with MIT License 4 votes vote down vote up
@Override
public void postFrameCallback(Choreographer.FrameCallback callback) {
  mChoreographer.postFrameCallback(callback);
}
 
Example 12
Source File: AnimationHandler.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void postFrameCallback(Choreographer.FrameCallback callback) {
    mChoreographer.postFrameCallback(callback);
}
 
Example 13
Source File: ChoreographerCompat.java    From StackCardsView with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerRemoveFrameCallback(Choreographer.FrameCallback frameCallback) {
  mChoreographer.removeFrameCallback(frameCallback);
}
 
Example 14
Source File: ChoreographerCompat.java    From StackCardsView with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerPostFrameCallback(Choreographer.FrameCallback frameCallback) {
  mChoreographer.postFrameCallback(frameCallback);
}
 
Example 15
Source File: ChoreographerCompatImpl.java    From litho with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerRemoveFrameCallback(Choreographer.FrameCallback frameCallback) {
  mChoreographer.removeFrameCallback(frameCallback);
}
 
Example 16
Source File: ChoreographerCompatImpl.java    From litho with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerPostFrameCallbackDelayed(
    Choreographer.FrameCallback frameCallback, long delayMillis) {
  mChoreographer.postFrameCallbackDelayed(frameCallback, delayMillis);
}
 
Example 17
Source File: ChoreographerCompatImpl.java    From litho with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerPostFrameCallback(Choreographer.FrameCallback frameCallback) {
  mChoreographer.postFrameCallback(frameCallback);
}
 
Example 18
Source File: ChoreographerCompat.java    From react-native-GPay with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerPostFrameCallbackDelayed(
  Choreographer.FrameCallback frameCallback,
  long delayMillis) {
  mChoreographer.postFrameCallbackDelayed(frameCallback, delayMillis);
}
 
Example 19
Source File: ChoreographerCompat.java    From react-native-GPay with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void choreographerPostFrameCallback(Choreographer.FrameCallback frameCallback) {
  mChoreographer.postFrameCallback(frameCallback);
}
 
Example 20
Source File: AnimationHandler.java    From CircularReveal with MIT License votes vote down vote up
void postFrameCallback(Choreographer.FrameCallback callback);