Recent

Author Topic: UI and whole app much slower and laggy on OSX than on Windows (BGRAControls)  (Read 4772 times)

tom.tom

  • New Member
  • *
  • Posts: 43
Hi,

  Our app uses BGRAControls quite extensively and what I noticed is that the app's UI is very laggy on OSX. Also the CPU usage jumps even up to 70% when I simply move the mouse over the UI componens forcing them to repaint. On windows whn I do the same there is maybe 1-2% increase in the CPU usage.

Does anybode have any experience with that or suggestions where to look before I start debugging everything?

Of course the app is compiled without debug information and stripped out, because without that it's even much worse...

Thanks,
Tomasz
« Last Edit: January 30, 2015, 05:16:15 pm by tom.tom »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: UI and whole app much slower and laggy on OSX than on Windows
« Reply #1 on: January 29, 2015, 05:34:51 pm »
Sounds like the repainting is occurring too many times - or even worse - painting outside of the OnPaint  event. for Carbon it would forcefully trigger another paint event.

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: UI and whole app much slower and laggy on OSX than on Windows
« Reply #2 on: January 29, 2015, 06:32:04 pm »
Or too much Repaint() instead of Update()

tom.tom

  • New Member
  • *
  • Posts: 43
Re: UI and whole app much slower and laggy on OSX than on Windows
« Reply #3 on: January 30, 2015, 03:36:50 pm »
Well, does that mean that there is some refresh/repaint chain in carbon which does not exist on windows and therefore such difference in performance?

When I do the mouse over, the panel changes it's color, so yes, there is repaint triggerred, but that just a small 20px x 20px square for repainting... or does this force everything (i.e whole form) to be repainted?

Tomasz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: UI and whole app much slower and laggy on OSX than on Windows
« Reply #4 on: January 30, 2015, 04:33:13 pm »
When I do the mouse over, the panel changes it's color, so yes, there is repaint triggerred, but that just a small 20px x 20px square for repainting... or does this force everything (i.e whole form) to be repainted?
Are you saying that the panel that changes the color is only 20px x 20px?
Also, how do you "change" the color? are you triggering "invalidate" A) or just paint B)?
A)
Code: [Select]
procedure TMyPanel.OnMouseMove()
begin
  self.invalidate;
end;

B)
Code: [Select]
procedure TMyPanel.OnMouseMove()
begin
  Canvas.FillColor (randomcolor, BoundsRect);
end;

« Last Edit: January 30, 2015, 04:39:12 pm by skalogryz »

tom.tom

  • New Member
  • *
  • Posts: 43
Re: UI and whole app much slower and laggy on OSX than on Windows
« Reply #5 on: January 30, 2015, 05:04:08 pm »
Hmmm, this is BGRAControls - let me have a look into the code...

in OnMouseEnter I do:
Code: [Select]
TBCPanel(TControl(Sender).Parent).Background.Color := .....
Which, looking into BGRAControls:

Code: [Select]
TBCBackground.SetColor
...
Change;

then...

Code: [Select]
procedure TBCProperty.Change(AData: PtrInt);
begin
  if Assigned(FOnChange) then
    FOnChange(Self,AData);
end

...so nothing really special.

To be precise, there are 7 such panels and they are 52x52 size. When I move the mouse over one of them the other one that was activated before gets deactivated (changes the background back to normal color) and the new panel get's activated (backgound changes).

I observe that high CPU usage when I simply move the mouse along all 7 panels back ang forth.

EDIT: Have just talked to Dibo, who is one of the BGRAControls developers and he said there may be something wrong with how the underlaying BGRABitmap is supported on OSX...
« Last Edit: January 30, 2015, 05:17:53 pm by tom.tom »

tom.tom

  • New Member
  • *
  • Posts: 43
OK, I think I have something

When in TBCPanel you set XRounding and YRouning to 0 - changing the background color takes so much time.

If you do not set them to 0, there is no way to get rid of the left and top border.

Will continue my research.

tom.tom

  • New Member
  • *
  • Posts: 43
OK, seems like there are several issues with both TBCPanel and TBGRABitmap:

1) TBCPanel seems to have Allign not working right - if I put one TBCPanel on another TBCPanel and set alTop for the inner one - there is no way to make the inner Top and Left equal to 0 - they are always at least =1 [issue #1] - event if Bevel is set to none in the parent panel

2) because of the above, setting RoundingX and RoundingY of the inner panel to 0 is a kind of hack that eliminates the visual effects of the above Allign issue, but ---> 3)

3) when setting Rounding to 0 calls FBGRA.Draw() with the Opaque param set to false -- why? what for? [issue #2] ...it seems more logical to draw the control as transparent, when rounding <>0, not opaque...?

Code: [Select]
procedure TCustomBCPanel.DrawControl;
begin
  inherited DrawControl;
  if FBGRA.NeedRender then
    Render;
  if Assigned (FRounding) then
  begin
    if (FRounding.RoundX<>0) and (FRounding.RoundY<>0) then
      FBGRA.Draw(Self.Canvas, 0, 0, False)
    else
      FBGRA.Draw(Self.Canvas, 0, 0);
  end
  else
    FBGRA.Draw(Self.Canvas, 0, 0);
end; 

4) this leads to the performance problem on OSX - apparently procedure TBGRADefaultBitmap.DataDrawOpaque() on OSX is very slow [issue #3] - do not know why yet...

Code: [Select]
procedure TBGRADefaultBitmap.Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean);
begin
  if self = nil then
    exit;
  if Opaque then
    DataDrawOpaque(ACanvas, Rect(X, Y, X + Width, Y + Height), Data,
      FLineOrder, FWidth, FHeight)
  else
  begin
    LoadFromBitmapIfNeeded;
    if Empty then
      exit;
    ACanvas.Draw(X, Y, Bitmap);
  end;
end;   

Any suggestions?
« Last Edit: February 02, 2015, 06:43:19 pm by tom.tom »

 

TinyPortal © 2005-2018