开发者选项 Disable HW overlays

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.layerStack, dirty);
    }    
   // ALOGE("visibleRegions =%s",visibleRegions ? "true" : "false");   false


    mVisibleRegionsDirty |= visibleRegions;
}


10.

void SurfaceFlinger::handleMessageRefresh() {
    ATRACE_CALL();
    preComposition();
    rebuildLayerStacks();
    setUpHWComposer();
    doDebugFlashRegions();
    doComposition();
    postComposition();
}

11.



void SurfaceFlinger::setUpHWComposer()

           if (CC_UNLIKELY(mHwWorkListDirty)) {
            ALOGE("test 718 setUpHWComposer mHwWorkListDirty==TURE");
            mHwWorkListDirty = false;//保证只运行一次

              if (mDebugDisableHWC || mDebugRegion) {
                                cur->setSkip(true);//设置HWC_SKIP_LAYER标志
              }


            status_t err = hwc.prepare();

  virtual void setSkip(bool skip) {
        if (skip) {
            getLayer()->flags |= HWC_SKIP_LAYER;
        } else {
            getLayer()->flags &= ~HWC_SKIP_LAYER;
        }
    }


hwc.prepare();--------->status_t HWComposer::prepare()------------>int err = mHwc->prepare(mHwc, mNumDisplays, mLists);


12. hardware/qcom/display/libhwcomposer/hwc.cpp  hwc_prepare 

在updateLayerCache中,HWC_SKIP_LAYER和HWC_FRAMEBUFFER处理的方式不一样。why??

hardware/qcom/display/libhwcomposer/hwc.cpp

static int hwc_prepare_primary(hwc_composer_device_1 *dev,
        hwc_display_contents_1_t *list)

                              ctx->mLayerCache[dpy]->updateLayerCache(list);

   for(uint32_t i = 0; i < list->numHwLayers; i++) {
             //Bail on skip layers
        if(list->hwLayers[i].flags & HWC_SKIP_LAYER) {
            resetLayerCache(list->numHwLayers);
            return;
        }
    
        if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) {
            numFbLayers++;
            if(hnd[i] == NULL) {
                hnd[i] = list->hwLayers[i].handle;
            } else if (hnd[i] ==
                       list->hwLayers[i].handle) {
                numCacheableLayers++;
            } else {
                hnd[i] = NULL;
                return;
            }
        } else {
            hnd[i] = NULL;
        }
    }


void LayerCache::resetLayerCache(int num) {
    for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) {
        hnd[i] = NULL;
    }
    numHwLayers = num;
}


13.frameworks/native/services/surfaceflinger/DisplayHardware/HWComposer.cpp

把有HWC_SKIP_LAYER标志的层设置合成方式是HWC_FRAMEBUFFER

status_t HWComposer::prepare()      

for (size_t i=0 ; i<disp.list->numHwLayers ; i++) {
                    hwc_layer_1_t& l = disp.list->hwLayers[i];

                    //ALOGD("prepare: %d, type=%d, handle=%p",
                    //        i, l.compositionType, l.handle);

                    if (l.flags & HWC_SKIP_LAYER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_SKIP_LAYER");
                        l.compositionType = HWC_FRAMEBUFFER;// HWC_SKIP_LAYER  => HWC_FRAMEBUFFER
                    }
                    if (l.compositionType == HWC_FRAMEBUFFER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_FRAMEBUFFER");
                        disp.hasFbComp = true;
                    }
                    if (l.compositionType == HWC_OVERLAY) {
                        disp.hasOvComp = true;
                    }
                }



14.

SurfaceFlinger.cpp

void SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty)

      /*
     * and then, render the layers targeted at the framebuffer
     */

    const Vector< sp<LayerBase> >& layers(hw->getVisibleLayersSortedByZ());
    const size_t count = layers.size();
    const Transform& tr = hw->getTransform();
    if (cur != end) {
        // we're using h/w composer
        for (size_t i=0 ; i<count && cur!=end ; ++i, ++cur) {
            const sp<LayerBase>& layer(layers[i]);
            const Region clip(dirty.intersect(tr.transform(layer->visibleRegion)));
            if (!clip.isEmpty()) {
                switch (cur->getCompositionType()) {
                    case HWC_OVERLAY: {
                        ALOGE("test 718 doComposeSurfaces case HWC_OVERLAY");
                        ALOGE("test 718 hasGlesComposition=%s",hasGlesComposition ? "true" : "false");
                        if ((cur->getHints() & HWC_HINT_CLEAR_FB)
                                && i
                                && layer->isOpaque()
                                && hasGlesComposition) {
                            // never clear the very first layer since we're
                            // guaranteed the FB is already cleared
                            ALOGE("test 718 clear");
                            layer->clearWithOpenGL(hw, clip);
                        }
                        break;
                    }
                    case HWC_FRAMEBUFFER: {
                        ALOGE("test 718 doComposeSurfaces case HWC_FRAMEBUFFER");
                        layer->draw(hw, clip);
                        break;

                    case HWC_FRAMEBUFFER_TARGET: {
                        // this should not happen as the iterator shouldn't
                        // let us get there.
                        ALOGW("HWC_FRAMEBUFFER_TARGET found in hwc list (index=%d)", i);
                        break;
                    }
                }
            }
            layer->setAcquireFence(hw, *cur);
        }











     
               

      








13.


当Disable HW overlays ,这个log‘test 718’会不停的打。如果不选,则不会打log。



                   if (l.flags & HWC_SKIP_LAYER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_SKIP_LAYER");
                        l.compositionType = HWC_FRAMEBUFFER;
                    }
                    if (l.compositionType == HWC_FRAMEBUFFER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_FRAMEBUFFER");
                        disp.hasFbComp = true;
                    }
                    if (l.compositionType == HWC_OVERLAY) {
                        disp.hasOvComp = true;
                    }





选中

D/CallStack(  275): #00  pc 00006f74  /system/lib/hw/hwcomposer.msm8960.so
D/CallStack(  275): #01  pc 00007248  /system/lib/hw/hwcomposer.msm8960.so
D/CallStack(  275): #02  pc 000233be  /system/lib/libsurfaceflinger.so (android::HWComposer::prepare()+145)
D/CallStack(  275): #03  pc 00026710  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::setUpHWComposer()+363)
D/CallStack(  275): #04  pc 00029324  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::handleMessageRefresh()+39)
D/CallStack(  275): #05  pc 00029f7a  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::onMessageReceived(int)+57)
D/CallStack(  275): #06  pc 00014c70  /system/lib/libutils.so (android::Looper::pollInner(int)+423)
D/CallStack(  275): #07  pc 00014d90  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+103)
D/CallStack(  275): #08  pc 00024894  /system/lib/libsurfaceflinger.so (android::MessageQueue::waitMessage()+39)
D/CallStack(  275): #09  pc 00024e80  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::threadLoop()+5)
D/CallStack(  275): #10  pc 00011264  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+111)
D/CallStack(  275): #11  pc 00010dca  /system/lib/libutils.so
D/CallStack(  275): #12  pc 0000e4f8  /system/lib/libc.so (__thread_entry+72)
D/CallStack(  275): #13  pc 0000dbe4  /system/lib/libc.so (pthread_create+160)
E/qdhwcomposer(  275): test 718 hwc_prepare_primary MDPcomp fails
E/qdhwcomposer(  275): test 718 updateLayerCache HWC_SKIP_LAYER
E/qdhwcomposer(  275): test 718 hwc_prepare_primary mCopyBit
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER

// prepare结束,就是清cache的时候,用到了HWC_SKIP_LAYER

  
    目的把HWC_SKIP_LAYER,变为HWC_FRAMEBUFFER属性。disp.hasFbComp表示有FB合成。











D/CallStack(  276): #00  pc 00025ccc  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doComposeSurfaces(android::sp<android::DisplayDevice const> const&, android::Region const&)+23)
D/CallStack(  276): #01  pc 00026014  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doDisplayComposition(android::sp<android::DisplayDevice const> const&, android::Region const&)+123)
D/CallStack(  276): #02  pc 000290ac  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doComposition()+95)
D/CallStack(  276): #03  pc 00029318  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::handleMessageRefresh()+51)
D/CallStack(  276): #04  pc 00029f62  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::onMessageReceived(int)+57)
D/CallStack(  276): #05  pc 00014c70  /system/lib/libutils.so (android::Looper::pollInner(int)+423)
D/CallStack(  276): #06  pc 00014d90  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+103)
D/CallStack(  276): #07  pc 00024894  /system/lib/libsurfaceflinger.so (android::MessageQueue::waitMessage()+39)
D/CallStack(  276): #08  pc 00024e80  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::threadLoop()+5)
D/CallStack(  276): #09  pc 00011264  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+111)
D/CallStack(  276): #10  pc 00010dca  /system/lib/libutils.so
D/CallStack(  276): #11  pc 0000e4f8  /system/lib/libc.so (__thread_entry+72)
D/CallStack(  276): #12  pc 0000dbe4  /system/lib/libc.so (pthread_create+160)
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER


















     
               

      














选中

D/CallStack(  275): #00  pc 00006f74  /system/lib/hw/hwcomposer.msm8960.so
D/CallStack(  275): #01  pc 00007248  /system/lib/hw/hwcomposer.msm8960.so
D/CallStack(  275): #02  pc 000233be  /system/lib/libsurfaceflinger.so (android::HWComposer::prepare()+145)
D/CallStack(  275): #03  pc 00026710  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::setUpHWComposer()+363)
D/CallStack(  275): #04  pc 00029324  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::handleMessageRefresh()+39)
D/CallStack(  275): #05  pc 00029f7a  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::onMessageReceived(int)+57)
D/CallStack(  275): #06  pc 00014c70  /system/lib/libutils.so (android::Looper::pollInner(int)+423)
D/CallStack(  275): #07  pc 00014d90  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+103)
D/CallStack(  275): #08  pc 00024894  /system/lib/libsurfaceflinger.so (android::MessageQueue::waitMessage()+39)
D/CallStack(  275): #09  pc 00024e80  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::threadLoop()+5)
D/CallStack(  275): #10  pc 00011264  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+111)
D/CallStack(  275): #11  pc 00010dca  /system/lib/libutils.so
D/CallStack(  275): #12  pc 0000e4f8  /system/lib/libc.so (__thread_entry+72)
D/CallStack(  275): #13  pc 0000dbe4  /system/lib/libc.so (pthread_create+160)
E/qdhwcomposer(  275): test 718 hwc_prepare_primary MDPcomp fails
E/qdhwcomposer(  275): test 718 updateLayerCache HWC_SKIP_LAYER
E/qdhwcomposer(  275): test 718 hwc_prepare_primary mCopyBit
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_SKIP_LAYER
E/SurfaceFlinger(  275): test 718 HWComposer::prepare() HWC_FRAMEBUFFER

// prepare结束,就是清cache的时候,用到了HWC_SKIP_LAYER

     // here we're just making sure that "skip" layers are set
        // to HWC_FRAMEBUFFER and we're also counting how many layers
        // we have of each type.
        for (size_t i=0 ; i<mNumDisplays ; i++) {
            DisplayData& disp(mDisplayData[i]);
            disp.hasFbComp = false;
            disp.hasOvComp = false;
            if (disp.list) {
                for (size_t i=0 ; i<disp.list->numHwLayers ; i++) {
                    hwc_layer_1_t& l = disp.list->hwLayers[i];

                    //ALOGD("prepare: %d, type=%d, handle=%p",
                    //        i, l.compositionType, l.handle);

                    if (l.flags & HWC_SKIP_LAYER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_SKIP_LAYER");
                        l.compositionType = HWC_FRAMEBUFFER;
                    }
                    if (l.compositionType == HWC_FRAMEBUFFER) {
                        ALOGE("test 718 HWComposer::prepare() HWC_FRAMEBUFFER");
                        disp.hasFbComp = true;
                    }
                    if (l.compositionType == HWC_OVERLAY) {
                        disp.hasOvComp = true;
                    }
                }
            }
        }

目的把HWC_SKIP_LAYER,变为HWC_FRAMEBUFFER属性。disp.hasFbComp表示有FB合成。











D/CallStack(  276): #00  pc 00025ccc  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doComposeSurfaces(android::sp<android::DisplayDevice const> const&, android::Region const&)+23)
D/CallStack(  276): #01  pc 00026014  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doDisplayComposition(android::sp<android::DisplayDevice const> const&, android::Region const&)+123)
D/CallStack(  276): #02  pc 000290ac  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::doComposition()+95)
D/CallStack(  276): #03  pc 00029318  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::handleMessageRefresh()+51)
D/CallStack(  276): #04  pc 00029f62  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::onMessageReceived(int)+57)
D/CallStack(  276): #05  pc 00014c70  /system/lib/libutils.so (android::Looper::pollInner(int)+423)
D/CallStack(  276): #06  pc 00014d90  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+103)
D/CallStack(  276): #07  pc 00024894  /system/lib/libsurfaceflinger.so (android::MessageQueue::waitMessage()+39)
D/CallStack(  276): #08  pc 00024e80  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::threadLoop()+5)
D/CallStack(  276): #09  pc 00011264  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+111)
D/CallStack(  276): #10  pc 00010dca  /system/lib/libutils.so
D/CallStack(  276): #11  pc 0000e4f8  /system/lib/libc.so (__thread_entry+72)
D/CallStack(  276): #12  pc 0000dbe4  /system/lib/libc.so (pthread_create+160)
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER
E/SurfaceFlinger(  276): test 718 doComposeSurfaces case HWC_FRAMEBUFFER





你可能感兴趣的:(开发者选项 Disable HW overlays)