summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByunghun Jeon <bjeon@codeaurora.org>2015-11-13 11:33:57 -0800
committerJay Wang <jaywang@codeaurora.org>2015-12-22 17:35:06 -0800
commitfa9e745bec7c98ff68649959521efebbbe715c74 (patch)
treeab7108637fd982a924df163162095d3fd0b48c15
parent8f0f5c0439c2a6aee50ea78bff3454d887cee6b4 (diff)
downloadandroid_packages_apps_Gallery2-fa9e745bec7c98ff68649959521efebbbe715c74.tar.gz
android_packages_apps_Gallery2-fa9e745bec7c98ff68649959521efebbbe715c74.tar.bz2
android_packages_apps_Gallery2-fa9e745bec7c98ff68649959521efebbbe715c74.zip
Gallery2: Split DDM loading into two parts to hide latency
Split DDM loading into two parts: parsing and loading. Filter categories will be available once parsing is done. Ladoing of DDM will continue to happen in the background after parsing is complete. When the user selects the dual camera filter category, we will show a loading dialog if DDM loading is not yet complete. Conflicts: src/com/android/gallery3d/filtershow/category/MainPanel.java Change-Id: I5c7b454f0dcf00989d4bb0bbe95735b67785284d
-rw-r--r--res/values/filtershow_strings.xml1
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java56
-rw-r--r--src/com/android/gallery3d/filtershow/category/MainPanel.java9
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageShow.java2
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/MasterImage.java10
-rw-r--r--src/com/android/gallery3d/filtershow/tools/DualCameraNativeEngine.java1
6 files changed, 66 insertions, 13 deletions
diff --git a/res/values/filtershow_strings.xml b/res/values/filtershow_strings.xml
index fdc8f6a16..8e1c4e27f 100644
--- a/res/values/filtershow_strings.xml
+++ b/res/values/filtershow_strings.xml
@@ -339,6 +339,7 @@
<string name="fusion_pick_point">Pick Segment</string>
<string name="fusion_pick_underlay">Pick Underlay</string>
<string name="dualcam_no_segment_toast">No segment found at this point</string>
+ <string name="dualcam_filter_not_supported">Dual camera filters not supported for this image</string>
<string name="color">Color</string>
<string name="frames">Frames</string>
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 99449a45e..1824e7fd0 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -122,6 +122,7 @@ import com.android.gallery3d.filtershow.tools.XmpPresets;
import com.android.gallery3d.filtershow.tools.XmpPresets.XMresults;
import com.android.gallery3d.filtershow.ui.ExportDialog;
import com.android.gallery3d.filtershow.ui.FramedTextButton;
+import com.android.gallery3d.mpo.MpoParser;
import com.android.gallery3d.util.GalleryUtils;
import com.android.photos.data.GalleryBitmapPool;
import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine;
@@ -165,6 +166,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private LoadBitmapTask mLoadBitmapTask;
private LoadHighresBitmapTask mHiResBitmapTask;
+ private ParseMpoDataTask mParseMpoTask;
private LoadMpoDataTask mLoadMpoTask;
private Uri mOriginalImageUri = null;
@@ -767,8 +769,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mLoadBitmapTask.execute(uri);
if(DualCameraNativeEngine.getInstance().isLibLoaded()) {
- mLoadMpoTask = new LoadMpoDataTask();
- mLoadMpoTask.execute();
+ mParseMpoTask = new ParseMpoDataTask();
+ mParseMpoTask.execute();
} else {
MasterImage.getImage().setDepthMapLoadingStatus(DdmStatus.DDM_FAILED);
}
@@ -877,6 +879,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
return;
}
+ if (representation.getFilterType() == FilterRepresentation.TYPE_DUALCAM &&
+ MasterImage.getImage().getDepthMapLoadingStatus() == DdmStatus.DDM_FAILED) {
+ Toast.makeText(this, getString(R.string.dualcam_filter_not_supported), Toast.LENGTH_SHORT).show();
+ return;
+ }
if (representation instanceof FilterRotateRepresentation) {
FilterRotateRepresentation r = (FilterRotateRepresentation) representation;
r.rotateCW();
@@ -995,15 +1002,28 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
- private class LoadMpoDataTask extends AsyncTask<Void, Void, Boolean> {
+ private class ParseMpoDataTask extends AsyncTask<Void, Void, byte[]> {
@Override
- protected Boolean doInBackground(Void... params) {
- return MasterImage.getImage().loadMpo();
+ protected void onPreExecute() {
+ MasterImage.getImage().setDepthMapLoadingStatus(DdmStatus.DDM_PARSING);
}
@Override
- protected void onPostExecute(Boolean result) {
- MasterImage.getImage().setDepthMapLoadingStatus(result?DdmStatus.DDM_LOADED:DdmStatus.DDM_FAILED);
+ protected byte[] doInBackground(Void... params) {
+ MpoParser parser = MpoParser.parse(FilterShowActivity.this, MasterImage.getImage().getUri());
+ return parser.readImgData(false);
+ }
+
+ @Override
+ protected void onPostExecute(byte[] result) {
+ if(result == null) {
+ // parse failed
+ MasterImage.getImage().setDepthMapLoadingStatus(DdmStatus.DDM_FAILED);
+ } else {
+ mLoadMpoTask = new LoadMpoDataTask();
+ mLoadMpoTask.execute(result);
+ }
+
Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
if (currentPanel instanceof MainPanel) {
MainPanel mainPanel = (MainPanel) currentPanel;
@@ -1012,6 +1032,24 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
}
+ private class LoadMpoDataTask extends AsyncTask<byte[], Void, Boolean> {
+ @Override
+ protected void onPreExecute() {
+ MasterImage.getImage().setDepthMapLoadingStatus(DdmStatus.DDM_LOADING);
+ }
+
+ @Override
+ protected Boolean doInBackground(byte[]... params) {
+ return MasterImage.getImage().loadMpo(params[0]);
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ MasterImage.getImage().setDepthMapLoadingStatus(result?DdmStatus.DDM_LOADED:DdmStatus.DDM_FAILED);
+ stopLoadingIndicator();
+ }
+ }
+
public boolean isLoadingVisible() {
if(mLoadingDialog != null) {
return mLoadingDialog.isShowing();
@@ -1168,6 +1206,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mHiResBitmapTask.cancel(false);
}
+ if(mParseMpoTask != null) {
+ mParseMpoTask.cancel(false);
+ }
+
if(mLoadMpoTask != null) {
mLoadMpoTask.cancel(false);
}
diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java
index e10dd51b2..0d7d6f6ce 100644
--- a/src/com/android/gallery3d/filtershow/category/MainPanel.java
+++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java
@@ -329,6 +329,12 @@ public class MainPanel extends Fragment {
setCategoryFragment(categoryPanel, fromRight);
mCurrentSelected = DUALCAM;
selection(mCurrentSelected, true);
+
+ if(MasterImage.getImage().isDepthMapLoadingDone() == false) {
+ FilterShowActivity activity = (FilterShowActivity) getActivity();
+ if(activity.isLoadingVisible() == false)
+ activity.startLoadingIndicator();
+ }
}
public void showPanel(int currentPanel) {
@@ -430,7 +436,8 @@ public class MainPanel extends Fragment {
public void updateDualCameraButton() {
if(dualCamButton != null) {
DdmStatus status = MasterImage.getImage().getDepthMapLoadingStatus();
- boolean enable = (status == DdmStatus.DDM_LOADED);
+ boolean enable = (status == DdmStatus.DDM_LOADING ||
+ status == DdmStatus.DDM_LOADED);
dualCamButton.setVisibility(enable?View.VISIBLE:View.GONE);
TextView tvDualCam = (TextView) mEffectsTextContainer
.findViewById(R.id.tvDualCam);
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java
index 58bddce65..d6f7e228b 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java
@@ -275,7 +275,7 @@ public class ImageShow extends View implements OnGestureListener,
if(img.getLoadedPreset() != null
&& !img.getLoadedPreset().equals(img.getCurrentPreset())) {
return;
- } else if (img.isDepthMapLoadingDone()) {
+ } else if (img.isDepthMapParsingDone()) {
mActivity.stopLoadingIndicator();
}
}
diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
index 85f7a664d..ec0b1476c 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
@@ -922,10 +922,8 @@ public class MasterImage implements RenderingRequestCaller {
return mPreset.contains(FilterRepresentation.TYPE_TINYPLANET);
}
- public boolean loadMpo() {
+ public boolean loadMpo(byte[] auxiliaryMpoData) {
boolean loaded = false;
- MpoParser parser = MpoParser.parse(getActivity(), getUri());
- byte[] auxiliaryMpoData = parser.readImgData(false);
if(auxiliaryMpoData != null) {
Bitmap primaryBm = ImageLoader.loadBitmap(getActivity(), getUri(), null);
@@ -938,7 +936,6 @@ public class MasterImage implements RenderingRequestCaller {
String mpoFilepath = ImageLoader.getLocalPathFromUri(getActivity(), getUri());
// read auxiliary image and generate depth map.
Bitmap auxiliaryBm = BitmapFactory.decodeByteArray(auxiliaryMpoData, 0, auxiliaryMpoData.length);
- auxiliaryMpoData = null;
if(auxiliaryBm == null) {
primaryBm.recycle();
@@ -1007,6 +1004,11 @@ public class MasterImage implements RenderingRequestCaller {
return mImageBounds;
}
+ public boolean isDepthMapParsingDone() {
+ return (mDepthMapLoadingStatus == DdmStatus.DDM_LOADING ||
+ mDepthMapLoadingStatus == DdmStatus.DDM_FAILED);
+ }
+
public boolean isDepthMapLoadingDone() {
return (mDepthMapLoadingStatus == DdmStatus.DDM_LOADED ||
mDepthMapLoadingStatus == DdmStatus.DDM_FAILED);
diff --git a/src/com/android/gallery3d/filtershow/tools/DualCameraNativeEngine.java b/src/com/android/gallery3d/filtershow/tools/DualCameraNativeEngine.java
index 5a8581ff1..902f54070 100644
--- a/src/com/android/gallery3d/filtershow/tools/DualCameraNativeEngine.java
+++ b/src/com/android/gallery3d/filtershow/tools/DualCameraNativeEngine.java
@@ -52,6 +52,7 @@ public class DualCameraNativeEngine {
// Status of Depth Map loading for current image
public static enum DdmStatus {
DDM_IDLE,
+ DDM_PARSING,
DDM_LOADING,
DDM_LOADED,
DDM_FAILED