added gralloc grabber method«

This commit is contained in:
JosePereira 2012-06-11 20:04:30 +01:00
parent 2f078ec195
commit c63e08216c
4 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES = \
gralloc.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)\
$(LOCAL_PATH)/..
LOCAL_PRELINK_MODULE:=false #override prelink map
LOCAL_MODULE := libdvnc_gralloc_sdk$(PLATFORM_SDK_VERSION)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(LOCAL_PATH)/../lib
LOCAL_SHARED_LIBRARIES := libhardware libcutils
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,4 @@
-This method should work for tegra2 devices which not use the linux framebuffer.
- Make sure you have the tegra read() patch applied on your sources.
http://nv-tegra.nvidia.com/gitweb/?p=android/platform/hardware/libhardware.git;a=commit;h=9e00d0630e6fd8503602389b18f13a8b220728b1

View File

@ -0,0 +1,178 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2011 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "gralloc.h"
#include "../common.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/fb.h>
#include <hardware/hardware.h>
#include <hardware/gralloc.h>
#include <cutils/log.h>
#define r(fd, ptr, size) (read((fd), (ptr), (size)) != (int)(size))
#define w(fd, ptr, size) (write((fd), (ptr), (size)) != (int)(size))
struct gralloc_module_t *gralloc;
struct framebuffer_device_t *fbdev = 0;
struct alloc_device_t *allocdev = 0;
buffer_handle_t buf = 0;
unsigned char* data = 0;
int stride;
static int fill_format(int format)
{
// bpp, red, green, blue, alpha
static const int format_map[][9] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0}, // INVALID
{32, 0, 8, 8, 8, 16, 8, 24, 8}, // HAL_PIXEL_FORMAT_RGBA_8888
{32, 0, 8, 8, 8, 16, 8, 0, 0}, // HAL_PIXEL_FORMAT_RGBX_8888
{24, 16, 8, 8, 8, 0, 8, 0, 0}, // HAL_PIXEL_FORMAT_RGB_888
{16, 11, 5, 5, 6, 0, 5, 0, 0}, // HAL_PIXEL_FORMAT_RGB_565
{32, 16, 8, 8, 8, 0, 8, 24, 8}, // HAL_PIXEL_FORMAT_BGRA_8888
{16, 11, 5, 6, 5, 1, 5, 0, 1}, // HAL_PIXEL_FORMAT_RGBA_5551
{16, 12, 4, 8, 4, 4, 4, 0, 4} // HAL_PIXEL_FORMAT_RGBA_4444
};
const int *p;
if (format == 0 || format > HAL_PIXEL_FORMAT_RGBA_4444)
return -ENOTSUP;
p = format_map[format];
screenformat.bitsPerPixel = *(p++);
screenformat.redShift = *(p++);
screenformat.redMax = *(p++);
screenformat.greenShift = *(p++);
screenformat.greenMax = *(p++);
screenformat.blueShift = *(p++);
screenformat.blueMax = *(p++);
screenformat.alphaShift = *(p++);
screenformat.alphaMax = *(p++);
return 0;
}
#define CHECK_RV if (rv != 0){close_gralloc();return -1;}
#define CHECK_RV_P if (rv != 0){close_gralloc();return NULL;}
int init_gralloc()
{
printf("--Initializing gralloc access method--\n");
int linebytes;
int rv;
rv = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t**)&gralloc);
CHECK_RV;
rv = framebuffer_open(&gralloc->common, &fbdev);
CHECK_RV;
if (!fbdev->read) {
rv = -ENOTSUP;
close_gralloc();
return rv;
}
rv = gralloc_open(&gralloc->common, &allocdev);
CHECK_RV;
rv = allocdev->alloc(allocdev, fbdev->width, fbdev->height,
fbdev->format, GRALLOC_USAGE_SW_READ_OFTEN,
&buf, &stride);
rv = fbdev->read(fbdev, buf);
CHECK_RV;
rv = gralloc->lock(gralloc, buf, GRALLOC_USAGE_SW_READ_OFTEN, 0, 0,
fbdev->width, fbdev->height, (void**)&data);
CHECK_RV;
rv = fill_format(fbdev->format);
CHECK_RV;
stride *= (screenformat.bitsPerPixel >> 3);
linebytes = fbdev->width * (screenformat.bitsPerPixel >> 3);
screenformat.size = linebytes * fbdev->height;
screenformat.width = fbdev->width;
screenformat.height = fbdev->height;
// point of no return: don't attempt alternative means of reading
// after this
rv = 0;
L("Stride=%d Linebytes=%d %p\n",stride,linebytes,fbdev->setUpdateRect);
if (data)
gralloc->unlock(gralloc, buf);
L("Copy %d bytes\n",screenformat.size);
L("Returning rv=%d\n",rv);
return rv;
}
void close_gralloc()
{
if (buf)
allocdev->free(allocdev, buf);
if (allocdev)
gralloc_close(allocdev);
if (fbdev)
framebuffer_close(fbdev);
}
screenFormat getscreenformat_gralloc()
{
return screenformat;
}
unsigned char *readfb_gralloc ()
{
int rv;
rv = fbdev->read(fbdev, buf);
CHECK_RV_P;
rv = gralloc->lock(gralloc, buf, GRALLOC_USAGE_SW_READ_OFTEN, 0, 0,
fbdev->width, fbdev->height, (void**)&data);
CHECK_RV_P;
if (data)
gralloc->unlock(gralloc, buf);
return data;
}

View File

@ -0,0 +1,30 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2009 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRALLOC_H
#define GRALLOC_H
#include "screenFormat.h"
int init_gralloc();
unsigned char *readfb_gralloc();
void close_gralloc();
screenFormat getscreenformat_gralloc();
#endif