michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __mozilla_widget_nsShmImage_h__ michael@0: #define __mozilla_widget_nsShmImage_h__ michael@0: michael@0: #include "mozilla/ipc/SharedMemorySysV.h" michael@0: michael@0: #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV) michael@0: # define MOZ_HAVE_SHMIMAGE michael@0: #endif michael@0: michael@0: #ifdef MOZ_HAVE_SHMIMAGE michael@0: michael@0: #include "nsIWidget.h" michael@0: #include "gfxTypes.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: #include "mozilla/X11Util.h" michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #if defined(MOZ_WIDGET_GTK) michael@0: #define DISPLAY gdk_x11_get_default_xdisplay michael@0: #elif defined(MOZ_WIDGET_QT) michael@0: #define DISPLAY mozilla::DefaultXDisplay michael@0: #endif michael@0: michael@0: class QRect; michael@0: class QWindow; michael@0: class gfxASurface; michael@0: michael@0: class nsShmImage { michael@0: NS_INLINE_DECL_REFCOUNTING(nsShmImage) michael@0: michael@0: typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV; michael@0: michael@0: public: michael@0: typedef gfxImageFormat Format; michael@0: michael@0: static bool UseShm(); michael@0: static already_AddRefed michael@0: Create(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth); michael@0: static already_AddRefed michael@0: EnsureShmImage(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth, michael@0: nsRefPtr& aImage); michael@0: michael@0: ~nsShmImage() { michael@0: if (mImage) { michael@0: mozilla::FinishX(DISPLAY()); michael@0: if (mXAttached) { michael@0: XShmDetach(DISPLAY(), &mInfo); michael@0: } michael@0: XDestroyImage(mImage); michael@0: } michael@0: } michael@0: michael@0: already_AddRefed AsSurface(); michael@0: michael@0: #if (MOZ_WIDGET_GTK == 2) michael@0: void Put(GdkWindow* aWindow, GdkRectangle* aRects, GdkRectangle* aEnd); michael@0: #elif (MOZ_WIDGET_GTK == 3) michael@0: void Put(GdkWindow* aWindow, cairo_rectangle_list_t* aRects); michael@0: #elif defined(MOZ_WIDGET_QT) michael@0: void Put(QWindow* aWindow, QRect& aRect); michael@0: #endif michael@0: michael@0: gfxIntSize Size() const { return mSize; } michael@0: michael@0: private: michael@0: nsShmImage() michael@0: : mImage(nullptr) michael@0: , mXAttached(false) michael@0: { mInfo.shmid = SharedMemorySysV::NULLHandle(); } michael@0: michael@0: nsRefPtr mSegment; michael@0: XImage* mImage; michael@0: XShmSegmentInfo mInfo; michael@0: gfxIntSize mSize; michael@0: Format mFormat; michael@0: bool mXAttached; michael@0: }; michael@0: michael@0: #endif // MOZ_HAVE_SHMIMAGE michael@0: michael@0: #endif