Skip to content

Commit 63f1c43

Browse files
committed
update to new SurfaceComposerClient API
Change-Id: I8f2c96df56fe3a851b8ec03bb8734db0b6bea3d5
1 parent d2a8df9 commit 63f1c43

File tree

4 files changed

+58
-112
lines changed

4 files changed

+58
-112
lines changed

core/java/android/view/Surface.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,8 @@ private static native void nativeSetDisplaySurface(
262262
IBinder displayToken, SurfaceTexture surfaceTexture);
263263
private static native void nativeSetDisplayLayerStack(
264264
IBinder displayToken, int layerStack);
265-
private static native void nativeSetDisplayOrientation(
266-
IBinder displayToken, int orientation);
267-
private static native void nativeSetDisplayViewport(
268-
IBinder displayToken, Rect viewport);
269-
private static native void nativeSetDisplayFrame(
270-
IBinder displayToken, Rect frame);
265+
private static native void nativeSetDisplayProjection(
266+
IBinder displayToken, int orientation, Rect layerStackRect, Rect displayRect);
271267
private static native boolean nativeGetDisplayInfo(
272268
IBinder displayToken, PhysicalDisplayInfo outInfo);
273269

@@ -617,33 +613,18 @@ public static void setDisplayLayerStack(IBinder displayToken, int layerStack) {
617613
}
618614

619615
/** @hide */
620-
public static void setDisplayOrientation(IBinder displayToken, int orientation) {
616+
public static void setDisplayProjection(IBinder displayToken,
617+
int orientation, Rect layerStackRect, Rect displayRect) {
621618
if (displayToken == null) {
622619
throw new IllegalArgumentException("displayToken must not be null");
623620
}
624-
nativeSetDisplayOrientation(displayToken, orientation);
625-
}
626-
627-
/** @hide */
628-
public static void setDisplayViewport(IBinder displayToken, Rect viewport) {
629-
if (displayToken == null) {
630-
throw new IllegalArgumentException("displayToken must not be null");
631-
}
632-
if (viewport == null) {
633-
throw new IllegalArgumentException("viewport must not be null");
634-
}
635-
nativeSetDisplayViewport(displayToken, viewport);
636-
}
637-
638-
/** @hide */
639-
public static void setDisplayFrame(IBinder displayToken, Rect frame) {
640-
if (displayToken == null) {
641-
throw new IllegalArgumentException("displayToken must not be null");
621+
if (layerStackRect == null) {
622+
throw new IllegalArgumentException("layerStackRect must not be null");
642623
}
643-
if (frame == null) {
644-
throw new IllegalArgumentException("frame must not be null");
624+
if (displayRect == null) {
625+
throw new IllegalArgumentException("displayRect must not be null");
645626
}
646-
nativeSetDisplayFrame(displayToken, frame);
627+
nativeSetDisplayProjection(displayToken, orientation, layerStackRect, displayRect);
647628
}
648629

649630
/** @hide */

core/jni/android_view_Surface.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -647,38 +647,24 @@ static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
647647
SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
648648
}
649649

650-
static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
651-
jobject tokenObj, jint orientation) {
650+
static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
651+
jobject tokenObj, jint orientation, jobject rect1Obj, jobject rect2Obj) {
652652
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
653653
if (token == NULL) return;
654654

655-
SurfaceComposerClient::setDisplayOrientation(token, orientation);
656-
}
657-
658-
static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz,
659-
jobject tokenObj, jobject rectObj) {
660-
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
661-
if (token == NULL) return;
655+
Rect rect1;
656+
rect1.left = env->GetIntField(rect1Obj, gRectClassInfo.left);
657+
rect1.top = env->GetIntField(rect1Obj, gRectClassInfo.top);
658+
rect1.right = env->GetIntField(rect1Obj, gRectClassInfo.right);
659+
rect1.bottom = env->GetIntField(rect1Obj, gRectClassInfo.bottom);
662660

663-
Rect rect;
664-
rect.left = env->GetIntField(rectObj, gRectClassInfo.left);
665-
rect.top = env->GetIntField(rectObj, gRectClassInfo.top);
666-
rect.right = env->GetIntField(rectObj, gRectClassInfo.right);
667-
rect.bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
668-
SurfaceComposerClient::setDisplayViewport(token, rect);
669-
}
670-
671-
static void nativeSetDisplayFrame(JNIEnv* env, jclass clazz,
672-
jobject tokenObj, jobject rectObj) {
673-
sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
674-
if (token == NULL) return;
661+
Rect rect2;
662+
rect2.left = env->GetIntField(rect2Obj, gRectClassInfo.left);
663+
rect2.top = env->GetIntField(rect2Obj, gRectClassInfo.top);
664+
rect2.right = env->GetIntField(rect2Obj, gRectClassInfo.right);
665+
rect2.bottom = env->GetIntField(rect2Obj, gRectClassInfo.bottom);
675666

676-
Rect rect;
677-
rect.left = env->GetIntField(rectObj, gRectClassInfo.left);
678-
rect.top = env->GetIntField(rectObj, gRectClassInfo.top);
679-
rect.right = env->GetIntField(rectObj, gRectClassInfo.right);
680-
rect.bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
681-
SurfaceComposerClient::setDisplayFrame(token, rect);
667+
SurfaceComposerClient::setDisplayProjection(token, orientation, rect1, rect2);
682668
}
683669

