블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

최근에 올라온 글

NDK에서 화면을 더블 버퍼링하려면?

How to Render Image Buffer in Android NDK Native Code

ANativeWindow* window = ANativeWindow_fromSurface(env, javaSurface);

ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(window, &buffer, NULL) == 0) {
  memcpy(buffer.bits, pixels,  w * h * 2);
  ANativeWindow_unlockAndPost(window);
}

ANativeWindow_release(window);

일반적으로 위의 방법을 사용한다.
그런데, 문제가 좀 있다.
본인이 확인한 화면은 2장이 아니라, 4장이었다.
4장을 내 마음대로 골라서, swap하질 못한다.
무조건 순차적으로 강제 버퍼링(swap)되어 진다.
2장만 있으면, swap할 수 있는데, 4장이니, 메모리 낭비가 발생한다.

또한 swap기능을 사용 하기위해서는
1) 화면 전체를 새로 그리던가,
2) 별도의 화면 메모리를 할당하여, 그리고, 필요한 부분만 업데이트 해주면 되나,
   문제가 많다.

1), 2)번 모두 처리비용이 비싸다. 비효율적이라는 말이다.
왜 일반적인 sawp기능이 왜 없는지 의문스럽다.


Graphics architecture


Posted by 안녕1999
, |

화면을 그릴때, 사용되는 픽셀정보 구조체

관련함수 : ANativeWindow_lockANativeWindow_unlockAndPost

native_window.h


typedef struct ANativeWindow_Buffer {

    // The number of pixels that are show horizontally.

    int32_t width;


    // The number of pixels that are shown vertically.

    int32_t height;


    // The number of *pixels* that a line in the buffer takes in

    // memory.  This may be >= width.

    int32_t stride; //1줄당 픽셀수


    // The format of the buffer.  One of WINDOW_FORMAT_*

    int32_t format;//WINDOW_FORMAT_RGB_565


    // The actual bits.

    void* bits;

    

    // Do not touch.

    uint32_t reserved[6];

} ANativeWindow_Buffer;

Posted by 안녕1999
, |

Looper

키보드, 모션(터치) 등을 처리하는 기능.

..\Android\android-ndk-r13b\platforms\android-12\arch-x86\usr\include\android\looper.h

/**

 * For callback-based event loops, this is the prototype of the function

 * that is called when a file descriptor event occurs.

 * It is given the file descriptor it is associated with,

 * a bitmask of the poll events that were triggered (typically ALOOPER_EVENT_INPUT),

 * and the data pointer that was originally supplied.

 *

 * Implementations should return 1 to continue receiving callbacks, or 0

 * to have this file descriptor and callback unregistered from the looper.

 */

typedef int (*ALooper_callbackFunc)(int fd, int events, void* data);


/**

 * Waits for events to be available, with optional timeout in milliseconds.

 * Invokes callbacks for all file descriptors on which an event occurred.

 *

 * If the timeout is zero, returns immediately without blocking.

 * If the timeout is negative, waits indefinitely until an event appears.

 *

 * Returns ALOOPER_POLL_WAKE if the poll was awoken using wake() before

 * the timeout expired and no callbacks were invoked and no other file

 * descriptors were ready.

 *

 * Returns ALOOPER_POLL_CALLBACK if one or more callbacks were invoked.

 *

 * Returns ALOOPER_POLL_TIMEOUT if there was no data before the given

 * timeout expired.

 *

 * Returns ALOOPER_POLL_ERROR if an error occurred.

 *

 * Returns a value >= 0 containing an identifier if its file descriptor has data

 * and it has no callback function (requiring the caller here to handle it).

 * In this (and only this) case outFd, outEvents and outData will contain the poll

 * events and data associated with the fd, otherwise they will be set to NULL.

 *

 * This method does not return until it has finished invoking the appropriate callbacks

 * for all file descriptors that were signalled.

 */

int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData);


/**

 * Like ALooper_pollOnce(), but performs all pending callbacks until all

 * data has been consumed or a file descriptor is available with no callback.

 * This function will never return ALOOPER_POLL_CALLBACK.

 */

int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);






   // loop waiting for stuff to do.

//on_program_start();

while (1) {

// Read all pending events.

int ident;

int events;

struct android_poll_source* source;


// If not animating, we will block forever waiting for events.

// If animating, we loop until all events are read, then continue

// to draw the next frame of animation.

while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,

(void**)&source)) >= 0) {


// Process this event.

if (source != NULL) {

source->process(state, source);

}


// Check if we are exiting.

if (state->destroyRequested != 0) {

DEBUG_socket_printf("Engine thread destroy requested!\r\n");

//engine_term_display(&engine);

goto end;//return;

}

}


if (engine.animating)

{

engine_draw_frame(&engine);

}

}

Posted by 안녕1999
, |

