From 2f078ec1955d9a963a884d6b7783de810d631ae5 Mon Sep 17 00:00:00 2001 From: JosePereira Date: Mon, 11 Jun 2012 20:04:16 +0100 Subject: [PATCH] added flinger grabber method --- nativeMethods/flinger/Android.mk | 29 +++++++++++ nativeMethods/flinger/README | 2 + nativeMethods/flinger/flinger.cpp | 87 +++++++++++++++++++++++++++++++ nativeMethods/flinger/flinger.h | 37 +++++++++++++ 4 files changed, 155 insertions(+) create mode 100755 nativeMethods/flinger/Android.mk create mode 100644 nativeMethods/flinger/README create mode 100755 nativeMethods/flinger/flinger.cpp create mode 100755 nativeMethods/flinger/flinger.h diff --git a/nativeMethods/flinger/Android.mk b/nativeMethods/flinger/Android.mk new file mode 100755 index 0000000..73df982 --- /dev/null +++ b/nativeMethods/flinger/Android.mk @@ -0,0 +1,29 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES = \ + flinger.cpp + +#LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/.. + +LOCAL_PRELINK_MODULE:=false #override prelink map +LOCAL_MODULE:= libdvnc_flinger_sdk$(PLATFORM_SDK_VERSION) +LOCAL_MODULE_TAGS:= optional +LOCAL_MODULE_PATH := $(LOCAL_PATH)/../lib + +ifeq ($(PLATFORM_SDK_VERSION),9) +LOCAL_SHARED_LIBRARIES := libsurfaceflinger_client libui libbinder libutils libcutils #libcrypto libssl libhardware +else ifeq ($(PLATFORM_SDK_VERSION),10) +LOCAL_SHARED_LIBRARIES := libsurfaceflinger_client libui libbinder libutils libcutils #libcrypto libssl libhardware +else ifeq ($(PLATFORM_SDK_VERSION),15) +LOCAL_SHARED_LIBRARIES := libgui libui libbinder libcutils +else +#add here more sdk versions +LOCAL_SHARED_LIBRARIES := libgui libui libbinder libcutils +endif + +include $(BUILD_SHARED_LIBRARY) diff --git a/nativeMethods/flinger/README b/nativeMethods/flinger/README new file mode 100644 index 0000000..e6cbb2b --- /dev/null +++ b/nativeMethods/flinger/README @@ -0,0 +1,2 @@ +- The surfaceflinger method is present from version 2.3.X and should be supported by all devices. +- It connects with the surfaceflinger service through a Binder interface. diff --git a/nativeMethods/flinger/flinger.cpp b/nativeMethods/flinger/flinger.cpp new file mode 100755 index 0000000..2ce899a --- /dev/null +++ b/nativeMethods/flinger/flinger.cpp @@ -0,0 +1,87 @@ +/* + droid vnc server - Android VNC server + Copyright (C) 2009 Jose Pereira + + 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 "flinger.h" +#include "screenFormat.h" + +#include +#include +#include + +#include +#include +#include + +using namespace android; + +ScreenshotClient *screenshotClient=NULL; + +extern "C" screenFormat getscreenformat_flinger() +{ + //get format on PixelFormat struct + PixelFormat f=screenshotClient->getFormat(); + + PixelFormatInfo pf; + getPixelFormatInfo(f,&pf); + + screenFormat format; + + format.bitsPerPixel = pf.bitsPerPixel; + format.width = screenshotClient->getWidth(); + format.height = screenshotClient->getHeight(); + format.size = pf.bitsPerPixel*format.width*format.height/CHAR_BIT; + format.redShift = pf.l_red; + format.redMax = pf.h_red; + format.greenShift = pf.l_green; + format.greenMax = pf.h_green-pf.h_red; + format.blueShift = pf.l_blue; + format.blueMax = pf.h_blue-pf.h_green; + format.alphaShift = pf.l_alpha; + format.alphaMax = pf.h_alpha-pf.h_blue; + + return format; +} + + +extern "C" int init_flinger() +{ + int errno; + + L("--Initializing gingerbread access method--\n"); + + screenshotClient=new ScreenshotClient(); + errno=screenshotClient->update(); + if (errno != NO_ERROR) { + L("screen capture failed: %s\n", strerror(-errno)); + return -1; + } + + return 0; +} + +extern "C" unsigned int *readfb_flinger() +{ + screenshotClient->update(); + return (unsigned int*)screenshotClient->getPixels(); +} + +extern "C" void close_flinger() +{ + free(screenshotClient); +} diff --git a/nativeMethods/flinger/flinger.h b/nativeMethods/flinger/flinger.h new file mode 100755 index 0000000..0581091 --- /dev/null +++ b/nativeMethods/flinger/flinger.h @@ -0,0 +1,37 @@ +/* + droid vnc server - Android VNC server + Copyright (C) 2009 Jose Pereira + + 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 DISPLAY_BINDER +#define DISPLAY_BINDER + +#ifdef __cplusplus +#define L(...) __android_log_print(ANDROID_LOG_INFO,"VNCserver",__VA_ARGS__);printf(__VA_ARGS__); + + +extern "C" { +#endif + unsigned int * readfb_flinger(); + int init_flinger(); + void close_flinger(); +#ifdef __cplusplus +} + +#endif + +#endif