Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor drm backend (v3) #116

Merged
merged 56 commits into from
Dec 9, 2018
Merged

Refactor drm backend (v3) #116

merged 56 commits into from
Dec 9, 2018

Conversation

Drakulix
Copy link
Member

Still work in progress (docs and anvil support as well as some new examples are missing).

Ready for a first review.

The biggest change is the split of the DrmDevice and DrmBackend into

  • LegacyDrmDevice and LegacyDrmSurface
  • GbmDevice and GbmSurface
  • EglDevice and EglSurface

To be able to do this clean seperation new traits have been added.
Most importantly Device and Surface, describing drm devices in general

  • RawDevice and RawSurface providing the lowest layer and modesetting support, while the higher-level devices rely on other means of swapping buffers.
  • LegacyDrm* implements the Raw*-traits, Gbm* requires a Raw*-object as it provides buffer management, but itself does not provide Raw*-implementations anymore, but instead the more high-level page_flip, recreate and unlock_buffer functions.

  • EglDevice can wrap any Device that also implements egl's NativeDisplay trait (and where it's surface also implements NativeSurface), which is provided by the GbmDevice (and GbmSurface), through the methods listed above.

This provides very high composability, as the usual (and currently only viable) chain of an egl-gbm-drm-device, is not dictated anymore by the implementation, but by public-accessible traits.

In future this will allow us to add the following implementations easily:

  • AtomicDrmDevice to support atomic modesetting (once drm-rs current refactor is done)
  • EglStreamDevice to support nVidia's buffer mangement
  • VulkanDevice to support Vulkan instead of OpenGL as a rendering api
  • ... (probably some more)
  • this also allows users of the library to provide their own implementations for more exotic devices.

During the refactor some additional changes have been made:

  • Usage of the calloop 0.4 update to utilize EventedFd instead of EventedRawFd
  • Seperate egl and gl modules
  • Provide a raw GL loader additionally to the mostly deprecated (although still working) glium wrapper
  • Renaming the GraphicsBackend to the more fitting CursorBackend
  • Don't let any graphical backend depend on CursorBackend anymore
  • Rebuild the udev-backend, so that it no longer creates devices (move this responsibility to the library user). This greatly simplifies the backend (removing most of it's weird api quirks). Additionally this makes working with the new drm-devices much nicer, as the concrete type of the device is not dictated by the udev backend anymore.

- Remove gbm code
- rename EGLWaylandExtensions to EGLGraphicsBackend
- remove OpenGL specific code where possible
- Move parts of glium & egl module into own module
- Add raw GL loader as an alternative
- Don't let backend depend on `CursorBackend` (used to be `GraphicsBackend`) anymore
- Do not open devices for `UdevHandler` anymore
- `UdevBackend` does not require `LoopHandle` or `Session` anymore
- Type of the created device can be choosed freely by the handler
- `UdevBackendObserver` is not needed anymore
- Split `DrmDevice` into `LegacyDrmDevice`, `GbmDevice` and `EglDevice`
- Provide common `Device` and `RawDevice` traits

- Change `DrmBackend` into `Surface` (and `RawSurface`) implementations of each `Device` (or `RawDevice`)
src/backend/drm/egl/mod.rs Outdated Show resolved Hide resolved
src/backend/graphics/cursor.rs Outdated Show resolved Hide resolved
src/backend/graphics/gl.rs Outdated Show resolved Hide resolved
///
/// This remains valid as long as the underlying `GLGraphicsBackend` is alive
/// and may only be used in combination with the backend. Using this with any
/// other gl context *may* cause undefined behavior.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't there be some link between the backend and the returned Gles2 ? Maybe adding a PhantomData lifetime to Gles2 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly not. This is auto-generated code from gl_generator and it would probably also cause a lot of inconveniences for the user. GL Contexts are weird and many gl functions are unsafe anyway. If you want a safe alternative there is glium.

src/backend/drm/gbm/egl.rs Outdated Show resolved Hide resolved
src/backend/drm/gbm/surface.rs Outdated Show resolved Hide resolved
Co-Authored-By: Drakulix <github@drakulix.de>
@Drakulix Drakulix force-pushed the refactor/backend branch 2 times, most recently from b9459a0 to c1944ed Compare December 8, 2018 16:17
@Drakulix Drakulix merged commit 60bb5e8 into master Dec 9, 2018
@Drakulix Drakulix deleted the refactor/backend branch December 9, 2018 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants