Ignore:
Timestamp:
Feb 1, 2012, 3:02:33 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package to version 5.5.
  • Modified: Removed draw method ComboBox and reorganized method list to single listview with using ownerdraw facility.
  • Added: New draw method TBitmap.RawImage.Data Move which use fast Move operation. It requires same pixel format.
  • Added: New draw method Dummy for comparion of empty method and to determine possibily max frame rate limit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/UMainForm.pas

    r212 r317  
    2020
    2121  TMainForm = class(TForm)
     22    ButtonStop: TButton;
    2223    ButtonBenchmark: TButton;
    23     ButtonStart: TButton;
    24     ButtonStop: TButton;
    25     ComboBox1: TComboBox;
     24    ButtonSingleTest: TButton;
    2625    FloatSpinEdit1: TFloatSpinEdit;
    2726    Image1: TImage;
    2827    Label1: TLabel;
    2928    Label2: TLabel;
    30     Label3: TLabel;
    31     Label4: TLabel;
    32     Label5: TLabel;
    33     ListView1: TListView;
     29    ListViewMethods: TListView;
    3430    PageControl1: TPageControl;
    3531    PaintBox1: TPaintBox;
     
    3935    Timer1: TTimer;
    4036    procedure ButtonBenchmarkClick(Sender: TObject);
    41     procedure ButtonStartClick(Sender: TObject);
     37    procedure ButtonSingleTestClick(Sender: TObject);
    4238    procedure ButtonStopClick(Sender: TObject);
    4339    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    4440    procedure FormCreate(Sender: TObject);
    4541    procedure FormDestroy(Sender: TObject);
     42    procedure FormShow(Sender: TObject);
     43    procedure ListViewMethodsData(Sender: TObject; Item: TListItem);
     44    procedure ListViewMethodsSelectItem(Sender: TObject; Item: TListItem;
     45      Selected: Boolean);
    4646    procedure Timer1Timer(Sender: TObject);
    4747  private
     
    5050    TextureData: Pointer;
    5151    MethodIndex: Integer;
     52    SingleTestActive: Boolean;
     53    AllTestActive: Boolean;
    5254    procedure OpenGLControl1Resize(Sender: TObject);
    5355    procedure InitGL;
     56    procedure UpdateMethodList;
     57    procedure UpdateInterface;
    5458  public
    5559    DrawMethods: TObjectList; // TObjectList<TDrawMethod>
     
    8690  Bitmap.PixelFormat := pf24bit;
    8791  Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
     92  Image1.Picture.Bitmap.PixelFormat := pf32bit;
    8893  Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
    8994
     
    100105
    101106  DrawMethods := TObjectList.Create;
    102   ComboBox1.Clear;
    103107  for I := 0 to High(DrawMethodClasses) do begin
    104108    NewDrawMethod := DrawMethodClasses[I].Create;
     
    109113    NewDrawMethod.Init;
    110114    DrawMethods.Add(NewDrawMethod);
    111     ComboBox1.Items.Add(NewDrawMethod.Caption);
    112   end;
    113   ComboBox1.ItemIndex := DrawMethods.Count - 1;
    114 end;
    115 
    116 procedure TMainForm.ButtonStartClick(Sender: TObject);
    117 begin
    118   MethodIndex := ComboBox1.ItemIndex;
    119   ButtonStop.Enabled := True;
    120   ButtonStart.Enabled := False;
    121   Timer1.Enabled := True;
    122   if MethodIndex >= 0 then
    123   with TDrawMethod(DrawMethods[MethodIndex]) do begin
    124     PageControl1.TabIndex := Integer(PaintObject);
    125     Application.ProcessMessages;
    126     repeat
    127       DrawFrameTiming(TFastBitmap(Scenes[SceneIndex]));
    128       SceneIndex := (SceneIndex + 1) mod Scenes.Count;
     115  end;
     116end;
     117
     118procedure TMainForm.ButtonSingleTestClick(Sender: TObject);
     119begin
     120  try
     121    SingleTestActive := True;
     122    UpdateInterface;
     123    Timer1.Enabled := True;
     124    MethodIndex := ListViewMethods.Selected.Index;
     125    Timer1.Enabled := True;
     126    if MethodIndex >= 0 then
     127    with TDrawMethod(DrawMethods[MethodIndex]) do begin
     128      PageControl1.TabIndex := Integer(PaintObject);
    129129      Application.ProcessMessages;
    130     until not ButtonStop.Enabled;
    131   end;
    132   ButtonStopClick(Self);
     130      repeat
     131        DrawFrameTiming(TFastBitmap(Scenes[SceneIndex]));
     132        SceneIndex := (SceneIndex + 1) mod Scenes.Count;
     133        Application.ProcessMessages;
     134      until not SingleTestActive;
     135    end;
     136  finally
     137    Timer1.Enabled := False;
     138    SingleTestActive := False;
     139    UpdateInterface;
     140  end;
    133141end;
    134142
    135143procedure TMainForm.ButtonBenchmarkClick(Sender: TObject);
    136144var
    137   NewItem: TListItem;
    138145  I: Integer;
    139146  C: Integer;
    140147  StartTime: TDateTime;
    141148begin
    142   Timer1.Enabled := True;
    143   with ListView1, Items do
    144149  try
    145     //BeginUpdate;
    146     Clear;
     150    AllTestActive := True;
     151    UpdateInterface;
     152    Timer1.Enabled := True;
     153    with ListViewMethods, Items do
    147154    for I := 0 to DrawMethods.Count - 1 do
    148155    with TDrawMethod(DrawMethods[I]) do begin
     
    154161        SceneIndex := (SceneIndex + 1) mod Scenes.Count;
    155162        Application.ProcessMessages;
    156       until (NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value;
    157       NewItem := Add;
    158       NewItem.Caption := Caption;
    159       NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)));
    160       NewItem.SubItems.Add(FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3)));
     163      until ((NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value) or not AllTestActive;
    161164    end;
    162165  finally
    163     //EndUpdate;
     166    Timer1.Enabled := False;
     167    AllTestActive := False;
     168    UpdateInterface;
    164169  end;
    165170end;
     
    167172procedure TMainForm.ButtonStopClick(Sender: TObject);
    168173begin
    169   ButtonStart.Enabled := True;
    170   ButtonStop.Enabled := False;
     174  SingleTestActive := False;
     175  AllTestActive := False;
    171176end;
    172177
     
    184189end;
    185190
     191procedure TMainForm.FormShow(Sender: TObject);
     192begin
     193  UpdateMethodList;
     194  UpdateInterface;
     195end;
     196
     197procedure TMainForm.ListViewMethodsData(Sender: TObject; Item: TListItem);
     198begin
     199  if (Item.Index >= 0) and (Item.Index < DrawMethods.Count) then
     200  with TDrawMethod(DrawMethods[Item.Index]) do begin
     201    Item.Caption := Caption;
     202    if FrameDuration > 0 then
     203      Item.SubItems.Add(FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3)))
     204      else Item.SubItems.Add('0');
     205    Item.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)) + ' ms');
     206  end;
     207end;
     208
     209procedure TMainForm.ListViewMethodsSelectItem(Sender: TObject; Item: TListItem;
     210  Selected: Boolean);
     211begin
     212  UpdateInterface;
     213end;
     214
    186215procedure TMainForm.Timer1Timer(Sender: TObject);
    187216begin
    188   if (MethodIndex >= 0) then
    189   with TDrawMethod(DrawMethods[MethodIndex]) do begin
    190     if (FrameDuration > 0) then
    191       Label2.Caption := FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3))
    192       else Label2.Caption := '0';
    193     Label4.Caption := FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)) + ' ms';
    194   end;
     217  UpdateMethodList;
    195218end;
    196219
     
    220243end;
    221244
     245procedure TMainForm.UpdateMethodList;
     246begin
     247  ListViewMethods.Items.Count := DrawMethods.Count;
     248  ListViewMethods.Refresh;
     249end;
     250
     251procedure TMainForm.UpdateInterface;
     252begin
     253  ButtonSingleTest.Enabled := not SingleTestActive and not AllTestActive and Assigned(ListViewMethods.Selected);
     254  ButtonBenchmark.Enabled := not AllTestActive and not SingleTestActive;
     255  ButtonStop.Enabled := SingleTestActive or AllTestActive;
     256end;
     257
    222258end.
    223259
Note: See TracChangeset for help on using the changeset viewer.