Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef __mozilla_widget_nsShmImage_h__
8 #define __mozilla_widget_nsShmImage_h__
10 #include "mozilla/ipc/SharedMemorySysV.h"
12 #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
13 # define MOZ_HAVE_SHMIMAGE
14 #endif
16 #ifdef MOZ_HAVE_SHMIMAGE
18 #include "nsIWidget.h"
19 #include "gfxTypes.h"
20 #include "nsAutoPtr.h"
22 #include "mozilla/X11Util.h"
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/extensions/XShm.h>
27 #if defined(MOZ_WIDGET_GTK)
28 #define DISPLAY gdk_x11_get_default_xdisplay
29 #elif defined(MOZ_WIDGET_QT)
30 #define DISPLAY mozilla::DefaultXDisplay
31 #endif
33 class QRect;
34 class QWindow;
35 class gfxASurface;
37 class nsShmImage {
38 NS_INLINE_DECL_REFCOUNTING(nsShmImage)
40 typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV;
42 public:
43 typedef gfxImageFormat Format;
45 static bool UseShm();
46 static already_AddRefed<nsShmImage>
47 Create(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth);
48 static already_AddRefed<gfxASurface>
49 EnsureShmImage(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth,
50 nsRefPtr<nsShmImage>& aImage);
52 ~nsShmImage() {
53 if (mImage) {
54 mozilla::FinishX(DISPLAY());
55 if (mXAttached) {
56 XShmDetach(DISPLAY(), &mInfo);
57 }
58 XDestroyImage(mImage);
59 }
60 }
62 already_AddRefed<gfxASurface> AsSurface();
64 #if (MOZ_WIDGET_GTK == 2)
65 void Put(GdkWindow* aWindow, GdkRectangle* aRects, GdkRectangle* aEnd);
66 #elif (MOZ_WIDGET_GTK == 3)
67 void Put(GdkWindow* aWindow, cairo_rectangle_list_t* aRects);
68 #elif defined(MOZ_WIDGET_QT)
69 void Put(QWindow* aWindow, QRect& aRect);
70 #endif
72 gfxIntSize Size() const { return mSize; }
74 private:
75 nsShmImage()
76 : mImage(nullptr)
77 , mXAttached(false)
78 { mInfo.shmid = SharedMemorySysV::NULLHandle(); }
80 nsRefPtr<SharedMemorySysV> mSegment;
81 XImage* mImage;
82 XShmSegmentInfo mInfo;
83 gfxIntSize mSize;
84 Format mFormat;
85 bool mXAttached;
86 };
88 #endif // MOZ_HAVE_SHMIMAGE
90 #endif