Skip to content

Commit e2909e1

Browse files
author
Jamie Gennis
committed
SurfaceFlinger: update orientation via transactions
This change merges the ISurfaceComposer::setOrientation functionality into ISurfaceComposer::setTransactionState. It enables the window manager to atomically update both the display orientation and the position and size of the windows in a single transaction with SurfaceFlinger. Bug: 5439574 Change-Id: I18a8ccc564d7d760ef8afb2d015ccdb7a7963900
1 parent 99f3668 commit e2909e1

File tree

7 files changed

+64
-99
lines changed

7 files changed

+64
-99
lines changed

include/surfaceflinger/ISurfaceComposer.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ISurfaceComposer : public IInterface
8080
eOrientation90 = 1,
8181
eOrientation180 = 2,
8282
eOrientation270 = 3,
83+
eOrientationUnchanged = 4,
8384
eOrientationSwapMask = 0x01
8485
};
8586

@@ -101,15 +102,8 @@ class ISurfaceComposer : public IInterface
101102
virtual sp<IMemoryHeap> getCblk() const = 0;
102103

103104
/* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
104-
virtual void setTransactionState(const Vector<ComposerState>& state) = 0;
105-
106-
/* [un]freeze display. requires ACCESS_SURFACE_FLINGER permission */
107-
virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) = 0;
108-
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) = 0;
109-
110-
/* Set display orientation. requires ACCESS_SURFACE_FLINGER permission
111-
* No flags are currently defined. Set flags to 0. */
112-
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) = 0;
105+
virtual void setTransactionState(const Vector<ComposerState>& state,
106+
int orientation) = 0;
113107

