aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-06-07 14:22:37 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-07 14:22:38 -0700
commitd94ad5823b7da7f115e997d12828314e290981f6 (patch)
tree411aa309e9f52b386bd7375ab789913cb6beaadf /platform_tools
parent93e3fff79eaaa86bc2fb740a42111a074ccc73ab (diff)
Implement Raster Backend on Android Viewer App
Diffstat (limited to 'platform_tools')
-rw-r--r--platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java17
-rw-r--r--platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java8
2 files changed, 20 insertions, 5 deletions
diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
index d546c7bb3e..5ee68efc3c 100644
--- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
+++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
@@ -1,6 +1,7 @@
package org.skia.viewer;
import android.view.LayoutInflater;
+import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -30,6 +31,7 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
static final String NAME = "name";
static final String VALUE = "value";
static final String OPTIONS = "options";
+ private static final String BACKEND_STATE_NAME = "Backend";
ViewerActivity mViewerActivity;
LinearLayout mLayout;
@@ -146,6 +148,21 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
stateItem.setTag(null); // Reset the tag to let updateDrawer update this item view.
mViewerActivity.onStateChanged(stateName, stateValue);
}
+
+ // Due to the current Android limitation, we're required to recreate the SurfaceView for
+ // switching to/from the Raster backend.
+ // (Although we can switch between GPU backend without recreating the SurfaceView.)
+ final Object oldValue = stateItem.getTag(R.integer.value_tag_key);
+ if (stateName.equals(BACKEND_STATE_NAME)
+ && oldValue != null && !stateValue.equals(oldValue)) {
+ LinearLayout mainLayout = (LinearLayout) mViewerActivity.findViewById(R.id.mainLayout);
+ mainLayout.removeAllViews();
+ SurfaceView surfaceView = new SurfaceView(mViewerActivity);
+ surfaceView.setId(R.id.surfaceView);
+ surfaceView.getHolder().addCallback(mViewerActivity);
+ surfaceView.setOnTouchListener(mViewerActivity);
+ mainLayout.addView(surfaceView);
+ }
}
@Override
diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java
index ce5bb0deda..0291f5e291 100644
--- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java
+++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java
@@ -32,7 +32,6 @@ public class ViewerActivity
private ListView mDrawerList;
private StateAdapter mStateAdapter;
- private SurfaceView mView;
private ViewerApplication mApplication;
private native void onSurfaceCreated(long handle, Surface surface);
@@ -74,10 +73,9 @@ public class ViewerActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- mView = (SurfaceView) findViewById(R.id.surfaceView);
- mView.getHolder().addCallback(this);
-
- mView.setOnTouchListener(this);
+ SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
+ surfaceView.getHolder().addCallback(this);
+ surfaceView.setOnTouchListener(this);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,