2012-07-30 19:54:21 -07:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2010-10-26 21:56:31 -07:00
*
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
2015-09-15 13:46:39 -07:00
# include "mozilla/gfx/2D.h"
2010-10-26 21:56:31 -07:00
# include "nsIWidget.h"
2013-09-24 13:45:13 -07:00
# include "nsAutoPtr.h"
2010-10-26 21:56:31 -07:00
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>
2015-09-15 13:46:39 -07:00
# ifdef MOZ_WIDGET_QT
2010-10-26 21:56:31 -07:00
class QRect ;
2014-02-20 18:08:53 -08:00
class QWindow ;
2015-09-15 13:46:39 -07:00
# endif
2010-10-26 21:56:31 -07:00
class nsShmImage {
2015-05-27 08:20:26 -07:00
// bug 1168843, compositor thread may create shared memory instances that are destroyed by main thread on shutdown, so this must use thread-safe RC to avoid hitting assertion
NS_INLINE_DECL_THREADSAFE_REFCOUNTING ( nsShmImage )
2010-10-26 21:56:31 -07:00
2010-11-05 00:17:07 -07:00
typedef mozilla : : ipc : : SharedMemorySysV SharedMemorySysV ;
2010-10-26 21:56:31 -07:00
public :
2011-09-28 23:19:26 -07:00
static bool UseShm ( ) ;
2010-10-26 21:56:31 -07:00
static already_AddRefed < nsShmImage >
2015-09-23 11:49:05 -07:00
Create ( const mozilla : : gfx : : IntSize & aSize ,
2015-09-15 13:46:39 -07:00
Display * aDisplay , Visual * aVisual , unsigned int aDepth ) ;
static already_AddRefed < mozilla : : gfx : : DrawTarget >
2015-09-23 11:49:05 -07:00
EnsureShmImage ( const mozilla : : gfx : : IntSize & aSize ,
2015-09-15 13:46:39 -07:00
Display * aDisplay , Visual * aVisual , unsigned int aDepth ,
2010-10-26 21:56:31 -07:00
nsRefPtr < nsShmImage > & aImage ) ;
2014-06-20 04:08:25 -07:00
private :
2010-10-26 21:56:31 -07:00
~ nsShmImage ( ) {
if ( mImage ) {
2015-09-15 13:46:39 -07:00
mozilla : : FinishX ( mDisplay ) ;
2010-10-26 21:56:31 -07:00
if ( mXAttached ) {
2015-09-15 13:46:39 -07:00
XShmDetach ( mDisplay , & mInfo ) ;
2010-10-26 21:56:31 -07:00
}
XDestroyImage ( mImage ) ;
}
}
2014-06-20 04:08:25 -07:00
public :
2015-09-15 13:46:39 -07:00
already_AddRefed < mozilla : : gfx : : DrawTarget > CreateDrawTarget ( ) ;
2010-10-26 21:56:31 -07:00
2015-05-01 11:08:04 -07:00
# ifdef MOZ_WIDGET_GTK
2015-09-15 13:46:39 -07:00
void Put ( Display * aDisplay , Drawable aWindow , const nsIntRegion & aRegion ) ;
2010-10-26 21:56:31 -07:00
# elif defined(MOZ_WIDGET_QT)
2014-02-20 18:08:53 -08:00
void Put ( QWindow * aWindow , QRect & aRect ) ;
2010-10-26 21:56:31 -07:00
# endif
2015-09-23 11:49:05 -07:00
mozilla : : gfx : : IntSize Size ( ) const { return mSize ; }
2010-10-26 21:56:31 -07:00
private :
nsShmImage ( )
2012-07-30 07:20:58 -07:00
: mImage ( nullptr )
2015-09-15 13:46:39 -07:00
, mDisplay ( nullptr )
, mFormat ( mozilla : : gfx : : SurfaceFormat : : UNKNOWN )
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 ;
2015-09-15 13:46:39 -07:00
Display * mDisplay ;
2010-10-26 21:56:31 -07:00
XShmSegmentInfo mInfo ;
2015-09-23 11:49:05 -07:00
mozilla : : gfx : : IntSize mSize ;
2015-09-15 13:46:39 -07:00
mozilla : : gfx : : SurfaceFormat mFormat ;
2011-09-28 23:19:26 -07:00
bool mXAttached ;
2010-10-26 21:56:31 -07:00
} ;
# endif // MOZ_HAVE_SHMIMAGE
# endif