Changeset 8 for trunk/Platform


Ignore:
Timestamp:
May 9, 2015, 1:32:38 AM (10 years ago)
Author:
chronos
Message:
  • Moved: Kernel related files moved to separate lazarus package named Kernel.
  • Modified: Implemented simple graphic device driver and drawin example.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Platform/Base/UPlatformBase.pas

    r7 r8  
    77uses
    88  Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory,
    9   DateUtils;
     9  DateUtils, UDevice, Contnrs, Graphics, Forms, UScreen;
    1010
    1111type
     
    4242  end;
    4343
    44   TReceiveEvent = procedure(Data: TMemory) of object;
     44  TReceiveEvent = procedure(Text: string) of object;
    4545
    4646  { TBaseSerialDevice }
    4747
    48   TBaseSerialDevice = class(TDevice)
     48  TBaseSerialDevice = class(TDeviceSerial)
    4949  private
    5050    Lock: TCriticalSection;
     
    5353    constructor Create; override;
    5454    destructor Destroy; override;
    55     procedure Service(Index: Integer; DataIn, DataOut: TMemory); override;
     55    procedure WriteText(Text: string); override;
    5656    property OnReceiveData: TReceiveEvent read FOnReceiveData write FOnReceiveData;
    5757  end;
    5858
    59   { TBaseVideoDevice }
    60 
    61   TBaseVideoDevice = class(TDevice)
     59  { TDeviceVideoBase }
     60
     61  TDeviceVideoBase = class(TDeviceVideo)
    6262  private
     63    FOnModeChanged: TNotifyEvent;
    6364    FOnRedraw: TNotifyEvent;
     65    OnModeChanged: TNotifyEvent;
     66    procedure DoRedraw;
    6467  public
    6568    VideoMemory: PByte;
    6669    VideoMemorySize: TPoint;
    6770    DPI: Integer;
    68     constructor Create; override;
    69     destructor Destroy; override;
    70     procedure Service(Index: Integer; DataIn, DataOut: TMemory); override;
     71    Canvas: TCanvas;
     72    VideoMode: TVideoMode;
     73    procedure SetMode(Mode: TVideoMode); override;
     74    procedure GetSupportedModes(Modes: TObjectList); override;
     75    function GetVideoMemory: PByte; override;
     76    procedure VideoMemoryChange; override;
     77    constructor Create; override;
     78    destructor Destroy; override;
    7179    property OnRedraw: TNotifyEvent read FOnRedraw write FOnRedraw;
     80    property OnModeChanged: TNotifyEvent read FOnModeChanged write FOnModeChanged;
    7281  end;
    7382
    7483implementation
    7584
    76 { TBaseVideoDevice }
    77 
    78 constructor TBaseVideoDevice.Create;
     85{ TDeviceVideoBase }
     86
     87procedure TDeviceVideoBase.DoRedraw;
     88begin
     89
     90end;
     91
     92procedure TDeviceVideoBase.SetMode(Mode: TVideoMode);
     93begin
     94  if (VideoMode.Size.X <> Mode.Size.X) or
     95    (VideoMode.Size.Y <> Mode.Size.Y) or
     96    (VideoMode.ColorFormat <> Mode.ColorFormat) then begin
     97      VideoMode.Size := Mode.Size;
     98      VideoMode.ColorFormat := Mode.ColorFormat;
     99      if Assigned(FOnModeChanged) then
     100        FOnModeChanged(Self);
     101    end;
     102end;
     103
     104procedure TDeviceVideoBase.GetSupportedModes(Modes: TObjectList);
     105var
     106  NewMode: TVideoMode;
     107begin
     108  Modes.Clear;
     109  NewMode := TVideoMode.Create;
     110  NewMode.Size := Point(320, 240);
     111  NewMode.ColorFormat := cfRGBA8;
     112  Modes.Add(NewMode);
     113  NewMode := TVideoMode.Create;
     114  NewMode.Size := Point(640, 480);
     115  NewMode.ColorFormat := cfRGBA8;
     116  Modes.Add(NewMode);
     117{  NewMode := TVideoMode.Create;
     118  NewMode.Size := Point(800, 600);
     119  NewMode.ColorFormat := cfRGBA8;
     120  Modes.Add(NewMode);
     121  NewMode := TVideoMode.Create;
     122  NewMode.Size := Point(1024, 768);
     123  NewMode.ColorFormat := cfRGBA8;
     124  Modes.Add(NewMode);
     125  NewMode := TVideoMode.Create;
     126  NewMode.Size := Point(1278, 1024);
     127  NewMode.ColorFormat := cfRGBA8;
     128  Modes.Add(NewMode);
     129  NewMode := TVideoMode.Create;
     130  NewMode.Size := Point(1920, 1080);
     131  NewMode.ColorFormat := cfRGBA8;
     132  Modes.Add(NewMode);
     133  }
     134end;
     135
     136function TDeviceVideoBase.GetVideoMemory: PByte;
     137begin
     138  VideoMemory := GetMem(VideoMode.GetBytesPerImage);
     139  FillDWord(VideoMemory^, VideoMode.GetBytesPerImage div 4, $ffffff);
     140  Result := VideoMemory;
     141end;
     142
     143procedure TDeviceVideoBase.VideoMemoryChange;
     144begin
     145  if Assigned(FOnRedraw) then FOnRedraw(Self);
     146end;
     147
     148constructor TDeviceVideoBase.Create;
    79149begin
    80150  inherited Create;
    81 end;
    82 
    83 destructor TBaseVideoDevice.Destroy;
    84 begin
    85   inherited Destroy;
    86 end;
    87 
    88 procedure TBaseVideoDevice.Service(Index: Integer; DataIn, DataOut: TMemory);
    89 begin
    90   if Index = 0 then begin
    91     // Redraw to screen
    92     if Assigned(FOnRedraw) then
    93       FOnRedraw(Self);
    94   end else
    95   if Index = 1 then begin
    96     // Get video memory
    97     VideoMemory := GetMem(VideoMemorySize.X * VideoMemorySize.Y * 4);
    98 //    DataOut^ := VideoMemory;
    99 //    DataOut^ := VideoMemory;
    100   end else inherited;
     151  VideoMode := TVideoMode.Create;
     152end;
     153
     154destructor TDeviceVideoBase.Destroy;
     155begin
     156  VideoMode.Free;
     157  inherited Destroy;
    101158end;
    102159
     
    116173end;
    117174
    118 procedure TBaseSerialDevice.Service(Index: Integer; DataIn, DataOut: TMemory);
    119 begin
    120   if Index = 0 then begin
    121     Lock.Acquire;
    122     if Assigned(FOnReceiveData) then
    123       FOnReceiveData(DataIn);
    124     Lock.Release;
    125   end else inherited;
     175procedure TBaseSerialDevice.WriteText(Text: string);
     176begin
     177  Lock.Acquire;
     178  if Assigned(FOnReceiveData) then
     179    FOnReceiveData(Text);
     180  Lock.Release;
    126181end;
    127182
Note: See TracChangeset for help on using the changeset viewer.