android 4.2.2
取得flags位,并mTransactionFlags把相应的位清零。
uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
{
return android_atomic_and(~flags, &mTransactionFlags) & flags;
}
1.Disable HW overlays
1../packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
setting得到SurfaceFlinger服务,通过binder发命令。
private void writeDisableOverlaysOption() {
try {IBinder flinger = ServiceManager.getService("SurfaceFlinger");
if (flinger != null) {
Parcel data = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
data.writeInt(disableOverlays);
flinger.transact(1008, data, null, 0);
data.recycle();
updateFlingerOptions();
}
} catch (RemoteException ex) {
}
}
2.SurfaceFlinger.cpp
SurfaceFlinger处理命令,置位相应的标志,重新画图。
case 1008: // toggle use of hw composer
n = data.readInt32();
mDebugDisableHWC = n ? 1 : 0;
invalidateHwcGeometry(); //mHwWorkListDirty = true;
repaintEverything();
return NO_ERROR;
3.SurfaceFlinger.cpp
重新画图。
void SurfaceFlinger::repaintEverything() {
android_atomic_or(1, &mRepaintEverything);
signalTransaction();
}
4. 4-6给队列发消息
void SurfaceFlinger::signalTransaction() {
mEventQueue.invalidate();
}
5.
#define INVALIDATE_ON_VSYNC 1
void MessageQueue::invalidate() {
#if INVALIDATE_ON_VSYNC
mEvents->requestNextVsync();
#else
mHandler->dispatchInvalidate();
#endif
}
6.
frameworks/native/services/surfaceflinger/MessageQueue.cpp
void MessageQueue::Handler::dispatchInvalidate() {
if ((android_atomic_or(eventMaskInvalidate, &mEventMask) & eventMaskInvalidate) == 0) {
mQueue.mLooper->sendMessage(this, Message(MessageQueue::INVALIDATE));
}
}
7.处理重画的消息
void SurfaceFlinger::onMessageReceived(int32_t what) {
ATRACE_CALL();
switch (what) {
case MessageQueue::INVALIDATE:
TF_PRINT(TF_EVENT_START, "SF", "Invalidate", "Composition invalidate start");
handleMessageTransaction();
handleMessageInvalidate();
signalRefresh();
TF_PRINT(TF_EVENT_STOP, "SF", "Invalidate", "Composition invalidate end");
break;
case MessageQueue::REFRESH:
TF_PRINT(TF_EVENT_START, "SF", "CompositionRefresh", "Composition refresh start");
handleMessageRefresh();
TF_PRINT(TF_EVENT_STOP, "SF", "CompositionRefresh", "Composition refresh end");
break;
}
}
8.图形属性大小、旋转方向没有发生变化,所以不会调用
void SurfaceFlinger::handleMessageTransaction() {
uint32_t transactionFlags = peekTransactionFlags(eTransactionMask);// transactionFlags=mTransactionFlags
if (transactionFlags) {
// transactionFlags = false 所以不会走下边。
handleTransaction(transactionFlags);
}
}
9.重新计算可视区,mVisibleRegionsDirty推测是false.
void SurfaceFlinger::handleMessageInvalidate() {
ATRACE_CALL();
handlePageFlip();
}
void SurfaceFlinger::handlePageFlip()
{
Region dirtyRegion;
bool visibleRegions = false;
const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
const size_t count = currentLayers.size();
for (size_t i=0 ; i<count ; i++) {
const sp<LayerBase>& layer(currentLayers[i]);
const Region dirty(layer->latchBuffer(visibleRegions));
const Layer::State& s(layer->drawingState());
invalidateLayerStack(s