Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / widget / nsShmImage.h
blobdae09c6c8dcacdab18f9a6bac600e8f9aeaa2474
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef __mozilla_widget_nsShmImage_h__
8 #define __mozilla_widget_nsShmImage_h__
10 #if defined(MOZ_X11)
11 # define MOZ_HAVE_SHMIMAGE
12 #endif
14 #ifdef MOZ_HAVE_SHMIMAGE
16 #include "mozilla/gfx/2D.h"
17 #include "nsIWidget.h"
18 #include "Units.h"
20 #include <X11/Xlib-xcb.h>
21 #include <xcb/shm.h>
23 class nsShmImage {
24 // 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
25 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsShmImage)
27 public:
28 static bool UseShm();
30 already_AddRefed<mozilla::gfx::DrawTarget>
31 CreateDrawTarget(const mozilla::LayoutDeviceIntRegion& aRegion);
33 void Put(const mozilla::LayoutDeviceIntRegion& aRegion);
35 nsShmImage(Display* aDisplay,
36 Drawable aWindow,
37 Visual* aVisual,
38 unsigned int aDepth);
40 private:
41 ~nsShmImage();
43 bool InitExtension();
45 bool CreateShmSegment();
46 void DestroyShmSegment();
48 bool CreateImage(const mozilla::gfx::IntSize& aSize);
49 void DestroyImage();
51 void WaitIfPendingReply();
53 Display* mDisplay;
54 xcb_connection_t* mConnection;
55 Window mWindow;
56 Visual* mVisual;
57 unsigned int mDepth;
59 mozilla::gfx::SurfaceFormat mFormat;
60 mozilla::gfx::IntSize mSize;
61 int mStride;
63 xcb_pixmap_t mPixmap;
64 xcb_gcontext_t mGC;
65 xcb_get_input_focus_cookie_t mSyncRequest;
66 bool mRequestPending;
68 xcb_shm_seg_t mShmSeg;
69 int mShmId;
70 uint8_t* mShmAddr;
73 #endif // MOZ_HAVE_SHMIMAGE
75 #endif