widget/shared/nsShmImage.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:37c8868e3a08
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/. */
6
7 #ifndef __mozilla_widget_nsShmImage_h__
8 #define __mozilla_widget_nsShmImage_h__
9
10 #include "mozilla/ipc/SharedMemorySysV.h"
11
12 #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
13 # define MOZ_HAVE_SHMIMAGE
14 #endif
15
16 #ifdef MOZ_HAVE_SHMIMAGE
17
18 #include "nsIWidget.h"
19 #include "gfxTypes.h"
20 #include "nsAutoPtr.h"
21
22 #include "mozilla/X11Util.h"
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/extensions/XShm.h>
26
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
32
33 class QRect;
34 class QWindow;
35 class gfxASurface;
36
37 class nsShmImage {
38 NS_INLINE_DECL_REFCOUNTING(nsShmImage)
39
40 typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV;
41
42 public:
43 typedef gfxImageFormat Format;
44
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);
51
52 ~nsShmImage() {
53 if (mImage) {
54 mozilla::FinishX(DISPLAY());
55 if (mXAttached) {
56 XShmDetach(DISPLAY(), &mInfo);
57 }
58 XDestroyImage(mImage);
59 }
60 }
61
62 already_AddRefed<gfxASurface> AsSurface();
63
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
71
72 gfxIntSize Size() const { return mSize; }
73
74 private:
75 nsShmImage()
76 : mImage(nullptr)
77 , mXAttached(false)
78 { mInfo.shmid = SharedMemorySysV::NULLHandle(); }
79
80 nsRefPtr<SharedMemorySysV> mSegment;
81 XImage* mImage;
82 XShmSegmentInfo mInfo;
83 gfxIntSize mSize;
84 Format mFormat;
85 bool mXAttached;
86 };
87
88 #endif // MOZ_HAVE_SHMIMAGE
89
90 #endif

mercurial