Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Henry Vermaak
On Mon, May 12, 2014 at 08:12:45PM +0200, Sven Barth wrote:
> On 12.05.2014 15:33, Michael Schnell wrote:
> >On 05/12/2014 02:47 PM, Reinier Olislagers wrote:
> >>Do you mean direct access to the hardware bypassing the OS? I
> >>thought that wasn't possible in Windows?
> >
> >I don't know how the dynamic library call in Windows works.
> 
> If in doubt, take a look at ReactOS ;)
> 
> QueryPerformanceCounter calls NtQueryPerformanceCounter (which is a
> system call), which in turn calls KeQueryPerformanceCounter (which is
> implemented by the Hardware Abstraction Layer) which is defined here
> at around line 250:
> http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/timer.c?revision=58489&view=markup

On linux, glibc (and others) will route gettimeofday() (and
clock_gettime() for certain clock IDs) via vDSO and no syscall will be
called, so it's very fast.  I don't think the fpc rtl does this, though?

More info in the vdso man page for which functions are supported for
which architectures.

Henry

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Sven Barth

On 12.05.2014 15:33, Michael Schnell wrote:

On 05/12/2014 02:47 PM, Reinier Olislagers wrote:

Do you mean direct access to the hardware bypassing the OS? I thought
that wasn't possible in Windows?


I don't know how the dynamic library call in Windows works.


If in doubt, take a look at ReactOS ;)

QueryPerformanceCounter calls NtQueryPerformanceCounter (which is a 
system call), which in turn calls KeQueryPerformanceCounter (which is 
implemented by the Hardware Abstraction Layer) which is defined here at 
around line 250: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/timer.c?revision=58489&view=markup


Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Michael Van Canneyt



On Mon, 12 May 2014, Reinier Olislagers wrote:


On 12/05/2014 13:32, Michael Schnell wrote:

On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:


Take a look at EpikTimer. It uses hardware timers where available, with
an easy to use API for the developer.


IO took a look.

Seemingly this is only available for X86 and X86_64.

How did you get that idea? The wiki page even explicitly mentions ARM.


Yes, it WORKS on arm.

But on all systems except i386, you can just as well use Now() and Sleep(), 
because that is what epiktimer uses:


(sources quoted from the lazarus-ccr repository)

function SystemTicks: TickType;
{$IFDEF Windows}
begin
  QueryPerformanceCounter(Result);
{$ELSE}
var t : timeval;
begin
  fpgettimeofday(@t,nil);
  Result := (TickType(t.tv_sec) * 100) + t.tv_usec;
{$ENDIF}

and

function TEpikTimer.SystemSleep(Milliseconds: Integer):Integer;
{$IFDEF Windows}
begin
  Sleep(Milliseconds);
  Result := 0;
end;
{$ELSE}
  {$IFDEF CPUX86_64}
begin
  Sleep(Milliseconds);
  Result := 0;
end;
  {$ELSE}
var
  timerequested, timeremaining: timespec;
begin
  timerequested.tv_sec:=Milliseconds div 1000;
  timerequested.tv_nsec:=(Milliseconds mod 1000) * 100;
  Result := fpnanosleep(@timerequested, @timeremaining) // returns 0 if ok
end;
{$ENDIF}
{$ENDIF}

Why you would not use fpnanosleep on CPUX86_64 as well is a mystery to me...

