Bumping manifests a=b2g-bump
[gecko.git] / widget / nsShmImage.h
blobdf71a9ed1afd29897aa62cfd54b4470a234cfa46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 private:
53 ~nsShmImage() {
54 if (mImage) {
55 mozilla::FinishX(DISPLAY());
56 if (mXAttached) {
57 XShmDetach(DISPLAY(), &mInfo);
59 XDestroyImage(mImage);
63 public:
64 already_AddRefed<gfxASurface> AsSurface();
66 #if (MOZ_WIDGET_GTK == 2)
67 void Put(GdkWindow* aWindow, GdkRectangle* aRects, GdkRectangle* aEnd);
68 #elif (MOZ_WIDGET_GTK == 3)
69 void Put(GdkWindow* aWindow, cairo_rectangle_list_t* aRects);
70 #elif defined(MOZ_WIDGET_QT)
71 void Put(QWindow* aWindow, QRect& aRect);
72 #endif
74 gfxIntSize Size() const { return mSize; }
76 private:
77 nsShmImage()
78 : mImage(nullptr)
79 , mXAttached(false)
80 { mInfo.shmid = SharedMemorySysV::NULLHandle(); }
82 nsRefPtr<SharedMemorySysV> mSegment;
83 XImage* mImage;
84 XShmSegmentInfo mInfo;
85 gfxIntSize mSize;
86 Format mFormat;
87 bool mXAttached;
90 #endif // MOZ_HAVE_SHMIMAGE
92 #endif