2016-11-08 19:56:27 +00:00
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2010-10-27 04:56:31 +00:00
*
2012-05-21 11:12:37 +00: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-27 04:56:31 +00:00
# ifndef __mozilla_widget_nsShmImage_h__
# define __mozilla_widget_nsShmImage_h__
2016-02-18 15:56:15 +00:00
# if defined(MOZ_X11)
2010-10-27 04:56:31 +00:00
# define MOZ_HAVE_SHMIMAGE
# endif
# ifdef MOZ_HAVE_SHMIMAGE
2015-09-15 20:46:39 +00:00
# include "mozilla/gfx/2D.h"
2010-10-27 04:56:31 +00:00
# include "nsIWidget.h"
2016-02-28 04:16:57 +00:00
# include "Units.h"
2010-10-27 04:56:31 +00:00
2016-07-13 20:28:28 +00:00
# include <X11/Xlib-xcb.h>
# include <xcb/shm.h>
2010-10-27 04:56:31 +00:00
class nsShmImage {
2016-02-25 19:38:05 +00: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-27 04:56:31 +00:00
public :
2016-02-25 19:38:05 +00:00
static bool UseShm ( ) ;
already_AddRefed < mozilla : : gfx : : DrawTarget >
CreateDrawTarget ( const mozilla : : LayoutDeviceIntRegion & aRegion ) ;
void Put ( const mozilla : : LayoutDeviceIntRegion & aRegion ) ;
nsShmImage ( Display * aDisplay ,
Drawable aWindow ,
Visual * aVisual ,
2016-02-28 04:16:57 +00:00
unsigned int aDepth ) ;
2010-10-27 04:56:31 +00:00
private :
2016-02-28 04:16:57 +00:00
~ nsShmImage ( ) ;
bool InitExtension ( ) ;
2016-02-25 19:38:05 +00:00
bool CreateShmSegment ( ) ;
void DestroyShmSegment ( ) ;
bool CreateImage ( const mozilla : : gfx : : IntSize & aSize ) ;
void DestroyImage ( ) ;
2016-11-08 19:56:27 +00:00
void WaitIfPendingReply ( ) ;
2016-07-13 20:28:28 +00:00
xcb_connection_t * mConnection ;
2016-02-28 04:16:57 +00:00
Window mWindow ;
2016-02-25 19:38:05 +00:00
Visual * mVisual ;
unsigned int mDepth ;
2016-07-13 20:28:28 +00:00
2016-02-25 19:38:05 +00:00
mozilla : : gfx : : SurfaceFormat mFormat ;
2016-07-13 20:28:28 +00:00
mozilla : : gfx : : IntSize mSize ;
xcb_pixmap_t mPixmap ;
xcb_gcontext_t mGC ;
2016-07-21 17:41:09 +00:00
xcb_get_input_focus_cookie_t mSyncRequest ;
bool mRequestPending ;
2016-07-13 20:28:28 +00:00
xcb_shm_seg_t mShmSeg ;
int mShmId ;
uint8_t * mShmAddr ;
2010-10-27 04:56:31 +00:00
} ;
# endif // MOZ_HAVE_SHMIMAGE
# endif