mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 21:30:04 +02:00
LCL-CustomDrawn: Buffers the canvas bitmap in Android which greatly diminishes the garbage collector activity and speeds drawing. Also adds a new callback routine to select forms of the project which should have the background drawing painting skipped to speed up drawing
git-svn-id: trunk@36700 -
This commit is contained in:
parent
31a6eef00a
commit
cd24e7b458
examples/androidlcl/android/src/com/pascal/lcltest
lcl/interfaces/customdrawn
@ -46,7 +46,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
||||
.newEditable("Placeholder");
|
||||
}
|
||||
return _editable;
|
||||
} This crashes in HTC */
|
||||
} This crashes in HTC!!! */
|
||||
|
||||
// This method sends a text to be added at the current cursor position
|
||||
@Override public boolean commitText(CharSequence text, int newCursorPosition)
|
||||
@ -97,6 +97,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
||||
// -------------------------------------------
|
||||
private class LCLSurface extends View
|
||||
{
|
||||
private Bitmap canvasbitmap; // This is the buffered canvas bitmap, which is reused until the canvas size changes
|
||||
|
||||
public LCLSurface(Context context)
|
||||
{
|
||||
super(context);
|
||||
@ -121,16 +123,19 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
||||
lclscreenwidth = lclformwidth;
|
||||
lclscreenheight = lclformheight;
|
||||
|
||||
// Check if we rotated in the draw event, OnConfigurationChanged can't return the new form width =(
|
||||
// Check if we rotated in the draw event.
|
||||
// LCLOnConfigurationChanged is called from here because the Android event
|
||||
// OnConfigurationChanged can't return the new form width =(
|
||||
// see http://stackoverflow.com/questions/2524683/how-to-get-new-width-height-of-root-layout-in-onconfigurationchanged
|
||||
if (lWidth != oldlclformwidth) LCLOnConfigurationChanged(lclxdpi, lWidth); // we send xdpi because thats what the LCL uses for Screen.PixelsPerInch
|
||||
|
||||
//Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth)
|
||||
// + " height=" + Integer.toString(lHeight));
|
||||
|
||||
Bitmap localbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888);
|
||||
LCLDrawToBitmap(lWidth, lHeight, localbitmap);
|
||||
canvas.drawBitmap(localbitmap, 0, 0, null);
|
||||
|
||||
if ((canvasbitmap == null) || (canvasbitmap.getWidth() != lWidth) || (canvasbitmap.getHeight() != lHeight))
|
||||
canvasbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888);
|
||||
LCLDrawToBitmap(lWidth, lHeight, canvasbitmap);
|
||||
canvas.drawBitmap(canvasbitmap, 0, 0, null);
|
||||
//Log.i("lclapp", "onDraw finished");
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,9 @@ type
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
// Return true to disable the form background drawing
|
||||
TDisableFormBackgroundDrawingProc = function (AForm: TCustomForm): Boolean of object;
|
||||
|
||||
{ TLazCDCustomFont }
|
||||
|
||||
TLazCDCustomFont = class(TFPCustomFont)
|
||||
@ -304,6 +307,15 @@ type
|
||||
{$ifdef WinCE}
|
||||
WinCETitlePolicy: TWinCETitlePolicy;
|
||||
{$endif}
|
||||
|
||||
// This callback might be set to provide a routine which will select for
|
||||
// which forms the drawing of the background should be disabled
|
||||
// This is provided for speeding up the drawing
|
||||
//
|
||||
// Only use it if you are 100% sure that you are filling the entire buffer
|
||||
// in the form paint event. Note that the form might sometimes be smaller
|
||||
// then the buffer in Android so fill the entire Canvas area, not only the form size
|
||||
DisableFormBackgroundDrawingProc: TDisableFormBackgroundDrawingProc;
|
||||
end;
|
||||
|
||||
var
|
||||
|
@ -579,8 +579,16 @@ begin
|
||||
|
||||
// Disable the drawing itself, but keep the window org and region operations
|
||||
// or else clicking and other things are broken, specially in Android
|
||||
lDrawControl := lWindowHandle.IsControlBackgroundVisible();
|
||||
|
||||
//
|
||||
// If the form is smaller then the buffer (this might happen in Android)
|
||||
// then we need to force drawing the background to erase old contents of the buffer
|
||||
//
|
||||
// Consider also if the user wants to manually disable the background drawing
|
||||
lDrawControl := True;
|
||||
if Assigned(CDWidgetset.DisableFormBackgroundDrawingProc) then
|
||||
lDrawControl := CDWidgetset.DisableFormBackgroundDrawingProc(AForm);
|
||||
if lDrawControl then
|
||||
lDrawControl := lWindowHandle.IsControlBackgroundVisible() or (AForm.Height < AImage.Height);
|
||||
if lDrawControl then
|
||||
DrawFormBackground(AImage, ACanvas);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user