Android API level XX
레벨 = 추가기능
"사용하고자 하는 기능"이 있는 레벨 이상으로 설정해주어야 한다.
예) 미디어플레이어 제작하려면, 레벨14이상 필요하다.
자세한 내용은 Android NDK Native APIs 에서 확인가능하다.
또한, 각 API레벨을 사용하기 위해서는 Android.mk 파일에 아래와 같은 내용을 추가해주어야 한다. 그러나, 자동으로 링크가 된다고 설명되어 있다. 어느것이 맞는지는 모르겠음.
For all API levels, the build system automatically links the standard C libraries, the standard C++ libraries, real-time extensions, and pthread; you do not need to include them when defining your LOCAL_LDLIBS variable. For more information about the C and C++ libraries, see Android API level 3.
LOCAL_LDLIBS += -lOpenMAXAL        //Android API level 14


Android API level 9
Android native application APIs
Starting from API level 9, you can write an entire Android app with native code, without using any Java.
아래의 경로에 가면, 안드로이드 NDK(JNI)헤더파일이 있다.
..\ANDROID\ANDROID-NDK-R13B\platforms\android-12\arch-x86\usr\include\android

api-level.h
asset_manager.h
asset_manager_jni.h
bitmap.h
configuration.h
dir.bat
input.h
keycodes.h
list.txt
log.h
looper.h
native_activity.h
native_window.h
native_window_jni.h
obb.h
rect.h
sensor.h
storage_manager.h
window.h

Android API level 14

The NDK provides the following APIs for developing native code that runs on Android 4.0 system images and above.

OpenMAX AL






Vulkan - Industry Forged - Khronos Group

https://www.khronos.org/vulkan/
이 페이지 번역하기
Vulkan is a new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices ...

벌컨 (API) - 위키백과, 우리 모두의 백과사전

https://ko.wikipedia.org/wiki/벌컨_(API)
벌컨(Vulkan)은 오버헤드가 적은 크로스 플랫폼 3D 그래픽스 및 컴퓨팅 API이다. 이는 GDC 2015에서 크로노스 그룹에 의해 처음으로 소개되었다. 초기의 Vulkan ...

Vulkan (API) - Wikipedia

https://en.wikipedia.org/wiki/Vulkan_(API)
이 페이지 번역하기
Vulkan is a low-overhead, cross-platform 3D graphics and compute API first announced at GDC 2015 by the Khronos Group. The Vulkan API was initially ...


Posted by 안녕1999
, |

2번째 도전

gcc컴파일러로 C소스파일을 컴파일 할 수 는 있지만, 링크와 APK파일에 넣는것은 할 수 없어, 안드로이드 스튜디오 설치.

이클립스 개발환경도 있으나, 안드로이드 스튜디오가 대세인듯함.

그러나, 설치부터, 실행까지, 너무나 무겁다.

(이클립스는 더이상 업데이트 안되니, 안드로이드 스튜디오를 사용하란다.)


1) 컴파일러(개발환경) 다운로드

지난번에는 이클립스로 해서, 용량이 작았는데, 

안드로이드 스튜디오로 하려니, 용량이 너무 크다.(약 1.7G)

https://developer.android.com/studio/index.html?hl=ko

https://developer.android.com/studio/index.html?hl=ko#win-bundle


2) JDK 설치

안드로이드 스튜디오 실행하면, 나오는 에러 메세지

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

 Java SE Development Kit 8u121
You must accept the Oracle Binary Code License Agreement for Java SE to download this software.
  Accept License Agreement       Decline License Agreement
Product / File DescriptionFile SizeDownload


Windows x86189.36 MB  jdk-8u121-windows-i586.exe
Windows x64195.51 MB  jdk-8u121-windows-x64.exe

윈도우 XP에서 설치하면 아래의 메세지가 나옴.

설치는 계속할 수 있음.

설치가 다 될때쯤, 또 에러 메세지가 나옴.

계속 진행.

JDK설치후, 안드로이드 스튜디오 실행 -> 안드로이드 스튜디오 Setup, 다운로딩 진행.

처음 실행해서 설치(다운로드)하는데, 왜이리 오래걸리는지...ㅠ ㅠ


3) NDK(라이브러리) 다운로드

https://developer.android.com/ndk/downloads/index.html

PlatformPackageSize (Bytes)SHA1 Checksum
Windows 32-bitandroid-ndk-r13b-windows-x86.zip6204615444eb1288b1d4134a9d6474eb247f0448808d52408

윈도우용 NDK?? (NDK는 OS독립적이지 않은가?)
=> NDK는 C소스파일을 리눅스의 *.so(DLL)파일로 컴파일하는 역활을 함.(안드로이드는 리눅스로 만들어졌음)
    C소스파일을 *.so형태로 컴파일해서, APK파일에 넣는다.
    안드로이드 기기(휴대폰)마다 사용하는 CPU가 다르므로, 각 CPU별로 컴파일러가 있어야 한다.
    NDK에는 각 CPU별로 컴파일러(툴체인)도 들어 있다.
    참고 : 2016.11.29 APK파일


4) NDK 샘플 소스 다운로드

https://github.com/googlesamples/android-ndk

https://github.com/googlesamples/android-ndk/archive/master.zip

'안드로이드' 카테고리의 다른 글

안드로이드 - assets 폴더  (0) 2017.02.05
ant로 안드로이드 앱을 자동으로 빌드하자  (0) 2017.02.04
안드로이드 - keystore 파일  (0) 2017.02.04
안드로이드 AssetManager  (0) 2016.11.29
APK파일  (0) 2016.11.29
Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함