2010-10-26 21:56:31 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-26 21:56:31 -07:00
|
|
|
|
|
|
|
#ifndef __mozilla_widget_nsShmImage_h__
|
|
|
|
#define __mozilla_widget_nsShmImage_h__
|
|
|
|
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "mozilla/ipc/SharedMemorySysV.h"
|
2010-10-26 21:56:31 -07:00
|
|
|
|
|
|
|
#if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
|
|
|
|
# define MOZ_HAVE_SHMIMAGE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "gfxASurface.h"
|
|
|
|
|
2012-03-22 16:24:40 -07:00
|
|
|
#include "mozilla/X11Util.h"
|
2010-10-26 21:56:31 -07:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2) || defined(MOZ_WIDGET_GTK3)
|
2010-10-26 21:56:31 -07:00
|
|
|
#define DISPLAY gdk_x11_get_default_xdisplay
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
2012-03-22 16:24:40 -07:00
|
|
|
#define DISPLAY mozilla::DefaultXDisplay
|
2010-10-26 21:56:31 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class QRect;
|
|
|
|
class QWidget;
|
|
|
|
|
|
|
|
class nsShmImage {
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsShmImage)
|
|
|
|
|
2010-11-05 00:17:07 -07:00
|
|
|
typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV;
|
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
public:
|
|
|
|
typedef gfxASurface::gfxImageFormat Format;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool UseShm();
|
2010-10-26 21:56:31 -07:00
|
|
|
static already_AddRefed<nsShmImage>
|
|
|
|
Create(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth);
|
|
|
|
static already_AddRefed<gfxASurface>
|
|
|
|
EnsureShmImage(const gfxIntSize& aSize, Visual* aVisual, unsigned int aDepth,
|
|
|
|
nsRefPtr<nsShmImage>& aImage);
|
|
|
|
|
|
|
|
~nsShmImage() {
|
|
|
|
if (mImage) {
|
|
|
|
XSync(DISPLAY(), False);
|
|
|
|
if (mXAttached) {
|
|
|
|
XShmDetach(DISPLAY(), &mInfo);
|
|
|
|
}
|
|
|
|
XDestroyImage(mImage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface> AsSurface();
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
void Put(GdkWindow* aWindow, GdkRectangle* aRects, GdkRectangle* aEnd);
|
2011-09-22 13:58:07 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK3)
|
|
|
|
void Put(GdkWindow* aWindow, cairo_rectangle_list_t* aRects);
|
2010-10-26 21:56:31 -07:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
void Put(QWidget* aWindow, QRect& aRect);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gfxIntSize Size() const { return mSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsShmImage()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mImage(nullptr)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mXAttached(false)
|
2010-10-26 21:56:31 -07:00
|
|
|
{ mInfo.shmid = SharedMemorySysV::NULLHandle(); }
|
|
|
|
|
|
|
|
nsRefPtr<SharedMemorySysV> mSegment;
|
|
|
|
XImage* mImage;
|
|
|
|
XShmSegmentInfo mInfo;
|
|
|
|
gfxIntSize mSize;
|
|
|
|
Format mFormat;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mXAttached;
|
2010-10-26 21:56:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOZ_HAVE_SHMIMAGE
|
|
|
|
|
|
|
|
#endif
|