1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 09:12:19 -05:00

Ben, either get rid of those run parameters in your compiler options or stop commiting project1.lpi please ^_^.

Added a copydata parameter to TRawTarget.create. (This now fixes a memory leak in Unfreeze). Also please get rid of those two extra spaces in front of everything, so anti-pascal-syntax ^^. Also fixed the bug in IsTargetValid.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@452 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-01-23 13:17:56 +00:00
parent 3d4131af95
commit 2b8721e6b0

View File

@ -65,7 +65,7 @@ interface
| Currently this uses the pointer as-is, but it might be needed to make a local copy... }
TRawTarget = class(TTarget)
public
constructor Create(rgb: prgb32; w,h: integer);
constructor Create(rgb: prgb32; w,h: integer; CopyData : boolean);
destructor Destroy; override;
procedure GetTargetDimensions(var w, h: integer); override;
@ -73,6 +73,7 @@ interface
private
rgb: prgb32;
freedata : boolean;
w,h: integer;
end;
@ -255,6 +256,10 @@ implementation
frozen:= nil;
NativeInit;
SetDesktop;
{
self.create;
eios_controller.AddAndLoadPath(plugin_dir);
}
end;
constructor TIOManager_Abstract.Create;
@ -274,12 +279,12 @@ implementation
keymouse.Free();
image.Free();
end;
if frozen <> nil then frozen.Destroy();
if IsFrozen then frozen.Destroy();
end;
procedure TIOManager_Abstract.SetImageTarget(target: TTarget);
begin
if frozen <> nil then
if IsFrozen then
raise Exception.Create('You cannot set a target when Frozen');
if not(bothsame) then image.Free();
image:= target;
@ -293,7 +298,7 @@ implementation
end;
procedure TIOManager_Abstract.SetBothTargets(target: TTarget);
begin
if frozen <> nil then
if IsFrozen then
raise Exception.Create('You cannot set a target when Frozen');
if bothsame then image.Destroy() else
begin
@ -310,25 +315,23 @@ implementation
w,h: integer;
buffer: TRetData;
begin
if (makefrozen) and (frozen <> nil) then
if (makefrozen) and (IsFrozen) then
raise Exception.Create('The window is already frozen.');
//BenLand100 edit: I say we leave this exception out. POLS
//if not(isfrozen) and (frozen = nil) then
// raise Exception.Create('The window is not frozen.');
if not(makefrozen) then
begin
image.Free();
image:= frozen;
frozen:= nil;
end else if frozen = nil then
if makefrozen then //No need for the Frozen = nil check, already done above with the exception.
begin
frozen:= image;
frozen.GetTargetDimensions(w,h);
buffer:= frozen.ReturnData(0,0,w,h);
GetMem(freezebuffer, w * h * sizeof(TRGB32));
Move(buffer.Ptr[0], freezebuffer[0], w*h*sizeof(TRGB32));
image:= TRawTarget.Create(buffer.Ptr,w,h,true);
frozen.FreeReturnData;
image:= TRawTarget.Create(freezebuffer,w,h);
end else
begin
image.Free();
image:= frozen;
frozen:= nil;
end;
end;
@ -341,8 +344,8 @@ implementation
function TIOManager_Abstract.ReturnData(xs,ys,width,height: integer): TRetData; begin result:= image.ReturnData(xs,ys,width,height); end;
procedure TIOManager_Abstract.FreeReturnData; begin image.freeReturnData(); end;
function TIOManager_Abstract.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; begin SetImageTarget(TRawTarget.Create(ArrPtr,Size.X,Size.Y)); end;
function TIOManager_Abstract.SetTarget(bmp : TMufasaBitmap) : integer; begin SetImageTarget(TRawTarget.Create(bmp.FData,bmp.width,bmp.height)); end;
function TIOManager_Abstract.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; begin SetImageTarget(TRawTarget.Create(ArrPtr,Size.X,Size.Y,false)); end;
function TIOManager_Abstract.SetTarget(bmp : TMufasaBitmap) : integer; begin SetImageTarget(TRawTarget.Create(bmp.FData,bmp.width,bmp.height,false)); end;
function TIOManager_Abstract.SetTarget(name: string; initargs: pointer): integer;
var
client: TEIOS_Client;
@ -356,9 +359,7 @@ implementation
begin
result:= false;
if (keymouse <> nil) and (image <> nil) then
begin
end;
result := (keymouse.TargetValid and image.TargetValid);
end;
procedure TIOManager_Abstract.GetDimensions(var W, H: Integer); begin image.GetTargetDimensions(w,h) end;
@ -516,17 +517,24 @@ implementation
//***implementation*** TRawTarget
constructor TRawTarget.Create(rgb: prgb32; w,h: integer);
constructor TRawTarget.Create(rgb: prgb32; w,h: integer; CopyData : boolean);
begin
inherited Create;
self.rgb:= rgb;
self.w:= w;
self.h:= h;
self.freedata:= copydata;
if CopyData then
begin
GetMem(self.rgb,w*h*sizeof(TRGB32));
Move(rgb[0],self.rgb[0],w*h*sizeof(TRGB32));
end else
self.rgb:= rgb;
end;
destructor TRawTarget.Destroy;
begin
{do nothing}
if freedata then
Freemem(self.rgb,w*h*sizeof(TRGB32));
inherited Destroy;
end;