Merge "Reinstate SurfaceView Background from N" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-06-05 23:57:01 +00:00
committed by Android (Google) Code Review

View File

@@ -31,6 +31,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.SystemClock;
import android.util.AttributeSet;
@@ -452,6 +453,14 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
}
}
private void updateOpaqueFlag() {
if (PixelFormat.formatHasAlpha(mRequestedFormat)) {
mSurfaceFlags |= SurfaceControl.OPAQUE;
} else {
mSurfaceFlags &= ~SurfaceControl.OPAQUE;
}
}
private Rect getParentSurfaceInsets() {
final ViewRootImpl root = getViewRootImpl();
if (root == null) {
@@ -522,7 +531,9 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
if (creating) {
mSurfaceSession = new SurfaceSession(viewRoot.mSurface);
mDeferredDestroySurfaceControl = mSurfaceControl;
mSurfaceControl = new SurfaceControl(mSurfaceSession,
updateOpaqueFlag();
mSurfaceControl = new SurfaceControlWithBackground(mSurfaceSession,
"SurfaceView - " + viewRoot.getTitle().toString(),
mSurfaceWidth, mSurfaceHeight, mFormat,
mSurfaceFlags);
@@ -1071,4 +1082,126 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
return mSurfaceFrame;
}
};
class SurfaceControlWithBackground extends SurfaceControl {
private SurfaceControl mBackgroundControl;
private boolean mOpaque = true;
public boolean mVisible = false;
public SurfaceControlWithBackground(SurfaceSession s,
String name, int w, int h, int format, int flags)
throws Exception {
super(s, name, w, h, format, flags);
mBackgroundControl = new SurfaceControl(s, "Background for - " + name, w, h,
PixelFormat.OPAQUE, flags | SurfaceControl.FX_SURFACE_DIM);
mOpaque = (flags & SurfaceControl.OPAQUE) != 0;
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
mBackgroundControl.setAlpha(alpha);
}
@Override
public void setLayer(int zorder) {
super.setLayer(zorder);
// -3 is below all other child layers as SurfaceView never goes below -2
mBackgroundControl.setLayer(-3);
}
@Override
public void setPosition(float x, float y) {
super.setPosition(x, y);
mBackgroundControl.setPosition(x, y);
}
@Override
public void setSize(int w, int h) {
super.setSize(w, h);
mBackgroundControl.setSize(w, h);
}
@Override
public void setWindowCrop(Rect crop) {
super.setWindowCrop(crop);
mBackgroundControl.setWindowCrop(crop);
}
@Override
public void setFinalCrop(Rect crop) {
super.setFinalCrop(crop);
mBackgroundControl.setFinalCrop(crop);
}
@Override
public void setLayerStack(int layerStack) {
super.setLayerStack(layerStack);
mBackgroundControl.setLayerStack(layerStack);
}
@Override
public void setOpaque(boolean isOpaque) {
super.setOpaque(isOpaque);
mOpaque = isOpaque;
updateBackgroundVisibility();
}
@Override
public void setSecure(boolean isSecure) {
super.setSecure(isSecure);
}
@Override
public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
super.setMatrix(dsdx, dtdx, dsdy, dtdy);
mBackgroundControl.setMatrix(dsdx, dtdx, dsdy, dtdy);
}
@Override
public void hide() {
super.hide();
mVisible = false;
updateBackgroundVisibility();
}
@Override
public void show() {
super.show();
mVisible = true;
updateBackgroundVisibility();
}
@Override
public void destroy() {
super.destroy();
mBackgroundControl.destroy();
}
@Override
public void release() {
super.release();
mBackgroundControl.release();
}
@Override
public void setTransparentRegionHint(Region region) {
super.setTransparentRegionHint(region);
mBackgroundControl.setTransparentRegionHint(region);
}
@Override
public void deferTransactionUntil(IBinder handle, long frame) {
super.deferTransactionUntil(handle, frame);
mBackgroundControl.deferTransactionUntil(handle, frame);
}
void updateBackgroundVisibility() {
if (mOpaque && mVisible) {
mBackgroundControl.show();
} else {
mBackgroundControl.hide();
}
}
}
}