Skip to content

PySDL2 example. Partially done. #324

Closed

Description

@cztomczak

PySDL2 is a wrapper around the SDL2 library, a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.

https://github.com/marcusva/py-sdl2

Known issues (pull requests are welcome):

  • There are issues when running on slow machine - key events are being
    lost (noticed on Mac only so far), see comments in this issue for more details
  • Performance is still not perfect, see comments in this issue for further details
  • Keyboard modifiers that are not yet handled in this example:
    ctrl, marking text inputs with the shift key.
  • Backspace key doesn't work on Mac
  • Dragging with mouse not implemented
  • Window size is fixed, cannot be resized

Activity

  1. added a commit that references this issue on Jan 8, 2018
  2. cztomczak commented on Jan 8, 2018

    @cztomczak
    OwnerAuthor

    pysdl2.py example added in the examples/ directory via PR #379. Currently tested only on Linux.

  3. changed the title [-]Create PySDL2 example[/-] [+]PySDL2 example - support for Windows and Mac[/+] on Feb 20, 2018
  4. cztomczak commented on Feb 20, 2018

    @cztomczak
    OwnerAuthor

    I have tested pysdl2.py example on Windows and it runs very slow. Page loading is slow, typing is slow, scrolling is slow. I have installed sdl2+pysdl2 using these steps:

    1. Download SDL2.dll from http://www.libsdl.org/download-2.0.php (2.0.7 version as of now)
    2. Put SDL2.dll in C:\Python27\ (or wherever you installed Python)
    3. Install pysdl2: pip install pysdl2 (version 0.9.6)

    I don't know why the issue with app working so slow. Either PySDL2 support for Windows is broken or there is something that needs to be fixed in pysdl2.py example.

  5. cztomczak commented on Feb 20, 2018

    @cztomczak
    OwnerAuthor

    @neilmunday Adding a call to SDL_DELAY at the end of rendering loop didn't help (tried 1ms, 5ms, 10ms). I've added a print that counts how many times messageloopwork is called in the rendering loop and its about 100 times in a second, so that should be fine, as other examples execute it in a 10ms timer. I see that you haven't set necessary flags for off-screen rendering optimizations, as described in Issue #240 ("Tweaking OSR performance"). Here are the switches that should be set:

    switches = {
                # Tweaking OSR performance by setting the same Chromium flags
                # as in upstream cefclient (# Issue #240).
                "disable-surfaces": "",
                "disable-gpu": "",
                "disable-gpu-compositing": "",
                "enable-begin-frame-scheduling": "",
            }
            browserSettings = {
                # Tweaking OSR performance (Issue #240)
                "windowless_frame_rate": 100
            }

    I've applied these and it now renders much better, however it still doesn't render as smoothly as when running hello_world.py example. Typing is fine now. I don't feel any lag while typing, although it sometimes lags during initial loading when typing. Scrolling is still not as smooth as in hello_world. I've increased scroll delta to 40, however it's not about it, I test scrolling by dragging scrollbar. I guess it needs synchronizing FPS/frame rate between CEF and SDL. I've found this article:

    http://lazyfoo.net/SDL_tutorials/lesson14/index.php

    With such code:

            // If we want to cap the frame rate
            if( ( cap == true ) && ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) )
            {
                //Sleep the remaining frame time
                SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
            }

    I've updated pysdl2.py example in commit 5dbd9d6 - added performance switches and frame rate browser setting described earlier.

    @neilmunday Please test this updated example on Linux and see how these switches affect it now, as I've tested this only on Windows. It would be great if you could improve performance further by adding code that synchronizes frame rate between CEF <> SDL (the code above or similar). I think that having frame rate at 60 FPS would be sufficient for web browser. PR is welcome.

  6. neilmunday commented on Feb 20, 2018

    @neilmunday
    Contributor

    @cztomczak I've just tested the updated example under Fedora 26 with SDL2 2.0.7 and PySDL 0.9.6 and it works fine.

  7. neilmunday commented on Feb 20, 2018

    @neilmunday
    Contributor

    I have tried using SDL2_gfx's frame rater manager and it works really well under Linux. However, there do not appear to be any Windows binaries that I can see for this SDL2 add-on which is shame.

    Ref: http://www.ferzkopp.net/Software/SDL2_gfx/Docs/html/_s_d_l2__framerate_8c.html

  8. cztomczak commented on Feb 20, 2018

    @cztomczak
    OwnerAuthor

    Adding such code within if platform == linux block code is fine, if you want to go this way.

  9. neilmunday commented on Feb 20, 2018

    @neilmunday
    Contributor

    See pull request above.

    I avoided sdl2_gfx to try and keep the example cross platform compatible.

  10. added a commit that references this issue on Feb 23, 2018
  11. cztomczak commented on Feb 23, 2018

    @cztomczak
    OwnerAuthor

    I still see some issues on Windows, but looks like this is and issue with SDL, as it works fine on Linux.

    1. Scrolling is slow. When I increase "enhance" variable it is faster, but it doesn't work smoothly as on Linux.
    2. When dragging scrollbar with mouse it sometimes hangs, when I drag it, after a while it returns to the previous position, so can't really scroll the page, it jumps back constantly. On Linux all works good.
  12. changed the title [-]PySDL2 example - support for Windows and Mac[/-] [+]PySDL2 example[/+] on Feb 23, 2018
  13. cztomczak commented on Feb 23, 2018

    @cztomczak
    OwnerAuthor

    Initial Mac support added in commit 40e37b2.

    I've tested on Mac and there are issues with key events being lost, only about half of my key presses do work (also backspace key doesn't work). Sometimes I try pressing key multiple times for a second or two, but no key presses are arriving to pysdl. I am testing on an old Macbook with Intel Core 2 duo 2.26 GHZ and 4 GB ram. I can see that on average FPS is 50 (sometimes less - 30, sometimes more - up to 90). I think the issue might be not Mac specific, but just occurs on slower machines and might occur on Linux/Windows as well. On Windows and Linux I get 100 fps all the time. I think this might also occur on fast machines, but when CPU is heavy loaded (a heavy website). I've tried changing frameRate on Mac to 60 or 30, but this doesn't change anything, key events are still lost. Web page loading performs fast, as fast as on Windows/Mac, scrolling also works fine. Only these key presses are lost. I've tested loading url="data:text/html,<input type=text>" and I still only get 90 FPS. Key presses work much better in such case, about 80% of them work fine, but still about 20% is lost. Changing frame rate to 30 still doesn't help. I've tried different combinations of OSR flags (switches/browser_settings), but it doesn't make any difference.

    @neilmunday Would you be able to simulate heavy CPU load (or limit CPU in VM), so that you can get less FPS such as 50 and see how key presses behave on Linux in such case?

  14. neilmunday commented on Feb 25, 2018

    @neilmunday
    Contributor

    @cztomczak As it happens I my desktop PC where I do my development work etc. is an aging Intel Core 2 Quad Q6600 (4 CPUs @ 2.4GHz) and 8 GB RAM. With this set-up under Linux I get around 80-90 FPS and the example is fully responsive, including typing.

    On the same PC, under Windows using a Linux VM with no 3D acceleration, 2 CPUs and 2GB RAM I get 10-20 FPS from google.com. When typing in the search box there is lag but it does remember all the keys I type.

  15. neilmunday commented on Feb 25, 2018

    @neilmunday
    Contributor

    @cztomczak on your MAC and Windows set-ups, have you tried any of the PySDL2 examples? If they're laggy then perhaps the issue is with PySDL2/SDL2 under these set-ups?

  16. cztomczak commented on Feb 28, 2018

    @cztomczak
    OwnerAuthor

    I've tested on Mac again, with logging to key presses, and when keys are missing there is no SDL2 key event logged.

    @neilmunday I've tested py-sdl2 gui.py example and key presses do work fine on Mac. I see that this example uses different functions than ours, it uses sdl2.ext to create Renderer and uses software rendering by default. I see that our pysdl2.py example uses hardware rendering by default. When I run py-sdl2 gui.py example with the -hardware flag then the UI is messed up on both Mac and Linux, so I become to wonder if py-sdl2 hardware rendering is stable.

  17. neilmunday commented on Feb 28, 2018

    @neilmunday
    Contributor

    @cztomczak sounds like something isn't quite write with the SDL or PySDL set-up then on MAC?

    I've just updated the example to allow users to select either hardware or software rendering from the command line. See #414

    I've set software rendering as the default.

    Can you give this a go on the MAC?

    On the sdl2.ext front, it's just a helper module for wrapping the SDL2 calls when creating renderers, windows etc. The example only uses SDL2 API calls that exist in the SDL2 C/C++ API.

  18. cztomczak commented on Mar 1, 2018

    @cztomczak
    OwnerAuthor

    I want to be clear that I've never had any hardware rendering issues in pysdl2.py on any of the platforms. It is only the gui.py example that has issues, I've reported it here:

    py-sdl/py-sdl2#120

    I've tested both software and hardware rendering on all platforms using changes from PR #414 and all works good. So I'm not sure if it is necessary to use software rendering by default, since it is a bit slower (though not much, about 10%).

    There is an another issue though, the FPS meter sometimes shows 106-107 multiple times. Is this a correct behavior? From what I understand SDL_Delay function always slows it down to 100 FPS, so looks like this is FPS number of how high it could get, but it never gets there in reality, right?

  19. cztomczak commented on Mar 1, 2018

    @cztomczak
    OwnerAuthor

    The keyboard issues still occur on Mac even when software rendering is used.

  20. cztomczak commented on Mar 1, 2018

    @cztomczak
    OwnerAuthor

    The author of Py-SDL2 responded:

    The gui.py example does not redraw the window background, which leads to those screen fragments. It is a minor bug in the example only.

    So we should re-enable hardware rendering by default.

  21. neilmunday commented on Mar 3, 2018

    @neilmunday
    Contributor

    See pull request above for the renderer change.

    On the FPS side of things on my Linux desktop I only get 99 FPS max - I've not seen it go any higher so far.

  22. changed the title [-]PySDL2 example[/-] [+]PySDL2 example. Partially done.[/+] on Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions