use of com.android.ide.common.rendering.api.RenderSession in project android_frameworks_base by AOSPA.
the class Main method renderAndVerify.
/**
* Create a new rendering session and test that rendering the given layout doesn't throw any
* exceptions and matches the provided image.
* <p>
* If frameTimeNanos is >= 0 a frame will be executed during the rendering. The time indicates
* how far in the future is.
*/
@Nullable
private RenderResult renderAndVerify(SessionParams params, String goldenFileName, long frameTimeNanos) throws ClassNotFoundException {
// TODO: Set up action bar handler properly to test menu rendering.
// Create session params.
RenderSession session = sBridge.createSession(params);
if (frameTimeNanos != -1) {
session.setElapsedFrameTimeNanos(frameTimeNanos);
}
if (!session.getResult().isSuccess()) {
getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
}
// Render the session with a timeout of 50s.
Result renderResult = session.render(50000);
if (!renderResult.isSuccess()) {
getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
}
try {
String goldenImagePath = APP_TEST_DIR + "/golden/" + goldenFileName;
ImageUtils.requireSimilar(goldenImagePath, session.getImage());
return RenderResult.getFromSession(session);
} catch (IOException e) {
getLogger().error(e, e.getMessage());
} finally {
session.dispose();
}
return null;
}
use of com.android.ide.common.rendering.api.RenderSession in project android_frameworks_base by DirtyUnicorns.
the class AnimationThread method run.
@Override
public void run() {
Bridge.prepareThread();
try {
/* FIXME: The ANIMATION_FRAME message no longer exists. Instead, the
* animation timing loop is completely based on a Choreographer objects
* that schedules animation and drawing frames. The animation handler is
* no longer even a handler; it is just a Runnable enqueued on the Choreographer.
Handler_Delegate.setCallback(new IHandlerCallback() {
@Override
public void sendMessageAtTime(Handler handler, Message msg, long uptimeMillis) {
if (msg.what == ValueAnimator.ANIMATION_START ||
msg.what == ValueAnimator.ANIMATION_FRAME) {
mQueue.add(new MessageBundle(handler, msg, uptimeMillis));
} else {
// just ignore.
}
}
});
*/
// call out to the pre-animation work, which should start an animation or more.
Result result = preAnimation();
if (result.isSuccess() == false) {
mListener.done(result);
}
// loop the animation
RenderSession session = mSession.getSession();
do {
// check early.
if (mListener.isCanceled()) {
break;
}
// get the next message.
MessageBundle bundle = mQueue.poll();
if (bundle == null) {
break;
}
// sleep enough for this bundle to be on time
long currentTime = System.currentTimeMillis();
if (currentTime < bundle.mUptimeMillis) {
try {
sleep(bundle.mUptimeMillis - currentTime);
} catch (InterruptedException e) {
// FIXME log/do something/sleep again?
e.printStackTrace();
}
}
// check after sleeping.
if (mListener.isCanceled()) {
break;
}
// ready to do the work, acquire the scene.
result = mSession.acquire(250);
if (result.isSuccess() == false) {
mListener.done(result);
return;
}
// the next message, so mQueue will have another one.
try {
// check after acquiring in case it took a while.
if (mListener.isCanceled()) {
break;
}
bundle.mTarget.handleMessage(bundle.mMessage);
if (mSession.render(false).isSuccess()) {
mListener.onNewFrame(session);
}
} finally {
mSession.release();
}
} while (mListener.isCanceled() == false && mQueue.size() > 0);
mListener.done(Status.SUCCESS.createResult());
} catch (Throwable throwable) {
// can't use Bridge.getLog() as the exception might be thrown outside
// of an acquire/release block.
mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable));
} finally {
postAnimation();
Handler_Delegate.setCallback(null);
Bridge.cleanupThread();
}
}
use of com.android.ide.common.rendering.api.RenderSession in project android_frameworks_base by ResurrectionRemix.
the class AnimationThread method run.
@Override
public void run() {
Bridge.prepareThread();
try {
/* FIXME: The ANIMATION_FRAME message no longer exists. Instead, the
* animation timing loop is completely based on a Choreographer objects
* that schedules animation and drawing frames. The animation handler is
* no longer even a handler; it is just a Runnable enqueued on the Choreographer.
Handler_Delegate.setCallback(new IHandlerCallback() {
@Override
public void sendMessageAtTime(Handler handler, Message msg, long uptimeMillis) {
if (msg.what == ValueAnimator.ANIMATION_START ||
msg.what == ValueAnimator.ANIMATION_FRAME) {
mQueue.add(new MessageBundle(handler, msg, uptimeMillis));
} else {
// just ignore.
}
}
});
*/
// call out to the pre-animation work, which should start an animation or more.
Result result = preAnimation();
if (result.isSuccess() == false) {
mListener.done(result);
}
// loop the animation
RenderSession session = mSession.getSession();
do {
// check early.
if (mListener.isCanceled()) {
break;
}
// get the next message.
MessageBundle bundle = mQueue.poll();
if (bundle == null) {
break;
}
// sleep enough for this bundle to be on time
long currentTime = System.currentTimeMillis();
if (currentTime < bundle.mUptimeMillis) {
try {
sleep(bundle.mUptimeMillis - currentTime);
} catch (InterruptedException e) {
// FIXME log/do something/sleep again?
e.printStackTrace();
}
}
// check after sleeping.
if (mListener.isCanceled()) {
break;
}
// ready to do the work, acquire the scene.
result = mSession.acquire(250);
if (result.isSuccess() == false) {
mListener.done(result);
return;
}
// the next message, so mQueue will have another one.
try {
// check after acquiring in case it took a while.
if (mListener.isCanceled()) {
break;
}
bundle.mTarget.handleMessage(bundle.mMessage);
if (mSession.render(false).isSuccess()) {
mListener.onNewFrame(session);
}
} finally {
mSession.release();
}
} while (mListener.isCanceled() == false && mQueue.size() > 0);
mListener.done(Status.SUCCESS.createResult());
} catch (Throwable throwable) {
// can't use Bridge.getLog() as the exception might be thrown outside
// of an acquire/release block.
mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable));
} finally {
postAnimation();
Handler_Delegate.setCallback(null);
Bridge.cleanupThread();
}
}
use of com.android.ide.common.rendering.api.RenderSession in project android_frameworks_base by crdroidandroid.
the class AnimationThread method run.
@Override
public void run() {
Bridge.prepareThread();
try {
/* FIXME: The ANIMATION_FRAME message no longer exists. Instead, the
* animation timing loop is completely based on a Choreographer objects
* that schedules animation and drawing frames. The animation handler is
* no longer even a handler; it is just a Runnable enqueued on the Choreographer.
Handler_Delegate.setCallback(new IHandlerCallback() {
@Override
public void sendMessageAtTime(Handler handler, Message msg, long uptimeMillis) {
if (msg.what == ValueAnimator.ANIMATION_START ||
msg.what == ValueAnimator.ANIMATION_FRAME) {
mQueue.add(new MessageBundle(handler, msg, uptimeMillis));
} else {
// just ignore.
}
}
});
*/
// call out to the pre-animation work, which should start an animation or more.
Result result = preAnimation();
if (result.isSuccess() == false) {
mListener.done(result);
}
// loop the animation
RenderSession session = mSession.getSession();
do {
// check early.
if (mListener.isCanceled()) {
break;
}
// get the next message.
MessageBundle bundle = mQueue.poll();
if (bundle == null) {
break;
}
// sleep enough for this bundle to be on time
long currentTime = System.currentTimeMillis();
if (currentTime < bundle.mUptimeMillis) {
try {
sleep(bundle.mUptimeMillis - currentTime);
} catch (InterruptedException e) {
// FIXME log/do something/sleep again?
e.printStackTrace();
}
}
// check after sleeping.
if (mListener.isCanceled()) {
break;
}
// ready to do the work, acquire the scene.
result = mSession.acquire(250);
if (result.isSuccess() == false) {
mListener.done(result);
return;
}
// the next message, so mQueue will have another one.
try {
// check after acquiring in case it took a while.
if (mListener.isCanceled()) {
break;
}
bundle.mTarget.handleMessage(bundle.mMessage);
if (mSession.render(false).isSuccess()) {
mListener.onNewFrame(session);
}
} finally {
mSession.release();
}
} while (mListener.isCanceled() == false && mQueue.size() > 0);
mListener.done(Status.SUCCESS.createResult());
} catch (Throwable throwable) {
// can't use Bridge.getLog() as the exception might be thrown outside
// of an acquire/release block.
mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable));
} finally {
postAnimation();
Handler_Delegate.setCallback(null);
Bridge.cleanupThread();
}
}
use of com.android.ide.common.rendering.api.RenderSession in project android_frameworks_base by crdroidandroid.
the class Main method renderAndVerify.
/**
* Create a new rendering session and test that rendering the given layout doesn't throw any
* exceptions and matches the provided image.
* <p>
* If frameTimeNanos is >= 0 a frame will be executed during the rendering. The time indicates
* how far in the future is.
*/
@Nullable
private RenderResult renderAndVerify(SessionParams params, String goldenFileName, long frameTimeNanos) throws ClassNotFoundException {
// TODO: Set up action bar handler properly to test menu rendering.
// Create session params.
RenderSession session = sBridge.createSession(params);
if (frameTimeNanos != -1) {
session.setElapsedFrameTimeNanos(frameTimeNanos);
}
if (!session.getResult().isSuccess()) {
getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
}
// Render the session with a timeout of 50s.
Result renderResult = session.render(50000);
if (!renderResult.isSuccess()) {
getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
}
try {
String goldenImagePath = APP_TEST_DIR + "/golden/" + goldenFileName;
ImageUtils.requireSimilar(goldenImagePath, session.getImage());
return RenderResult.getFromSession(session);
} catch (IOException e) {
getLogger().error(e, e.getMessage());
} finally {
session.dispose();
}
return null;
}
Aggregations