mirror of
https://github.com/jamessanford/kegs.git
synced 2024-06-15 06:29:27 +00:00
Remove old software renderer, GL is used now.
This commit is contained in:
parent
af3ae51ec8
commit
19dfbdd245
|
@ -1,96 +0,0 @@
|
||||||
package com.froop.app.kegs;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
class BitmapThread extends Thread {
|
|
||||||
private Handler mHandler = new Handler() {
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
updateScreen();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private SurfaceHolder mSurfaceHolder;
|
|
||||||
private final ReentrantLock mSurfaceLock = new ReentrantLock();
|
|
||||||
private Bitmap mBitmap;
|
|
||||||
private Canvas mCanvas;
|
|
||||||
private boolean mHaveSurface = false;
|
|
||||||
private boolean mScaled = false;
|
|
||||||
private float mScaleFactorX = 1.0f;
|
|
||||||
private float mScaleFactorY = 1.0f;
|
|
||||||
private Rect mRectSrc = new Rect(0, 0, 0, 0);
|
|
||||||
private Rect mRectDst = new Rect(0, 0, 0, 0);
|
|
||||||
|
|
||||||
private FpsCounter fpsCount = new FpsCounter("kegs", "thread");
|
|
||||||
|
|
||||||
public void setBitmap(SurfaceHolder surfaceHolder, Bitmap bitmap) {
|
|
||||||
mSurfaceHolder = surfaceHolder;
|
|
||||||
mBitmap = bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
Looper.prepare();
|
|
||||||
Looper.loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Handler getHandler() {
|
|
||||||
return mHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreen() {
|
|
||||||
mSurfaceLock.lock();
|
|
||||||
try {
|
|
||||||
if (!mHaveSurface) {
|
|
||||||
return; // unlock with 'finally' clause
|
|
||||||
}
|
|
||||||
mCanvas = mSurfaceHolder.lockCanvas(); // Use Rect ?
|
|
||||||
if(mCanvas != null) {
|
|
||||||
if (!mScaled) {
|
|
||||||
mCanvas.drawBitmap(mBitmap, mRectSrc, mRectDst, null);
|
|
||||||
} else {
|
|
||||||
mCanvas.save();
|
|
||||||
mCanvas.scale(mScaleFactorX, mScaleFactorY);
|
|
||||||
mCanvas.drawBitmap(mBitmap, mRectSrc, mRectDst, null);
|
|
||||||
mCanvas.restore();
|
|
||||||
}
|
|
||||||
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
|
|
||||||
mCanvas = null;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
mSurfaceLock.unlock();
|
|
||||||
// for testing
|
|
||||||
// fpsCount.fps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreenSize(BitmapSize bitmapSize) {
|
|
||||||
// Keep our own copy of the size data, to give atomicity and
|
|
||||||
// possibly help performance with fewer indirections.
|
|
||||||
mSurfaceLock.lock();
|
|
||||||
mScaled = bitmapSize.isScaled();
|
|
||||||
mScaleFactorX = bitmapSize.getScaleX();
|
|
||||||
mScaleFactorY = bitmapSize.getScaleY();
|
|
||||||
mRectSrc = new Rect(bitmapSize.getRectSrc());
|
|
||||||
mRectDst = new Rect(bitmapSize.getRectDst());
|
|
||||||
mSurfaceLock.unlock();
|
|
||||||
updateScreen(); // NOTE: UI thread.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHaveSurface(boolean haveSurface) {
|
|
||||||
mSurfaceLock.lock();
|
|
||||||
mHaveSurface = haveSurface;
|
|
||||||
mSurfaceLock.unlock();
|
|
||||||
|
|
||||||
if (haveSurface) {
|
|
||||||
// Refresh the canvas when we obtain a surface.
|
|
||||||
updateScreen(); // NOTE: UI thread.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package com.froop.app.kegs;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
class FpsCounter {
|
|
||||||
private String mName;
|
|
||||||
private String mIdent;
|
|
||||||
private long fpsLast = System.currentTimeMillis() + 1000;
|
|
||||||
private int fpsCount = 0;
|
|
||||||
|
|
||||||
FpsCounter(String logName, String ident) {
|
|
||||||
mName = logName;
|
|
||||||
mIdent = "fps " + ident + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fps() {
|
|
||||||
fpsCount += 1;
|
|
||||||
long fpsNow = System.currentTimeMillis();
|
|
||||||
if (fpsNow > fpsLast) {
|
|
||||||
Log.w(mName, mIdent + fpsCount);
|
|
||||||
fpsLast = fpsNow + 1000;
|
|
||||||
fpsCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,8 +42,6 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S
|
||||||
private ConfigFile mConfigFile;
|
private ConfigFile mConfigFile;
|
||||||
private KegsThread mKegsThread;
|
private KegsThread mKegsThread;
|
||||||
|
|
||||||
// For the software renderer, use 'KegsView' here and in res/layout/main.xml
|
|
||||||
// Also consider undef ANDROID_GL in jni/android_driver.c
|
|
||||||
protected KegsViewGL mKegsView;
|
protected KegsViewGL mKegsView;
|
||||||
private KegsTouch mKegsTouch;
|
private KegsTouch mKegsTouch;
|
||||||
private KegsKeyboard mKegsKeyboard;
|
private KegsKeyboard mKegsKeyboard;
|
||||||
|
@ -595,9 +593,7 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
getThread().onPause();
|
getThread().onPause();
|
||||||
if (mKegsView instanceof KegsViewGL) {
|
mKegsView.onPause();
|
||||||
mKegsView.onPause();
|
|
||||||
}
|
|
||||||
mPaused = true;
|
mPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,9 +601,7 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
getThread().onResume();
|
getThread().onResume();
|
||||||
if (mKegsView instanceof KegsViewGL) {
|
mKegsView.onResume();
|
||||||
mKegsView.onResume();
|
|
||||||
}
|
|
||||||
mPaused = false;
|
mPaused = false;
|
||||||
|
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
package com.froop.app.kegs;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.inputmethod.EditorInfo;
|
|
||||||
import android.view.inputmethod.InputConnection;
|
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import android.view.SurfaceView;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
// This is the old software renderer that uses BitmapThread.
|
|
||||||
|
|
||||||
class KegsView extends SurfaceView implements KegsThread.UpdateScreen, SurfaceHolder.Callback {
|
|
||||||
// Reported area of this view, see updateScreenSize()
|
|
||||||
private int mWidth = 0;
|
|
||||||
private int mHeight = 0;
|
|
||||||
|
|
||||||
private Bitmap mBitmap;
|
|
||||||
private final BitmapThread mBitmapThread = new BitmapThread();
|
|
||||||
private Handler mHandler;
|
|
||||||
|
|
||||||
public KegsView(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
|
|
||||||
SurfaceHolder holder = getHolder();
|
|
||||||
holder.addCallback(this);
|
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(BitmapSize.Const.A2Width,
|
|
||||||
BitmapSize.Const.A2Height,
|
|
||||||
Bitmap.Config.RGB_565);
|
|
||||||
mBitmap = bitmap;
|
|
||||||
|
|
||||||
mBitmapThread.setBitmap(holder, bitmap);
|
|
||||||
mHandler = mBitmapThread.getHandler();
|
|
||||||
mBitmapThread.start();
|
|
||||||
|
|
||||||
setFocusable(true);
|
|
||||||
setFocusableInTouchMode(true);
|
|
||||||
requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
||||||
setMeasuredDimension(mWidth, mHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputConnection onCreateInputConnection(EditorInfo attrs) {
|
|
||||||
// Bug workaround to force KEYCODE_DEL.
|
|
||||||
return InputFix.getInputConnection(this, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private FpsCounter fpsCount = new FpsCounter("kegs", "native");
|
|
||||||
|
|
||||||
public Bitmap getBitmap() {
|
|
||||||
return mBitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typically updateScreen is called by the native thread,
|
|
||||||
// but it may also be run on the UI thread.
|
|
||||||
//
|
|
||||||
// We use a Handler to tell the bitmap thread to actually draw
|
|
||||||
// on the canvas. No locking is involved, so it is possible for
|
|
||||||
// the canvas to get a bitmap that is in the process of being updated
|
|
||||||
// by the native thread. This should be relatively uncommon.
|
|
||||||
//
|
|
||||||
// If you wish to draw to the canvas in the native thread, it should
|
|
||||||
// be safe to bypass the Handler and call mBitmapThread.updateScreen()
|
|
||||||
// here instead.
|
|
||||||
public void updateScreen() {
|
|
||||||
// Empty the queue first in case bitmap thread is lagging behind.
|
|
||||||
mHandler.removeMessages(0);
|
|
||||||
mHandler.sendEmptyMessage(0);
|
|
||||||
// for testing
|
|
||||||
// fpsCount.fps();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreenSize(BitmapSize bitmapSize) {
|
|
||||||
mWidth = bitmapSize.getViewWidth();
|
|
||||||
mHeight = bitmapSize.getViewHeight();
|
|
||||||
requestLayout();
|
|
||||||
mBitmapThread.updateScreenSize(bitmapSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void surfaceChanged(SurfaceHolder holder,
|
|
||||||
int format, int width, int height) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// The surface callbacks are occasionally called in between pause and resume.
|
|
||||||
|
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
|
||||||
mBitmapThread.setHaveSurface(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
||||||
mBitmapThread.setHaveSurface(false);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user