Recent

Author Topic: Ubuntu problem with Jpg LoadFromDevice into multithreading  (Read 2457 times)

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #15 on: October 19, 2020, 11:55:47 am »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #16 on: October 19, 2020, 01:27:15 pm »
yeah , yes or no but since this is Linux and the gtk interface it may not be the same..

however, if you use a synchronize method call from a thread I would be it to work, but them again it was stated about slow down. hmm. something tells me someone is trying to run a real time screen capture... naughty !
The only true wisdom is knowing you know nothing

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #17 on: October 19, 2020, 01:54:26 pm »
something tells me someone is trying to run a real time screen capture... naughty !
Exactly
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #18 on: October 19, 2020, 02:20:21 pm »
For information, taking a screenshot works very well under Linux (Ubuntu distro.) + GTK2, from a TForm.  Cf. the project Lazarus/...\.../examples/canvas_test/canvastest.lpi, with this code:
Code: Pascal  [Select][+][-]
  1. procedure TfrmScreenshot.btnScreenshotClick(Sender: TObject);
  2. var
  3.   bmp: TBitmap;
  4.   DC: HDC;
  5. begin
  6.   bmp := TBitmap.Create;
  7.   DC := GetDC(0);
  8.   try
  9.     bmp.LoadFromDevice(DC);
  10.   finally
  11.     ReleaseDC(0, DC);
  12.   end;
  13.   imgScreenshot.Picture.Bitmap.Assign(bmp);
  14.   FreeAndNil(bmp);
  15. end;  
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #19 on: October 19, 2020, 02:24:26 pm »
Cross-platform to boot :)

See also taking a screenshot and excluding your application.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #20 on: October 19, 2020, 06:08:43 pm »
Hi!

I was interested  about the speed of an endless loop taking a screenshot and assign it to an image.

That's what I did:
Code: Pascal  [Select][+][-]
  1. var loopRunning : Boolean = false;
  2.  
  3. procedure TForm1.Test1Click(Sender: TObject);
  4.    var
  5.       bmp: TBitmap;
  6.       DC: HDC;
  7.       Starttime: QWord;
  8.     begin
  9.       LoopRunning := NOT LoopRunning;
  10.       if loopRunning then
  11.       begin
  12.       repeat
  13.         Starttime := GetTickCount64;
  14.         bmp := TBitmap.Create;
  15.         DC := GetDC(0);
  16.       try
  17.         bmp.LoadFromDevice(DC);
  18.         application.ProcessMessages;
  19.       finally
  20.         ReleaseDC(0, DC);
  21.       end;
  22.       bmp.Canvas.TextOut(10,10,IntToStr(GetTickCount64-Starttime)+' ms');
  23.       image1.Picture.Bitmap.Assign(bmp);
  24.       FreeAndNil(bmp);
  25.       application.ProcessMessages;
  26.       until NOT loopRunning;
  27.    end;
  28.   end;
  29.  

Important is the application.ProcessMessages in the loop so that you can access the machine.

Without any other user actions the needed time per loop is 13-15 ms on my hardware.
Top says it needs 67% CPU time out of 800%.

I Think much higher speed you will not reach with Lazarus.
Except better hardware.
Or except creating low level routines.

Winni
« Last Edit: October 19, 2020, 06:10:15 pm by winni »

 

TinyPortal © 2005-2018