Epiktimer is probably the most overrated component on lazarus-ccr. 
No idea why people still recommend it, unless I missed something :(


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Michael Schnell

On 05/12/2014 02:47 PM, Reinier Olislagers wrote:
 The wiki page even explicitly mentions ARM. 
Right. As it does a system call in Linux, this should be independent of 
the CPU arch



Do you mean direct access to the hardware bypassing the OS? I thought
that wasn't possible in Windows?


I don't know how the dynamic library call in Windows works.

AFAIR, all modern X86 CPUs feature a CPU register and an ASM instruction 
for that purpose. As this is just a read, there is no reason for this 
ASM instruction to be protected in any way.


I'll recheck ASAP.

-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Reinier Olislagers
On 12/05/2014 13:32, Michael Schnell wrote:
> On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:
>>
>> Take a look at EpikTimer. It uses hardware timers where available, with
>> an easy to use API for the developer.
> 
> IO took a look.
> 
> Seemingly this is only available for X86 and X86_64.
How did you get that idea? The wiki page even explicitly mentions ARM.

> In Windows, "QueryPerformanceCounter" is called. I supposed (I don't
> have a Lazarus on Windows at hand) this library call in fact uses a
> hardware feature of the CPU instead of doing a time cosuming system call.
Do you mean direct access to the hardware bypassing the OS? I thought
that wasn't possible in Windows?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Mark Morgan Lloyd

Michael Schnell wrote:

On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:


Take a look at EpikTimer. It uses hardware timers where available, with
an easy to use API for the developer.


IO took a look.

Seemingly this is only available for X86 and X86_64.


Unless something's changed, I do not believe that to be the case. I've 
previously compiled and tested a program that uses it on SPARC/PPC/ARM 
Linux.


I've got reservations about excessive use of floating point, but at 
present I believe it's still the best option available.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How to program with time in milliseconds?

2014-05-12 Thread Michael Schnell

On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:


Take a look at EpikTimer. It uses hardware timers where available, with
an easy to use API for the developer.


IO took a look.

Seemingly this is only available for X86 and X86_64.

In Windows, "QueryPerformanceCounter" is called. I supposed (I don't 
have a Lazarus on Windows at hand) this library call in fact uses a 
hardware feature of the CPU instead of doing a time cosuming system call.


But on Linux the EpikTimer (exactly like "Now") just does 
"fpgettimeofday()" (exactly like "Now") and this finally does a system 
call.


Are there no better options ?

Thanks,
-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Colourful Themes

2014-05-12 Thread zeljko

On 05/12/2014 11:41 AM, Vojtěch Čihák wrote:

I tried:

var aNewColor, aOldColor: TColorRef;
begin
  aNewColor:=ColorToRGB(clRed);
  aOldColor:=LCLIntf.SetBkColor(Canvas.Handle, aNewColor);
  ThemeServices.DrawElement(Canvas.Handle, 
ThemeServices.GetElementDetails(caThemedItems[AItemState]), ARect, nil);
  writeln(ColorToString(LCLIntf.SetBkColor(Canvas.Handle, AOldColor)));

Now the output is now clRed, which means that clRed was set during DrawElement 
but painted element (tbPushButtonNormal) is still default.


if you doing that in Qt, then you should set palette brush from current 
painter (in DrawElement) brush. That's not implemented, I've just said 
that it's maybe possible to implement it in that way.


zeljko



Vojtěch
__

Od: zeljko 
Komu: Lazarus mailing list 
Datum: 12.05.2014 11:23
Předmět: Re: [Lazarus] Colourful Themes


On 05/12/2014 10:54 AM, Vojtěch Čihák wrote:

Thanks,

I tried LCLIntf.SetBkColor(Canvas.Handle, clRed); and no visual change.
And if I try writeln(ColorToString(LCLIntf.SetBkColor(HANDLE, $00FF))); it 
never returns the color that I set (Qt4, GTK2), so it seems widgetsets doesn't 
support it.


1.SetBkColor as param uses TColorRef, not TColor
2.When setting new color with SetBkColor, old TColorRef is returned as
result.
var
AOldColor, ANewColorRef: TColorRef;
begin
ANewColorRef := ColorToRGB(clRed);
AOldColor := LCLIntf.SetBkColor(Canvas.Handle, ANewColorRef);
...do something
LCLIntf.SetBkColor(Canvas.Handle, AOldColor);
end;

zeljko

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Colourful Themes

2014-05-12 Thread zeljko

On 05/12/2014 10:54 AM, Vojtěch Čihák wrote:

Thanks,

I tried LCLIntf.SetBkColor(Canvas.Handle, clRed); and no visual change.
And if I try writeln(ColorToString(LCLIntf.SetBkColor(HANDLE, $00FF))); it 
never returns the color that I set (Qt4, GTK2), so it seems widgetsets doesn't 
support it.


1.SetBkColor as param uses TColorRef, not TColor
2.When setting new color with SetBkColor, old TColorRef is returned as 
result.

var
  AOldColor, ANewColorRef: TColorRef;
begin
  ANewColorRef := ColorToRGB(clRed);
  AOldColor := LCLIntf.SetBkColor(Canvas.Handle, ANewColorRef);
  ...do something
  LCLIntf.SetBkColor(Canvas.Handle, AOldColor);
end;

zeljko


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Colourful Themes

2014-05-12 Thread Vojtěch Čihák
I tried:
 
var aNewColor, aOldColor: TColorRef;
begin
 aNewColor:=ColorToRGB(clRed);
 aOldColor:=LCLIntf.SetBkColor(Canvas.Handle, aNewColor);
 ThemeServices.DrawElement(Canvas.Handle, 
ThemeServices.GetElementDetails(caThemedItems[AItemState]), ARect, nil);  
 writeln(ColorToString(LCLIntf.SetBkColor(Canvas.Handle, AOldColor)));  
 
Now the output is now clRed, which means that clRed was set during DrawElement 
but painted element (tbPushButtonNormal) is still default.
 
Vojtěch 
__
> Od: zeljko 
> Komu: Lazarus mailing list 
> Datum: 12.05.2014 11:23
> Předmět: Re: [Lazarus] Colourful Themes
>
On 05/12/2014 10:54 AM, Vojtěch Čihák wrote:
> Thanks,
>
> I tried LCLIntf.SetBkColor(Canvas.Handle, clRed); and no visual change.
> And if I try writeln(ColorToString(LCLIntf.SetBkColor(HANDLE, $00FF))); 
> it never returns the color that I set (Qt4, GTK2), so it seems widgetsets 
> doesn't support it.

1.SetBkColor as param uses TColorRef, not TColor
2.When setting new color with SetBkColor, old TColorRef is returned as 
result.
var
   AOldColor, ANewColorRef: TColorRef;
begin
   ANewColorRef := ColorToRGB(clRed);
   AOldColor := LCLIntf.SetBkColor(Canvas.Handle, ANewColorRef);
   ...do something
   LCLIntf.SetBkColor(Canvas.Handle, AOldColor);
end;

zeljko

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Colourful Themes

2014-05-12 Thread Vojtěch Čihák
Thanks,
 
I tried LCLIntf.SetBkColor(Canvas.Handle, clRed); and no visual change.
And if I try writeln(ColorToString(LCLIntf.SetBkColor(HANDLE, $00FF))); it 
never returns the color that I set (Qt4, GTK2), so it seems widgetsets doesn't 
support it.
 
Vojtěch 
__
> Od: zeljko 
> Komu: Lazarus mailing list 
> Datum: 12.05.2014 07:16
> Předmět: Re: [Lazarus] Colourful Themes
>
On 05/11/2014 08:08 PM, Vojtěch Čihák wrote:

hm...I don't think that color param is needed. If you set 
TWidgetSet.SetBgColor() DC brush is setted up to that color, so DC have 
information about brush color and can pass it to theme drawer (if ws 
supports overriding default theme brush).

> Are widgetsets capable do it? I mean if there is support in libQT4pas and 
> other bindings.

Qt can do that, don't know abot others.

zeljko

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus