|
| 1 | +/* |
| 2 | +** Copyright (c) 2025 LunarG, Inc. |
| 3 | +** Copyright (c) 2025 Arm Limited and/or its affiliates <[email protected]> |
| 4 | +** |
| 5 | +** Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | +** copy of this software and associated documentation files (the "Software"), |
| 7 | +** to deal in the Software without restriction, including without limitation |
| 8 | +** the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | +** and/or sell copies of the Software, and to permit persons to whom the |
| 10 | +** Software is furnished to do so, subject to the following conditions: |
| 11 | +** |
| 12 | +** The above copyright notice and this permission notice shall be included in |
| 13 | +** all copies or substantial portions of the Software. |
| 14 | +** |
| 15 | +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | +** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | +** DEALINGS IN THE SOFTWARE. |
| 22 | +*/ |
| 23 | + |
| 24 | +package com.lunarg.gfxreconstruct.replay; |
| 25 | +import java.util.List; |
| 26 | +import java.util.ArrayList; |
| 27 | +import android.app.NativeActivity; |
| 28 | +import android.os.Bundle; |
| 29 | +import android.widget.FrameLayout; |
| 30 | +import android.view.SurfaceView; |
| 31 | +import android.view.SurfaceHolder; |
| 32 | +import android.view.ViewGroup.LayoutParams; |
| 33 | +import android.view.Surface; |
| 34 | +import android.util.Log; |
| 35 | +import android.content.Context; |
| 36 | +import android.view.View; |
| 37 | + |
| 38 | +public class ReplayActivity extends NativeActivity |
| 39 | +{ |
| 40 | + private FrameLayout mFrameLayout; |
| 41 | + private static final String TAG = "gfxrecon"; |
| 42 | + private Surface mSurface; |
| 43 | + public native void setSurface(Surface surface); |
| 44 | + private List<VKSurfaceView> mSurfaceviewList = new ArrayList<VKSurfaceView>(); |
| 45 | + |
| 46 | + @Override protected void onCreate(Bundle savedInstanceState) |
| 47 | + { |
| 48 | + super.onCreate(savedInstanceState); |
| 49 | + |
| 50 | + // Create a FrameLayout to hold SurfaceView instances |
| 51 | + mFrameLayout = new FrameLayout(this); |
| 52 | + setContentView(mFrameLayout); |
| 53 | + |
| 54 | + System.loadLibrary("gfxrecon-replay"); |
| 55 | + } |
| 56 | + |
| 57 | + private class VKSurfaceView extends SurfaceView implements SurfaceHolder.Callback |
| 58 | + { |
| 59 | + private int width; |
| 60 | + private int height; |
| 61 | + |
| 62 | + public VKSurfaceView(Context context, int w, int h) |
| 63 | + { |
| 64 | + super(context); |
| 65 | + |
| 66 | + width = w; |
| 67 | + height = h; |
| 68 | + |
| 69 | + SurfaceHolder holder = getHolder(); |
| 70 | + holder.addCallback(this); |
| 71 | + } |
| 72 | + |
| 73 | + @Override public void surfaceCreated(SurfaceHolder holder) |
| 74 | + { |
| 75 | + mSurface = holder.getSurface(); |
| 76 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceCreated:" + mSurface); |
| 77 | + } |
| 78 | + |
| 79 | + @Override public void surfaceDestroyed(SurfaceHolder holder) |
| 80 | + { |
| 81 | + mSurface = holder.getSurface(); |
| 82 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceDestroyed:" + mSurface); |
| 83 | + } |
| 84 | + |
| 85 | + @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) |
| 86 | + { |
| 87 | + mSurface = holder.getSurface(); |
| 88 | + Log.i(TAG, "SurfaceHolder.Callback: surfaceChanged:" + mSurface + " " + w + " " + h); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + public void addNewView(int width, int height) |
| 93 | + { |
| 94 | + // Create a new SurfaceView |
| 95 | + final Context context = this; |
| 96 | + final int wid = width; |
| 97 | + final int hei = height; |
| 98 | + mSurface = null; |
| 99 | + runOnUiThread(new Runnable() { |
| 100 | + @Override public void run() |
| 101 | + { |
| 102 | + System.loadLibrary("gfxrecon-replay"); |
| 103 | + VKSurfaceView newSurfaceView = new VKSurfaceView(context, wid, hei); |
| 104 | + mFrameLayout.addView(newSurfaceView, |
| 105 | + new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
| 106 | + Log.i(TAG, |
| 107 | + "Create a new surface view:" |
| 108 | + + " width:" + wid + " height:" + hei); |
| 109 | + mSurfaceviewList.add(newSurfaceView); |
| 110 | + } |
| 111 | + }); |
| 112 | + while (mSurface == null) |
| 113 | + { |
| 114 | + try |
| 115 | + { |
| 116 | + Thread.sleep(100); |
| 117 | + } |
| 118 | + catch (Exception e) |
| 119 | + { |
| 120 | + Log.w(TAG, "Create new surface failed"); |
| 121 | + e.printStackTrace(); |
| 122 | + } |
| 123 | + } |
| 124 | + setSurface(mSurface); |
| 125 | + } |
| 126 | + |
| 127 | + private void removeOneView(int surface_idx) |
| 128 | + { |
| 129 | + final int sur_idx = surface_idx; |
| 130 | + runOnUiThread(new Runnable() { |
| 131 | + @Override public void run() |
| 132 | + { |
| 133 | + if (mFrameLayout != null) |
| 134 | + { |
| 135 | + Log.i(TAG, "Remove one view"); |
| 136 | + mFrameLayout.removeView(mSurfaceviewList.get(sur_idx)); |
| 137 | + } |
| 138 | + else |
| 139 | + { |
| 140 | + Log.w(TAG, "View container has been destroyed!"); |
| 141 | + } |
| 142 | + } |
| 143 | + }); |
| 144 | + } |
| 145 | +} |
0 commit comments