|
| 1 | +package com.lunarg.gfxreconstruct.replay; |
| 2 | +import java.util.List; |
| 3 | +import java.util.ArrayList; |
| 4 | +import android.app.NativeActivity; |
| 5 | +import android.os.Bundle; |
| 6 | +import android.widget.FrameLayout; |
| 7 | +import android.view.SurfaceView; |
| 8 | +import android.view.SurfaceHolder; |
| 9 | +import android.view.ViewGroup.LayoutParams; |
| 10 | +import android.view.Surface; |
| 11 | +import android.util.Log; |
| 12 | +import android.content.Context; |
| 13 | +import android.view.View; |
| 14 | + |
| 15 | +public class ReplayActivity extends NativeActivity |
| 16 | +{ |
| 17 | + private FrameLayout frameLayout; |
| 18 | + private static final String TAG = "gfxrecon: ReplayActivity"; |
| 19 | + private Surface mSurface; |
| 20 | + public native void setSurface(Surface surface); |
| 21 | + private List<VKSurfaceView> mSurfaceviewList = new ArrayList<VKSurfaceView>(); |
| 22 | + |
| 23 | + @Override protected void onCreate(Bundle savedInstanceState) |
| 24 | + { |
| 25 | + super.onCreate(savedInstanceState); |
| 26 | + |
| 27 | + // Create a FrameLayout to hold SurfaceView instances |
| 28 | + frameLayout = new FrameLayout(this); |
| 29 | + setContentView(frameLayout); |
| 30 | + |
| 31 | + System.loadLibrary("gfxrecon-replay"); |
| 32 | + } |
| 33 | + |
| 34 | + private class VKSurfaceView extends SurfaceView implements SurfaceHolder.Callback |
| 35 | + { |
| 36 | + private int width; |
| 37 | + private int height; |
| 38 | + |
| 39 | + public VKSurfaceView(Context context, int w, int h) |
| 40 | + { |
| 41 | + super(context); |
| 42 | + |
| 43 | + width = w; |
| 44 | + height = h; |
| 45 | + |
| 46 | + SurfaceHolder holder = getHolder(); |
| 47 | + holder.addCallback(this); |
| 48 | + } |
| 49 | + |
| 50 | + @Override public void surfaceCreated(SurfaceHolder holder) |
| 51 | + { |
| 52 | + mSurface = holder.getSurface(); |
| 53 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceCreated:" + mSurface); |
| 54 | + } |
| 55 | + |
| 56 | + @Override public void surfaceDestroyed(SurfaceHolder holder) |
| 57 | + { |
| 58 | + mSurface = holder.getSurface(); |
| 59 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceDestroyed:" + mSurface); |
| 60 | + } |
| 61 | + |
| 62 | + @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) |
| 63 | + { |
| 64 | + mSurface = holder.getSurface(); |
| 65 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceChanged:" + mSurface + " " + w + " " + h); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + public void addNewView(int width, int height) |
| 70 | + { |
| 71 | + // Create a new SurfaceView |
| 72 | + final Context context = this; |
| 73 | + final int wid = width; |
| 74 | + final int hei = height; |
| 75 | + mSurface = null; |
| 76 | + runOnUiThread(new Runnable() { |
| 77 | + @Override public void run() |
| 78 | + { |
| 79 | + System.loadLibrary("gfxrecon-replay"); |
| 80 | + VKSurfaceView newSurfaceView = new VKSurfaceView(context, wid, hei); |
| 81 | + frameLayout.addView(newSurfaceView, |
| 82 | + new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
| 83 | + Log.i(TAG, |
| 84 | + "Create a new surface view:" |
| 85 | + + " width:" + wid + " height:" + hei); |
| 86 | + mSurfaceviewList.add(newSurfaceView); |
| 87 | + } |
| 88 | + }); |
| 89 | + while (mSurface == null) |
| 90 | + { |
| 91 | + try |
| 92 | + { |
| 93 | + Thread.sleep(100); |
| 94 | + } |
| 95 | + catch (Exception e) |
| 96 | + { |
| 97 | + Log.w(TAG, "Create new surface failed"); |
| 98 | + e.printStackTrace(); |
| 99 | + } |
| 100 | + } |
| 101 | + setSurface(mSurface); |
| 102 | + } |
| 103 | + |
| 104 | + private void removeOneView(int surface_idx) |
| 105 | + { |
| 106 | + final int sur_idx = surface_idx; |
| 107 | + runOnUiThread(new Runnable() { |
| 108 | + @Override public void run() |
| 109 | + { |
| 110 | + if (frameLayout != null) |
| 111 | + { |
| 112 | + Log.i(TAG, "Remove one view"); |
| 113 | + frameLayout.removeView(mSurfaceviewList.get(sur_idx)); |
| 114 | + } |
| 115 | + else |
| 116 | + { |
| 117 | + Log.w(TAG, "View container has been destroyed!"); |
| 118 | + } |
| 119 | + } |
| 120 | + }); |
| 121 | + } |
| 122 | +} |
0 commit comments