gfxXlibSurface.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef GFX_XLIBSURFACE_H
  6. #define GFX_XLIBSURFACE_H
  7. #include "gfxASurface.h"
  8. #include <X11/extensions/Xrender.h>
  9. #include <X11/Xlib.h>
  10. #include "X11UndefineNone.h"
  11. #if defined(GL_PROVIDER_GLX)
  12. #include "GLXLibrary.h"
  13. #endif
  14. #include "nsSize.h"
  15. // Although the dimension parameters in the xCreatePixmapReq wire protocol are
  16. // 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if
  17. // either dimension cannot be represented by a 16-bit *signed* integer.
  18. #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff
  19. class gfxXlibSurface final : public gfxASurface {
  20. public:
  21. // construct a wrapper around the specified drawable with dpy/visual.
  22. // Will use XGetGeometry to query the window/pixmap size.
  23. gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual);
  24. // construct a wrapper around the specified drawable with dpy/visual,
  25. // and known width/height.
  26. gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const mozilla::gfx::IntSize& size);
  27. // construct a wrapper around the specified drawable with dpy/format,
  28. // and known width/height.
  29. gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
  30. const mozilla::gfx::IntSize& size);
  31. explicit gfxXlibSurface(cairo_surface_t *csurf);
  32. // create a new Pixmap and wrapper surface.
  33. // |relatedDrawable| provides a hint to the server for determining whether
  34. // the pixmap should be in video or system memory. It must be on
  35. // |screen| (if specified).
  36. static already_AddRefed<gfxXlibSurface>
  37. Create(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size,
  38. Drawable relatedDrawable = X11None);
  39. static cairo_surface_t *
  40. CreateCairoSurface(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size,
  41. Drawable relatedDrawable = X11None);
  42. static already_AddRefed<gfxXlibSurface>
  43. Create(Screen* screen, XRenderPictFormat *format, const mozilla::gfx::IntSize& size,
  44. Drawable relatedDrawable = X11None);
  45. virtual ~gfxXlibSurface();
  46. virtual already_AddRefed<gfxASurface>
  47. CreateSimilarSurface(gfxContentType aType,
  48. const mozilla::gfx::IntSize& aSize) override;
  49. virtual void Finish() override;
  50. virtual const mozilla::gfx::IntSize GetSize() const override;
  51. Display* XDisplay() { return mDisplay; }
  52. Screen* XScreen();
  53. Drawable XDrawable() { return mDrawable; }
  54. XRenderPictFormat* XRenderFormat();
  55. static int DepthOfVisual(const Screen* screen, const Visual* visual);
  56. static Visual* FindVisual(Screen* screen, gfxImageFormat format);
  57. static XRenderPictFormat *FindRenderFormat(Display *dpy, gfxImageFormat format);
  58. static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface, Colormap* colormap, Visual **visual);
  59. // take ownership of a passed-in Pixmap, calling XFreePixmap on it
  60. // when the gfxXlibSurface is destroyed.
  61. void TakePixmap();
  62. // Release ownership of this surface's Pixmap. This is only valid
  63. // on gfxXlibSurfaces for which the user called TakePixmap(), or
  64. // on those created by a Create() factory method.
  65. Drawable ReleasePixmap();
  66. // Find a visual and colormap pair suitable for rendering to this surface.
  67. bool GetColormapAndVisual(Colormap* colormap, Visual **visual);
  68. #if defined(GL_PROVIDER_GLX)
  69. GLXPixmap GetGLXPixmap();
  70. // Binds a GLXPixmap backed by this context's surface.
  71. // Primarily for use in sharing surfaces.
  72. void BindGLXPixmap(GLXPixmap aPixmap);
  73. #endif
  74. // Return true if cairo will take its slow path when this surface is used
  75. // in a pattern with EXTEND_PAD. As a workaround for XRender's RepeatPad
  76. // not being implemented correctly on old X servers, cairo avoids XRender
  77. // and instead reads back to perform EXTEND_PAD with pixman. Cairo does
  78. // this for servers older than xorg-server 1.7.
  79. bool IsPadSlow() {
  80. // The test here matches that for buggy_pad_reflect in
  81. // _cairo_xlib_device_create.
  82. return VendorRelease(mDisplay) >= 60700000 ||
  83. VendorRelease(mDisplay) < 10699000;
  84. }
  85. protected:
  86. // if TakePixmap() has been called on this
  87. bool mPixmapTaken;
  88. Display *mDisplay;
  89. Drawable mDrawable;
  90. const mozilla::gfx::IntSize DoSizeQuery();
  91. #if defined(GL_PROVIDER_GLX)
  92. GLXPixmap mGLXPixmap;
  93. #endif
  94. };
  95. #endif /* GFX_XLIBSURFACE_H */