Kaydet (Commit) 8734422b authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

android: remove DrawTimingQueue and PanningPerfAPI

Change-Id: I094c345524059030a157a940702ad47fad358176
üst e3cd64d3
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
import android.os.SystemClock;
/**
* A custom-built data structure to assist with measuring draw times.
*
* This class maintains a fixed-size circular buffer of DisplayPortMetrics
* objects and associated timestamps. It provides only three operations, which
* is all we require for our purposes of measuring draw times. Note
* in particular that the class is designed so that even though it is
* accessed from multiple threads, it does not require synchronization;
* any concurrency errors that result from this are handled gracefully.
*
* Assuming an unrolled buffer so that mTail is greater than mHead, the data
* stored in the buffer at entries [mHead, mTail) will never be modified, and
* so are "safe" to read. If this reading is done on the same thread that
* owns mHead, then reading the range [mHead, mTail) is guaranteed to be safe
* since the range itself will not shrink.
*/
final class DrawTimingQueue {
private static final String LOGTAG = "GeckoDrawTimingQueue";
private static final int BUFFER_SIZE = 16;
private final DisplayPortMetrics[] mMetrics;
private final long[] mTimestamps;
private int mHead;
private int mTail;
DrawTimingQueue() {
mMetrics = new DisplayPortMetrics[BUFFER_SIZE];
mTimestamps = new long[BUFFER_SIZE];
mHead = BUFFER_SIZE - 1;
mTail = 0;
}
/**
* Add a new entry to the tail of the queue. If the buffer is full,
* do nothing. This must only be called from the Java UI thread.
*/
boolean add(DisplayPortMetrics metrics) {
if (mHead == mTail) {
return false;
}
mMetrics[mTail] = metrics;
mTimestamps[mTail] = SystemClock.uptimeMillis();
mTail = (mTail + 1) % BUFFER_SIZE;
return true;
}
/**
* Find the timestamp associated with the given metrics, AND remove
* all metrics objects from the start of the queue up to and including
* the one provided. Note that because of draw coalescing, the metrics
* object passed in here may not be the one at the head of the queue,
* and so we must iterate our way through the list to find it.
* This must only be called from the compositor thread.
*/
long findTimeFor(DisplayPortMetrics metrics) {
// keep a copy of the tail pointer so that we ignore new items
// added to the queue while we are searching. this is fine because
// the one we are looking for will either have been added already
// or will not be in the queue at all.
int tail = mTail;
// walk through the "safe" range from mHead to tail; these entries
// will not be modified unless we change mHead.
int i = (mHead + 1) % BUFFER_SIZE;
while (i != tail) {
if (mMetrics[i].fuzzyEquals(metrics)) {
// found it, copy out the timestamp to a local var BEFORE
// changing mHead or add could clobber the timestamp.
long timestamp = mTimestamps[i];
mHead = i;
return timestamp;
}
i = (i + 1) % BUFFER_SIZE;
}
return -1;
}
/**
* Reset the buffer to empty.
* This must only be called from the compositor thread.
*/
void reset() {
// we can only modify mHead on this thread.
mHead = (mTail + BUFFER_SIZE - 1) % BUFFER_SIZE;
}
}
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
import android.os.SystemClock;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class PanningPerfAPI {
private static final String LOGTAG = "GeckoPanningPerfAPI";
// make this large enough to avoid having to resize the frame time
// list, as that may be expensive and impact the thing we're trying
// to measure.
private static final int EXPECTED_FRAME_COUNT = 2048;
private static boolean mRecordingFrames = false;
private static List<Long> mFrameTimes;
private static long mFrameStartTime;
private static boolean mRecordingCheckerboard = false;
private static List<Float> mCheckerboardAmounts;
private static long mCheckerboardStartTime;
public static void startFrameTimeRecording() {
if (mRecordingFrames) {
Log.e(LOGTAG, "Error: startFrameTimeRecording() called while already recording!");
return;
}
mRecordingFrames = true;
if (mFrameTimes == null) {
mFrameTimes = new ArrayList<Long>(EXPECTED_FRAME_COUNT);
} else {
mFrameTimes.clear();
}
mFrameStartTime = SystemClock.uptimeMillis();
}
public static List<Long> stopFrameTimeRecording() {
if (!mRecordingFrames) {
Log.e(LOGTAG, "Error: stopFrameTimeRecording() called when not recording!");
return null;
}
mRecordingFrames = false;
return mFrameTimes;
}
public static void recordFrameTime() {
// this will be called often, so try to make it as quick as possible
if (mRecordingFrames) {
mFrameTimes.add(SystemClock.uptimeMillis() - mFrameStartTime);
}
}
public static boolean isRecordingCheckerboard() {
return mRecordingCheckerboard;
}
public static void startCheckerboardRecording() {
if (mRecordingCheckerboard) {
Log.e(LOGTAG, "Error: startCheckerboardRecording() called while already recording!");
return;
}
mRecordingCheckerboard = true;
if (mCheckerboardAmounts == null) {
mCheckerboardAmounts = new ArrayList<Float>(EXPECTED_FRAME_COUNT);
} else {
mCheckerboardAmounts.clear();
}
mCheckerboardStartTime = SystemClock.uptimeMillis();
}
public static List<Float> stopCheckerboardRecording() {
if (!mRecordingCheckerboard) {
Log.e(LOGTAG, "Error: stopCheckerboardRecording() called when not recording!");
return null;
}
mRecordingCheckerboard = false;
return mCheckerboardAmounts;
}
public static void recordCheckerboard(float amount) {
// this will be called often, so try to make it as quick as possible
if (mRecordingCheckerboard) {
mCheckerboardAmounts.add(amount);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment