2012-02-01 06:18:30 +04: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 15:12:37 +04: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-02-01 06:18:30 +04:00
|
|
|
|
2012-07-31 19:11:57 +04:00
|
|
|
#ifndef MacIOSurface_h__
|
|
|
|
#define MacIOSurface_h__
|
2015-06-12 15:48:42 +03:00
|
|
|
#ifdef XP_DARWIN
|
2013-11-08 07:53:54 +04:00
|
|
|
#include <QuartzCore/QuartzCore.h>
|
2015-06-12 15:48:42 +03:00
|
|
|
#include <CoreVideo/CoreVideo.h>
|
2013-11-08 07:53:54 +04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2015-06-12 15:48:42 +03:00
|
|
|
struct _CGLContextObject;
|
|
|
|
|
|
|
|
typedef _CGLContextObject* CGLContextObj;
|
|
|
|
typedef struct CGContext* CGContextRef;
|
|
|
|
typedef struct CGImage* CGImageRef;
|
|
|
|
typedef uint32_t IOSurfaceID;
|
|
|
|
|
|
|
|
#ifdef XP_IOS
|
|
|
|
typedef kern_return_t IOReturn;
|
|
|
|
typedef int CGLError;
|
|
|
|
#endif
|
|
|
|
|
2013-11-08 07:53:54 +04:00
|
|
|
typedef CFTypeRef IOSurfacePtr;
|
|
|
|
typedef IOSurfacePtr (*IOSurfaceCreateFunc) (CFDictionaryRef properties);
|
|
|
|
typedef IOSurfacePtr (*IOSurfaceLookupFunc) (uint32_t io_surface_id);
|
2014-09-03 11:09:24 +04:00
|
|
|
typedef IOSurfaceID (*IOSurfaceGetIDFunc)(IOSurfacePtr io_surface);
|
|
|
|
typedef void (*IOSurfaceVoidFunc)(IOSurfacePtr io_surface);
|
|
|
|
typedef IOReturn (*IOSurfaceLockFunc)(IOSurfacePtr io_surface, uint32_t options,
|
|
|
|
uint32_t *seed);
|
|
|
|
typedef IOReturn (*IOSurfaceUnlockFunc)(IOSurfacePtr io_surface,
|
|
|
|
uint32_t options, uint32_t *seed);
|
|
|
|
typedef void* (*IOSurfaceGetBaseAddressFunc)(IOSurfacePtr io_surface);
|
|
|
|
typedef void* (*IOSurfaceGetBaseAddressOfPlaneFunc)(IOSurfacePtr io_surface,
|
|
|
|
size_t planeIndex);
|
|
|
|
typedef size_t (*IOSurfaceSizeTFunc)(IOSurfacePtr io_surface);
|
2015-08-04 00:57:19 +03:00
|
|
|
typedef size_t (*IOSurfaceSizePlaneTFunc)(IOSurfacePtr io_surface, size_t plane);
|
2014-07-12 10:08:54 +04:00
|
|
|
typedef size_t (*IOSurfaceGetPropertyMaximumFunc) (CFStringRef property);
|
2013-11-08 07:53:54 +04: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);
|
|
|
|
|
2014-09-03 11:09:24 +04:00
|
|
|
typedef IOSurfacePtr (*CVPixelBufferGetIOSurfaceFunc)(
|
|
|
|
CVPixelBufferRef pixelBuffer);
|
2013-11-08 07:53:54 +04:00
|
|
|
|
2015-08-04 00:57:19 +03:00
|
|
|
typedef OSType (*IOSurfacePixelFormatFunc)(IOSurfacePtr io_surface);
|
|
|
|
|
2015-06-12 15:48:42 +03:00
|
|
|
#ifdef XP_MACOSX
|
2012-02-01 06:18:30 +04:00
|
|
|
#import <OpenGL/OpenGL.h>
|
2015-06-12 15:48:42 +03:00
|
|
|
#else
|
|
|
|
#import <OpenGLES/ES2/gl.h>
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 19:11:57 +04:00
|
|
|
#include "2D.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-10-13 05:24:05 +03:00
|
|
|
#include "mozilla/RefCounted.h"
|
2012-02-01 06:18:30 +04:00
|
|
|
|
2013-11-08 07:53:54 +04: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);
|
|
|
|
|
2015-09-23 14:34:40 +03:00
|
|
|
class MacIOSurface final : public mozilla::external::AtomicRefCounted<MacIOSurface> {
|
2012-02-01 06:18:30 +04:00
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(MacIOSurface)
|
2012-07-31 19:11:57 +04:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
2012-02-01 06:18:30 +04:00
|
|
|
|
2014-09-03 11:09:24 +04:00
|
|
|
// The usage count of the IOSurface is increased by 1 during the lifetime
|
|
|
|
// of the MacIOSurface instance.
|
|
|
|
// MacIOSurface holds a reference to the corresponding IOSurface.
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<MacIOSurface> CreateIOSurface(int aWidth, int aHeight,
|
2013-07-18 07:24:14 +04:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 19:11:57 +04:00
|
|
|
static void ReleaseIOSurface(MacIOSurface *aIOSurface);
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<MacIOSurface> LookupSurface(IOSurfaceID aSurfaceID,
|
2013-07-18 07:24:14 +04:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 19:11:57 +04:00
|
|
|
|
2014-09-03 11:09:24 +04:00
|
|
|
explicit MacIOSurface(const void *aIOSurfacePtr,
|
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2015-09-23 14:34:40 +03:00
|
|
|
~MacIOSurface();
|
2012-02-01 06:18:30 +04:00
|
|
|
IOSurfaceID GetIOSurfaceID();
|
|
|
|
void *GetBaseAddress();
|
2014-09-03 11:09:24 +04:00
|
|
|
void *GetBaseAddressOfPlane(size_t planeIndex);
|
|
|
|
size_t GetPlaneCount();
|
2015-08-04 00:57:19 +03:00
|
|
|
OSType GetPixelFormat();
|
2012-10-02 23:48:05 +04: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-25 02:31:12 +04:00
|
|
|
// device pixel. Use GetDevicePixel**() to get device pixels.
|
2015-08-04 00:57:19 +03:00
|
|
|
size_t GetWidth(size_t plane = 0);
|
|
|
|
size_t GetHeight(size_t plane = 0);
|
2012-10-02 23:48:05 +04:00
|
|
|
double GetContentsScaleFactor() { return mContentsScaleFactor; }
|
2015-08-04 00:57:19 +03:00
|
|
|
size_t GetDevicePixelWidth(size_t plane = 0);
|
|
|
|
size_t GetDevicePixelHeight(size_t plane = 0);
|
|
|
|
size_t GetBytesPerRow(size_t plane = 0);
|
2012-02-01 06:18:30 +04:00
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
2014-09-03 11:09:24 +04:00
|
|
|
void IncrementUseCount();
|
|
|
|
void DecrementUseCount();
|
2013-07-18 07:24:14 +04:00
|
|
|
bool HasAlpha() { return mHasAlpha; }
|
2015-08-04 00:57:19 +03:00
|
|
|
mozilla::gfx::SurfaceFormat GetFormat();
|
2012-02-14 18:22:23 +04: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 *.
|
2015-08-04 00:57:19 +03:00
|
|
|
CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, size_t plane = 0);
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface> GetAsSurface();
|
2012-07-31 19:11:57 +04:00
|
|
|
CGContextRef CreateIOSurfaceContext();
|
|
|
|
|
|
|
|
// FIXME This doesn't really belong here
|
|
|
|
static CGImageRef CreateImageFromIOSurfaceContext(CGContextRef aContext);
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext,
|
2013-07-18 07:24:14 +04:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2014-07-12 10:08:54 +04:00
|
|
|
static size_t GetMaxWidth();
|
|
|
|
static size_t GetMaxHeight();
|
2012-07-31 19:11:57 +04:00
|
|
|
|
2012-02-01 06:18:30 +04:00
|
|
|
private:
|
|
|
|
friend class nsCARenderer;
|
|
|
|
const void* mIOSurfacePtr;
|
2012-10-02 23:48:05 +04:00
|
|
|
double mContentsScaleFactor;
|
2013-07-18 07:24:14 +04:00
|
|
|
bool mHasAlpha;
|
2012-02-01 06:18:30 +04:00
|
|
|
};
|
|
|
|
|
2015-09-23 14:34:40 +03:00
|
|
|
class MacIOSurfaceLib {
|
2013-11-08 07:53:54 +04:00
|
|
|
public:
|
2015-09-23 14:34:40 +03:00
|
|
|
MacIOSurfaceLib() = delete;
|
2013-11-08 07:53:54 +04:00
|
|
|
static void *sIOSurfaceFramework;
|
|
|
|
static void *sOpenGLFramework;
|
|
|
|
static void *sCoreGraphicsFramework;
|
2014-09-03 11:09:24 +04:00
|
|
|
static void *sCoreVideoFramework;
|
2013-11-08 07:53:54 +04:00
|
|
|
static bool isLoaded;
|
|
|
|
static IOSurfaceCreateFunc sCreate;
|
|
|
|
static IOSurfaceGetIDFunc sGetID;
|
|
|
|
static IOSurfaceLookupFunc sLookup;
|
|
|
|
static IOSurfaceGetBaseAddressFunc sGetBaseAddress;
|
2014-09-03 11:09:24 +04:00
|
|
|
static IOSurfaceGetBaseAddressOfPlaneFunc sGetBaseAddressOfPlane;
|
|
|
|
static IOSurfaceSizeTFunc sPlaneCount;
|
2013-11-08 07:53:54 +04:00
|
|
|
static IOSurfaceLockFunc sLock;
|
|
|
|
static IOSurfaceUnlockFunc sUnlock;
|
2014-09-03 11:09:24 +04:00
|
|
|
static IOSurfaceVoidFunc sIncrementUseCount;
|
|
|
|
static IOSurfaceVoidFunc sDecrementUseCount;
|
2015-08-04 00:57:19 +03:00
|
|
|
static IOSurfaceSizePlaneTFunc sWidth;
|
|
|
|
static IOSurfaceSizePlaneTFunc sHeight;
|
|
|
|
static IOSurfaceSizePlaneTFunc sBytesPerRow;
|
2014-07-12 10:08:54 +04:00
|
|
|
static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum;
|
2013-11-08 07:53:54 +04:00
|
|
|
static CGLTexImageIOSurface2DFunc sTexImage;
|
|
|
|
static IOSurfaceContextCreateFunc sIOSurfaceContextCreate;
|
|
|
|
static IOSurfaceContextCreateImageFunc sIOSurfaceContextCreateImage;
|
|
|
|
static IOSurfaceContextGetSurfaceFunc sIOSurfaceContextGetSurface;
|
2014-09-03 11:09:24 +04:00
|
|
|
static CVPixelBufferGetIOSurfaceFunc sCVPixelBufferGetIOSurface;
|
2015-08-04 00:57:19 +03:00
|
|
|
static IOSurfacePixelFormatFunc sPixelFormat;
|
2013-11-08 07:53:54 +04:00
|
|
|
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-12 10:08:54 +04:00
|
|
|
static void* IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr);
|
2014-09-03 11:09:24 +04:00
|
|
|
static void* IOSurfaceGetBaseAddressOfPlane(IOSurfacePtr aIOSurfacePtr,
|
|
|
|
size_t aPlaneIndex);
|
|
|
|
static size_t IOSurfaceGetPlaneCount(IOSurfacePtr aIOSurfacePtr);
|
2015-08-04 00:57:19 +03:00
|
|
|
static size_t IOSurfaceGetWidth(IOSurfacePtr aIOSurfacePtr, size_t plane);
|
|
|
|
static size_t IOSurfaceGetHeight(IOSurfacePtr aIOSurfacePtr, size_t plane);
|
|
|
|
static size_t IOSurfaceGetBytesPerRow(IOSurfacePtr aIOSurfacePtr, size_t plane);
|
2014-07-12 10:08:54 +04:00
|
|
|
static size_t IOSurfaceGetPropertyMaximum(CFStringRef property);
|
2014-09-03 11:09:24 +04:00
|
|
|
static IOReturn IOSurfaceLock(IOSurfacePtr aIOSurfacePtr,
|
2013-11-08 07:53:54 +04:00
|
|
|
uint32_t options, uint32_t *seed);
|
2014-09-03 11:09:24 +04:00
|
|
|
static IOReturn IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr,
|
2013-11-08 07:53:54 +04:00
|
|
|
uint32_t options, uint32_t *seed);
|
2014-09-03 11:09:24 +04:00
|
|
|
static void IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr);
|
|
|
|
static void IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr);
|
2013-11-08 07:53:54 +04:00
|
|
|
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);
|
2014-09-03 11:09:24 +04:00
|
|
|
static IOSurfacePtr CVPixelBufferGetIOSurface(CVPixelBufferRef apixelBuffer);
|
2015-08-04 00:57:19 +03:00
|
|
|
static OSType IOSurfaceGetPixelFormat(IOSurfacePtr aIOSurfacePtr);
|
2013-11-08 07:53:54 +04:00
|
|
|
static unsigned int (*sCGContextGetTypePtr) (CGContextRef);
|
|
|
|
static void LoadLibrary();
|
|
|
|
static void CloseLibrary();
|
|
|
|
|
|
|
|
// Static deconstructor
|
|
|
|
static class LibraryUnloader {
|
|
|
|
public:
|
|
|
|
~LibraryUnloader() {
|
|
|
|
CloseLibrary();
|
|
|
|
}
|
|
|
|
} sLibraryUnloader;
|
|
|
|
};
|
|
|
|
|
2012-02-01 06:18:30 +04:00
|
|
|
#endif
|
|
|
|
#endif
|