2012-01-31 18:18:30 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
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/. */
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
#ifndef MacIOSurface_h__
|
|
|
|
#define MacIOSurface_h__
|
2012-01-31 18:18:30 -08:00
|
|
|
#ifdef XP_MACOSX
|
2013-11-07 19:53:54 -08:00
|
|
|
#include <QuartzCore/QuartzCore.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
|
|
|
|
typedef CFTypeRef IOSurfacePtr;
|
|
|
|
typedef IOSurfacePtr (*IOSurfaceCreateFunc) (CFDictionaryRef properties);
|
|
|
|
typedef IOSurfacePtr (*IOSurfaceLookupFunc) (uint32_t io_surface_id);
|
|
|
|
typedef IOSurfaceID (*IOSurfaceGetIDFunc) (CFTypeRef io_surface);
|
|
|
|
typedef IOReturn (*IOSurfaceLockFunc) (CFTypeRef io_surface,
|
|
|
|
uint32_t options,
|
|
|
|
uint32_t *seed);
|
|
|
|
typedef IOReturn (*IOSurfaceUnlockFunc) (CFTypeRef io_surface,
|
|
|
|
uint32_t options,
|
|
|
|
uint32_t *seed);
|
|
|
|
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);
|
2014-07-11 23:08:54 -07:00
|
|
|
typedef size_t (*IOSurfaceGetPropertyMaximumFunc) (CFStringRef property);
|
2013-11-07 19:53:54 -08:00
|
|
|
typedef CGLError (*CGLTexImageIOSurface2DFunc) (CGLContextObj ctxt,
|
|
|
|
GLenum target, GLenum internalFormat,
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type,
|
|
|
|
IOSurfacePtr ioSurface, GLuint plane);
|
|
|
|
typedef CGContextRef (*IOSurfaceContextCreateFunc)(CFTypeRef io_surface,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned bitsPerComponent, unsigned bytes,
|
|
|
|
CGColorSpaceRef colorSpace, CGBitmapInfo bitmapInfo);
|
|
|
|
typedef CGImageRef (*IOSurfaceContextCreateImageFunc)(CGContextRef ref);
|
|
|
|
typedef IOSurfacePtr (*IOSurfaceContextGetSurfaceFunc)(CGContextRef ref);
|
|
|
|
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
#import <OpenGL/OpenGL.h>
|
2012-07-31 08:11:57 -07:00
|
|
|
#include "2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2012-02-16 05:20:51 -08:00
|
|
|
struct _CGLContextObject;
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
typedef _CGLContextObject* CGLContextObj;
|
2012-07-31 08:11:57 -07:00
|
|
|
typedef struct CGContext* CGContextRef;
|
|
|
|
typedef struct CGImage* CGImageRef;
|
2012-01-31 18:18:30 -08:00
|
|
|
typedef uint32_t IOSurfaceID;
|
|
|
|
|
2013-11-07 19:53:54 -08:00
|
|
|
enum CGContextType {
|
|
|
|
CG_CONTEXT_TYPE_UNKNOWN = 0,
|
|
|
|
// These are found by inspection, it's possible they could be changed
|
|
|
|
CG_CONTEXT_TYPE_BITMAP = 4,
|
|
|
|
CG_CONTEXT_TYPE_IOSURFACE = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
CGContextType GetContextType(CGContextRef ref);
|
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
class MacIOSurface : public mozilla::RefCounted<MacIOSurface> {
|
2012-01-31 18:18:30 -08:00
|
|
|
public:
|
2014-02-24 05:23:37 -08:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(MacIOSurface)
|
2012-07-31 08:11:57 -07:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> CreateIOSurface(int aWidth, int aHeight,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 08:11:57 -07:00
|
|
|
static void ReleaseIOSurface(MacIOSurface *aIOSurface);
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> LookupSurface(IOSurfaceID aSurfaceID,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 08:11:57 -07:00
|
|
|
|
2013-07-17 20:24:14 -07:00
|
|
|
MacIOSurface(const void *aIOSurfacePtr, double aContentsScaleFactor = 1.0, bool aHasAlpha = true)
|
|
|
|
: mIOSurfacePtr(aIOSurfacePtr), mContentsScaleFactor(aContentsScaleFactor), mHasAlpha(aHasAlpha) {}
|
2014-02-24 05:23:37 -08:00
|
|
|
virtual ~MacIOSurface();
|
2012-01-31 18:18:30 -08:00
|
|
|
IOSurfaceID GetIOSurfaceID();
|
|
|
|
void *GetBaseAddress();
|
2012-10-02 12:48:05 -07:00
|
|
|
// GetWidth() and GetHeight() return values in "display pixels". A
|
|
|
|
// "display pixel" is the smallest fully addressable part of a display.
|
|
|
|
// But in HiDPI modes each "display pixel" corresponds to more than one
|
2013-04-24 15:31:12 -07:00
|
|
|
// device pixel. Use GetDevicePixel**() to get device pixels.
|
2012-01-31 18:18:30 -08:00
|
|
|
size_t GetWidth();
|
|
|
|
size_t GetHeight();
|
2012-10-02 12:48:05 -07:00
|
|
|
double GetContentsScaleFactor() { return mContentsScaleFactor; }
|
2013-04-24 15:31:12 -07:00
|
|
|
size_t GetDevicePixelWidth();
|
|
|
|
size_t GetDevicePixelHeight();
|
2012-01-31 18:18:30 -08:00
|
|
|
size_t GetBytesPerRow();
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
2013-07-17 20:24:14 -07:00
|
|
|
bool HasAlpha() { return mHasAlpha; }
|
2012-02-14 06:22:23 -08:00
|
|
|
// We would like to forward declare NSOpenGLContext, but it is an @interface
|
|
|
|
// and this file is also used from c++, so we use a void *.
|
2013-11-07 19:53:54 -08:00
|
|
|
CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt);
|
2012-07-31 08:11:57 -07:00
|
|
|
mozilla::TemporaryRef<SourceSurface> GetAsSurface();
|
|
|
|
CGContextRef CreateIOSurfaceContext();
|
|
|
|
|
|
|
|
// FIXME This doesn't really belong here
|
|
|
|
static CGImageRef CreateImageFromIOSurfaceContext(CGContextRef aContext);
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2014-07-11 23:08:54 -07:00
|
|
|
static size_t GetMaxWidth();
|
|
|
|
static size_t GetMaxHeight();
|
2012-07-31 08:11:57 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
private:
|
|
|
|
friend class nsCARenderer;
|
|
|
|
const void* mIOSurfacePtr;
|
2012-10-02 12:48:05 -07:00
|
|
|
double mContentsScaleFactor;
|
2013-07-17 20:24:14 -07:00
|
|
|
bool mHasAlpha;
|
2012-01-31 18:18:30 -08:00
|
|
|
};
|
|
|
|
|
2013-11-07 19:53:54 -08:00
|
|
|
class MacIOSurfaceLib: public MacIOSurface {
|
|
|
|
public:
|
2014-02-24 05:23:37 -08:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(MacIOSurfaceLib)
|
2013-11-07 19:53:54 -08:00
|
|
|
static void *sIOSurfaceFramework;
|
|
|
|
static void *sOpenGLFramework;
|
|
|
|
static void *sCoreGraphicsFramework;
|
|
|
|
static bool isLoaded;
|
|
|
|
static IOSurfaceCreateFunc sCreate;
|
|
|
|
static IOSurfaceGetIDFunc sGetID;
|
|
|
|
static IOSurfaceLookupFunc sLookup;
|
|
|
|
static IOSurfaceGetBaseAddressFunc sGetBaseAddress;
|
|
|
|
static IOSurfaceLockFunc sLock;
|
|
|
|
static IOSurfaceUnlockFunc sUnlock;
|
|
|
|
static IOSurfaceGetWidthFunc sWidth;
|
|
|
|
static IOSurfaceGetHeightFunc sHeight;
|
|
|
|
static IOSurfaceGetBytesPerRowFunc sBytesPerRow;
|
2014-07-11 23:08:54 -07:00
|
|
|
static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum;
|
2013-11-07 19:53:54 -08:00
|
|
|
static CGLTexImageIOSurface2DFunc sTexImage;
|
|
|
|
static IOSurfaceContextCreateFunc sIOSurfaceContextCreate;
|
|
|
|
static IOSurfaceContextCreateImageFunc sIOSurfaceContextCreateImage;
|
|
|
|
static IOSurfaceContextGetSurfaceFunc sIOSurfaceContextGetSurface;
|
|
|
|
static CFStringRef kPropWidth;
|
|
|
|
static CFStringRef kPropHeight;
|
|
|
|
static CFStringRef kPropBytesPerElem;
|
|
|
|
static CFStringRef kPropBytesPerRow;
|
|
|
|
static CFStringRef kPropIsGlobal;
|
|
|
|
|
|
|
|
static bool isInit();
|
|
|
|
static CFStringRef GetIOConst(const char* symbole);
|
|
|
|
static IOSurfacePtr IOSurfaceCreate(CFDictionaryRef properties);
|
|
|
|
static IOSurfacePtr IOSurfaceLookup(IOSurfaceID aIOSurfaceID);
|
|
|
|
static IOSurfaceID IOSurfaceGetID(IOSurfacePtr aIOSurfacePtr);
|
2014-07-11 23:08:54 -07:00
|
|
|
static void* IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr);
|
2013-11-07 19:53:54 -08:00
|
|
|
static size_t IOSurfaceGetWidth(IOSurfacePtr aIOSurfacePtr);
|
|
|
|
static size_t IOSurfaceGetHeight(IOSurfacePtr aIOSurfacePtr);
|
|
|
|
static size_t IOSurfaceGetBytesPerRow(IOSurfacePtr aIOSurfacePtr);
|
2014-07-11 23:08:54 -07:00
|
|
|
static size_t IOSurfaceGetPropertyMaximum(CFStringRef property);
|
2013-11-07 19:53:54 -08:00
|
|
|
static IOReturn IOSurfaceLock(IOSurfacePtr aIOSurfacePtr,
|
|
|
|
uint32_t options, uint32_t *seed);
|
|
|
|
static IOReturn IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr,
|
|
|
|
uint32_t options, uint32_t *seed);
|
|
|
|
static CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt,
|
|
|
|
GLenum target, GLenum internalFormat,
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type,
|
|
|
|
IOSurfacePtr ioSurface, GLuint plane);
|
|
|
|
static CGContextRef IOSurfaceContextCreate(IOSurfacePtr aIOSurfacePtr,
|
|
|
|
unsigned aWidth, unsigned aHeight,
|
|
|
|
unsigned aBitsPerCompoent, unsigned aBytes,
|
|
|
|
CGColorSpaceRef aColorSpace, CGBitmapInfo bitmapInfo);
|
|
|
|
static CGImageRef IOSurfaceContextCreateImage(CGContextRef ref);
|
|
|
|
static IOSurfacePtr IOSurfaceContextGetSurface(CGContextRef ref);
|
|
|
|
static unsigned int (*sCGContextGetTypePtr) (CGContextRef);
|
|
|
|
static void LoadLibrary();
|
|
|
|
static void CloseLibrary();
|
|
|
|
|
|
|
|
// Static deconstructor
|
|
|
|
static class LibraryUnloader {
|
|
|
|
public:
|
|
|
|
~LibraryUnloader() {
|
|
|
|
CloseLibrary();
|
|
|
|
}
|
|
|
|
} sLibraryUnloader;
|
|
|
|
};
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
#endif
|
|
|
|
#endif
|