native_pixmap.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 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_GFX_NATIVE_PIXMAP_H_
  5. #define UI_GFX_NATIVE_PIXMAP_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "ui/gfx/buffer_types.h"
  8. #include "ui/gfx/geometry/size.h"
  9. #include "ui/gfx/native_pixmap_handle.h"
  10. #include "ui/gfx/native_widget_types.h"
  11. namespace gfx {
  12. struct OverlayPlaneData;
  13. class GpuFence;
  14. // This represents a buffer that can be directly imported via GL for
  15. // rendering, or exported via dma-buf fds.
  16. class NativePixmap : public base::RefCountedThreadSafe<NativePixmap> {
  17. public:
  18. NativePixmap() {}
  19. NativePixmap(const NativePixmap&) = delete;
  20. NativePixmap& operator=(const NativePixmap&) = delete;
  21. virtual bool AreDmaBufFdsValid() const = 0;
  22. virtual int GetDmaBufFd(size_t plane) const = 0;
  23. virtual uint32_t GetDmaBufPitch(size_t plane) const = 0;
  24. virtual size_t GetDmaBufOffset(size_t plane) const = 0;
  25. virtual size_t GetDmaBufPlaneSize(size_t plane) const = 0;
  26. // Return the number of non-interleaved "color" planes.
  27. virtual size_t GetNumberOfPlanes() const = 0;
  28. virtual bool SupportsZeroCopyWebGPUImport() const = 0;
  29. // The following methods return format, modifier and size of the buffer,
  30. // respectively.
  31. virtual gfx::BufferFormat GetBufferFormat() const = 0;
  32. virtual uint64_t GetBufferFormatModifier() const = 0;
  33. virtual gfx::Size GetBufferSize() const = 0;
  34. // Return an id that is guaranteed to be unique and equal for all instances
  35. // of this NativePixmap backed by the same buffer, for the duration of its
  36. // lifetime. If such id cannot be generated, 0 (an invalid id) is returned.
  37. //
  38. // TODO(posciak): crbug.com/771863, remove this once a different mechanism
  39. // for protected shared memory buffers is implemented.
  40. virtual uint32_t GetUniqueId() const = 0;
  41. // Sets the overlay plane to switch to at the next page flip.
  42. // |widget| specifies the screen to display this overlay plane on.
  43. // |acquire_fences| specifies gpu fences to wait on before the pixmap is ready
  44. // to be displayed. These fence are fired when the gpu has finished writing to
  45. // the pixmap.
  46. // |release_fences| specifies gpu fences that are signalled when the pixmap
  47. // has been displayed and is ready for reuse.
  48. // |overlay_plane_data| specifies overlay data such as opacity, z_order, size,
  49. // etc.
  50. virtual bool ScheduleOverlayPlane(
  51. gfx::AcceleratedWidget widget,
  52. const gfx::OverlayPlaneData& overlay_plane_data,
  53. std::vector<gfx::GpuFence> acquire_fences,
  54. std::vector<gfx::GpuFence> release_fences) = 0;
  55. // Export the buffer for sharing across processes.
  56. // Any file descriptors in the exported handle are owned by the caller.
  57. virtual gfx::NativePixmapHandle ExportHandle() = 0;
  58. protected:
  59. virtual ~NativePixmap() {}
  60. private:
  61. friend class base::RefCountedThreadSafe<NativePixmap>;
  62. };
  63. } // namespace gfx
  64. #endif // UI_GFX_NATIVE_PIXMAP_H_