widget/shared/nsShmImage.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial