summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2013-09-26 14:57:30 -0700
committer Romain Guy <romainguy@google.com> 2013-09-26 22:01:01 +0000
commit33ed738d49dce3af5851d0566739e9ed593057a5 (patch)
treea3505e10b1cb75eec8e6ffa1d3bb23b99857a897
parentc449613ec6ffed7b4605a6708a3341ab2dd5320f (diff)
Expose View.executeHardwareAction()
Bug #10911502 Views creating hardware resources need a way to safely interact with the hardware. This new method invokes HardwareRenderer.safelyRun() which executes a Runnable after making sure the hardawre rendering context is in a valid state. With the OpenGL backend, executeHardwareAction() tries to call eglMakeCurrent() if needed. This method is not guaranteed to work. Change-Id: I38ec65132eeba85605cffb1a6de12b7a0184e213
-rw-r--r--core/java/android/view/TextureView.java4
-rw-r--r--core/java/android/view/View.java27
2 files changed, 29 insertions, 2 deletions
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index b2c9f8c6d37c..47f7628f8e88 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -213,8 +213,8 @@ public class TextureView extends View {
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- if (mLayer != null && mAttachInfo != null && mAttachInfo.mHardwareRenderer != null) {
- boolean success = mAttachInfo.mHardwareRenderer.safelyRun(new Runnable() {
+ if (mLayer != null) {
+ boolean success = executeHardwareAction(new Runnable() {
@Override
public void run() {
destroySurface();
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 4680e769f050..c67e0366d251 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -12368,6 +12368,33 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
}
+ /**
+ * This method ensures the hardware renderer is in a valid state
+ * before executing the specified action.
+ *
+ * This method will attempt to set a valid state even if the window
+ * the renderer is attached to was destroyed.
+ *
+ * This method is not guaranteed to work. If the hardware renderer
+ * does not exist or cannot be put in a valid state, this method
+ * will not executed the specified action.
+ *
+ * The specified action is executed synchronously.
+ *
+ * @param action The action to execute after the renderer is in a valid state
+ *
+ * @return True if the specified Runnable was executed, false otherwise
+ *
+ * @hide
+ */
+ public boolean executeHardwareAction(Runnable action) {
+ //noinspection SimplifiableIfStatement
+ if (mAttachInfo != null && mAttachInfo.mHardwareRenderer != null) {
+ return mAttachInfo.mHardwareRenderer.safelyRun(action);
+ }
+ return false;
+ }
+
void invalidateInheritedLayoutMode(int layoutModeOfRoot) {
}