1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/shared/nsShmImage.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef __mozilla_widget_nsShmImage_h__ 1.11 +#define __mozilla_widget_nsShmImage_h__ 1.12 + 1.13 +#include "mozilla/ipc/SharedMemorySysV.h" 1.14 + 1.15 +#if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV) 1.16 +# define MOZ_HAVE_SHMIMAGE 1.17 +#endif 1.18 + 1.19 +#ifdef MOZ_HAVE_SHMIMAGE 1.20 + 1.21 +#include "nsIWidget.h" 1.22 +#include "gfxTypes.h" 1.23 +#include "nsAutoPtr.h" 1.24 + 1.25 +#include "mozilla/X11Util.h" 1.26 +#include <X11/Xlib.h> 1.27 +#include <X11/Xutil.h> 1.28 +#include <X11/extensions/XShm.h> 1.29 + 1.30 +#if defined(MOZ_WIDGET_GTK) 1.31 +#define DISPLAY gdk_x11_get_default_xdisplay 1.32 +#elif defined(MOZ_WIDGET_QT) 1.33 +#define DISPLAY mozilla::DefaultXDisplay 1.34 +#endif 1.35 + 1.36 +class QRect; 1.37 +class QWindow; 1.38 +class gfxASurface; 1.39 + 1.40 +class nsShmImage { 1.41 + NS_INLINE_DECL_REFCOUNTING(nsShmImage) 1.42 + 1.43 + typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV; 1.44 + 1.45 +public: 1.46 + typedef gfxImageFormat Format; 1.47 + 1.48 + static bool UseShm(); 1.49 + static already_AddRefed<nsShmImage> 1.50 + Create(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth); 1.51 + static already_AddRefed<gfxASurface> 1.52 + EnsureShmImage(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth, 1.53 + nsRefPtr<nsShmImage>& aImage); 1.54 + 1.55 + ~nsShmImage() { 1.56 + if (mImage) { 1.57 + mozilla::FinishX(DISPLAY()); 1.58 + if (mXAttached) { 1.59 + XShmDetach(DISPLAY(), &mInfo); 1.60 + } 1.61 + XDestroyImage(mImage); 1.62 + } 1.63 + } 1.64 + 1.65 + already_AddRefed<gfxASurface> AsSurface(); 1.66 + 1.67 +#if (MOZ_WIDGET_GTK == 2) 1.68 + void Put(GdkWindow* aWindow, GdkRectangle* aRects, GdkRectangle* aEnd); 1.69 +#elif (MOZ_WIDGET_GTK == 3) 1.70 + void Put(GdkWindow* aWindow, cairo_rectangle_list_t* aRects); 1.71 +#elif defined(MOZ_WIDGET_QT) 1.72 + void Put(QWindow* aWindow, QRect& aRect); 1.73 +#endif 1.74 + 1.75 + gfxIntSize Size() const { return mSize; } 1.76 + 1.77 +private: 1.78 + nsShmImage() 1.79 + : mImage(nullptr) 1.80 + , mXAttached(false) 1.81 + { mInfo.shmid = SharedMemorySysV::NULLHandle(); } 1.82 + 1.83 + nsRefPtr<SharedMemorySysV> mSegment; 1.84 + XImage* mImage; 1.85 + XShmSegmentInfo mInfo; 1.86 + gfxIntSize mSize; 1.87 + Format mFormat; 1.88 + bool mXAttached; 1.89 +}; 1.90 + 1.91 +#endif // MOZ_HAVE_SHMIMAGE 1.92 + 1.93 +#endif