HAL层保存Layer数据

HAL层增加每个layer的dump数据保存在文件中

//dump layer but need selinux permission: surfaceflinger default no permission to write
static void dump_layer_list( malidp_hwc_device_t* dev,  hwc_display_contents_1_t * HwDisplay)
{
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.sf.dumptofile", value, "0");
    int dump = atoi(value);
    gralloc_module_t* module = dev->gralloc_module;

    if (!dump || !HwDisplay || HwDisplay->numHwLayers < 2)
    {
        return;
    }

    static int frame_count = 0;
    frame_count++;

    for (size_t i = 0; i < HwDisplay->numHwLayers - 1; i++)
    {
        hwc_layer_1_t * layer  = &HwDisplay->hwLayers[i];
        int cur_w, cur_h, format, size;
        if ( layer->handle == NULL)
        {
            continue;
        }
        private_handle_t* handle = ( private_handle_t*)layer->handle;
        cur_w = handle->width;
        cur_h = handle->height;
        format = handle->format;
        size = handle->size;
        void *vaddr =  (void *) handle->base;
        module->lock(module, handle, GRALLOC_USAGE_SW_READ_OFTEN,
                     0, 0, cur_w, cur_h, &vaddr);
        cur_w = HWC_ALIGN(cur_w, 16);
        char fname[256] = "/data/misc/surface/Layer";
        snprintf(fname, 256,  "%s_%d-%d_%dx%d-%d.raw", fname, frame_count, i, cur_w, cur_h, format);
        int fd = open(fname, O_CREAT | O_RDWR, 0666);
        if(fd < 0)
        {
            ALOGE("open file failed %s:(errnor=%d)", fname, errno);
        }
        else
        {
            write(fd, vaddr, size);
            close(fd);
        }
        module->unlock(module, handle);
    }
}

int hwc_primary_prepare(malidp_hwc_device_t* dev, hwc_display_contents_1_t* content)
{
    int status = -EINVAL;
    malidp_display_dev_t* disp_dev = &dev->display_dev[HWC_DISPLAY_PRIMARY];

    if(disp_dev->actived)
    {
        if(dev->force_gpu)
        {
            status = prepare_fb_target(disp_dev, content);
        }
        else if(need_flatten_frame(dev->static_tracer))
        {
            ALOGV("Flatten all layers to framebuffer.");
            status = prepare_fb_target(disp_dev, content);
        }
        else
        {
            status = prepare_bottom_up(disp_dev, content);
        }
    }
    else if(content->numHwLayers <= 1)
    {
        status = 0;
    }

    dump_layer_list(dev, content); //add dump func

    return status;
}

你可能感兴趣的:(android显示系统)