diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 114 | ||||
-rw-r--r-- | core/java/android/view/Surface.java | 23 | ||||
-rw-r--r-- | core/java/android/view/SurfaceControl.java | 16 | ||||
-rw-r--r-- | core/java/android/view/SurfaceView.java | 94 | ||||
-rw-r--r-- | core/java/android/view/ViewRootImpl.java | 117 | ||||
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 2 |
6 files changed, 215 insertions, 151 deletions
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index ba64f6b..f215189 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -34,6 +34,8 @@ import android.os.SystemProperties; import android.os.Trace; import android.util.DisplayMetrics; import android.util.Log; +import android.view.Surface.OutOfResourcesException; + import com.google.android.gles_jni.EGLImpl; import javax.microedition.khronos.egl.EGL10; @@ -74,7 +76,7 @@ public abstract class HardwareRenderer { * System property used to enable or disable dirty regions invalidation. * This property is only queried if {@link #RENDER_DIRTY_REGIONS} is true. * The default value of this property is assumed to be true. - * + * * Possible values: * "true", to enable partial invalidates * "false", to disable partial invalidates @@ -134,7 +136,7 @@ public abstract class HardwareRenderer { /** * System property used to debug EGL configuration choice. - * + * * Possible values: * "choice", print the chosen configuration only * "all", print all possible configurations @@ -147,7 +149,7 @@ public abstract class HardwareRenderer { * Possible values: * "true", to enable dirty regions debugging * "false", to disable dirty regions debugging - * + * * @hide */ public static final String DEBUG_DIRTY_REGIONS_PROPERTY = "debug.hwui.show_dirty_regions"; @@ -208,14 +210,14 @@ public abstract class HardwareRenderer { /** * A process can set this flag to false to prevent the use of hardware * rendering. - * + * * @hide */ public static boolean sRendererDisabled = false; /** * Further hardware renderer disabling for the system process. - * + * * @hide */ public static boolean sSystemRendererDisabled = false; @@ -235,7 +237,7 @@ public abstract class HardwareRenderer { /** * Invoke this method to disable hardware rendering in the current process. - * + * * @hide */ public static void disable(boolean system) { @@ -248,7 +250,7 @@ public abstract class HardwareRenderer { /** * Indicates whether hardware acceleration is available under any form for * the view hierarchy. - * + * * @return True if the view hierarchy can potentially be hardware accelerated, * false otherwise */ @@ -258,30 +260,30 @@ public abstract class HardwareRenderer { /** * Destroys the hardware rendering context. - * + * * @param full If true, destroys all associated resources. */ abstract void destroy(boolean full); /** * Initializes the hardware renderer for the specified surface. - * + * * @param surface The surface to hardware accelerate - * + * * @return True if the initialization was successful, false otherwise. */ - abstract boolean initialize(Surface surface) throws Surface.OutOfResourcesException; - + abstract boolean initialize(Surface surface) throws OutOfResourcesException; + /** * Updates the hardware renderer for the specified surface. * * @param surface The surface to hardware accelerate */ - abstract void updateSurface(Surface surface) throws Surface.OutOfResourcesException; + abstract void updateSurface(Surface surface) throws OutOfResourcesException; /** * Destroys the layers used by the specified view hierarchy. - * + * * @param view The root of the view hierarchy */ abstract void destroyLayers(View view); @@ -289,11 +291,11 @@ public abstract class HardwareRenderer { /** * Destroys all hardware rendering resources associated with the specified * view hierarchy. - * + * * @param view The root of the view hierarchy */ abstract void destroyHardwareResources(View view); - + /** * This method should be invoked whenever the current hardware renderer * context should be reset. @@ -306,7 +308,7 @@ public abstract class HardwareRenderer { * This method should be invoked to ensure the hardware renderer is in * valid state (for instance, to ensure the correct EGL context is bound * to the current thread.) - * + * * @return true if the renderer is now valid, false otherwise */ abstract boolean validate(); @@ -314,7 +316,7 @@ public abstract class HardwareRenderer { /** * 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. * @@ -325,7 +327,7 @@ public abstract class HardwareRenderer { /** * Setup the hardware renderer for drawing. This is called whenever the * size of the target surface changes or when the surface is first created. - * + * * @param width Width of the drawing surface. * @param height Height of the drawing surface. */ @@ -384,7 +386,7 @@ public abstract class HardwareRenderer { /** * Sets the directory to use as a persistent storage for hardware rendering * resources. - * + * * @param cacheDir A directory the current process can write to * * @hide @@ -447,7 +449,7 @@ public abstract class HardwareRenderer { /** * Indicates that the specified hardware layer needs to be updated * as soon as possible. - * + * * @param layer The hardware layer that needs an update * * @see #flushLayerUpdates() @@ -481,7 +483,7 @@ public abstract class HardwareRenderer { * Invoked before a view is drawn by a hardware renderer. * This method can be used to apply transformations to the * canvas but no drawing command should be issued. - * + * * @param canvas The Canvas used to render the view. */ void onHardwarePreDraw(HardwareCanvas canvas); @@ -489,7 +491,7 @@ public abstract class HardwareRenderer { /** * Invoked after a view is drawn by a hardware renderer. * It is safe to invoke drawing commands from this method. - * + * * @param canvas The Canvas used to render the view. */ void onHardwarePostDraw(HardwareCanvas canvas); @@ -509,9 +511,9 @@ public abstract class HardwareRenderer { /** * Creates a new display list that can be used to record batches of * drawing operations. - * + * * @param name The name of the display list, used for debugging purpose. May be null. - * + * * @return A new display list. * * @hide @@ -521,20 +523,20 @@ public abstract class HardwareRenderer { /** * Creates a new hardware layer. A hardware layer built by calling this * method will be treated as a texture layer, instead of as a render target. - * + * * @param isOpaque Whether the layer should be opaque or not - * + * * @return A hardware layer */ abstract HardwareLayer createHardwareLayer(boolean isOpaque); /** * Creates a new hardware layer. - * + * * @param width The minimum width of the layer * @param height The minimum height of the layer * @param isOpaque Whether the layer should be opaque or not - * + * * @return A hardware layer */ abstract HardwareLayer createHardwareLayer(int width, int height, boolean isOpaque); @@ -544,7 +546,7 @@ public abstract class HardwareRenderer { * specified hardware layer. * * @param layer The layer to render into using a {@link android.graphics.SurfaceTexture} - * + * * @return A {@link SurfaceTexture} */ abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer); @@ -560,11 +562,11 @@ public abstract class HardwareRenderer { /** * Detaches the specified functor from the current functor execution queue. - * + * * @param functor The native functor to remove from the execution queue. - * - * @see HardwareCanvas#callDrawGLFunction(int) - * @see #attachFunctor(android.view.View.AttachInfo, int) + * + * @see HardwareCanvas#callDrawGLFunction(int) + * @see #attachFunctor(android.view.View.AttachInfo, int) */ abstract void detachFunctor(int functor); @@ -591,12 +593,12 @@ public abstract class HardwareRenderer { * @param width The width of the drawing surface. * @param height The height of the drawing surface. * @param surface The surface to hardware accelerate - * + * * @return true if the surface was initialized, false otherwise. Returning * false might mean that the surface was already initialized. */ boolean initializeIfNeeded(int width, int height, Surface surface) - throws Surface.OutOfResourcesException { + throws OutOfResourcesException { if (isRequested()) { // We lost the gl context, so recreate it. if (!isEnabled()) { @@ -618,10 +620,10 @@ public abstract class HardwareRenderer { /** * Creates a hardware renderer using OpenGL. - * + * * @param glVersion The version of OpenGL to use (1 for OpenGL 1, 11 for OpenGL 1.1, etc.) * @param translucent True if the surface is translucent, false otherwise - * + * * @return A hardware renderer backed by OpenGL. */ static HardwareRenderer createGlRenderer(int glVersion, boolean translucent) { @@ -636,7 +638,7 @@ public abstract class HardwareRenderer { * Invoke this method when the system is running out of memory. This * method will attempt to recover as much memory as possible, based on * the specified hint. - * + * * @param level Hint about the amount of memory that should be trimmed, * see {@link android.content.ComponentCallbacks} */ @@ -649,7 +651,7 @@ public abstract class HardwareRenderer { * Starts the process of trimming memory. Usually this call will setup * hardware rendering context and reclaim memory.Extra cleanup might * be required by calling {@link #endTrimMemory()}. - * + * * @param level Hint about the amount of memory that should be trimmed, * see {@link android.content.ComponentCallbacks} */ @@ -667,7 +669,7 @@ public abstract class HardwareRenderer { /** * Indicates whether hardware acceleration is currently enabled. - * + * * @return True if hardware acceleration is in use, false otherwise. */ boolean isEnabled() { @@ -676,7 +678,7 @@ public abstract class HardwareRenderer { /** * Indicates whether hardware acceleration is currently enabled. - * + * * @param enabled True if the hardware renderer is in use, false otherwise. */ void setEnabled(boolean enabled) { @@ -686,7 +688,7 @@ public abstract class HardwareRenderer { /** * Indicates whether hardware acceleration is currently request but not * necessarily enabled yet. - * + * * @return True if requested, false otherwise. */ boolean isRequested() { @@ -696,7 +698,7 @@ public abstract class HardwareRenderer { /** * Indicates whether hardware acceleration is currently requested but not * necessarily enabled yet. - * + * * @return True to request hardware acceleration, false otherwise. */ void setRequested(boolean requested) { @@ -837,7 +839,7 @@ public abstract class HardwareRenderer { Thread mEglThread; EGLSurface mEglSurface; - + GL mGl; HardwareCanvas mCanvas; @@ -1050,7 +1052,7 @@ public abstract class HardwareRenderer { } @Override - boolean initialize(Surface surface) throws Surface.OutOfResourcesException { + boolean initialize(Surface surface) throws OutOfResourcesException { if (isRequested() && !isEnabled()) { boolean contextCreated = initializeEgl(); mGl = createEglSurface(surface); @@ -1078,9 +1080,9 @@ public abstract class HardwareRenderer { } return false; } - + @Override - void updateSurface(Surface surface) throws Surface.OutOfResourcesException { + void updateSurface(Surface surface) throws OutOfResourcesException { if (isRequested() && isEnabled()) { createEglSurface(surface); } @@ -1094,15 +1096,15 @@ public abstract class HardwareRenderer { synchronized (sEglLock) { if (sEgl == null && sEglConfig == null) { sEgl = (EGL10) EGLContext.getEGL(); - + // Get to the default display. sEglDisplay = sEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY); - + if (sEglDisplay == EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed " + GLUtils.getEGLErrorString(sEgl.eglGetError())); } - + // We can now initialize EGL for that display int[] version = new int[2]; if (!sEgl.eglInitialize(sEglDisplay, version)) { @@ -1216,7 +1218,7 @@ public abstract class HardwareRenderer { Log.d(LOG_TAG, " CONFIG_CAVEAT = 0x" + Integer.toHexString(value[0])); } - GL createEglSurface(Surface surface) throws Surface.OutOfResourcesException { + GL createEglSurface(Surface surface) throws OutOfResourcesException { // Check preconditions. if (sEgl == null) { throw new RuntimeException("egl not initialized"); @@ -1228,7 +1230,7 @@ public abstract class HardwareRenderer { throw new RuntimeException("eglConfig not initialized"); } if (Thread.currentThread() != mEglThread) { - throw new IllegalStateException("HardwareRenderer cannot be used " + throw new IllegalStateException("HardwareRenderer cannot be used " + "from multiple threads"); } @@ -1394,8 +1396,8 @@ public abstract class HardwareRenderer { boolean canDraw() { return mGl != null && mCanvas != null; - } - + } + int onPreDraw(Rect dirty) { return DisplayList.STATUS_DONE; } @@ -1732,7 +1734,7 @@ public abstract class HardwareRenderer { * Ensures the current EGL context and surface are the ones we expect. * This method throws an IllegalStateException if invoked from a thread * that did not initialize EGL. - * + * * @return {@link #SURFACE_STATE_ERROR} if the correct EGL context cannot be made current, * {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or * {@link #SURFACE_STATE_SUCCESS} if the EGL context was the correct one diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 409db84..1bfda2d 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -116,6 +116,7 @@ public class Surface implements Parcelable { * * @param surfaceTexture The {@link SurfaceTexture} that is updated by this * Surface. + * @throws OutOfResourcesException if the surface could not be created. */ public Surface(SurfaceTexture surfaceTexture) { if (surfaceTexture == null) { @@ -124,12 +125,7 @@ public class Surface implements Parcelable { synchronized (mLock) { mName = surfaceTexture.toString(); - try { - setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture)); - } catch (OutOfResourcesException ex) { - // We can't throw OutOfResourcesException because it would be an API change. - throw new RuntimeException(ex); - } + setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture)); } } @@ -229,9 +225,12 @@ public class Surface implements Parcelable { * The caller may also pass <code>null</code> instead, in the case where the * entire surface should be redrawn. * @return A canvas for drawing into the surface. + * + * @throws IllegalArgumentException If the inOutDirty rectangle is not valid. + * @throws OutOfResourcesException If the canvas cannot be locked. */ public Canvas lockCanvas(Rect inOutDirty) - throws OutOfResourcesException, IllegalArgumentException { + throws Surface.OutOfResourcesException, IllegalArgumentException { synchronized (mLock) { checkNotReleasedLocked(); if (mLockedObject != 0) { @@ -239,7 +238,7 @@ public class Surface implements Parcelable { // double-lock, but that won't happen if mNativeObject was updated. We can't // abandon the old mLockedObject because it might still be in use, so instead // we just refuse to re-lock the Surface. - throw new RuntimeException("Surface was already locked"); + throw new IllegalStateException("Surface was already locked"); } mLockedObject = nativeLockCanvas(mNativeObject, mCanvas, inOutDirty); return mCanvas; @@ -266,7 +265,7 @@ public class Surface implements Parcelable { Integer.toHexString(mLockedObject) +")"); } if (mLockedObject == 0) { - throw new RuntimeException("Surface was not locked"); + throw new IllegalStateException("Surface was not locked"); } nativeUnlockCanvasAndPost(mLockedObject, canvas); nativeRelease(mLockedObject); @@ -411,9 +410,11 @@ public class Surface implements Parcelable { } /** - * Exception thrown when a surface couldn't be created or resized. + * Exception thrown when a Canvas couldn't be locked with {@link Surface#lockCanvas}, or + * when a SurfaceTexture could not successfully be allocated. */ - public static class OutOfResourcesException extends Exception { + @SuppressWarnings("serial") + public static class OutOfResourcesException extends RuntimeException { public OutOfResourcesException() { } public OutOfResourcesException(String name) { diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index dc31e0b..b22d5cf 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -24,6 +24,7 @@ import android.view.Surface; import android.os.IBinder; import android.os.SystemProperties; import android.util.Log; +import android.view.Surface.OutOfResourcesException; /** * SurfaceControl @@ -75,23 +76,12 @@ public class SurfaceControl { private final CloseGuard mCloseGuard = CloseGuard.get(); - private String mName; + private final String mName; int mNativeObject; // package visibility only for Surface.java access private static final boolean HEADLESS = "1".equals( SystemProperties.get("ro.config.headless", "0")); - /** - * Exception thrown when a surface couldn't be created or resized. - */ - public static class OutOfResourcesException extends Exception { - public OutOfResourcesException() { - } - public OutOfResourcesException(String name) { - super(name); - } - } - /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */ /** @@ -220,6 +210,8 @@ public class SurfaceControl { * @param h The surface initial height. * @param flags The surface creation flags. Should always include {@link #HIDDEN} * in the creation flags. + * + * @throws throws OutOfResourcesException If the SurfaceControl cannot be created. */ public SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 8b2b556..1e4b29f 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -43,7 +43,7 @@ import java.util.concurrent.locks.ReentrantLock; * You can control the format of this surface and, if you like, its size; the * SurfaceView takes care of placing the surface at the correct location on the * screen - * + * * <p>The surface is Z ordered so that it is behind the window holding its * SurfaceView; the SurfaceView punches a hole in its window to allow its * surface to be displayed. The view hierarchy will take care of correctly @@ -52,7 +52,7 @@ import java.util.concurrent.locks.ReentrantLock; * buttons on top of the Surface, though note however that it can have an * impact on performance since a full alpha-blended composite will be performed * each time the Surface changes. - * + * * <p> The transparent region that makes the surface visible is based on the * layout positions in the view hierarchy. If the post-layout transform * properties are used to draw a sibling view on top of the SurfaceView, the @@ -60,16 +60,16 @@ import java.util.concurrent.locks.ReentrantLock; * * <p>Access to the underlying surface is provided via the SurfaceHolder interface, * which can be retrieved by calling {@link #getHolder}. - * + * * <p>The Surface will be created for you while the SurfaceView's window is * visible; you should implement {@link SurfaceHolder.Callback#surfaceCreated} * and {@link SurfaceHolder.Callback#surfaceDestroyed} to discover when the * Surface is created and destroyed as the window is shown and hidden. - * + * * <p>One of the purposes of this class is to provide a surface in which a * secondary thread can render into the screen. If you are going to use it * this way, you need to be aware of some threading semantics: - * + * * <ul> * <li> All SurfaceView and * {@link SurfaceHolder.Callback SurfaceHolder.Callback} methods will be called @@ -91,7 +91,7 @@ public class SurfaceView extends View { = new ArrayList<SurfaceHolder.Callback>(); final int[] mLocation = new int[2]; - + final ReentrantLock mSurfaceLock = new ReentrantLock(); final Surface mSurface = new Surface(); // Current surface in use final Surface mNewSurface = new Surface(); // New surface we are switching to @@ -106,13 +106,13 @@ public class SurfaceView extends View { final Rect mOverscanInsets = new Rect(); final Rect mContentInsets = new Rect(); final Configuration mConfiguration = new Configuration(); - + static final int KEEP_SCREEN_ON_MSG = 1; static final int GET_NEW_SURFACE_MSG = 2; static final int UPDATE_WINDOW_MSG = 3; - + int mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; - + boolean mIsCreating = false; final Handler mHandler = new Handler() { @@ -131,14 +131,15 @@ public class SurfaceView extends View { } } }; - + final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() { + @Override public void onScrollChanged() { updateWindow(false, false); } }; - + boolean mRequestedVisible = false; boolean mWindowVisibility = false; boolean mViewVisibility = false; @@ -152,7 +153,7 @@ public class SurfaceView extends View { boolean mHaveFrame = false; boolean mSurfaceCreated = false; long mLastLockTime = 0; - + boolean mVisible = false; int mLeft = -1; int mTop = -1; @@ -169,7 +170,7 @@ public class SurfaceView extends View { new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { - // reposition ourselves where the surface is + // reposition ourselves where the surface is mHaveFrame = getWidth() > 0 && getHeight() > 0; updateWindow(false, false); return true; @@ -181,7 +182,7 @@ public class SurfaceView extends View { super(context); init(); } - + public SurfaceView(Context context, AttributeSet attrs) { super(context, attrs); init(); @@ -195,11 +196,11 @@ public class SurfaceView extends View { private void init() { setWillNotDraw(true); } - + /** * Return the SurfaceHolder providing access and control over this * SurfaceView's underlying surface. - * + * * @return SurfaceHolder The holder of the surface. */ public SurfaceHolder getHolder() { @@ -285,7 +286,7 @@ public class SurfaceView extends View { : getDefaultSize(0, heightMeasureSpec); setMeasuredDimension(width, height); } - + /** @hide */ @Override protected boolean setFrame(int left, int top, int right, int bottom) { @@ -299,7 +300,7 @@ public class SurfaceView extends View { if (mWindowType == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { return super.gatherTransparentRegion(region); } - + boolean opaque = true; if ((mPrivateFlags & PFLAG_SKIP_DRAW) == 0) { // this view draws, remove it from the transparent region @@ -350,10 +351,10 @@ public class SurfaceView extends View { * regular surface view in the window (but still behind the window itself). * This is typically used to place overlays on top of an underlying media * surface view. - * + * * <p>Note that this must be set before the surface view's containing * window is attached to the window manager. - * + * * <p>Calling this overrides any previous call to {@link #setZOrderOnTop}. */ public void setZOrderMediaOverlay(boolean isMediaOverlay) { @@ -361,7 +362,7 @@ public class SurfaceView extends View { ? WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY : WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; } - + /** * Control whether the surface view's surface is placed on top of its * window. Normally it is placed behind the window, to allow it to @@ -369,10 +370,10 @@ public class SurfaceView extends View { * hierarchy. By setting this, you cause it to be placed above the * window. This means that none of the contents of the window this * SurfaceView is in will be visible on top of its surface. - * + * * <p>Note that this must be set before the surface view's containing * window is attached to the window manager. - * + * * <p>Calling this overrides any previous call to {@link #setZOrderMediaOverlay}. */ public void setZOrderOnTop(boolean onTop) { @@ -427,7 +428,7 @@ public class SurfaceView extends View { if (mTranslator != null) { mSurface.setCompatibilityTranslator(mTranslator); } - + int myWidth = mRequestedWidth; if (myWidth <= 0) myWidth = getWidth(); int myHeight = mRequestedHeight; @@ -458,7 +459,7 @@ public class SurfaceView extends View { mFormat = mRequestedFormat; // Scaling/Translate window's layout here because mLayout is not used elsewhere. - + // Places the window relative mLayout.x = mLeft; mLayout.y = mTop; @@ -467,7 +468,7 @@ public class SurfaceView extends View { if (mTranslator != null) { mTranslator.translateLayoutParamsInAppWindowToScreen(mLayout); } - + mLayout.format = mRequestedFormat; mLayout.flags |=WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE @@ -489,7 +490,7 @@ public class SurfaceView extends View { mSession.addToDisplayWithoutInputChannel(mWindow, mWindow.mSeq, mLayout, mVisible ? VISIBLE : GONE, display.getDisplayId(), mContentInsets); } - + boolean realSizeChanged; boolean reportDrawNeeded; @@ -501,7 +502,7 @@ public class SurfaceView extends View { reportDrawNeeded = mReportDrawNeeded; mReportDrawNeeded = false; mDrawingStopped = !visible; - + if (DEBUG) Log.i(TAG, "Cur surface: " + mSurface); relayoutResult = mSession.relayout( @@ -527,7 +528,7 @@ public class SurfaceView extends View { mSurfaceFrame.right = (int) (mWinFrame.width() * appInvertedScale + 0.5f); mSurfaceFrame.bottom = (int) (mWinFrame.height() * appInvertedScale + 0.5f); } - + final int surfaceWidth = mSurfaceFrame.right; final int surfaceHeight = mSurfaceFrame.bottom; realSizeChanged = mLastSurfaceWidth != surfaceWidth @@ -667,10 +668,12 @@ public class SurfaceView extends View { } } + @Override public void dispatchAppVisibility(boolean visible) { // The point of SurfaceView is to let the app control the surface. } + @Override public void dispatchGetNewSurface() { SurfaceView surfaceView = mSurfaceView.get(); if (surfaceView != null) { @@ -679,10 +682,12 @@ public class SurfaceView extends View { } } + @Override public void windowFocusChanged(boolean hasFocus, boolean touchEnabled) { Log.w("SurfaceView", "Unexpected focus in surface: focus=" + hasFocus + ", touchEnabled=" + touchEnabled); } + @Override public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { } @@ -690,30 +695,34 @@ public class SurfaceView extends View { int mCurHeight = -1; } - private SurfaceHolder mSurfaceHolder = new SurfaceHolder() { - + private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() { + private static final String LOG_TAG = "SurfaceHolder"; - + + @Override public boolean isCreating() { return mIsCreating; } + @Override public void addCallback(Callback callback) { synchronized (mCallbacks) { - // This is a linear search, but in practice we'll + // This is a linear search, but in practice we'll // have only a couple callbacks, so it doesn't matter. - if (mCallbacks.contains(callback) == false) { + if (mCallbacks.contains(callback) == false) { mCallbacks.add(callback); } } } + @Override public void removeCallback(Callback callback) { synchronized (mCallbacks) { mCallbacks.remove(callback); } } - + + @Override public void setFixedSize(int width, int height) { if (mRequestedWidth != width || mRequestedHeight != height) { mRequestedWidth = width; @@ -722,6 +731,7 @@ public class SurfaceView extends View { } } + @Override public void setSizeFromLayout() { if (mRequestedWidth != -1 || mRequestedHeight != -1) { mRequestedWidth = mRequestedHeight = -1; @@ -729,6 +739,7 @@ public class SurfaceView extends View { } } + @Override public void setFormat(int format) { // for backward compatibility reason, OPAQUE always @@ -745,15 +756,17 @@ public class SurfaceView extends View { /** * @deprecated setType is now ignored. */ + @Override @Deprecated public void setType(int type) { } + @Override public void setKeepScreenOn(boolean screenOn) { Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG); msg.arg1 = screenOn ? 1 : 0; mHandler.sendMessage(msg); } - + /** * Gets a {@link Canvas} for drawing into the SurfaceView's Surface * @@ -763,6 +776,7 @@ public class SurfaceView extends View { * The caller must redraw the entire surface. * @return A canvas for drawing into the surface. */ + @Override public Canvas lockCanvas() { return internalLockCanvas(null); } @@ -782,6 +796,7 @@ public class SurfaceView extends View { * entire surface should be redrawn. * @return A canvas for drawing into the surface. */ + @Override public Canvas lockCanvas(Rect inOutDirty) { return internalLockCanvas(inOutDirty); } @@ -806,7 +821,7 @@ public class SurfaceView extends View { mLastLockTime = SystemClock.uptimeMillis(); return c; } - + // If the Surface is not ready to be drawn, then return null, // but throttle calls to this function so it isn't called more // than every 100ms. @@ -821,7 +836,7 @@ public class SurfaceView extends View { } mLastLockTime = now; mSurfaceLock.unlock(); - + return null; } @@ -831,15 +846,18 @@ public class SurfaceView extends View { * * @param canvas The canvas previously obtained from {@link #lockCanvas}. */ + @Override public void unlockCanvasAndPost(Canvas canvas) { mSurface.unlockCanvasAndPost(canvas); mSurfaceLock.unlock(); } + @Override public Surface getSurface() { return mSurface; } + @Override public Rect getSurfaceFrame() { return mSurfaceFrame; } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index c7d61eb..50d5d45 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -68,6 +68,7 @@ import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; +import android.view.Surface.OutOfResourcesException; import android.widget.Scroller; import com.android.internal.R; @@ -187,7 +188,7 @@ public final class ViewRootImpl implements ViewParent, InputQueue mInputQueue; FallbackEventHandler mFallbackEventHandler; Choreographer mChoreographer; - + final Rect mTempRect; // used in the transaction to not thrash the heap. final Rect mVisRect; // used to retrieve visible rect of focused view. @@ -278,8 +279,8 @@ public final class ViewRootImpl implements ViewParent, volatile Object mLocalDragState; final PointF mDragPoint = new PointF(); final PointF mLastTouchPoint = new PointF(); - - private boolean mProfileRendering; + + private boolean mProfileRendering; private Choreographer.FrameCallback mRenderProfiler; private boolean mRenderProfilingEnabled; @@ -291,7 +292,7 @@ public final class ViewRootImpl implements ViewParent, private int mFpsNumFrames; private final ArrayList<DisplayList> mDisplayLists = new ArrayList<DisplayList>(); - + /** * see {@link #playSoundEffect(int)} */ @@ -332,7 +333,7 @@ public final class ViewRootImpl implements ViewParent, int localValue; int localChanges; } - + public ViewRootImpl(Context context, Display display) { mContext = context; mWindowSession = WindowManagerGlobal.getWindowSession(); @@ -383,13 +384,13 @@ public final class ViewRootImpl implements ViewParent, } } } - + public static void addConfigCallback(ComponentCallbacks callback) { synchronized (sConfigCallbacks) { sConfigCallbacks.add(callback); } } - + // FIXME for perf testing only private boolean mProfile = false; @@ -514,7 +515,7 @@ public final class ViewRootImpl implements ViewParent, attrs.restore(); } } - + if (mTranslator != null) { mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); } @@ -680,7 +681,7 @@ public final class ViewRootImpl implements ViewParent, if (mTranslator != null) return; // Try to enable hardware acceleration if requested - final boolean hardwareAccelerated = + final boolean hardwareAccelerated = (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; if (hardwareAccelerated) { @@ -707,7 +708,7 @@ public final class ViewRootImpl implements ViewParent, // Don't enable hardware acceleration when we're not on the main thread if (!HardwareRenderer.sSystemRendererDisabled && Looper.getMainLooper() != Looper.myLooper()) { - Log.w(HardwareRenderer.LOG_TAG, "Attempting to initialize hardware " + Log.w(HardwareRenderer.LOG_TAG, "Attempting to initialize hardware " + "acceleration outside of the main thread, aborting"); return; } @@ -918,6 +919,7 @@ public final class ViewRootImpl implements ViewParent, return r.intersect(0, 0, mWidth, mHeight); } + @Override public void bringChildToFront(View child) { } @@ -1152,9 +1154,9 @@ public final class ViewRootImpl implements ViewParent, mLastInCompatMode = true; } } - + mWindowAttributesChangesFlag = 0; - + Rect frame = mWinFrame; if (mFirst) { mFullRedrawNeeded = true; @@ -1522,7 +1524,7 @@ public final class ViewRootImpl implements ViewParent, try { hwInitialized = mAttachInfo.mHardwareRenderer.initialize( mHolder.getSurface()); - } catch (Surface.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); return; } @@ -1549,7 +1551,7 @@ public final class ViewRootImpl implements ViewParent, mFullRedrawNeeded = true; try { mAttachInfo.mHardwareRenderer.updateSurface(mHolder.getSurface()); - } catch (Surface.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); return; } @@ -1644,23 +1646,23 @@ public final class ViewRootImpl implements ViewParent, || mHeight != host.getMeasuredHeight() || contentInsetsChanged) { int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); - + if (DEBUG_LAYOUT) Log.v(TAG, "Ooops, something changed! mWidth=" + mWidth + " measuredWidth=" + host.getMeasuredWidth() + " mHeight=" + mHeight + " measuredHeight=" + host.getMeasuredHeight() + " coveredInsetsChanged=" + contentInsetsChanged); - + // Ask host how big it wants to be performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); - + // Implementation of weights from WindowManager.LayoutParams // We just grow the dimensions as needed and re-measure if // needs be int width = host.getMeasuredWidth(); int height = host.getMeasuredHeight(); boolean measureAgain = false; - + if (lp.horizontalWeight > 0.0f) { width += (int) ((mWidth - width) * lp.horizontalWeight); childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, @@ -1673,14 +1675,14 @@ public final class ViewRootImpl implements ViewParent, MeasureSpec.EXACTLY); measureAgain = true; } - + if (measureAgain) { if (DEBUG_LAYOUT) Log.v(TAG, "And hey let's measure once more: width=" + width + " height=" + height); performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); } - + layoutRequested = true; } } @@ -1851,7 +1853,7 @@ public final class ViewRootImpl implements ViewParent, } mPendingTransitions.clear(); } - + performDraw(); } } else { @@ -2078,6 +2080,7 @@ public final class ViewRootImpl implements ViewParent, return validLayoutRequesters; } + @Override public void requestTransparentRegion(View child) { // the test below should not fail unless someone is messing with us checkThread(); @@ -2128,10 +2131,12 @@ public final class ViewRootImpl implements ViewParent, int mResizeAlpha; final Paint mResizePaint = new Paint(); + @Override public void onHardwarePreDraw(HardwareCanvas canvas) { canvas.translate(0, -mHardwareYOffset); } + @Override public void onHardwarePostDraw(HardwareCanvas canvas) { if (mResizeBuffer != null) { mResizePaint.setAlpha(mResizeAlpha); @@ -2365,7 +2370,7 @@ public final class ViewRootImpl implements ViewParent, try { attachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight, mHolder.getSurface()); - } catch (Surface.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); return; } @@ -2741,6 +2746,7 @@ public final class ViewRootImpl implements ViewParent, mAccessibilityFocusedVirtualView = node; } + @Override public void requestChildFocus(View child, View focused) { if (DEBUG_INPUT_RESIZE) { Log.v(TAG, "Request child focus: focus now " + focused); @@ -2749,6 +2755,7 @@ public final class ViewRootImpl implements ViewParent, scheduleTraversals(); } + @Override public void clearChildFocus(View child) { if (DEBUG_INPUT_RESIZE) { Log.v(TAG, "Clearing child focus"); @@ -2762,6 +2769,7 @@ public final class ViewRootImpl implements ViewParent, return null; } + @Override public void focusableViewAvailable(View v) { checkThread(); if (mView != null) { @@ -2783,6 +2791,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void recomputeViewAttributes(View child) { checkThread(); if (mView == child) { @@ -3076,7 +3085,7 @@ public final class ViewRootImpl implements ViewParent, try { mAttachInfo.mHardwareRenderer.initializeIfNeeded( mWidth, mHeight, mHolder.getSurface()); - } catch (Surface.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Log.e(TAG, "OutOfResourcesException locking surface", e); try { if (!mWindowSession.outOfMemory(mWindow)) { @@ -4990,7 +4999,7 @@ public final class ViewRootImpl implements ViewParent, // most recent data. mSeq = args.seq; mAttachInfo.mForceReportNewAttributes = true; - scheduleTraversals(); + scheduleTraversals(); } if (mView == null) return; if (args.localChanges != 0) { @@ -5080,7 +5089,7 @@ public final class ViewRootImpl implements ViewParent, if (restore) { params.restore(); } - + if (mTranslator != null) { mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); @@ -5093,6 +5102,7 @@ public final class ViewRootImpl implements ViewParent, /** * {@inheritDoc} */ + @Override public void playSoundEffect(int effectId) { checkThread(); @@ -5133,6 +5143,7 @@ public final class ViewRootImpl implements ViewParent, /** * {@inheritDoc} */ + @Override public boolean performHapticFeedback(int effectId, boolean always) { try { return mWindowSession.performHapticFeedback(mWindow, effectId, always); @@ -5144,6 +5155,7 @@ public final class ViewRootImpl implements ViewParent, /** * {@inheritDoc} */ + @Override public View focusSearch(View focused, int direction) { checkThread(); if (!(mView instanceof ViewGroup)) { @@ -5155,7 +5167,7 @@ public final class ViewRootImpl implements ViewParent, public void debug() { mView.debug(); } - + public void dumpGfxInfo(int[] info) { info[0] = info[1] = 0; if (mView != null) { @@ -5574,8 +5586,8 @@ public final class ViewRootImpl implements ViewParent, final class InvalidateOnAnimationRunnable implements Runnable { private boolean mPosted; - private ArrayList<View> mViews = new ArrayList<View>(); - private ArrayList<AttachInfo.InvalidateInfo> mViewRects = + private final ArrayList<View> mViews = new ArrayList<View>(); + private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = new ArrayList<AttachInfo.InvalidateInfo>(); private View[] mTempViews; private AttachInfo.InvalidateInfo[] mTempViewRects; @@ -5813,20 +5825,25 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public boolean showContextMenuForChild(View originalView) { return false; } + @Override public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { return null; } + @Override public void createContextMenu(ContextMenu menu) { } + @Override public void childDrawableStateChanged(View child) { } + @Override public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { if (mView == null) { return false; @@ -5958,10 +5975,12 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { // ViewAncestor never intercepts touch event, so this can be a no-op } + @Override public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); if (rectangle != null) { @@ -5977,6 +5996,7 @@ public final class ViewRootImpl implements ViewParent, return scrolled; } + @Override public void childHasTransientStateChanged(View child, boolean hasTransientState) { // Do nothing. } @@ -5997,20 +6017,23 @@ public final class ViewRootImpl implements ViewParent, // Not currently interesting -- from changing between fixed and layout size. } + @Override public void setFormat(int format) { ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); } + @Override public void setType(int type) { ((RootViewSurfaceTaker)mView).setSurfaceType(type); } - + @Override public void onUpdateSurface() { // We take care of format and type changes on our own. throw new IllegalStateException("Shouldn't be here"); } + @Override public boolean isCreating() { return mIsCreating; } @@ -6020,7 +6043,8 @@ public final class ViewRootImpl implements ViewParent, throw new UnsupportedOperationException( "Currently only support sizing from layout"); } - + + @Override public void setKeepScreenOn(boolean screenOn) { ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); } @@ -6035,6 +6059,7 @@ public final class ViewRootImpl implements ViewParent, mWindowSession = viewAncestor.mWindowSession; } + @Override public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, Rect visibleInsets, boolean reportDraw, Configuration newConfig) { final ViewRootImpl viewAncestor = mViewAncestor.get(); @@ -6052,6 +6077,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void dispatchAppVisibility(boolean visible) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6059,6 +6085,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void dispatchScreenState(boolean on) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6066,6 +6093,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void dispatchGetNewSurface() { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6073,6 +6101,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6089,6 +6118,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6119,14 +6149,16 @@ public final class ViewRootImpl implements ViewParent, } } } - + + @Override public void closeSystemDialogs(String reason) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { viewAncestor.dispatchCloseSystemDialogs(reason); } } - + + @Override public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, boolean sync) { if (sync) { @@ -6137,6 +6169,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void dispatchWallpaperCommand(String action, int x, int y, int z, Bundle extras, boolean sync) { if (sync) { @@ -6148,6 +6181,7 @@ public final class ViewRootImpl implements ViewParent, } /* Drag/drop */ + @Override public void dispatchDragEvent(DragEvent event) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6155,6 +6189,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, int localValue, int localChanges) { final ViewRootImpl viewAncestor = mViewAncestor.get(); @@ -6164,6 +6199,7 @@ public final class ViewRootImpl implements ViewParent, } } + @Override public void doneAnimating() { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { @@ -6178,50 +6214,63 @@ public final class ViewRootImpl implements ViewParent, } } - private SurfaceHolder mHolder = new SurfaceHolder() { + private final SurfaceHolder mHolder = new SurfaceHolder() { // we only need a SurfaceHolder for opengl. it would be nice // to implement everything else though, especially the callback // support (opengl doesn't make use of it right now, but eventually // will). + @Override public Surface getSurface() { return mSurface; } + @Override public boolean isCreating() { return false; } + @Override public void addCallback(Callback callback) { } + @Override public void removeCallback(Callback callback) { } + @Override public void setFixedSize(int width, int height) { } + @Override public void setSizeFromLayout() { } + @Override public void setFormat(int format) { } + @Override public void setType(int type) { } + @Override public void setKeepScreenOn(boolean screenOn) { } + @Override public Canvas lockCanvas() { return null; } + @Override public Canvas lockCanvas(Rect dirty) { return null; } + @Override public void unlockCanvasAndPost(Canvas canvas) { } + @Override public Rect getSurfaceFrame() { return null; } @@ -6316,6 +6365,7 @@ public final class ViewRootImpl implements ViewParent, */ final class AccessibilityInteractionConnectionManager implements AccessibilityStateChangeListener { + @Override public void onAccessibilityStateChanged(boolean enabled) { if (enabled) { ensureConnection(); @@ -6491,6 +6541,7 @@ public final class ViewRootImpl implements ViewParent, public View mSource; public long mLastEventTimeMillis; + @Override public void run() { // The accessibility may be turned off while we were waiting so check again. if (AccessibilityManager.getInstance(mContext).isEnabled()) { diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index bacfdf6..0c9b3bc 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -37,7 +37,7 @@ namespace android { static const char* const OutOfResourcesException = - "android/graphics/SurfaceTexture$OutOfResourcesException"; + "android/view/Surface$OutOfResourcesException"; static const char* const IllegalStateException = "java/lang/IllegalStateException"; const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture"; |