FramebufferNativeWindow() 理解(5)

來源:互聯網
上載者:User
/* * This implements the (main) framebuffer management. This class is used * mostly by SurfaceFlinger, but also by command line GL application. *  * In fact this is an implementation of ANativeWindow on top of * the framebuffer. *  * Currently it is pretty simple, it manages only two buffers (the front and  * back buffer). *  */ /*  *這實現了(主要)框架緩衝區管理。這個類是主要由SurfaceFlinger使用,但也通過命令列GL應用程式。  *事實上這是一個實現ANativeWindow頂部的框架緩衝區。  *目前它是非常簡單的,它管理著只有兩個緩衝區(前後緩衝)。  */FramebufferNativeWindow::FramebufferNativeWindow()     : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false){/** *通過模組ID得到gralloc模組 *hardware/libhardware/include/hardware/gralloc.h中定義如下模組ID; *#define GRALLOC_HARDWARE_MODULE_ID "gralloc" *(1)module:是一個輸出參數,由此證明;通過模組ID找到這個模組; */    hw_module_t const* module;    if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {        int stride;        int err;        int i;/**hardware/libhardware/include/hardware/fb.h定義 *#define GRALLOC_HARDWARE_FB0 "fb0" 模組ID *framebuffer_device_t* fbDev; *(2)通過這個module找個這個裝置即:framebuffer_device_t(hw_device_t裝置)*/        err = framebuffer_open(module, &fbDev/*輸出參數?*/);        LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err));/** alloc_device_t* grDev; *(3)同上; */        err = gralloc_open(module, &grDev/*輸出參數?*/);        LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err));        // bail out if we can't initialize the modules        //如果我們不能初始化模組則返回        if (!fbDev || !grDev)            return;                mUpdateOnDemand = (fbDev->setUpdateRect != 0);                // initialize the buffer FIFO        //雙緩衝        mNumBuffers = NUM_FRAME_BUFFERS;        mNumFreeBuffers = NUM_FRAME_BUFFERS;        mBufferHead = mNumBuffers-1;        for (i = 0; i < mNumBuffers; i++)        {        /*(4)width、height、format、usage是由上面framebuffer_open()->framebuffer_device_t得到*/                buffers[i] = new NativeBuffer(                        fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB);        }        for (i = 0; i < mNumBuffers; i++)        {        /*(5)同上 *grDev是上面gralloc_open開啟的alloc_device_t{hw_device_t}; *returns a buffer_handle_t *gralloc.cpp=>dev->device.alloc==gralloc_alloc;即grDev->alloc == dev->device.alloc; */                err = grDev->alloc(grDev,                        fbDev->width, fbDev->height, fbDev->format,                        GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride);                LOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s",                        i, fbDev->width, fbDev->height, strerror(-err));                if (err)                {                        mNumBuffers = i;                        mNumFreeBuffers = i;                        mBufferHead = mNumBuffers-1;                        break;                }        }/*從framebuffer裝置中獲得常量 *system/core/include/system/window.h定義"ANativeWindow" *Surface類繼承了ANativeWindow類。ANativeWindow類是串連OpenGL和Android視窗系統的橋樑? *即OpenGL需要通過ANativeWindow類來間接地操作Android視窗系統。 *這種橋樑關係是通過EGL庫來建立的,所有以egl為首碼的函數名均為EGL庫提供的介面。 */        const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags;         const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi;        const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi;        const_cast<int&>(ANativeWindow::minSwapInterval) =             fbDev->minSwapInterval;        const_cast<int&>(ANativeWindow::maxSwapInterval) =             fbDev->maxSwapInterval;    } else {        LOGE("Couldn't get gralloc module");    }    ANativeWindow::setSwapInterval = setSwapInterval;    ANativeWindow::dequeueBuffer = dequeueBuffer;    ANativeWindow::lockBuffer = lockBuffer;    ANativeWindow::queueBuffer = queueBuffer;    ANativeWindow::query = query;    ANativeWindow::perform = perform;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.