x11_software_bitmap_presenter.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_X_X11_SOFTWARE_BITMAP_PRESENTER_H_
  5. #define UI_BASE_X_X11_SOFTWARE_BITMAP_PRESENTER_H_
  6. #include "base/component_export.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "base/sequence_checker.h"
  10. #include "base/task/sequenced_task_runner.h"
  11. #include "third_party/skia/include/core/SkRefCnt.h"
  12. #include "third_party/skia/include/core/SkSurface.h"
  13. #include "ui/gfx/geometry/rect.h"
  14. #include "ui/gfx/geometry/size.h"
  15. #include "ui/gfx/native_widget_types.h"
  16. #include "ui/gfx/x/xproto.h"
  17. class SkCanvas;
  18. namespace ui {
  19. class XShmImagePool;
  20. class COMPONENT_EXPORT(UI_BASE_X) X11SoftwareBitmapPresenter {
  21. public:
  22. // Corresponds to SwapBuffersCallback alias in SoftwareOutputDevice.
  23. using SwapBuffersCallback = base::OnceCallback<void(const gfx::Size&)>;
  24. X11SoftwareBitmapPresenter(x11::Connection* connection,
  25. gfx::AcceleratedWidget widget,
  26. bool enable_multibuffering);
  27. X11SoftwareBitmapPresenter(const X11SoftwareBitmapPresenter&) = delete;
  28. X11SoftwareBitmapPresenter& operator=(const X11SoftwareBitmapPresenter&) =
  29. delete;
  30. ~X11SoftwareBitmapPresenter();
  31. void Resize(const gfx::Size& pixel_size);
  32. SkCanvas* GetSkCanvas();
  33. void EndPaint(const gfx::Rect& damage_rect);
  34. void OnSwapBuffers(SwapBuffersCallback swap_ack_callback);
  35. int MaxFramesPending() const;
  36. private:
  37. // Draw |data| over |widget|'s parent-relative background, and write the
  38. // resulting image to |widget|. Returns true on success.
  39. static bool CompositeBitmap(x11::Connection* connection,
  40. x11::Drawable widget,
  41. int x,
  42. int y,
  43. int width,
  44. int height,
  45. int depth,
  46. x11::GraphicsContext gc,
  47. const void* data);
  48. bool ShmPoolReady() const;
  49. x11::Window widget_;
  50. raw_ptr<x11::Connection> connection_;
  51. x11::GraphicsContext gc_{};
  52. x11::VisualId visual_{};
  53. int depth_ = 0;
  54. const bool enable_multibuffering_;
  55. // If nonzero, indicates that the widget should be drawn over its
  56. // parent-relative background.
  57. uint8_t composite_ = 0;
  58. std::unique_ptr<ui::XShmImagePool> shm_pool_;
  59. bool needs_swap_ = false;
  60. sk_sp<SkSurface> surface_;
  61. gfx::Size viewport_pixel_size_;
  62. SEQUENCE_CHECKER(sequence_checker_);
  63. };
  64. } // namespace ui
  65. #endif // UI_BASE_X_X11_SOFTWARE_BITMAP_PRESENTER_H_