GR32_Backends_Generic.pas 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. unit GR32_Backends_Generic;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is Backend Extension for Graphics32
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Andre Beckedorf - metaException
  26. * [email protected]
  27. *
  28. * Portions created by the Initial Developer are Copyright (C) 2007-2009
  29. * the Initial Developer. All Rights Reserved.
  30. *
  31. * Contributor(s):
  32. *
  33. * ***** END LICENSE BLOCK ***** *)
  34. interface
  35. {$I GR32.inc}
  36. uses
  37. SysUtils, Classes, GR32;
  38. type
  39. { TMemoryBackend }
  40. { A backend that keeps the backing buffer entirely in memory.}
  41. TMemoryBackend = class(TCustomBackend)
  42. protected
  43. procedure InitializeSurface(NewWidth, NewHeight: Integer; ClearBuffer: Boolean); override;
  44. procedure FinalizeSurface; override;
  45. end;
  46. implementation
  47. uses
  48. System.IOUtils,
  49. GR32_LowLevel;
  50. {$IFDEF Windows}
  51. var
  52. TempPath: TFileName;
  53. resourcestring
  54. RCStrFailedToMapFile = 'Failed to map file';
  55. RCStrFailedToCreateMapFile = 'Failed to create map file (%s)';
  56. RCStrFailedToMapViewOfFile = 'Failed to map view of file.';
  57. function GetTempPath: TFileName;
  58. begin
  59. Result := TPath.GetTempFileName;
  60. end;
  61. {$ENDIF}
  62. { TMemoryBackend }
  63. procedure TMemoryBackend.InitializeSurface(NewWidth, NewHeight: Integer; ClearBuffer: Boolean);
  64. begin
  65. GetMem(FBits, NewWidth * NewHeight * 4);
  66. if ClearBuffer then
  67. FillLongword(FBits[0], NewWidth * NewHeight, clBlack32);
  68. end;
  69. procedure TMemoryBackend.FinalizeSurface;
  70. begin
  71. if Assigned(FBits) then
  72. begin
  73. FreeMem(FBits);
  74. FBits := nil;
  75. end;
  76. end;
  77. end.