mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 04:19:19 +02:00
customdrawnws-android: Adds support for the jnigraphics version of our Android code, it loads correctly, but doesnt yet render like I expected
git-svn-id: trunk@33814 -
This commit is contained in:
parent
e90ba7e010
commit
d80dc9727c
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -5419,6 +5419,7 @@ lcl/interfaces/customdrawn/Makefile.fpc svneol=native#text/plain
|
||||
lcl/interfaces/customdrawn/alllclintfunits.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/android_native_app_glue.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/asset_manager.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/bitmap.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/configuration.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/egl.pas svneol=native#text/pascal
|
||||
lcl/interfaces/customdrawn/android/eglplatform.pas svneol=native#text/pascal
|
||||
|
88
lcl/interfaces/customdrawn/android/bitmap.pas
Normal file
88
lcl/interfaces/customdrawn/android/bitmap.pas
Normal file
@ -0,0 +1,88 @@
|
||||
{*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*}
|
||||
unit bitmap;
|
||||
|
||||
{$mode delphi}
|
||||
{$packrecords c}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
ctypes, jni;
|
||||
|
||||
{#include <stdint.h>
|
||||
#include <jni.h>}
|
||||
|
||||
const
|
||||
libname='libjnigraphics.so';
|
||||
|
||||
ANDROID_BITMAP_RESUT_SUCCESS = 0;
|
||||
ANDROID_BITMAP_RESULT_BAD_PARAMETER =-1;
|
||||
ANDROID_BITMAP_RESULT_JNI_EXCEPTION =-2;
|
||||
ANDROID_BITMAP_RESULT_ALLOCATION_FAILED =-3;
|
||||
|
||||
type
|
||||
AndroidBitmapFormat = (
|
||||
ANDROID_BITMAP_FORMAT_NONE = 0,
|
||||
ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
|
||||
ANDROID_BITMAP_FORMAT_RGB_565 = 4,
|
||||
ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
|
||||
ANDROID_BITMAP_FORMAT_A_8 = 8
|
||||
);
|
||||
|
||||
AndroidBitmapInfo = record
|
||||
width: Cardinal;//uint32_t;
|
||||
height: Cardinal;//uint32_t
|
||||
stride: Cardinal;//uint32_t
|
||||
format: Integer;//int32_t
|
||||
flags: Cardinal;//uint32_t // 0 for now
|
||||
end;
|
||||
PAndroidBitmapInfo = ^AndroidBitmapInfo;
|
||||
|
||||
{**
|
||||
* Given a java bitmap object, fill out the AndroidBitmap struct for it.
|
||||
* If the call fails, the info parameter will be ignored
|
||||
*}
|
||||
function AndroidBitmap_getInfo(env: PJNIEnv;
|
||||
jbitmap: jobject; info: PAndroidBitmapInfo): cint;
|
||||
cdecl; external libname name 'AndroidBitmap_getInfo';
|
||||
|
||||
{**
|
||||
* Given a java bitmap object, attempt to lock the pixel address.
|
||||
* Locking will ensure that the memory for the pixels will not move
|
||||
* until the unlockPixels call, and ensure that, if the pixels had been
|
||||
* previously purged, they will have been restored.
|
||||
*
|
||||
* If this call succeeds, it must be balanced by a call to
|
||||
* AndroidBitmap_unlockPixels, after which time the address of the pixels should
|
||||
* no longer be used.
|
||||
*
|
||||
* If this succeeds, *addrPtr will be set to the pixel address. If the call
|
||||
* fails, addrPtr will be ignored.
|
||||
*}
|
||||
function AndroidBitmap_lockPixels(env: PJNIEnv; jbitmap: jobject;
|
||||
addrPtr: PPointer {void**}): cint; cdecl; external libname name 'AndroidBitmap_lockPixels';
|
||||
|
||||
{**
|
||||
* Call this to balanace a successful call to AndroidBitmap_lockPixels
|
||||
*}
|
||||
function AndroidBitmap_unlockPixels(env: PJNIEnv;
|
||||
jbitmap: jobject): cint; cdecl; external libname name 'AndroidBitmap_unlockPixels';
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
@ -35,8 +35,9 @@ uses
|
||||
{$ifdef CD_Cocoa}MacOSAll, CocoaAll, CocoaPrivate,{$endif}
|
||||
{$ifdef CD_X11}X, XLib, XUtil, customdrawn_x11proc,{unitxft, Xft font support}{$endif}
|
||||
{$ifdef CD_Android}
|
||||
customdrawn_androidproc,
|
||||
cmem,
|
||||
customdrawn_androidproc,
|
||||
{$ifdef CD_Android_NativeApp}
|
||||
gles,
|
||||
egl,
|
||||
native_activity,
|
||||
@ -44,6 +45,10 @@ uses
|
||||
looper,
|
||||
input,
|
||||
android_native_app_glue,
|
||||
{$else}
|
||||
jni,
|
||||
bitmap,
|
||||
{$endif}
|
||||
log,
|
||||
{$endif}
|
||||
// Widgetset
|
||||
@ -197,6 +202,15 @@ function WindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
|
||||
LParam: Windows.LParam): LResult; stdcall;
|
||||
{$endif}
|
||||
|
||||
{$ifndef CD_Android_NATIVEAPP}
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_intFromJNI(env:PJNIEnv;this:jobject): jint; cdecl;
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_LCLDrawToBitmap(
|
||||
env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl;
|
||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
||||
{$endif}
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
|
@ -17,7 +17,7 @@
|
||||
* *
|
||||
*****************************************************************************
|
||||
}
|
||||
|
||||
{$ifdef CD_Android_NATIVEAPP}
|
||||
type
|
||||
Psaved_state = ^Tsaved_state;
|
||||
Tsaved_state = packed record
|
||||
@ -177,6 +177,7 @@ begin
|
||||
if lError <> GL_NO_ERROR then LOGW(PChar('[engine_draw_frame] 8 Error='+IntToStr(Integer(lError))));
|
||||
|
||||
// Draw a square
|
||||
glColor4f(1, 0, 0, 1);
|
||||
glVertexPointer(2, GL_FLOAT, 0, @vertices[0]);
|
||||
lError := glGetError();
|
||||
if lError <> GL_NO_ERROR then LOGW(PChar('[engine_draw_frame] 9 Error='+IntToStr(Integer(lError))));
|
||||
@ -389,6 +390,94 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{$else}
|
||||
|
||||
const curClass:JClass=nil;
|
||||
nativeCodeLoaded:JfieldID=nil;
|
||||
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
||||
var x:single;
|
||||
begin
|
||||
{ __android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI entered');
|
||||
curEnv^.SetLongField(curEnv,curClass,nativeCodeLoaded,1);
|
||||
x:=8;
|
||||
result:=env^.NewStringUTF(env,pchar('Hello from native free pascal code by BeRo to the java world on the android platform ! '+floattostr(x*0.5)));
|
||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI exited');}
|
||||
end;
|
||||
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_intFromJNI(env:PJNIEnv;this:jobject): jint; cdecl;
|
||||
begin
|
||||
Result := 8;
|
||||
end;
|
||||
|
||||
function Java_com_pascal_jnitest_AndroidJNITest_LCLDrawToBitmap(
|
||||
env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl;
|
||||
var
|
||||
pixels: PCardinal;
|
||||
begin
|
||||
Result := 0;
|
||||
AndroidBitmap_lockPixels(env, abitmap, @pixels);
|
||||
pixels[30*width+30] := $FFFFFFFF;
|
||||
pixels[30*width+31] := $FFFFFFFF;
|
||||
pixels[30*width+32] := $FFFFFFFF;
|
||||
pixels[30*width+33] := $FFFFFFFF;
|
||||
pixels[30*width+34] := $FFFFFFFF;
|
||||
pixels[30*width+35] := $FFFFFFFF;
|
||||
AndroidBitmap_unlockPixels(env, abitmap);
|
||||
end;
|
||||
|
||||
const NativeMethods:array[0..2] of JNINativeMethod=
|
||||
((name:'stringFromJNI';
|
||||
signature:'()Ljava/lang/String;';
|
||||
fnPtr:@Java_com_pascal_jnitest_AndroidJNITest_stringFromJNI;),
|
||||
(name:'intFromJNI';
|
||||
signature:'()I';
|
||||
fnPtr:@Java_com_pascal_jnitest_AndroidJNITest_intFromJNI;),
|
||||
(name:'LCLDrawToBitmap';
|
||||
signature:'(IILandroid/graphics/Bitmap;)I';
|
||||
fnPtr:@Java_com_pascal_jnitest_AndroidJNITest_LCLDrawToBitmap;)
|
||||
);
|
||||
|
||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||
begin
|
||||
curVM:=vm;
|
||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called');
|
||||
(* __android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM=%x', [PtrInt(CurVM)])));
|
||||
if curVM^.GetEnv(curVM,@curEnv,JNI_VERSION_1_6)<>JNI_OK then begin <<<--- THIS CRASHES
|
||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curVM^.GetEnv failed');
|
||||
result:=JNI_ERR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Reading curClass');
|
||||
curClass:=curEnv^.FindClass(curEnv,'com/pascal/jnitest/AndroidJNITest');
|
||||
if not assigned(curClass) then begin
|
||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.FindClass failed');
|
||||
result:=JNI_ERR;
|
||||
exit;
|
||||
end;
|
||||
if curEnv^.RegisterNatives(curEnv,curClass,@NativeMethods[0],length(NativeMethods))<0 then begin
|
||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.RegisterNatives failed');
|
||||
result:=JNI_ERR;
|
||||
exit;
|
||||
end;
|
||||
|
||||
nativeCodeLoaded:=curEnv^.GetFieldID(curEnv,curClass,'nativeCodeLoaded','J');
|
||||
if not assigned(nativeCodeLoaded) then begin
|
||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.GetFieldID failed');
|
||||
result:=JNI_ERR;
|
||||
exit;
|
||||
end;*)
|
||||
|
||||
result:=JNI_VERSION_1_6;
|
||||
end;
|
||||
|
||||
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
||||
begin
|
||||
end;
|
||||
|
||||
{$endif}
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCDWidgetSet.Create
|
||||
Params: None
|
||||
|
Loading…
Reference in New Issue
Block a user