1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- unit GR32_Backends_Generic;
- (* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1 or LGPL 2.1 with linking exception
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Alternatively, the contents of this file may be used under the terms of the
- * Free Pascal modified version of the GNU Lesser General Public License
- * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
- * of this license are applicable instead of those above.
- * Please see the file LICENSE.txt for additional information concerning this
- * license.
- *
- * The Original Code is Backend Extension for Graphics32
- *
- * The Initial Developer of the Original Code is
- * Andre Beckedorf - metaException
- * [email protected]
- *
- * Portions created by the Initial Developer are Copyright (C) 2007-2009
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** *)
- interface
- {$I GR32.inc}
- uses
- SysUtils, Classes, GR32;
- type
- { TMemoryBackend }
- { A backend that keeps the backing buffer entirely in memory.}
- TMemoryBackend = class(TCustomBackend)
- protected
- procedure InitializeSurface(NewWidth, NewHeight: Integer; ClearBuffer: Boolean); override;
- procedure FinalizeSurface; override;
- end;
- implementation
- uses
- System.IOUtils,
- GR32_LowLevel;
- {$IFDEF Windows}
- var
- TempPath: TFileName;
- resourcestring
- RCStrFailedToMapFile = 'Failed to map file';
- RCStrFailedToCreateMapFile = 'Failed to create map file (%s)';
- RCStrFailedToMapViewOfFile = 'Failed to map view of file.';
- function GetTempPath: TFileName;
- begin
- Result := TPath.GetTempFileName;
- end;
- {$ENDIF}
- { TMemoryBackend }
- procedure TMemoryBackend.InitializeSurface(NewWidth, NewHeight: Integer; ClearBuffer: Boolean);
- begin
- GetMem(FBits, NewWidth * NewHeight * 4);
- if ClearBuffer then
- FillLongword(FBits[0], NewWidth * NewHeight, clBlack32);
- end;
- procedure TMemoryBackend.FinalizeSurface;
- begin
- if Assigned(FBits) then
- begin
- FreeMem(FBits);
- FBits := nil;
- end;
- end;
- end.
|