mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-01 06:09:36 +01: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
@ -46,7 +46,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
.newEditable("Placeholder");
|
.newEditable("Placeholder");
|
||||||
}
|
}
|
||||||
return _editable;
|
return _editable;
|
||||||
} This crashes in HTC */
|
} This crashes in HTC!!! */
|
||||||
|
|
||||||
// This method sends a text to be added at the current cursor position
|
// This method sends a text to be added at the current cursor position
|
||||||
@Override public boolean commitText(CharSequence text, int newCursorPosition)
|
@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 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)
|
public LCLSurface(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
@ -121,16 +123,19 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
lclscreenwidth = lclformwidth;
|
lclscreenwidth = lclformwidth;
|
||||||
lclscreenheight = lclformheight;
|
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
|
// 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
|
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)
|
//Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth)
|
||||||
// + " height=" + Integer.toString(lHeight));
|
// + " height=" + Integer.toString(lHeight));
|
||||||
|
|
||||||
Bitmap localbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888);
|
if ((canvasbitmap == null) || (canvasbitmap.getWidth() != lWidth) || (canvasbitmap.getHeight() != lHeight))
|
||||||
LCLDrawToBitmap(lWidth, lHeight, localbitmap);
|
canvasbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888);
|
||||||
canvas.drawBitmap(localbitmap, 0, 0, null);
|
LCLDrawToBitmap(lWidth, lHeight, canvasbitmap);
|
||||||
|
canvas.drawBitmap(canvasbitmap, 0, 0, null);
|
||||||
//Log.i("lclapp", "onDraw finished");
|
//Log.i("lclapp", "onDraw finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,6 +91,9 @@ type
|
|||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
// Return true to disable the form background drawing
|
||||||
|
TDisableFormBackgroundDrawingProc = function (AForm: TCustomForm): Boolean of object;
|
||||||
|
|
||||||
{ TLazCDCustomFont }
|
{ TLazCDCustomFont }
|
||||||
|
|
||||||
TLazCDCustomFont = class(TFPCustomFont)
|
TLazCDCustomFont = class(TFPCustomFont)
|
||||||
@ -304,6 +307,15 @@ type
|
|||||||
{$ifdef WinCE}
|
{$ifdef WinCE}
|
||||||
WinCETitlePolicy: TWinCETitlePolicy;
|
WinCETitlePolicy: TWinCETitlePolicy;
|
||||||
{$endif}
|
{$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;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|||||||
@ -579,8 +579,16 @@ begin
|
|||||||
|
|
||||||
// Disable the drawing itself, but keep the window org and region operations
|
// Disable the drawing itself, but keep the window org and region operations
|
||||||
// or else clicking and other things are broken, specially in Android
|
// 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
|
if lDrawControl then
|
||||||
DrawFormBackground(AImage, ACanvas);
|
DrawFormBackground(AImage, ACanvas);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user