gl_surface.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/gl/gl_detection.h"
  9. #include <QtGui/QOpenGLFunctions>
  10. class Painter;
  11. class QOpenGLWidget;
  12. namespace Ui {
  13. class RpWidgetWrap;
  14. } // namespace Ui
  15. namespace Ui::GL {
  16. class Renderer {
  17. public:
  18. virtual void init(
  19. not_null<QOpenGLWidget*> widget,
  20. QOpenGLFunctions &f) {
  21. }
  22. virtual void deinit(
  23. not_null<QOpenGLWidget*> widget,
  24. QOpenGLFunctions *f) {
  25. }
  26. virtual void resize(
  27. not_null<QOpenGLWidget*> widget,
  28. QOpenGLFunctions &f,
  29. int w,
  30. int h) {
  31. }
  32. virtual void paint(
  33. not_null<QOpenGLWidget*> widget,
  34. QOpenGLFunctions &f);
  35. [[nodiscard]] virtual std::optional<QColor> clearColor() {
  36. return std::nullopt;
  37. }
  38. virtual void paintFallback(
  39. Painter &&p,
  40. const QRegion &clip,
  41. Backend backend) {
  42. }
  43. virtual ~Renderer() = default;
  44. };
  45. struct ChosenRenderer {
  46. std::unique_ptr<Renderer> renderer;
  47. Backend backend = Backend::Raster;
  48. };
  49. [[nodiscard]] std::unique_ptr<RpWidgetWrap> CreateSurface(
  50. Fn<ChosenRenderer(Capabilities)> chooseRenderer);
  51. [[nodiscard]] std::unique_ptr<RpWidgetWrap> CreateSurface(
  52. QWidget *parent,
  53. ChosenRenderer chosen);
  54. } // namespace Ui::GL