Bug 1321129 - make nsShmImage stride compatible with XShm. r=karlt

MozReview-Commit-ID: GuiVTPKvAZM
This commit is contained in:
Lee Salzman 2017-02-21 10:00:52 -05:00
parent ca571e7995
commit fffec15aa3
3 changed files with 21 additions and 6 deletions

View File

@ -1231,6 +1231,7 @@ X11/extensions/Xrender.h
X11/extensions/Xfixes.h
X11/extensions/Xdamage.h
X11/extensions/Xcomposite.h
X11/ImUtil.h
X11/Intrinsic.h
X11/keysymdef.h
X11/keysym.h

View File

@ -19,6 +19,10 @@
#include <sys/ipc.h>
#include <sys/shm.h>
extern "C" {
#include <X11/ImUtil.h>
}
using namespace mozilla::ipc;
using namespace mozilla::gfx;
@ -26,11 +30,14 @@ nsShmImage::nsShmImage(Display* aDisplay,
Drawable aWindow,
Visual* aVisual,
unsigned int aDepth)
: mWindow(aWindow)
: mDisplay(aDisplay)
, mConnection(XGetXCBConnection(aDisplay))
, mWindow(aWindow)
, mVisual(aVisual)
, mDepth(aDepth)
, mFormat(mozilla::gfx::SurfaceFormat::UNKNOWN)
, mSize(0, 0)
, mStride(0)
, mPixmap(XCB_NONE)
, mGC(XCB_NONE)
, mRequestPending(false)
@ -38,7 +45,6 @@ nsShmImage::nsShmImage(Display* aDisplay,
, mShmId(-1)
, mShmAddr(nullptr)
{
mConnection = XGetXCBConnection(aDisplay);
mozilla::PodZero(&mSyncRequest);
}
@ -58,8 +64,7 @@ bool nsShmImage::UseShm()
bool
nsShmImage::CreateShmSegment()
{
size_t size = SharedMemory::PageAlignedSize(BytesPerPixel(mFormat) *
mSize.width * mSize.height);
size_t size = SharedMemory::PageAlignedSize(mStride * mSize.height);
mShmId = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600);
if (mShmId == -1) {
@ -187,6 +192,13 @@ nsShmImage::CreateImage(const IntSize& aSize)
return false;
}
// Round up stride to the display's scanline pad (in bits) as XShm expects.
int scanlinePad = _XGetScanlinePad(mDisplay, mDepth);
int bitsPerPixel = _XGetBitsPerPixel(mDisplay, mDepth);
int bitsPerLine = ((bitsPerPixel * aSize.width + scanlinePad - 1)
/ scanlinePad) * scanlinePad;
mStride = bitsPerLine / 8;
if (!CreateShmSegment()) {
DestroyImage();
return false;
@ -277,9 +289,9 @@ nsShmImage::CreateDrawTarget(const mozilla::LayoutDeviceIntRegion& aRegion)
return gfxPlatform::CreateDrawTargetForData(
reinterpret_cast<unsigned char*>(mShmAddr)
+ BytesPerPixel(mFormat) * (bounds.y * mSize.width + bounds.x),
+ bounds.y * mStride + bounds.x * BytesPerPixel(mFormat),
bounds.Size(),
BytesPerPixel(mFormat) * mSize.width,
mStride,
mFormat);
}

View File

@ -50,6 +50,7 @@ private:
void WaitIfPendingReply();
Display* mDisplay;
xcb_connection_t* mConnection;
Window mWindow;
Visual* mVisual;
@ -57,6 +58,7 @@ private:
mozilla::gfx::SurfaceFormat mFormat;
mozilla::gfx::IntSize mSize;
int mStride;
xcb_pixmap_t mPixmap;
xcb_gcontext_t mGC;