Bug 1034398 - Query for max IOSurf sizes. - r=benwa

This commit is contained in:
Jeff Gilbert 2014-07-11 23:08:54 -07:00
parent b0b624ea02
commit e3e56e7710
6 changed files with 51 additions and 7 deletions

View File

@ -43,6 +43,7 @@ IOSurfaceGetBaseAddressFunc MacIOSurfaceLib::sGetBaseAddress;
IOSurfaceGetWidthFunc MacIOSurfaceLib::sWidth;
IOSurfaceGetHeightFunc MacIOSurfaceLib::sHeight;
IOSurfaceGetBytesPerRowFunc MacIOSurfaceLib::sBytesPerRow;
IOSurfaceGetPropertyMaximumFunc MacIOSurfaceLib::sGetPropertyMaximum;
IOSurfaceLockFunc MacIOSurfaceLib::sLock;
IOSurfaceUnlockFunc MacIOSurfaceLib::sUnlock;
CGLTexImageIOSurface2DFunc MacIOSurfaceLib::sTexImage;
@ -94,6 +95,10 @@ size_t MacIOSurfaceLib::IOSurfaceGetBytesPerRow(IOSurfacePtr aIOSurfacePtr) {
return sBytesPerRow(aIOSurfacePtr);
}
size_t MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(CFStringRef property) {
return sGetPropertyMaximum(property);
}
IOReturn MacIOSurfaceLib::IOSurfaceLock(IOSurfacePtr aIOSurfacePtr,
uint32_t options, uint32_t *seed) {
return sLock(aIOSurfacePtr, options, seed);
@ -177,6 +182,7 @@ void MacIOSurfaceLib::LoadLibrary() {
sWidth = GET_IOSYM(sWidth, "IOSurfaceGetWidth");
sHeight = GET_IOSYM(sHeight, "IOSurfaceGetHeight");
sBytesPerRow = GET_IOSYM(sBytesPerRow, "IOSurfaceGetBytesPerRow");
sGetPropertyMaximum = GET_IOSYM(sGetPropertyMaximum, "IOSurfaceGetPropertyMaximum");
sLookup = GET_IOSYM(sLookup, "IOSurfaceLookup");
sLock = GET_IOSYM(sLock, "IOSurfaceLock");
sUnlock = GET_IOSYM(sUnlock, "IOSurfaceUnlock");
@ -192,7 +198,7 @@ void MacIOSurfaceLib::LoadLibrary() {
if (!sCreate || !sGetID || !sLookup || !sTexImage || !sGetBaseAddress ||
!kPropWidth || !kPropHeight || !kPropBytesPerElem || !kPropIsGlobal ||
!sLock || !sUnlock || !sWidth || !sHeight || !kPropBytesPerRow ||
!sBytesPerRow) {
!sBytesPerRow || !sGetPropertyMaximum) {
CloseLibrary();
}
}
@ -225,6 +231,9 @@ TemporaryRef<MacIOSurface> MacIOSurface::CreateIOSurface(int aWidth, int aHeight
if (!props)
return nullptr;
MOZ_ASSERT((size_t)aWidth <= GetMaxWidth());
MOZ_ASSERT((size_t)aHeight <= GetMaxHeight());
int32_t bytesPerElem = 4;
size_t intScaleFactor = ceil(aContentsScaleFactor);
aWidth *= intScaleFactor;
@ -295,6 +304,14 @@ size_t MacIOSurface::GetHeight() {
return GetDevicePixelHeight() / intScaleFactor;
}
/*static*/ size_t MacIOSurface::GetMaxWidth() {
return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(MacIOSurfaceLib::kPropWidth);
}
/*static*/ size_t MacIOSurface::GetMaxHeight() {
return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(MacIOSurfaceLib::kPropHeight);
}
size_t MacIOSurface::GetDevicePixelWidth() {
return MacIOSurfaceLib::IOSurfaceGetWidth(mIOSurfacePtr);
}

View File

@ -25,6 +25,7 @@ typedef void* (*IOSurfaceGetBaseAddressFunc) (CFTypeRef io_surface);
typedef size_t (*IOSurfaceGetWidthFunc) (IOSurfacePtr io_surface);
typedef size_t (*IOSurfaceGetHeightFunc) (IOSurfacePtr io_surface);
typedef size_t (*IOSurfaceGetBytesPerRowFunc) (IOSurfacePtr io_surface);
typedef size_t (*IOSurfaceGetPropertyMaximumFunc) (CFStringRef property);
typedef CGLError (*CGLTexImageIOSurface2DFunc) (CGLContextObj ctxt,
GLenum target, GLenum internalFormat,
GLsizei width, GLsizei height,
@ -38,7 +39,6 @@ typedef CGImageRef (*IOSurfaceContextCreateImageFunc)(CGContextRef ref);
typedef IOSurfacePtr (*IOSurfaceContextGetSurfaceFunc)(CGContextRef ref);
#import <OpenGL/OpenGL.h>
#include "2D.h"
#include "mozilla/RefPtr.h"
@ -101,6 +101,8 @@ public:
static mozilla::TemporaryRef<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext,
double aContentsScaleFactor = 1.0,
bool aHasAlpha = true);
static size_t GetMaxWidth();
static size_t GetMaxHeight();
private:
friend class nsCARenderer;
@ -125,6 +127,7 @@ public:
static IOSurfaceGetWidthFunc sWidth;
static IOSurfaceGetHeightFunc sHeight;
static IOSurfaceGetBytesPerRowFunc sBytesPerRow;
static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum;
static CGLTexImageIOSurface2DFunc sTexImage;
static IOSurfaceContextCreateFunc sIOSurfaceContextCreate;
static IOSurfaceContextCreateImageFunc sIOSurfaceContextCreateImage;
@ -140,10 +143,11 @@ public:
static IOSurfacePtr IOSurfaceCreate(CFDictionaryRef properties);
static IOSurfacePtr IOSurfaceLookup(IOSurfaceID aIOSurfaceID);
static IOSurfaceID IOSurfaceGetID(IOSurfacePtr aIOSurfacePtr);
static void *IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr);
static void* IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr);
static size_t IOSurfaceGetWidth(IOSurfacePtr aIOSurfacePtr);
static size_t IOSurfaceGetHeight(IOSurfacePtr aIOSurfacePtr);
static size_t IOSurfaceGetBytesPerRow(IOSurfacePtr aIOSurfacePtr);
static size_t IOSurfaceGetPropertyMaximum(CFStringRef property);
static IOReturn IOSurfaceLock(IOSurfacePtr aIOSurfacePtr,
uint32_t options, uint32_t *seed);
static IOReturn IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr,

View File

@ -51,7 +51,7 @@ GLScreenBuffer::Create(GLContext* gl,
#ifdef XP_MACOSX
/* On OSX, we want an IOSurface factory, and we want one right at the start */
if (!factory) {
factory = new SurfaceFactory_IOSurface(gl, caps);
factory = SurfaceFactory_IOSurface::Create(gl, caps);
}
#endif

View File

@ -134,9 +134,25 @@ SharedSurface_IOSurface::~SharedSurface_IOSurface()
}
}
/*static*/ SurfaceFactory_IOSurface*
SurfaceFactory_IOSurface::Create(GLContext* gl,
const SurfaceCaps& caps)
{
gfx::IntSize maxDims(MacIOSurface::GetMaxWidth(),
MacIOSurface::GetMaxHeight());
return new SurfaceFactory_IOSurface(gl, caps, maxDims);
}
SharedSurface*
SurfaceFactory_IOSurface::CreateShared(const gfx::IntSize& size)
{
if (size.width > mMaxDims.width ||
size.height > mMaxDims.height)
{
return nullptr;
}
bool hasAlpha = mReadCaps.alpha;
RefPtr<MacIOSurface> surf =
MacIOSurface::CreateIOSurface(size.width, size.height, 1.0, hasAlpha);

View File

@ -65,13 +65,20 @@ private:
class SurfaceFactory_IOSurface : public SurfaceFactory
{
public:
// Infallible.
static SurfaceFactory_IOSurface* Create(GLContext* gl,
const SurfaceCaps& caps);
protected:
const gfx::IntSize mMaxDims;
SurfaceFactory_IOSurface(GLContext* gl,
const SurfaceCaps& caps)
const SurfaceCaps& caps,
const gfx::IntSize& maxDims)
: SurfaceFactory(gl, SharedSurfaceType::IOSurface, caps)
, mMaxDims(maxDims)
{
}
protected:
virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE;
};

View File

@ -94,7 +94,7 @@ ClientCanvasLayer::Initialize(const Data& aData)
// [Basic Layers, OMTC] WebGL layer init.
// Well, this *should* work...
#ifdef XP_MACOSX
factory = new SurfaceFactory_IOSurface(mGLContext, caps);
factory = SurfaceFactory_IOSurface::Create(mGLContext, caps);
#else
factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
#endif