Skip to content

Commit

Permalink
remove Volatile from TALTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeus64 committed Jan 7, 2019
1 parent 3f500d3 commit 4e1615d
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 309 deletions.
83 changes: 55 additions & 28 deletions source/ALFMXTypes3D.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ TALTextureAccessPrivate = class(TInterfacedPersistent)
{**************************}
TALTexture = class(TTexture)
private
fVolatile: Boolean;
FisExternalOES: Boolean;
protected
public
constructor Create(const aVolatile: Boolean = {$IF CompilerVersion <= 31}{berlin}False{$ELSE}True{$ENDIF}); reintroduce; virtual;
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property isExternalOES: boolean read fisExternalOES write fisExternalOES;
Expand All @@ -69,7 +68,7 @@ TALBiPlanarTexture = class(TALTexture)
FFormat: TALTextureFormat;
protected
public
constructor Create(const aVolatile: Boolean = {$IF CompilerVersion <= 31}{berlin}False{$ELSE}True{$ENDIF}); override;
constructor Create; override;
destructor Destroy; override;
property SecondTexture: TTexture read FSecondTexture;
property Format: TALTextureFormat read fformat write fformat;
Expand All @@ -83,7 +82,7 @@ TALPlanarTexture = class(TALTexture)
FFormat: TALTextureFormat;
protected
public
constructor Create(const aVolatile: Boolean = {$IF CompilerVersion <= 31}{berlin}False{$ELSE}True{$ENDIF}); override;
constructor Create; override;
destructor Destroy; override;
property SecondTexture: TTexture read FSecondTexture;
property ThirdTexture: TTexture read FThirdTexture;
Expand Down Expand Up @@ -138,11 +137,6 @@ TALCanvas420YpCbCr8PlanarTextureMaterial = class(TCanvasTextureMaterial)
property CrTexture: TTexture read FCrTexture write SetCrTexture;
end;

{$IFDEF DEBUG}
var TotalMemoryUsedByTextures: int64;
LastTotalMemoryUsedByTexturesLog: int64;
{$ENDIF}

implementation

uses system.sysutils,
Expand All @@ -159,17 +153,27 @@ implementation
{$ENDIF}
ALCommon;

{******************************************************************}
//aVolatile = true mean DO NOT COPY the bytes in an internal storage
//to have the possibility to recreate later the texture if we lost the
//context. From Tokyo we don't lost anymore the context when the app go
//in background/foreground so it's useless to set it to false
constructor TALTexture.Create(const aVolatile: Boolean = True);
{$IFDEF DEBUG}
var TotalMemoryUsedByTextures: int64;
LastTotalMemoryUsedByTexturesLog: int64;
{$ENDIF}

{****************************}
constructor TALTexture.Create;
begin

//inherited create
inherited Create;
fVolatile := aVolatile;
if fVolatile then Style := Style + [TTextureStyle.Volatile];

//TTextureStyle.Volatile mean DO NOT COPY the bytes in an internal storage
//to have the possibility to recreate later the texture if we lost the
//context. From Berlin we don't lost anymore the context when the app go
//in background/foreground so it's useless to set it to false
Style := Style + [TTextureStyle.Volatile];

//init FisExternalOES
FisExternalOES := False;

end;

{****************************}
Expand Down Expand Up @@ -221,8 +225,7 @@ procedure TALTexture.Assign(Source: TPersistent);
{$ENDIF}
if Handle <> 0 then TContextManager.DefaultContextClass.FinalizeTexture(Self);
PixelFormat := TBitmap(Source).PixelFormat;
Style := [TTextureStyle.Dynamic];
if fVolatile then Style := Style + [TTextureStyle.Volatile];
Style := [TTextureStyle.Dynamic, TTextureStyle.Volatile];
TALTextureAccessPrivate(self).fTextureScale := TBitmap(Source).BitmapScale;
SetSize(TBitmap(Source).Width, TBitmap(Source).Height);
if TBitmap(Source).Map(TMapAccess.Read, M) then
Expand All @@ -244,8 +247,7 @@ procedure TALTexture.Assign(Source: TPersistent);
//try
{$ENDIF}
if Handle <> 0 then TContextManager.DefaultContextClass.FinalizeTexture(Self);
Style := [TTextureStyle.Dynamic];
if fVolatile then Style := Style + [TTextureStyle.Volatile];
Style := [TTextureStyle.Dynamic, TTextureStyle.Volatile];
SetSize(TBitmapSurface(Source).Width, TBitmapSurface(Source).Height);
UpdateTexture(TBitmapSurface(Source).Bits, TBitmapSurface(Source).Pitch);
{$IF CompilerVersion >= 32} // tokyo
Expand All @@ -255,6 +257,31 @@ procedure TALTexture.Assign(Source: TPersistent);
{$ENDIF}
end

else if Source is TTexture then begin
{$IF CompilerVersion >= 32} // tokyo
//TMonitor.Enter(Self);
//try
{$ENDIF}
if Handle <> 0 then TContextManager.DefaultContextClass.FinalizeTexture(Self);
TALTextureAccessPrivate(self).FWidth := TTexture(Source).width;
TALTextureAccessPrivate(self).FHeight := TTexture(Source).height;
TALTextureAccessPrivate(self).FPixelFormat := TTexture(Source).PixelFormat;
TALTextureAccessPrivate(self).FHandle := TTexture(Source).Handle;
TALTextureAccessPrivate(self).FStyle := TTexture(Source).Style + [TTextureStyle.Volatile];
TALTextureAccessPrivate(self).FMagFilter := TTexture(Source).MagFilter;
TALTextureAccessPrivate(self).FMinFilter := TTexture(Source).MinFilter;
TALTextureAccessPrivate(self).FTextureScale := TTexture(Source).TextureScale;
//FRequireInitializeAfterLost: Boolean;
//FBits: Pointer;
//FContextLostId: Integer;
//FContextResetId: Integer;
{$IF CompilerVersion >= 32} // tokyo
//finally
// TMonitor.exit(Self);
//end;
{$ENDIF}
end

else inherited ;

{$IFDEF DEBUG}
Expand All @@ -269,11 +296,11 @@ procedure TALTexture.Assign(Source: TPersistent);

end;

{*********************************************************************}
constructor TALBiPlanarTexture.Create(const aVolatile: Boolean = True);
{************************************}
constructor TALBiPlanarTexture.Create;
begin
inherited;
FSecondTexture := TALTexture.Create(aVolatile);
FSecondTexture := TALTexture.Create;
FFormat := TALTextureFormat.f420YpCbCr8BiPlanarVideoRange;
end;

Expand All @@ -284,12 +311,12 @@ destructor TALBiPlanarTexture.Destroy;
inherited;
end;

{*******************************************************************}
constructor TALPlanarTexture.Create(const aVolatile: Boolean = True);
{**********************************}
constructor TALPlanarTexture.Create;
begin
inherited;
FSecondTexture := TALTexture.Create(aVolatile);
FThirdTexture := TALTexture.Create(aVolatile);
FSecondTexture := TALTexture.Create;
FThirdTexture := TALTexture.Create;
FFormat := TALTextureFormat.f420YpCbCr8Planar;
end;

Expand Down
Loading

0 comments on commit 4e1615d

Please sign in to comment.