684670
static jboolean nativeGetDisplayInfo(JNIEnv* env, jclass clazz,
@@ -818,12 +804,8 @@ static JNINativeMethod gSurfaceMethods[] = {
818804
(void*)nativeSetDisplaySurface },
819805
{"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
820806
(void*)nativeSetDisplayLayerStack },
821-
{"nativeSetDisplayOrientation", "(Landroid/os/IBinder;I)V",
822-
(void*)nativeSetDisplayOrientation },
823-
{"nativeSetDisplayViewport", "(Landroid/os/IBinder;Landroid/graphics/Rect;)V",
824-
(void*)nativeSetDisplayViewport },
825-
{"nativeSetDisplayFrame", "(Landroid/os/IBinder;Landroid/graphics/Rect;)V",
826-
(void*)nativeSetDisplayFrame },
807+
{"nativeSetDisplayProjection", "(Landroid/os/IBinder;ILandroid/graphics/Rect;Landroid/graphics/Rect;)V",
808+
(void*)nativeSetDisplayProjection },
827809
{"nativeGetDisplayInfo", "(Landroid/os/IBinder;Landroid/view/Surface$PhysicalDisplayInfo;)Z",
828810
(void*)nativeGetDisplayInfo },
829811
{"nativeCopyFrom", "(Landroid/view/Surface;)V",

services/java/com/android/server/display/DisplayDevice.java

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ abstract class DisplayDevice {
3838
// the display manager service. The display device shouldn't really be looking at these.
3939
private int mCurrentLayerStack = -1;
4040
private int mCurrentOrientation = -1;
41-
private Rect mCurrentViewport;
42-
private Rect mCurrentFrame;
41+
private Rect mCurrentLayerStackRect;
42+
private Rect mCurrentDisplayRect;
4343

4444
// The display device does own its surface texture, but it should only set it
4545
// within a transaction from performTraversalInTransactionLocked.
@@ -117,44 +117,26 @@ public final void setLayerStackInTransactionLocked(int layerStack) {
117117
}
118118

119119
/**
120-
* Sets the display orientation while in a transaction.
120+
* Sets the display projection while in a transaction.
121+
*
122+
* @param orientation defines the display's orientation
123+
* @param layerStackRect defines which area of the window manager coordinate
124+
* space will be used
125+
* @param displayRect defines where on the display will layerStackRect be
126+
* mapped to. displayRect is specified post-orientation, that is
127+
* it uses the orientation seen by the end-user
121128
*/
122-
public final void setOrientationInTransactionLocked(int orientation) {
123-
if (mCurrentOrientation == orientation) {
124-
return;
125-
}
129+
public final void setProjectionInTransactionLocked(int orientation, Rect layerStackRect, Rect displayRect) {
126130
mCurrentOrientation = orientation;
127-
Surface.setDisplayOrientation(mDisplayToken, orientation);
128-
}
129-
130-
/**
131-
* Sets the display viewport while in a transaction.
132-
*/
133-
public final void setViewportInTransactionLocked(Rect viewport) {
134-
if (mCurrentViewport != null) {
135-
if (mCurrentViewport.equals(viewport)) {
136-
return;
137-
}
138-
} else {
139-
mCurrentViewport = new Rect();
131+
if (mCurrentLayerStackRect == null) {
132+
mCurrentLayerStackRect = new Rect();
140133
}
141-
mCurrentViewport.set(viewport);
142-
Surface.setDisplayViewport(mDisplayToken, viewport);
143-
}
144-
145-
/**
146-
* Sets the display frame while in a transaction.
147-
*/
148-
public final void setFrameInTransactionLocked(Rect frame) {
149-
if (mCurrentFrame != null) {
150-
if (mCurrentFrame.equals(frame)) {
151-
return;
152-
}
153-
} else {
154-
mCurrentFrame = new Rect();
134+
mCurrentLayerStackRect.set(layerStackRect);
135+
if (mCurrentDisplayRect == null) {
136+
mCurrentDisplayRect = new Rect();
155137
}
156-
mCurrentFrame.set(frame);
157-
Surface.setDisplayFrame(mDisplayToken, frame);
138+
mCurrentDisplayRect.set(displayRect);
139+
Surface.setDisplayProjection(mDisplayToken, orientation, layerStackRect, displayRect);
158140
}
159141

160142
/**
@@ -176,8 +158,8 @@ public void dumpLocked(PrintWriter pw) {
176158
pw.println("mAdapter=" + mDisplayAdapter.getName());
177159
pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
178160
pw.println("mCurrentOrientation=" + mCurrentOrientation);
179-
pw.println("mCurrentViewport=" + mCurrentViewport);
180-
pw.println("mCurrentFrame=" + mCurrentFrame);
161+
pw.println("mCurrentViewport=" + mCurrentLayerStackRect);
162+
pw.println("mCurrentFrame=" + mCurrentDisplayRect);
181163
pw.println("mCurrentSurfaceTexture=" + mCurrentSurfaceTexture);
182164
}
183165
}

services/java/com/android/server/display/LogicalDisplay.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ final class LogicalDisplay {
6464
private DisplayDeviceInfo mPrimaryDisplayDeviceInfo;
6565

6666
// Temporary rectangle used when needed.
67-
private final Rect mTempRect = new Rect();
67+
private final Rect mTempLayerStackRect = new Rect();
68+
private final Rect mTempDisplayRect = new Rect();
6869

6970
public LogicalDisplay(int layerStack, DisplayDevice primaryDisplayDevice) {
7071
mLayerStack = layerStack;
@@ -208,8 +209,7 @@ public void configureDisplayInTransactionLocked(DisplayDevice device) {
208209
// Set the viewport.
209210
// This is the area of the logical display that we intend to show on the
210211
// display device. For now, it is always the full size of the logical display.
211-
mTempRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
212-
device.setViewportInTransactionLocked(mTempRect);
212+
mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
213213

214214
// Set the orientation.
215215
// The orientation specifies how the physical coordinate system of the display
@@ -219,7 +219,6 @@ public void configureDisplayInTransactionLocked(DisplayDevice device) {
219219
&& (displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_SUPPORTS_ROTATION) != 0) {
220220
orientation = displayInfo.rotation;
221221
}
222-
device.setOrientationInTransactionLocked(orientation);
223222

224223
// Set the frame.
225224
// The frame specifies the rotated physical coordinates into which the viewport
@@ -238,21 +237,23 @@ public void configureDisplayInTransactionLocked(DisplayDevice device) {
238237
// We avoid a division (and possible floating point imprecision) here by
239238
// multiplying the fractions by the product of their denominators before
240239
// comparing them.
241-
int frameWidth, frameHeight;
240+
int displayRectWidth, displayRectHeight;
242241
if (physWidth * displayInfo.logicalHeight
243242
< physHeight * displayInfo.logicalWidth) {
244243
// Letter box.
245-
frameWidth = physWidth;
246-
frameHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth;
244+
displayRectWidth = physWidth;
245+
displayRectHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth;
247246
} else {
248247
// Pillar box.
249-
frameWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight;
250-
frameHeight = physHeight;
248+
displayRectWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight;
249+
displayRectHeight = physHeight;
251250
}
252-
int frameTop = (physHeight - frameHeight) / 2;
253-
int frameLeft = (physWidth - frameWidth) / 2;
254-
mTempRect.set(frameLeft, frameTop, frameLeft + frameWidth, frameTop + frameHeight);
255-
device.setFrameInTransactionLocked(mTempRect);
251+
int displayRectTop = (physHeight - displayRectHeight) / 2;
252+
int displayRectLeft = (physWidth - displayRectWidth) / 2;
253+
mTempDisplayRect.set(displayRectLeft, displayRectTop,
254+
displayRectLeft + displayRectWidth, displayRectTop + displayRectHeight);
255+
256+
device.setProjectionInTransactionLocked(orientation, mTempLayerStackRect, mTempDisplayRect);
256257
}
257258

258259
public void dumpLocked(PrintWriter pw) {

0 commit comments

Comments
 (0)