Android SurfaceFlinger 사용하기. Surface 에서 ISurface를 받는다.
Android :
2010. 3. 3. 16:04
반응형
PDK에서 Surface를 제어하는 예제를 가져다가 JNI를 통해 어플과 연동시키려고 했는데
JAVA Application과 연동하면 자꾸만 Permission 문제가 발생하였다.
W/ServiceManager( 577): Permission failure: android.permission.ACCESS_SURFACE_FLINGER from uid=10020 pid=735
E/SurfaceFlinger( 577): Permission Denial: can't access SurfaceFlinger pid=735, uid=10020
위와 같이 Surface를 생성하려니까 자꾸만 Permission Denial 이라는 메세지가 나와서 ServiceManager 쪽에서 Permission 체크하는 부분을 아예 없애버렸는데 없애니까 작동을 잘 하기는 했다.
하지만 이렇게하면 올바른 방법이 아니기 때문에 한참 삽질끝에 JAVA에서 Surface를 JNI를 통해 끌어내리고 그것을 이용해서 Surface를 잡고, 또 그것을 이용해서 ISurface를 얻는 방법으로 진행했다.
다음의 코드를 참조하면 된다.
- #include <utils/IPCThreadState.h>
- #include <utils/ProcessState.h>
- #include <utils/IServiceManager.h>
- #include <utils/Log.h>
- #include <ui/Surface.h>
- #include <ui/ISurface.h>
- #include <ui/Overlay.h>
- #include <ui/SurfaceComposerClient.h>
- using namespace android;
- namespace android {
- class Test {
- public:
- static const sp<ISurface>& getISurface(const sp<Surface>& s) {
- return s->getISurface();
- }
- };
- };
- int main(int argc, char** argv)
- {
- // set up the thread-pool
- sp<ProcessState> proc(ProcessState::self());
- ProcessState::self()->startThreadPool();
- // create a client to surfaceflinger
- sp<SurfaceComposerClient> client = new SurfaceComposerClient();
- // create pushbuffer surface
- sp<Surface> surface = client->createSurface(getpid(), 0, 320, 240,
- PIXEL_FORMAT_UNKNOWN, ISurfaceComposer::ePushBuffers);
- // get to the isurface
- sp<ISurface> isurface = Test::getISurface(surface);
- printf("isurface = %p\n", isurface.get());
- // now request an overlay
- sp<OverlayRef> ref = isurface->createOverlay(320, 240, PIXEL_FORMAT_RGB_565);
- sp<Overlay> overlay = new Overlay(ref);
- /*
- * here we can use the overlay API
- */
- overlay_buffer_t buffer;
- overlay->dequeueBuffer(&buffer);
- printf("buffer = %p\n", buffer);
- void* address = overlay->getBufferAddress(buffer);
- printf("address = %p\n", address);
- overlay->queueBuffer(buffer);
- return 0;
- }
안드로이드의 frameworks/base/include/ui/Surface.h에 보면 getISurface가 private로 지정되어 있어서 다른 곳에서 접근 할 수가 없다.
그래서 Surface에 접근하는 Camera나 MediaRecoder, MediaPlayer 등등은 자신의 클래스를 friend class로 등록함으로써 Surface에 접근한다.
그중에 Test라는 클래스가 있는데 이놈을 이용하여 Surface에 접근 가능하다.
frameworks/base/libs/surfaceflinger/tests/overlays/overlays.cpp
를 참고하면 된다.
반응형
'Android' 카테고리의 다른 글
Android Display System (0) | 2010.03.05 |
---|---|
Allows an application to use SurfaceFlinger's low level features (0) | 2010.02.24 |
Android JAVA Application 에서 Hardware Control 하기. (안드로이드 자바 어플리케이션으로 하드웨어 제어하기) (0) | 2010.02.20 |