114108
/* signal that we're done booting.
115109
* Requires ACCESS_SURFACE_FLINGER permission

include/surfaceflinger/SurfaceComposerClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,3 @@ class ScreenshotClient
195195
}; // namespace android
196196

197197
#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
198-

libs/gui/ISurfaceComposer.cpp

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
7878
return interface_cast<IMemoryHeap>(reply.readStrongBinder());
7979
}
8080

81-
virtual void setTransactionState(const Vector<ComposerState>& state)
81+
virtual void setTransactionState(const Vector<ComposerState>& state,
82+
int orientation)
8283
{
8384
Parcel data, reply;
8485
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -88,38 +89,8 @@ class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
8889
for ( ; b != e ; ++b ) {
8990
b->write(data);
9091
}
91-
remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
92-
}
93-
94-
virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
95-
{
96-
Parcel data, reply;
97-
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
98-
data.writeInt32(dpy);
99-
data.writeInt32(flags);
100-
remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
101-
return reply.readInt32();
102-
}
103-
104-
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
105-
{
106-
Parcel data, reply;
107-
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
108-
data.writeInt32(dpy);
109-
data.writeInt32(flags);
110-
remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
111-
return reply.readInt32();
112-
}
113-
114-
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
115-
{
116-
Parcel data, reply;
117-
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
118-
data.writeInt32(dpy);
11992
data.writeInt32(orientation);
120-
data.writeInt32(flags);
121-
remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
122-
return reply.readInt32();
93+
remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
12394
}
12495

12596
virtual void bootFinished()
@@ -232,26 +203,8 @@ status_t BnSurfaceComposer::onTransact(
232203
s.read(data);
233204
state.add(s);
234205
}
235-
setTransactionState(state);
236-
} break;
237-
case SET_ORIENTATION: {
238-
CHECK_INTERFACE(ISurfaceComposer, data, reply);
239-
DisplayID dpy = data.readInt32();
240206
int orientation = data.readInt32();
241-
uint32_t flags = data.readInt32();
242-
reply->writeInt32( setOrientation(dpy, orientation, flags) );
243-
} break;
244-
case FREEZE_DISPLAY: {
245-
CHECK_INTERFACE(ISurfaceComposer, data, reply);
246-
DisplayID dpy = data.readInt32();
247-
uint32_t flags = data.readInt32();
248-
reply->writeInt32( freezeDisplay(dpy, flags) );
249-
} break;
250-
case UNFREEZE_DISPLAY: {
251-
CHECK_INTERFACE(ISurfaceComposer, data, reply);
252-
DisplayID dpy = data.readInt32();
253-
uint32_t flags = data.readInt32();
254-
reply->writeInt32( unfreezeDisplay(dpy, flags) );
207+
setTransactionState(state, orientation);
255208
} break;
256209
case BOOT_FINISHED: {
257210
CHECK_INTERFACE(ISurfaceComposer, data, reply);

libs/gui/SurfaceComposerClient.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ class Composer : public Singleton<Composer>
9191

9292
mutable Mutex mLock;
9393
SortedVector<ComposerState> mStates;
94+
int mOrientation;
9495

95-
Composer() : Singleton<Composer>() { }
96+
Composer() : Singleton<Composer>(),
97+
mOrientation(ISurfaceComposer::eOrientationUnchanged) { }
9698

9799
void closeGlobalTransactionImpl();
98100

@@ -119,6 +121,7 @@ class Composer : public Singleton<Composer>
119121
status_t setFreezeTint(
120122
const sp<SurfaceComposerClient>& client, SurfaceID id,
121123
uint32_t tint);
124+
status_t setOrientation(int orientation);
122125

123126
static void closeGlobalTransaction() {
124127
Composer::getInstance().closeGlobalTransactionImpl();
@@ -133,14 +136,18 @@ void Composer::closeGlobalTransactionImpl() {
133136
sp<ISurfaceComposer> sm(getComposerService());
134137

135138
Vector<ComposerState> transaction;
139+
int orientation;
136140

137141
{ // scope for the lock
138142
Mutex::Autolock _l(mLock);
139143
transaction = mStates;
140144
mStates.clear();
145+
146+
orientation = mOrientation;
147+
mOrientation = ISurfaceComposer::eOrientationUnchanged;
141148
}
142149

143-
sm->setTransactionState(transaction);
150+
sm->setTransactionState(transaction, orientation);
144151
}
145152

146153
layer_state_t* Composer::getLayerStateLocked(
@@ -260,6 +267,12 @@ status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client,
260267
return NO_ERROR;
261268
}
262269

270+
status_t Composer::setOrientation(int orientation) {
271+
Mutex::Autolock _l(mLock);
272+
mOrientation = orientation;
273+
return NO_ERROR;
274+
}
275+
263276
// ---------------------------------------------------------------------------
264277

265278
SurfaceComposerClient::SurfaceComposerClient()
@@ -427,6 +440,12 @@ status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
427440
return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
428441
}
429442

443+
status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
444+
int orientation, uint32_t flags)
445+
{
446+
return Composer::getInstance().setOrientation(orientation);
447+
}
448+
430449
// ----------------------------------------------------------------------------
431450

432451
status_t SurfaceComposerClient::getDisplayInfo(
@@ -491,21 +510,14 @@ ssize_t SurfaceComposerClient::getNumberOfDisplays()
491510

492511
status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
493512
{
494-
sp<ISurfaceComposer> sm(getComposerService());
495-
return sm->freezeDisplay(dpy, flags);
513+
// This has been made a no-op because it can cause Gralloc buffer deadlocks.
514+
return NO_ERROR;
496515
}
497516

498517
status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
499518
{
500-
sp<ISurfaceComposer> sm(getComposerService());
501-
return sm->unfreezeDisplay(dpy, flags);
502-
}
503-
504-
int SurfaceComposerClient::setOrientation(DisplayID dpy,
505-
int orientation, uint32_t flags)
506-
{
507-
sp<ISurfaceComposer> sm(getComposerService());
508-
return sm->setOrientation(dpy, orientation, flags);
519+
// This has been made a no-op because it can cause Gralloc buffer deadlocks.
520+
return NO_ERROR;
509521
}
510522

511523
// ----------------------------------------------------------------------------
@@ -572,4 +584,3 @@ size_t ScreenshotClient::getSize() const {
572584

573585
// ----------------------------------------------------------------------------
574586
}; // namespace android
575-

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,32 +5230,27 @@ public boolean updateRotationUncheckedLocked(boolean inTransaction) {
52305230
startFreezingDisplayLocked(inTransaction);
52315231
mInputManager.setDisplayOrientation(0, rotation);
52325232

5233-
// NOTE: We disable the rotation in the emulator because
5234-
// it doesn't support hardware OpenGL emulation yet.
5235-
if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
5236-
&& mScreenRotationAnimation.hasScreenshot()) {
5237-
Surface.freezeDisplay(0);
5233+
if (!inTransaction) {
5234+
if (SHOW_TRANSACTIONS) Slog.i(TAG,
5235+
">>> OPEN TRANSACTION setRotationUnchecked");
5236+
Surface.openTransaction();
5237+
}
5238+
try {
5239+
// NOTE: We disable the rotation in the emulator because
5240+
// it doesn't support hardware OpenGL emulation yet.
5241+
if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
5242+
&& mScreenRotationAnimation.hasScreenshot()) {
5243+
mScreenRotationAnimation.setRotation(rotation);
5244+
}
5245+
Surface.setOrientation(0, rotation);
5246+
} finally {
52385247
if (!inTransaction) {
5248+
Surface.closeTransaction();
52395249
if (SHOW_TRANSACTIONS) Slog.i(TAG,
5240-
">>> OPEN TRANSACTION setRotationUnchecked");
5241-
Surface.openTransaction();
5250+
"<<< CLOSE TRANSACTION setRotationUnchecked");
52425251
}
5243-
try {
5244-
if (mScreenRotationAnimation != null) {
5245-
mScreenRotationAnimation.setRotation(rotation);
5246-
}
5247-
} finally {
5248-
if (!inTransaction) {
5249-
Surface.closeTransaction();
5250-
if (SHOW_TRANSACTIONS) Slog.i(TAG,
5251-
"<<< CLOSE TRANSACTION setRotationUnchecked");
5252-
}
5253-
}
5254-
Surface.setOrientation(0, rotation);
5255-
Surface.unfreezeDisplay(0);
5256-
} else {
5257-
Surface.setOrientation(0, rotation);
52585252
}
5253+
52595254
rebuildBlackFrame(inTransaction);
52605255

52615256
for (int i=mWindows.size()-1; i>=0; i--) {

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,10 +1234,22 @@ uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
12341234
}
12351235

12361236

1237-
void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state) {
1237+
void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state,
1238+
int orientation) {
12381239
Mutex::Autolock _l(mStateLock);
12391240

12401241
uint32_t flags = 0;
1242+
if (mCurrentState.orientation != orientation) {
1243+
if (uint32_t(orientation)<=eOrientation270 || orientation==42) {
1244+
mCurrentState.orientation = orientation;
1245+
flags |= eTransactionNeeded;
1246+
mResizeTransationPending = true;
1247+
} else if (orientation != eOrientationUnchanged) {
1248+
LOGW("setTransactionState: ignoring unrecognized orientation: %d",
1249+
orientation);
1250+
}
1251+
}
1252+
12411253
const size_t count = state.size();
12421254
for (size_t i=0 ; i<count ; i++) {
12431255
const ComposerState& s(state[i]);

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ class SurfaceFlinger :
167167
virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc();
168168
virtual sp<IMemoryHeap> getCblk() const;
169169
virtual void bootFinished();
170-
virtual void setTransactionState(const Vector<ComposerState>& state);
170+
virtual void setTransactionState(const Vector<ComposerState>& state,
171+
int orientation);
171172
virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags);
172173
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags);
173174
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags);

0 commit comments

Comments
 (0)