diff options
author | Moonchild <moonchild@palemoon.org> | 2021-05-02 07:11:32 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-05-02 07:11:32 +0000 |
commit | 1e0157b7a8a0c2092444ef4a50aa9be7537e0f2b (patch) | |
tree | 7e21b635976b723af30dc066fe857fe40cae91f9 /gfx | |
parent | baf2c56a671e0c428110918c37dd1d31a626115f (diff) | |
download | uxp-1e0157b7a8a0c2092444ef4a50aa9be7537e0f2b.tar.gz |
Issue mcp-graveyard/UXP#1751 -- Remove files unused without XP_DARWIN
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/2d/MacIOSurface.cpp | 615 | ||||
-rw-r--r-- | gfx/2d/MacIOSurface.h | 216 | ||||
-rw-r--r-- | gfx/2d/NativeFontResourceMac.cpp | 67 | ||||
-rw-r--r-- | gfx/2d/NativeFontResourceMac.h | 42 | ||||
-rw-r--r-- | gfx/2d/PathCG.cpp | 435 | ||||
-rw-r--r-- | gfx/2d/PathCG.h | 114 | ||||
-rw-r--r-- | gfx/2d/QuartzSupport.h | 98 | ||||
-rw-r--r-- | gfx/2d/QuartzSupport.mm | 625 | ||||
-rw-r--r-- | gfx/2d/ScaledFontMac.cpp | 247 | ||||
-rw-r--r-- | gfx/2d/ScaledFontMac.h | 79 | ||||
-rw-r--r-- | gfx/2d/moz.build | 20 |
11 files changed, 1 insertions, 2557 deletions
diff --git a/gfx/2d/MacIOSurface.cpp b/gfx/2d/MacIOSurface.cpp deleted file mode 100644 index 759de8575b..0000000000 --- a/gfx/2d/MacIOSurface.cpp +++ /dev/null @@ -1,615 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -// vim:set ts=2 sts=2 sw=2 et cin: -/* 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/. */ - -#include "MacIOSurface.h" -#include <OpenGL/gl.h> -#include <QuartzCore/QuartzCore.h> -#include <dlfcn.h> -#include "mozilla/RefPtr.h" -#include "mozilla/Assertions.h" -#include "GLConsts.h" - -using namespace mozilla; -// IOSurface signatures -#define IOSURFACE_FRAMEWORK_PATH \ - "/System/Library/Frameworks/IOSurface.framework/IOSurface" -#define OPENGL_FRAMEWORK_PATH \ - "/System/Library/Frameworks/OpenGL.framework/OpenGL" -#define COREGRAPHICS_FRAMEWORK_PATH \ - "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/" \ - "CoreGraphics.framework/CoreGraphics" -#define COREVIDEO_FRAMEWORK_PATH \ - "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/" \ - "CoreVideo.framework/CoreVideo" - -#define GET_CONST(const_name) \ - ((CFStringRef*) dlsym(sIOSurfaceFramework, const_name)) -#define GET_IOSYM(dest,sym_name) \ - (typeof(dest)) dlsym(sIOSurfaceFramework, sym_name) -#define GET_CGLSYM(dest,sym_name) \ - (typeof(dest)) dlsym(sOpenGLFramework, sym_name) -#define GET_CGSYM(dest,sym_name) \ - (typeof(dest)) dlsym(sCoreGraphicsFramework, sym_name) -#define GET_CVSYM(dest, sym_name) \ - (typeof(dest)) dlsym(sCoreVideoFramework, sym_name) - -MacIOSurfaceLib::LibraryUnloader MacIOSurfaceLib::sLibraryUnloader; -bool MacIOSurfaceLib::isLoaded = false; -void* MacIOSurfaceLib::sIOSurfaceFramework; -void* MacIOSurfaceLib::sOpenGLFramework; -void* MacIOSurfaceLib::sCoreGraphicsFramework; -void* MacIOSurfaceLib::sCoreVideoFramework; -IOSurfaceCreateFunc MacIOSurfaceLib::sCreate; -IOSurfaceGetIDFunc MacIOSurfaceLib::sGetID; -IOSurfaceLookupFunc MacIOSurfaceLib::sLookup; -IOSurfaceGetBaseAddressFunc MacIOSurfaceLib::sGetBaseAddress; -IOSurfaceGetBaseAddressOfPlaneFunc MacIOSurfaceLib::sGetBaseAddressOfPlane; -IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sWidth; -IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sHeight; -IOSurfaceSizeTFunc MacIOSurfaceLib::sPlaneCount; -IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sBytesPerRow; -IOSurfaceGetPropertyMaximumFunc MacIOSurfaceLib::sGetPropertyMaximum; -IOSurfaceVoidFunc MacIOSurfaceLib::sIncrementUseCount; -IOSurfaceVoidFunc MacIOSurfaceLib::sDecrementUseCount; -IOSurfaceLockFunc MacIOSurfaceLib::sLock; -IOSurfaceUnlockFunc MacIOSurfaceLib::sUnlock; -CGLTexImageIOSurface2DFunc MacIOSurfaceLib::sTexImage; -IOSurfaceContextCreateFunc MacIOSurfaceLib::sIOSurfaceContextCreate; -IOSurfaceContextCreateImageFunc MacIOSurfaceLib::sIOSurfaceContextCreateImage; -IOSurfaceContextGetSurfaceFunc MacIOSurfaceLib::sIOSurfaceContextGetSurface; -CVPixelBufferGetIOSurfaceFunc MacIOSurfaceLib::sCVPixelBufferGetIOSurface; -unsigned int (*MacIOSurfaceLib::sCGContextGetTypePtr) (CGContextRef) = nullptr; -IOSurfacePixelFormatFunc MacIOSurfaceLib::sPixelFormat; - -CFStringRef MacIOSurfaceLib::kPropWidth; -CFStringRef MacIOSurfaceLib::kPropHeight; -CFStringRef MacIOSurfaceLib::kPropBytesPerElem; -CFStringRef MacIOSurfaceLib::kPropBytesPerRow; -CFStringRef MacIOSurfaceLib::kPropIsGlobal; - -bool MacIOSurfaceLib::isInit() { - // Guard against trying to reload the library - // if it is not available. - if (!isLoaded) - LoadLibrary(); - MOZ_ASSERT(sIOSurfaceFramework); - return sIOSurfaceFramework; -} - -IOSurfacePtr MacIOSurfaceLib::IOSurfaceCreate(CFDictionaryRef properties) { - return sCreate(properties); -} - -IOSurfacePtr MacIOSurfaceLib::IOSurfaceLookup(IOSurfaceID aIOSurfaceID) { - return sLookup(aIOSurfaceID); -} - -IOSurfaceID MacIOSurfaceLib::IOSurfaceGetID(IOSurfacePtr aIOSurfacePtr) { - return sGetID(aIOSurfacePtr); -} - -void* MacIOSurfaceLib::IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr) { - return sGetBaseAddress(aIOSurfacePtr); -} - -void* MacIOSurfaceLib::IOSurfaceGetBaseAddressOfPlane(IOSurfacePtr aIOSurfacePtr, - size_t planeIndex) { - return sGetBaseAddressOfPlane(aIOSurfacePtr, planeIndex); -} - -size_t MacIOSurfaceLib::IOSurfaceGetPlaneCount(IOSurfacePtr aIOSurfacePtr) { - return sPlaneCount(aIOSurfacePtr); -} - -size_t MacIOSurfaceLib::IOSurfaceGetWidth(IOSurfacePtr aIOSurfacePtr, size_t plane) { - return sWidth(aIOSurfacePtr, plane); -} - -size_t MacIOSurfaceLib::IOSurfaceGetHeight(IOSurfacePtr aIOSurfacePtr, size_t plane) { - return sHeight(aIOSurfacePtr, plane); -} - -size_t MacIOSurfaceLib::IOSurfaceGetBytesPerRow(IOSurfacePtr aIOSurfacePtr, size_t plane) { - return sBytesPerRow(aIOSurfacePtr, plane); -} - -size_t MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(CFStringRef property) { - return sGetPropertyMaximum(property); -} - -OSType MacIOSurfaceLib::IOSurfaceGetPixelFormat(IOSurfacePtr aIOSurfacePtr) { - return sPixelFormat(aIOSurfacePtr); -} - -IOReturn MacIOSurfaceLib::IOSurfaceLock(IOSurfacePtr aIOSurfacePtr, - uint32_t options, uint32_t* seed) { - return sLock(aIOSurfacePtr, options, seed); -} - -IOReturn MacIOSurfaceLib::IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr, - uint32_t options, uint32_t *seed) { - return sUnlock(aIOSurfacePtr, options, seed); -} - -void MacIOSurfaceLib::IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr) { - sIncrementUseCount(aIOSurfacePtr); -} - -void MacIOSurfaceLib::IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr) { - sDecrementUseCount(aIOSurfacePtr); -} - -CGLError MacIOSurfaceLib::CGLTexImageIOSurface2D(CGLContextObj ctxt, - GLenum target, GLenum internalFormat, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - IOSurfacePtr ioSurface, GLuint plane) { - return sTexImage(ctxt, target, internalFormat, width, height, - format, type, ioSurface, plane); -} - -IOSurfacePtr MacIOSurfaceLib::CVPixelBufferGetIOSurface(CVPixelBufferRef aPixelBuffer) { - return sCVPixelBufferGetIOSurface(aPixelBuffer); -} - -CGContextRef MacIOSurfaceLib::IOSurfaceContextCreate(IOSurfacePtr aIOSurfacePtr, - unsigned aWidth, unsigned aHeight, - unsigned aBitsPerComponent, unsigned aBytes, - CGColorSpaceRef aColorSpace, CGBitmapInfo bitmapInfo) { - if (!sIOSurfaceContextCreate) - return nullptr; - return sIOSurfaceContextCreate(aIOSurfacePtr, aWidth, aHeight, aBitsPerComponent, aBytes, aColorSpace, bitmapInfo); -} - -CGImageRef MacIOSurfaceLib::IOSurfaceContextCreateImage(CGContextRef aContext) { - if (!sIOSurfaceContextCreateImage) - return nullptr; - return sIOSurfaceContextCreateImage(aContext); -} - -IOSurfacePtr MacIOSurfaceLib::IOSurfaceContextGetSurface(CGContextRef aContext) { - if (!sIOSurfaceContextGetSurface) - return nullptr; - return sIOSurfaceContextGetSurface(aContext); -} - -CFStringRef MacIOSurfaceLib::GetIOConst(const char* symbole) { - CFStringRef *address = (CFStringRef*)dlsym(sIOSurfaceFramework, symbole); - if (!address) - return nullptr; - - return *address; -} - -void MacIOSurfaceLib::LoadLibrary() { - if (isLoaded) { - return; - } - isLoaded = true; - sIOSurfaceFramework = dlopen(IOSURFACE_FRAMEWORK_PATH, - RTLD_LAZY | RTLD_LOCAL); - sOpenGLFramework = dlopen(OPENGL_FRAMEWORK_PATH, - RTLD_LAZY | RTLD_LOCAL); - - sCoreGraphicsFramework = dlopen(COREGRAPHICS_FRAMEWORK_PATH, - RTLD_LAZY | RTLD_LOCAL); - - sCoreVideoFramework = dlopen(COREVIDEO_FRAMEWORK_PATH, - RTLD_LAZY | RTLD_LOCAL); - - if (!sIOSurfaceFramework || !sOpenGLFramework || !sCoreGraphicsFramework || - !sCoreVideoFramework) { - if (sIOSurfaceFramework) - dlclose(sIOSurfaceFramework); - if (sOpenGLFramework) - dlclose(sOpenGLFramework); - if (sCoreGraphicsFramework) - dlclose(sCoreGraphicsFramework); - if (sCoreVideoFramework) - dlclose(sCoreVideoFramework); - sIOSurfaceFramework = nullptr; - sOpenGLFramework = nullptr; - sCoreGraphicsFramework = nullptr; - sCoreVideoFramework = nullptr; - return; - } - - kPropWidth = GetIOConst("kIOSurfaceWidth"); - kPropHeight = GetIOConst("kIOSurfaceHeight"); - kPropBytesPerElem = GetIOConst("kIOSurfaceBytesPerElement"); - kPropBytesPerRow = GetIOConst("kIOSurfaceBytesPerRow"); - kPropIsGlobal = GetIOConst("kIOSurfaceIsGlobal"); - sCreate = GET_IOSYM(sCreate, "IOSurfaceCreate"); - sGetID = GET_IOSYM(sGetID, "IOSurfaceGetID"); - sWidth = GET_IOSYM(sWidth, "IOSurfaceGetWidthOfPlane"); - sHeight = GET_IOSYM(sHeight, "IOSurfaceGetHeightOfPlane"); - sBytesPerRow = GET_IOSYM(sBytesPerRow, "IOSurfaceGetBytesPerRowOfPlane"); - sGetPropertyMaximum = GET_IOSYM(sGetPropertyMaximum, "IOSurfaceGetPropertyMaximum"); - sLookup = GET_IOSYM(sLookup, "IOSurfaceLookup"); - sLock = GET_IOSYM(sLock, "IOSurfaceLock"); - sUnlock = GET_IOSYM(sUnlock, "IOSurfaceUnlock"); - sIncrementUseCount = - GET_IOSYM(sIncrementUseCount, "IOSurfaceIncrementUseCount"); - sDecrementUseCount = - GET_IOSYM(sDecrementUseCount, "IOSurfaceDecrementUseCount"); - sGetBaseAddress = GET_IOSYM(sGetBaseAddress, "IOSurfaceGetBaseAddress"); - sGetBaseAddressOfPlane = - GET_IOSYM(sGetBaseAddressOfPlane, "IOSurfaceGetBaseAddressOfPlane"); - sPlaneCount = GET_IOSYM(sPlaneCount, "IOSurfaceGetPlaneCount"); - sPixelFormat = GET_IOSYM(sPixelFormat, "IOSurfaceGetPixelFormat"); - - sTexImage = GET_CGLSYM(sTexImage, "CGLTexImageIOSurface2D"); - sCGContextGetTypePtr = (unsigned int (*)(CGContext*))dlsym(RTLD_DEFAULT, "CGContextGetType"); - - sCVPixelBufferGetIOSurface = - GET_CVSYM(sCVPixelBufferGetIOSurface, "CVPixelBufferGetIOSurface"); - - // Optional symbols - sIOSurfaceContextCreate = GET_CGSYM(sIOSurfaceContextCreate, "CGIOSurfaceContextCreate"); - sIOSurfaceContextCreateImage = GET_CGSYM(sIOSurfaceContextCreateImage, "CGIOSurfaceContextCreateImage"); - sIOSurfaceContextGetSurface = GET_CGSYM(sIOSurfaceContextGetSurface, "CGIOSurfaceContextGetSurface"); - - if (!sCreate || !sGetID || !sLookup || !sTexImage || !sGetBaseAddress || - !sGetBaseAddressOfPlane || !sPlaneCount || - !kPropWidth || !kPropHeight || !kPropBytesPerElem || !kPropIsGlobal || - !sLock || !sUnlock || !sIncrementUseCount || !sDecrementUseCount || - !sWidth || !sHeight || !kPropBytesPerRow || - !sBytesPerRow || !sGetPropertyMaximum || !sCVPixelBufferGetIOSurface) { - CloseLibrary(); - } -} - -void MacIOSurfaceLib::CloseLibrary() { - if (sIOSurfaceFramework) { - dlclose(sIOSurfaceFramework); - } - if (sOpenGLFramework) { - dlclose(sOpenGLFramework); - } - if (sCoreVideoFramework) { - dlclose(sCoreVideoFramework); - } - sIOSurfaceFramework = nullptr; - sOpenGLFramework = nullptr; - sCoreVideoFramework = nullptr; -} - -MacIOSurface::MacIOSurface(const void* aIOSurfacePtr, - double aContentsScaleFactor, bool aHasAlpha) - : mIOSurfacePtr(aIOSurfacePtr) - , mContentsScaleFactor(aContentsScaleFactor) - , mHasAlpha(aHasAlpha) -{ - CFRetain(mIOSurfacePtr); - IncrementUseCount(); -} - -MacIOSurface::~MacIOSurface() { - DecrementUseCount(); - CFRelease(mIOSurfacePtr); -} - -already_AddRefed<MacIOSurface> MacIOSurface::CreateIOSurface(int aWidth, int aHeight, - double aContentsScaleFactor, - bool aHasAlpha) { - if (!MacIOSurfaceLib::isInit() || aContentsScaleFactor <= 0) - return nullptr; - - CFMutableDictionaryRef props = ::CFDictionaryCreateMutable( - kCFAllocatorDefault, 4, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - 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; - aHeight *= intScaleFactor; - CFNumberRef cfWidth = ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &aWidth); - CFNumberRef cfHeight = ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &aHeight); - CFNumberRef cfBytesPerElem = ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &bytesPerElem); - ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropWidth, - cfWidth); - ::CFRelease(cfWidth); - ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropHeight, - cfHeight); - ::CFRelease(cfHeight); - ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropBytesPerElem, - cfBytesPerElem); - ::CFRelease(cfBytesPerElem); - ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropIsGlobal, - kCFBooleanTrue); - - IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceCreate(props); - ::CFRelease(props); - - if (!surfaceRef) - return nullptr; - - RefPtr<MacIOSurface> ioSurface = new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha); - if (!ioSurface) { - ::CFRelease(surfaceRef); - return nullptr; - } - - // Release the IOSurface because MacIOSurface retained it - CFRelease(surfaceRef); - - return ioSurface.forget(); -} - -already_AddRefed<MacIOSurface> MacIOSurface::LookupSurface(IOSurfaceID aIOSurfaceID, - double aContentsScaleFactor, - bool aHasAlpha) { - if (!MacIOSurfaceLib::isInit() || aContentsScaleFactor <= 0) - return nullptr; - - IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceLookup(aIOSurfaceID); - if (!surfaceRef) - return nullptr; - - RefPtr<MacIOSurface> ioSurface = new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha); - if (!ioSurface) { - ::CFRelease(surfaceRef); - return nullptr; - } - - // Release the IOSurface because MacIOSurface retained it - CFRelease(surfaceRef); - - return ioSurface.forget(); -} - -IOSurfaceID MacIOSurface::GetIOSurfaceID() { - return MacIOSurfaceLib::IOSurfaceGetID(mIOSurfacePtr); -} - -void* MacIOSurface::GetBaseAddress() { - return MacIOSurfaceLib::IOSurfaceGetBaseAddress(mIOSurfacePtr); -} - -void* MacIOSurface::GetBaseAddressOfPlane(size_t aPlaneIndex) -{ - return MacIOSurfaceLib::IOSurfaceGetBaseAddressOfPlane(mIOSurfacePtr, - aPlaneIndex); -} - -size_t MacIOSurface::GetWidth(size_t plane) { - size_t intScaleFactor = ceil(mContentsScaleFactor); - return GetDevicePixelWidth(plane) / intScaleFactor; -} - -size_t MacIOSurface::GetHeight(size_t plane) { - size_t intScaleFactor = ceil(mContentsScaleFactor); - return GetDevicePixelHeight(plane) / intScaleFactor; -} - -size_t MacIOSurface::GetPlaneCount() { - return MacIOSurfaceLib::IOSurfaceGetPlaneCount(mIOSurfacePtr); -} - -/*static*/ size_t MacIOSurface::GetMaxWidth() { - if (!MacIOSurfaceLib::isInit()) - return -1; - return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(MacIOSurfaceLib::kPropWidth); -} - -/*static*/ size_t MacIOSurface::GetMaxHeight() { - if (!MacIOSurfaceLib::isInit()) - return -1; - return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(MacIOSurfaceLib::kPropHeight); -} - -size_t MacIOSurface::GetDevicePixelWidth(size_t plane) { - return MacIOSurfaceLib::IOSurfaceGetWidth(mIOSurfacePtr, plane); -} - -size_t MacIOSurface::GetDevicePixelHeight(size_t plane) { - return MacIOSurfaceLib::IOSurfaceGetHeight(mIOSurfacePtr, plane); -} - -size_t MacIOSurface::GetBytesPerRow(size_t plane) { - return MacIOSurfaceLib::IOSurfaceGetBytesPerRow(mIOSurfacePtr, plane); -} - -OSType MacIOSurface::GetPixelFormat() { - return MacIOSurfaceLib::IOSurfaceGetPixelFormat(mIOSurfacePtr); -} - -void MacIOSurface::IncrementUseCount() { - MacIOSurfaceLib::IOSurfaceIncrementUseCount(mIOSurfacePtr); -} - -void MacIOSurface::DecrementUseCount() { - MacIOSurfaceLib::IOSurfaceDecrementUseCount(mIOSurfacePtr); -} - -#define READ_ONLY 0x1 -void MacIOSurface::Lock(bool aReadOnly) { - MacIOSurfaceLib::IOSurfaceLock(mIOSurfacePtr, aReadOnly ? READ_ONLY : 0, nullptr); -} - -void MacIOSurface::Unlock(bool aReadOnly) { - MacIOSurfaceLib::IOSurfaceUnlock(mIOSurfacePtr, aReadOnly ? READ_ONLY : 0, nullptr); -} - -using mozilla::gfx::SourceSurface; -using mozilla::gfx::IntSize; -using mozilla::gfx::SurfaceFormat; - -void -MacIOSurfaceBufferDeallocator(void* aClosure) -{ - MOZ_ASSERT(aClosure); - - delete [] static_cast<unsigned char*>(aClosure); -} - -already_AddRefed<SourceSurface> -MacIOSurface::GetAsSurface() { - Lock(); - size_t bytesPerRow = GetBytesPerRow(); - size_t ioWidth = GetDevicePixelWidth(); - size_t ioHeight = GetDevicePixelHeight(); - - unsigned char* ioData = (unsigned char*)GetBaseAddress(); - unsigned char* dataCpy = - new unsigned char[bytesPerRow * ioHeight / sizeof(unsigned char)]; - for (size_t i = 0; i < ioHeight; i++) { - memcpy(dataCpy + i * bytesPerRow, - ioData + i * bytesPerRow, ioWidth * 4); - } - - Unlock(); - - SurfaceFormat format = HasAlpha() ? mozilla::gfx::SurfaceFormat::B8G8R8A8 : - mozilla::gfx::SurfaceFormat::B8G8R8X8; - - RefPtr<mozilla::gfx::DataSourceSurface> surf = - mozilla::gfx::Factory::CreateWrappingDataSourceSurface(dataCpy, - bytesPerRow, - IntSize(ioWidth, ioHeight), - format, - &MacIOSurfaceBufferDeallocator, - static_cast<void*>(dataCpy)); - - return surf.forget(); -} - -SurfaceFormat -MacIOSurface::GetFormat() -{ - OSType pixelFormat = GetPixelFormat(); - if (pixelFormat == '420v') { - return SurfaceFormat::NV12; - } else if (pixelFormat == '2vuy') { - return SurfaceFormat::YUV422; - } else { - return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; - } -} - -SurfaceFormat -MacIOSurface::GetReadFormat() -{ - OSType pixelFormat = GetPixelFormat(); - if (pixelFormat == '420v') { - return SurfaceFormat::NV12; - } else if (pixelFormat == '2vuy') { - return SurfaceFormat::R8G8B8X8; - } else { - return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; - } -} - -CGLError -MacIOSurface::CGLTexImageIOSurface2D(CGLContextObj ctx, size_t plane) -{ - MOZ_ASSERT(plane >= 0); - OSType pixelFormat = GetPixelFormat(); - - GLenum internalFormat; - GLenum format; - GLenum type; - if (pixelFormat == '420v') { - MOZ_ASSERT(GetPlaneCount() == 2); - MOZ_ASSERT(plane < 2); - - if (plane == 0) { - internalFormat = format = GL_LUMINANCE; - } else { - internalFormat = format = GL_LUMINANCE_ALPHA; - } - type = GL_UNSIGNED_BYTE; - } else if (pixelFormat == '2vuy') { - MOZ_ASSERT(plane == 0); - - internalFormat = GL_RGB; - format = LOCAL_GL_YCBCR_422_APPLE; - type = GL_UNSIGNED_SHORT_8_8_APPLE; - } else { - MOZ_ASSERT(plane == 0); - - internalFormat = HasAlpha() ? GL_RGBA : GL_RGB; - format = GL_BGRA; - type = GL_UNSIGNED_INT_8_8_8_8_REV; - } - CGLError temp = MacIOSurfaceLib::CGLTexImageIOSurface2D(ctx, - GL_TEXTURE_RECTANGLE_ARB, - internalFormat, - GetDevicePixelWidth(plane), - GetDevicePixelHeight(plane), - format, - type, - mIOSurfacePtr, plane); - return temp; -} - -static -CGColorSpaceRef CreateSystemColorSpace() { - CGColorSpaceRef cspace = ::CGDisplayCopyColorSpace(::CGMainDisplayID()); - if (!cspace) { - cspace = ::CGColorSpaceCreateDeviceRGB(); - } - return cspace; -} - -CGContextRef MacIOSurface::CreateIOSurfaceContext() { - CGColorSpaceRef cspace = CreateSystemColorSpace(); - CGContextRef ref = MacIOSurfaceLib::IOSurfaceContextCreate(mIOSurfacePtr, - GetDevicePixelWidth(), - GetDevicePixelHeight(), - 8, 32, cspace, 0x2002); - ::CGColorSpaceRelease(cspace); - return ref; -} - -CGImageRef MacIOSurface::CreateImageFromIOSurfaceContext(CGContextRef aContext) { - if (!MacIOSurfaceLib::isInit()) - return nullptr; - - return MacIOSurfaceLib::IOSurfaceContextCreateImage(aContext); -} - -already_AddRefed<MacIOSurface> MacIOSurface::IOSurfaceContextGetSurface(CGContextRef aContext, - double aContentsScaleFactor, - bool aHasAlpha) { - if (!MacIOSurfaceLib::isInit() || aContentsScaleFactor <= 0) - return nullptr; - - IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceContextGetSurface(aContext); - if (!surfaceRef) - return nullptr; - - RefPtr<MacIOSurface> ioSurface = new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha); - if (!ioSurface) { - ::CFRelease(surfaceRef); - return nullptr; - } - return ioSurface.forget(); -} - - -CGContextType GetContextType(CGContextRef ref) -{ - if (!MacIOSurfaceLib::isInit() || !MacIOSurfaceLib::sCGContextGetTypePtr) - return CG_CONTEXT_TYPE_UNKNOWN; - - unsigned int type = MacIOSurfaceLib::sCGContextGetTypePtr(ref); - if (type == CG_CONTEXT_TYPE_BITMAP) { - return CG_CONTEXT_TYPE_BITMAP; - } else if (type == CG_CONTEXT_TYPE_IOSURFACE) { - return CG_CONTEXT_TYPE_IOSURFACE; - } else { - return CG_CONTEXT_TYPE_UNKNOWN; - } -} - - diff --git a/gfx/2d/MacIOSurface.h b/gfx/2d/MacIOSurface.h deleted file mode 100644 index e9c76e5dd8..0000000000 --- a/gfx/2d/MacIOSurface.h +++ /dev/null @@ -1,216 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#ifndef MacIOSurface_h__ -#define MacIOSurface_h__ -#ifdef XP_DARWIN -#include <QuartzCore/QuartzCore.h> -#include <CoreVideo/CoreVideo.h> -#include <dlfcn.h> - -struct _CGLContextObject; - -typedef _CGLContextObject* CGLContextObj; -typedef struct CGContext* CGContextRef; -typedef struct CGImage* CGImageRef; -typedef uint32_t IOSurfaceID; - -typedef CFTypeRef IOSurfacePtr; -typedef IOSurfacePtr (*IOSurfaceCreateFunc) (CFDictionaryRef properties); -typedef IOSurfacePtr (*IOSurfaceLookupFunc) (uint32_t io_surface_id); -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); -typedef size_t (*IOSurfaceSizePlaneTFunc)(IOSurfacePtr io_surface, size_t plane); -typedef size_t (*IOSurfaceGetPropertyMaximumFunc) (CFStringRef property); -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); - -typedef IOSurfacePtr (*CVPixelBufferGetIOSurfaceFunc)( - CVPixelBufferRef pixelBuffer); - -typedef OSType (*IOSurfacePixelFormatFunc)(IOSurfacePtr io_surface); - -#ifdef XP_MACOSX -#import <OpenGL/OpenGL.h> -#else -#import <OpenGLES/ES2/gl.h> -#endif - -#include "2D.h" -#include "mozilla/RefPtr.h" -#include "mozilla/RefCounted.h" - -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); - -class MacIOSurface final : public mozilla::external::AtomicRefCounted<MacIOSurface> { -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(MacIOSurface) - typedef mozilla::gfx::SourceSurface SourceSurface; - - // 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. - - static already_AddRefed<MacIOSurface> CreateIOSurface(int aWidth, int aHeight, - double aContentsScaleFactor = 1.0, - bool aHasAlpha = true); - static void ReleaseIOSurface(MacIOSurface *aIOSurface); - static already_AddRefed<MacIOSurface> LookupSurface(IOSurfaceID aSurfaceID, - double aContentsScaleFactor = 1.0, - bool aHasAlpha = true); - - explicit MacIOSurface(const void *aIOSurfacePtr, - double aContentsScaleFactor = 1.0, - bool aHasAlpha = true); - ~MacIOSurface(); - IOSurfaceID GetIOSurfaceID(); - void *GetBaseAddress(); - void *GetBaseAddressOfPlane(size_t planeIndex); - size_t GetPlaneCount(); - OSType GetPixelFormat(); - // 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 - // device pixel. Use GetDevicePixel**() to get device pixels. - size_t GetWidth(size_t plane = 0); - size_t GetHeight(size_t plane = 0); - double GetContentsScaleFactor() { return mContentsScaleFactor; } - size_t GetDevicePixelWidth(size_t plane = 0); - size_t GetDevicePixelHeight(size_t plane = 0); - size_t GetBytesPerRow(size_t plane = 0); - void Lock(bool aReadOnly = true); - void Unlock(bool aReadOnly = true); - void IncrementUseCount(); - void DecrementUseCount(); - bool HasAlpha() { return mHasAlpha; } - mozilla::gfx::SurfaceFormat GetFormat(); - mozilla::gfx::SurfaceFormat GetReadFormat(); - - // 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 *. - CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, size_t plane = 0); - already_AddRefed<SourceSurface> GetAsSurface(); - CGContextRef CreateIOSurfaceContext(); - - // FIXME This doesn't really belong here - static CGImageRef CreateImageFromIOSurfaceContext(CGContextRef aContext); - static already_AddRefed<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext, - double aContentsScaleFactor = 1.0, - bool aHasAlpha = true); - static size_t GetMaxWidth(); - static size_t GetMaxHeight(); - -private: - friend class nsCARenderer; - const void* mIOSurfacePtr; - double mContentsScaleFactor; - bool mHasAlpha; -}; - -class MacIOSurfaceLib { -public: - MacIOSurfaceLib() = delete; - static void *sIOSurfaceFramework; - static void *sOpenGLFramework; - static void *sCoreGraphicsFramework; - static void *sCoreVideoFramework; - static bool isLoaded; - static IOSurfaceCreateFunc sCreate; - static IOSurfaceGetIDFunc sGetID; - static IOSurfaceLookupFunc sLookup; - static IOSurfaceGetBaseAddressFunc sGetBaseAddress; - static IOSurfaceGetBaseAddressOfPlaneFunc sGetBaseAddressOfPlane; - static IOSurfaceSizeTFunc sPlaneCount; - static IOSurfaceLockFunc sLock; - static IOSurfaceUnlockFunc sUnlock; - static IOSurfaceVoidFunc sIncrementUseCount; - static IOSurfaceVoidFunc sDecrementUseCount; - static IOSurfaceSizePlaneTFunc sWidth; - static IOSurfaceSizePlaneTFunc sHeight; - static IOSurfaceSizePlaneTFunc sBytesPerRow; - static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum; - static CGLTexImageIOSurface2DFunc sTexImage; - static IOSurfaceContextCreateFunc sIOSurfaceContextCreate; - static IOSurfaceContextCreateImageFunc sIOSurfaceContextCreateImage; - static IOSurfaceContextGetSurfaceFunc sIOSurfaceContextGetSurface; - static CVPixelBufferGetIOSurfaceFunc sCVPixelBufferGetIOSurface; - static IOSurfacePixelFormatFunc sPixelFormat; - 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); - static void* IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr); - static void* IOSurfaceGetBaseAddressOfPlane(IOSurfacePtr aIOSurfacePtr, - size_t aPlaneIndex); - static size_t IOSurfaceGetPlaneCount(IOSurfacePtr aIOSurfacePtr); - 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); - static size_t IOSurfaceGetPropertyMaximum(CFStringRef property); - static IOReturn IOSurfaceLock(IOSurfacePtr aIOSurfacePtr, - uint32_t options, uint32_t *seed); - static IOReturn IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr, - uint32_t options, uint32_t *seed); - static void IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr); - static void IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr); - 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 IOSurfacePtr CVPixelBufferGetIOSurface(CVPixelBufferRef apixelBuffer); - static OSType IOSurfaceGetPixelFormat(IOSurfacePtr aIOSurfacePtr); - static unsigned int (*sCGContextGetTypePtr) (CGContextRef); - static void LoadLibrary(); - static void CloseLibrary(); - - // Static deconstructor - static class LibraryUnloader { - public: - ~LibraryUnloader() { - CloseLibrary(); - } - } sLibraryUnloader; -}; - -#endif -#endif diff --git a/gfx/2d/NativeFontResourceMac.cpp b/gfx/2d/NativeFontResourceMac.cpp deleted file mode 100644 index 5747d737ef..0000000000 --- a/gfx/2d/NativeFontResourceMac.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#include "NativeFontResourceMac.h" -#include "Types.h" - -#include "mozilla/RefPtr.h" -#include "mozilla/gfx/Logging.h" - -#ifdef MOZ_WIDGET_UIKIT -#include <CoreFoundation/CoreFoundation.h> -#endif - -namespace mozilla { -namespace gfx { - -/* static */ -already_AddRefed<NativeFontResourceMac> -NativeFontResourceMac::Create(uint8_t *aFontData, uint32_t aDataLength) -{ - // copy font data - CFDataRef data = CFDataCreate(kCFAllocatorDefault, aFontData, aDataLength); - if (!data) { - return nullptr; - } - - // create a provider - CGDataProviderRef provider = CGDataProviderCreateWithCFData(data); - - // release our reference to the CFData, provider keeps it alive - CFRelease(data); - - // create the font object - CGFontRef fontRef = CGFontCreateWithDataProvider(provider); - - // release our reference, font will keep it alive as long as needed - CGDataProviderRelease(provider); - - if (!fontRef) { - return nullptr; - } - - // passes ownership of fontRef to the NativeFontResourceMac instance - RefPtr<NativeFontResourceMac> fontResource = - new NativeFontResourceMac(fontRef); - - return fontResource.forget(); -} - -already_AddRefed<ScaledFont> -NativeFontResourceMac::CreateScaledFont(uint32_t aIndex, Float aGlyphSize, - const uint8_t* aInstanceData, uint32_t aInstanceDataLength) -{ - RefPtr<ScaledFontBase> scaledFont = new ScaledFontMac(mFontRef, aGlyphSize); - - if (!scaledFont->PopulateCairoScaledFont()) { - gfxWarning() << "Unable to create cairo scaled Mac font."; - return nullptr; - } - - return scaledFont.forget(); -} - -} // gfx -} // mozilla diff --git a/gfx/2d/NativeFontResourceMac.h b/gfx/2d/NativeFontResourceMac.h deleted file mode 100644 index bba935bc54..0000000000 --- a/gfx/2d/NativeFontResourceMac.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#ifndef mozilla_gfx_NativeFontResourceMac_h -#define mozilla_gfx_NativeFontResourceMac_h - -#include "2D.h" -#include "mozilla/AlreadyAddRefed.h" -#include "ScaledFontMac.h" - -namespace mozilla { -namespace gfx { - -class NativeFontResourceMac final : public NativeFontResource -{ -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceMac) - - static already_AddRefed<NativeFontResourceMac> - Create(uint8_t *aFontData, uint32_t aDataLength); - - already_AddRefed<ScaledFont> - CreateScaledFont(uint32_t aIndex, Float aGlyphSize, - const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final; - - ~NativeFontResourceMac() - { - CFRelease(mFontRef); - } - -private: - explicit NativeFontResourceMac(CGFontRef aFontRef) : mFontRef(aFontRef) {} - - CGFontRef mFontRef; -}; - -} // gfx -} // mozilla - -#endif // mozilla_gfx_NativeFontResourceMac_h diff --git a/gfx/2d/PathCG.cpp b/gfx/2d/PathCG.cpp deleted file mode 100644 index 4d70b2607f..0000000000 --- a/gfx/2d/PathCG.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * 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/. */ - -#include "PathCG.h" -#include <math.h> -#include "Logging.h" -#include "PathHelpers.h" - -namespace mozilla { -namespace gfx { - -static inline Rect -CGRectToRect(CGRect rect) -{ - return Rect(rect.origin.x, - rect.origin.y, - rect.size.width, - rect.size.height); -} - -static inline Point -CGPointToPoint(CGPoint point) -{ - return Point(point.x, point.y); -} - -static inline void -SetStrokeOptions(CGContextRef cg, const StrokeOptions &aStrokeOptions) -{ - switch (aStrokeOptions.mLineCap) - { - case CapStyle::BUTT: - CGContextSetLineCap(cg, kCGLineCapButt); - break; - case CapStyle::ROUND: - CGContextSetLineCap(cg, kCGLineCapRound); - break; - case CapStyle::SQUARE: - CGContextSetLineCap(cg, kCGLineCapSquare); - break; - } - - switch (aStrokeOptions.mLineJoin) - { - case JoinStyle::BEVEL: - CGContextSetLineJoin(cg, kCGLineJoinBevel); - break; - case JoinStyle::ROUND: - CGContextSetLineJoin(cg, kCGLineJoinRound); - break; - case JoinStyle::MITER: - case JoinStyle::MITER_OR_BEVEL: - CGContextSetLineJoin(cg, kCGLineJoinMiter); - break; - } - - CGContextSetLineWidth(cg, aStrokeOptions.mLineWidth); - CGContextSetMiterLimit(cg, aStrokeOptions.mMiterLimit); - - // XXX: rename mDashLength to dashLength - if (aStrokeOptions.mDashLength > 0) { - // we use a regular array instead of a std::vector here because we don't want to leak the <vector> include - CGFloat *dashes = new CGFloat[aStrokeOptions.mDashLength]; - for (size_t i=0; i<aStrokeOptions.mDashLength; i++) { - dashes[i] = aStrokeOptions.mDashPattern[i]; - } - CGContextSetLineDash(cg, aStrokeOptions.mDashOffset, dashes, aStrokeOptions.mDashLength); - delete[] dashes; - } -} - -static inline CGAffineTransform -GfxMatrixToCGAffineTransform(const Matrix &m) -{ - CGAffineTransform t; - t.a = m._11; - t.b = m._12; - t.c = m._21; - t.d = m._22; - t.tx = m._31; - t.ty = m._32; - return t; -} - -PathBuilderCG::~PathBuilderCG() -{ - CGPathRelease(mCGPath); -} - -void -PathBuilderCG::MoveTo(const Point &aPoint) -{ - if (!aPoint.IsFinite()) { - return; - } - CGPathMoveToPoint(mCGPath, nullptr, aPoint.x, aPoint.y); -} - -void -PathBuilderCG::LineTo(const Point &aPoint) -{ - if (!aPoint.IsFinite()) { - return; - } - - if (CGPathIsEmpty(mCGPath)) - MoveTo(aPoint); - else - CGPathAddLineToPoint(mCGPath, nullptr, aPoint.x, aPoint.y); -} - -void -PathBuilderCG::BezierTo(const Point &aCP1, - const Point &aCP2, - const Point &aCP3) -{ - if (!aCP1.IsFinite() || !aCP2.IsFinite() || !aCP3.IsFinite()) { - return; - } - - if (CGPathIsEmpty(mCGPath)) - MoveTo(aCP1); - CGPathAddCurveToPoint(mCGPath, nullptr, - aCP1.x, aCP1.y, - aCP2.x, aCP2.y, - aCP3.x, aCP3.y); - -} - -void -PathBuilderCG::QuadraticBezierTo(const Point &aCP1, - const Point &aCP2) -{ - if (!aCP1.IsFinite() || !aCP2.IsFinite()) { - return; - } - - if (CGPathIsEmpty(mCGPath)) - MoveTo(aCP1); - CGPathAddQuadCurveToPoint(mCGPath, nullptr, - aCP1.x, aCP1.y, - aCP2.x, aCP2.y); -} - -void -PathBuilderCG::Close() -{ - if (!CGPathIsEmpty(mCGPath)) - CGPathCloseSubpath(mCGPath); -} - -void -PathBuilderCG::Arc(const Point &aOrigin, Float aRadius, Float aStartAngle, - Float aEndAngle, bool aAntiClockwise) -{ - if (!aOrigin.IsFinite() || !IsFinite(aRadius) || - !IsFinite(aStartAngle) || !IsFinite(aEndAngle)) { - return; - } - - // Disabled for now due to a CG bug when using CGPathAddArc with stroke - // dashing and rotation transforms that are multiples of 90 degrees. See: - // https://bugzilla.mozilla.org/show_bug.cgi?id=949661#c8 -#if 0 - // Core Graphic's initial coordinate system is y-axis up, whereas Moz2D's is - // y-axis down. Core Graphics therefore considers "clockwise" to mean "sweep - // in the direction of decreasing angle" whereas Moz2D considers it to mean - // "sweep in the direction of increasing angle". In other words if this - // Moz2D method is instructed to sweep anti-clockwise we need to tell - // CGPathAddArc to sweep clockwise, and vice versa. Hence why we pass the - // value of aAntiClockwise directly to CGPathAddArc's "clockwise" bool - // parameter. - CGPathAddArc(mCGPath, nullptr, - aOrigin.x, aOrigin.y, - aRadius, - aStartAngle, - aEndAngle, - aAntiClockwise); -#endif - ArcToBezier(this, aOrigin, Size(aRadius, aRadius), aStartAngle, aEndAngle, - aAntiClockwise); -} - -Point -PathBuilderCG::CurrentPoint() const -{ - Point ret; - if (!CGPathIsEmpty(mCGPath)) { - CGPoint pt = CGPathGetCurrentPoint(mCGPath); - ret.MoveTo(pt.x, pt.y); - } - return ret; -} - -void -PathBuilderCG::EnsureActive(const Point &aPoint) -{ -} - -already_AddRefed<Path> -PathBuilderCG::Finish() -{ - return MakeAndAddRef<PathCG>(mCGPath, mFillRule); -} - -already_AddRefed<PathBuilder> -PathCG::CopyToBuilder(FillRule aFillRule) const -{ - CGMutablePathRef path = CGPathCreateMutableCopy(mPath); - return MakeAndAddRef<PathBuilderCG>(path, aFillRule); -} - - - -already_AddRefed<PathBuilder> -PathCG::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const -{ - // 10.7 adds CGPathCreateMutableCopyByTransformingPath it might be faster than doing - // this by hand - - struct TransformApplier { - CGMutablePathRef path; - CGAffineTransform transform; - static void - TranformCGPathApplierFunc(void *vinfo, const CGPathElement *element) - { - TransformApplier *info = reinterpret_cast<TransformApplier*>(vinfo); - switch (element->type) { - case kCGPathElementMoveToPoint: - { - CGPoint pt = element->points[0]; - CGPathMoveToPoint(info->path, &info->transform, pt.x, pt.y); - break; - } - case kCGPathElementAddLineToPoint: - { - CGPoint pt = element->points[0]; - CGPathAddLineToPoint(info->path, &info->transform, pt.x, pt.y); - break; - } - case kCGPathElementAddQuadCurveToPoint: - { - CGPoint cpt = element->points[0]; - CGPoint pt = element->points[1]; - CGPathAddQuadCurveToPoint(info->path, &info->transform, cpt.x, cpt.y, pt.x, pt.y); - break; - } - case kCGPathElementAddCurveToPoint: - { - CGPoint cpt1 = element->points[0]; - CGPoint cpt2 = element->points[1]; - CGPoint pt = element->points[2]; - CGPathAddCurveToPoint(info->path, &info->transform, cpt1.x, cpt1.y, cpt2.x, cpt2.y, pt.x, pt.y); - break; - } - case kCGPathElementCloseSubpath: - { - CGPathCloseSubpath(info->path); - break; - } - } - } - }; - - TransformApplier ta; - ta.path = CGPathCreateMutable(); - ta.transform = GfxMatrixToCGAffineTransform(aTransform); - - CGPathApply(mPath, &ta, TransformApplier::TranformCGPathApplierFunc); - return MakeAndAddRef<PathBuilderCG>(ta.path, aFillRule); -} - -static void -StreamPathToSinkApplierFunc(void *vinfo, const CGPathElement *element) -{ - PathSink *sink = reinterpret_cast<PathSink*>(vinfo); - switch (element->type) { - case kCGPathElementMoveToPoint: - { - CGPoint pt = element->points[0]; - sink->MoveTo(CGPointToPoint(pt)); - break; - } - case kCGPathElementAddLineToPoint: - { - CGPoint pt = element->points[0]; - sink->LineTo(CGPointToPoint(pt)); - break; - } - case kCGPathElementAddQuadCurveToPoint: - { - CGPoint cpt = element->points[0]; - CGPoint pt = element->points[1]; - sink->QuadraticBezierTo(CGPointToPoint(cpt), - CGPointToPoint(pt)); - break; - } - case kCGPathElementAddCurveToPoint: - { - CGPoint cpt1 = element->points[0]; - CGPoint cpt2 = element->points[1]; - CGPoint pt = element->points[2]; - sink->BezierTo(CGPointToPoint(cpt1), - CGPointToPoint(cpt2), - CGPointToPoint(pt)); - break; - } - case kCGPathElementCloseSubpath: - { - sink->Close(); - break; - } - } -} - -void -PathCG::StreamToSink(PathSink *aSink) const -{ - CGPathApply(mPath, aSink, StreamPathToSinkApplierFunc); -} - -bool -PathCG::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const -{ - Matrix inverse = aTransform; - inverse.Invert(); - Point transformedPoint = inverse.TransformPoint(aPoint); - // We could probably drop the input transform and just transform the point at the caller? - CGPoint point = {transformedPoint.x, transformedPoint.y}; - - // The transform parameter of CGPathContainsPoint doesn't seem to work properly on OS X 10.5 - // so we transform aPoint ourselves. - return CGPathContainsPoint(mPath, nullptr, point, mFillRule == FillRule::FILL_EVEN_ODD); -} - -static size_t -PutBytesNull(void *info, const void *buffer, size_t count) -{ - return count; -} - -/* The idea of a scratch context comes from WebKit */ -static CGContextRef -CreateScratchContext() -{ - CGDataConsumerCallbacks callbacks = {PutBytesNull, nullptr}; - CGDataConsumerRef consumer = CGDataConsumerCreate(nullptr, &callbacks); - CGContextRef cg = CGPDFContextCreate(consumer, nullptr, nullptr); - CGDataConsumerRelease(consumer); - return cg; -} - -static CGContextRef -ScratchContext() -{ - static CGContextRef cg = CreateScratchContext(); - return cg; -} - -bool -PathCG::StrokeContainsPoint(const StrokeOptions &aStrokeOptions, - const Point &aPoint, - const Matrix &aTransform) const -{ - Matrix inverse = aTransform; - inverse.Invert(); - Point transformedPoint = inverse.TransformPoint(aPoint); - // We could probably drop the input transform and just transform the point at the caller? - CGPoint point = {transformedPoint.x, transformedPoint.y}; - - CGContextRef cg = ScratchContext(); - - CGContextSaveGState(cg); - - CGContextBeginPath(cg); - CGContextAddPath(cg, mPath); - - SetStrokeOptions(cg, aStrokeOptions); - - CGContextReplacePathWithStrokedPath(cg); - CGContextRestoreGState(cg); - - CGPathRef sPath = CGContextCopyPath(cg); - bool inStroke = CGPathContainsPoint(sPath, nullptr, point, false); - CGPathRelease(sPath); - - return inStroke; -} - -//XXX: what should these functions return for an empty path? -// currently they return CGRectNull {inf,inf, 0, 0} -Rect -PathCG::GetBounds(const Matrix &aTransform) const -{ - //XXX: are these bounds tight enough - Rect bounds = CGRectToRect(CGPathGetBoundingBox(mPath)); - - //XXX: currently this returns the bounds of the transformed bounds - // this is strictly looser than the bounds of the transformed path - return aTransform.TransformBounds(bounds); -} - -Rect -PathCG::GetStrokedBounds(const StrokeOptions &aStrokeOptions, - const Matrix &aTransform) const -{ - // 10.7 has CGPathCreateCopyByStrokingPath which we could use - // instead of this scratch context business - CGContextRef cg = ScratchContext(); - - CGContextSaveGState(cg); - - CGContextBeginPath(cg); - CGContextAddPath(cg, mPath); - - SetStrokeOptions(cg, aStrokeOptions); - - CGContextReplacePathWithStrokedPath(cg); - Rect bounds = CGRectToRect(CGContextGetPathBoundingBox(cg)); - - CGContextRestoreGState(cg); - - if (!bounds.IsFinite()) { - return Rect(); - } - - return aTransform.TransformBounds(bounds); -} - - -} // namespace gfx - -} // namespace mozilla diff --git a/gfx/2d/PathCG.h b/gfx/2d/PathCG.h deleted file mode 100644 index db609cb577..0000000000 --- a/gfx/2d/PathCG.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * 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/. */ - -#ifndef MOZILLA_GFX_PATHCG_H_ -#define MOZILLA_GFX_PATHCG_H_ - -#ifdef MOZ_WIDGET_COCOA -#include <ApplicationServices/ApplicationServices.h> -#else -#include <CoreGraphics/CoreGraphics.h> -#endif - -#include "2D.h" - -namespace mozilla { -namespace gfx { - -class PathCG; - -class PathBuilderCG : public PathBuilder -{ -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCG) - // absorbs a reference of aPath - PathBuilderCG(CGMutablePathRef aPath, FillRule aFillRule) - : mFillRule(aFillRule) - { - mCGPath = aPath; - } - - explicit PathBuilderCG(FillRule aFillRule) - : mFillRule(aFillRule) - { - mCGPath = CGPathCreateMutable(); - } - - virtual ~PathBuilderCG(); - - virtual void MoveTo(const Point &aPoint); - virtual void LineTo(const Point &aPoint); - virtual void BezierTo(const Point &aCP1, - const Point &aCP2, - const Point &aCP3); - virtual void QuadraticBezierTo(const Point &aCP1, - const Point &aCP2); - virtual void Close(); - virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle, - Float aEndAngle, bool aAntiClockwise = false); - virtual Point CurrentPoint() const; - - virtual already_AddRefed<Path> Finish(); - - virtual BackendType GetBackendType() const { return BackendType::SKIA; } - -private: - friend class PathCG; - friend class ScaledFontMac; - - void EnsureActive(const Point &aPoint); - - CGMutablePathRef mCGPath; - Point mCurrentPoint; - Point mBeginPoint; - FillRule mFillRule; -}; - -class PathCG : public Path -{ -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCG) - PathCG(CGMutablePathRef aPath, FillRule aFillRule) - : mPath(aPath) - , mFillRule(aFillRule) - { - CGPathRetain(mPath); - } - virtual ~PathCG() { CGPathRelease(mPath); } - - // Paths will always return BackendType::COREGRAPHICS, but note that they - // are compatible with BackendType::COREGRAPHICS_ACCELERATED backend. - virtual BackendType GetBackendType() const { return BackendType::SKIA; } - - virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const; - virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform, - FillRule aFillRule) const; - - virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const; - virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, - const Point &aPoint, - const Matrix &aTransform) const; - virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const; - virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, - const Matrix &aTransform = Matrix()) const; - - virtual void StreamToSink(PathSink *aSink) const; - - virtual FillRule GetFillRule() const { return mFillRule; } - - CGMutablePathRef GetPath() const { return mPath; } - -private: - friend class DrawTargetCG; - - CGMutablePathRef mPath; - Point mEndPoint; - FillRule mFillRule; -}; - -} // namespace gfx -} // namespace mozilla - -#endif diff --git a/gfx/2d/QuartzSupport.h b/gfx/2d/QuartzSupport.h deleted file mode 100644 index f56fcb77ca..0000000000 --- a/gfx/2d/QuartzSupport.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -// vim:set ts=2 sts=2 sw=2 et cin: -/* 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/. */ - -#ifndef nsCoreAnimationSupport_h__ -#define nsCoreAnimationSupport_h__ -#ifdef XP_MACOSX - -#import <OpenGL/OpenGL.h> -#import <OpenGL/gl.h> -#import "ApplicationServices/ApplicationServices.h" -#include "gfxTypes.h" -#include "mozilla/RefPtr.h" -#include "mozilla/gfx/MacIOSurface.h" -#include "nsError.h" - -// Get the system color space. -CGColorSpaceRef CreateSystemColorSpace(); - -// Manages a CARenderer -struct _CGLContextObject; - -enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER }; - -class nsCARenderer : public mozilla::RefCounted<nsCARenderer> { -public: - MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer) - nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0), - mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr), - mIOSurface(nullptr), mFBO(0), mIOTexture(0), - mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX), - mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER), - mContentsScaleFactor(1.0) {} - ~nsCARenderer(); - // aWidth and aHeight are 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 device pixel. Multiply - // display pixels by aContentsScaleFactor to get device pixels. - nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight, - double aContentsScaleFactor, - AllowOfflineRendererEnum aAllowOfflineRenderer); - // aWidth and aHeight are in "display pixels". Multiply by - // aContentsScaleFactor to get device pixels. - nsresult Render(int aWidth, int aHeight, - double aContentsScaleFactor, - CGImageRef *aOutCAImage); - bool isInit() { return mCARenderer != nullptr; } - /* - * Render the CALayer to an IOSurface. If no IOSurface - * is attached then an internal pixel buffer will be - * used. - */ - void AttachIOSurface(MacIOSurface *aSurface); - IOSurfaceID GetIOSurfaceID(); - // aX, aY, aWidth and aHeight are in "display pixels". Multiply by - // surf->GetContentsScaleFactor() to get device pixels. - static nsresult DrawSurfaceToCGContext(CGContextRef aContext, - MacIOSurface *surf, - CGColorSpaceRef aColorSpace, - int aX, int aY, - size_t aWidth, size_t aHeight); - - // Remove & Add the layer without destroying - // the renderer for fast back buffer swapping. - void DetachCALayer(); - void AttachCALayer(void *aCALayer); -#ifdef DEBUG - static void SaveToDisk(MacIOSurface *surf); -#endif -private: - // aWidth and aHeight are in "display pixels". Multiply by - // mContentsScaleFactor to get device pixels. - void SetBounds(int aWidth, int aHeight); - // aWidth and aHeight are in "display pixels". Multiply by - // mContentsScaleFactor to get device pixels. - void SetViewport(int aWidth, int aHeight); - void Destroy(); - - void *mCARenderer; - void *mWrapperCALayer; - GLuint mFBOTexture; - _CGLContextObject *mOpenGLContext; - CGImageRef mCGImage; - void *mCGData; - RefPtr<MacIOSurface> mIOSurface; - uint32_t mFBO; - uint32_t mIOTexture; - int mUnsupportedWidth; - int mUnsupportedHeight; - AllowOfflineRendererEnum mAllowOfflineRenderer; - double mContentsScaleFactor; -}; - -#endif // XP_MACOSX -#endif // nsCoreAnimationSupport_h__ - diff --git a/gfx/2d/QuartzSupport.mm b/gfx/2d/QuartzSupport.mm deleted file mode 100644 index 464db5ecee..0000000000 --- a/gfx/2d/QuartzSupport.mm +++ /dev/null @@ -1,625 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -// vim:set ts=2 sts=2 sw=2 et cin: -/* 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/. */ - -#include "QuartzSupport.h" -#include "nsDebug.h" -#include "MacIOSurface.h" -#include "mozilla/Sprintf.h" - -#import <QuartzCore/QuartzCore.h> -#import <AppKit/NSOpenGL.h> -#include <dlfcn.h> -#include "GLDefs.h" - -#define IOSURFACE_FRAMEWORK_PATH \ - "/System/Library/Frameworks/IOSurface.framework/IOSurface" -#define OPENGL_FRAMEWORK_PATH \ - "/System/Library/Frameworks/OpenGL.framework/OpenGL" -#define COREGRAPHICS_FRAMEWORK_PATH \ - "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/CoreGraphics" - -@interface CALayer (ContentsScale) -- (double)contentsScale; -- (void)setContentsScale:(double)scale; -@end - - -CGColorSpaceRef CreateSystemColorSpace() { - CGColorSpaceRef cspace = ::CGDisplayCopyColorSpace(::CGMainDisplayID()); - if (!cspace) { - cspace = ::CGColorSpaceCreateDeviceRGB(); - } - return cspace; -} - -nsCARenderer::~nsCARenderer() { - Destroy(); -} - -void cgdata_release_callback(void *aCGData, const void *data, size_t size) { - if (aCGData) { - free(aCGData); - } -} - -void nsCARenderer::Destroy() { - if (mCARenderer) { - CARenderer* caRenderer = (CARenderer*)mCARenderer; - // Bug 556453: - // Explicitly remove the layer from the renderer - // otherwise it does not always happen right away. - caRenderer.layer = nullptr; - [caRenderer release]; - } - if (mWrapperCALayer) { - CALayer* wrapperLayer = (CALayer*)mWrapperCALayer; - [wrapperLayer release]; - } - if (mOpenGLContext) { - if (mFBO || mIOTexture || mFBOTexture) { - // Release these resources with the context that allocated them - CGLContextObj oldContext = ::CGLGetCurrentContext(); - ::CGLSetCurrentContext(mOpenGLContext); - - if (mFBOTexture) { - ::glDeleteTextures(1, &mFBOTexture); - } - if (mIOTexture) { - ::glDeleteTextures(1, &mIOTexture); - } - if (mFBO) { - ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - ::glDeleteFramebuffersEXT(1, &mFBO); - } - - if (oldContext) - ::CGLSetCurrentContext(oldContext); - } - ::CGLDestroyContext((CGLContextObj)mOpenGLContext); - } - if (mCGImage) { - ::CGImageRelease(mCGImage); - } - // mCGData is deallocated by cgdata_release_callback - - mCARenderer = nil; - mWrapperCALayer = nil; - mFBOTexture = 0; - mOpenGLContext = nullptr; - mCGImage = nullptr; - mIOSurface = nullptr; - mFBO = 0; - mIOTexture = 0; -} - -nsresult nsCARenderer::SetupRenderer(void *aCALayer, int aWidth, int aHeight, - double aContentsScaleFactor, - AllowOfflineRendererEnum aAllowOfflineRenderer) { - mAllowOfflineRenderer = aAllowOfflineRenderer; - - if (aWidth == 0 || aHeight == 0 || aContentsScaleFactor <= 0) - return NS_ERROR_FAILURE; - - if (aWidth == mUnsupportedWidth && - aHeight == mUnsupportedHeight) { - return NS_ERROR_FAILURE; - } - - CGLPixelFormatAttribute attributes[] = { - kCGLPFAAccelerated, - kCGLPFADepthSize, (CGLPixelFormatAttribute)24, - kCGLPFAAllowOfflineRenderers, - (CGLPixelFormatAttribute)0 - }; - - if (mAllowOfflineRenderer == DISALLOW_OFFLINE_RENDERER) { - attributes[3] = (CGLPixelFormatAttribute)0; - } - - GLint screen; - CGLPixelFormatObj format; - if (::CGLChoosePixelFormat(attributes, &format, &screen) != kCGLNoError) { - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - - if (::CGLCreateContext(format, nullptr, &mOpenGLContext) != kCGLNoError) { - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - ::CGLDestroyPixelFormat(format); - - CARenderer* caRenderer = [[CARenderer rendererWithCGLContext:mOpenGLContext - options:nil] retain]; - if (caRenderer == nil) { - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - CALayer* wrapperCALayer = [[CALayer layer] retain]; - if (wrapperCALayer == nil) { - [caRenderer release]; - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - - mCARenderer = caRenderer; - mWrapperCALayer = wrapperCALayer; - caRenderer.layer = wrapperCALayer; - [wrapperCALayer addSublayer:(CALayer*)aCALayer]; - mContentsScaleFactor = aContentsScaleFactor; - size_t intScaleFactor = ceil(mContentsScaleFactor); - SetBounds(aWidth, aHeight); - - // We target rendering to a CGImage if no shared IOSurface are given. - if (!mIOSurface) { - mCGData = malloc(aWidth*intScaleFactor*aHeight*4*intScaleFactor); - if (!mCGData) { - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - memset(mCGData, 0, aWidth*intScaleFactor*aHeight*4*intScaleFactor); - - CGDataProviderRef dataProvider = nullptr; - dataProvider = ::CGDataProviderCreateWithData(mCGData, - mCGData, aHeight*intScaleFactor*aWidth*4*intScaleFactor, - cgdata_release_callback); - if (!dataProvider) { - cgdata_release_callback(mCGData, mCGData, - aHeight*intScaleFactor*aWidth*4*intScaleFactor); - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - - CGColorSpaceRef colorSpace = CreateSystemColorSpace(); - - mCGImage = ::CGImageCreate(aWidth * intScaleFactor, aHeight * intScaleFactor, - 8, 32, aWidth * intScaleFactor * 4, colorSpace, - kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, - dataProvider, nullptr, true, kCGRenderingIntentDefault); - - ::CGDataProviderRelease(dataProvider); - ::CGColorSpaceRelease(colorSpace); - if (!mCGImage) { - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - } - - CGLContextObj oldContext = ::CGLGetCurrentContext(); - ::CGLSetCurrentContext(mOpenGLContext); - - if (mIOSurface) { - // Create the IOSurface mapped texture. - ::glGenTextures(1, &mIOTexture); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mIOTexture); - ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - MacIOSurfaceLib::CGLTexImageIOSurface2D(mOpenGLContext, GL_TEXTURE_RECTANGLE_ARB, - GL_RGBA, aWidth * intScaleFactor, - aHeight * intScaleFactor, - GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, - mIOSurface->mIOSurfacePtr, 0); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - } else { - ::glGenTextures(1, &mFBOTexture); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mFBOTexture); - ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - } - - // Create the fbo - ::glGenFramebuffersEXT(1, &mFBO); - ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO); - if (mIOSurface) { - ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - GL_TEXTURE_RECTANGLE_ARB, mIOTexture, 0); - } else { - ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - GL_TEXTURE_RECTANGLE_ARB, mFBOTexture, 0); - } - - - // Make sure that the Framebuffer configuration is supported on the client machine - GLenum fboStatus; - fboStatus = ::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT) { - NS_ERROR("FBO not supported"); - if (oldContext) - ::CGLSetCurrentContext(oldContext); - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - return NS_ERROR_FAILURE; - } - - SetViewport(aWidth, aHeight); - - GLenum result = ::glGetError(); - if (result != GL_NO_ERROR) { - NS_ERROR("Unexpected OpenGL Error"); - mUnsupportedWidth = aWidth; - mUnsupportedHeight = aHeight; - Destroy(); - if (oldContext) - ::CGLSetCurrentContext(oldContext); - return NS_ERROR_FAILURE; - } - - if (oldContext) - ::CGLSetCurrentContext(oldContext); - - return NS_OK; -} - -void nsCARenderer::SetBounds(int aWidth, int aHeight) { - CARenderer* caRenderer = (CARenderer*)mCARenderer; - CALayer* wrapperLayer = (CALayer*)mWrapperCALayer; - NSArray* sublayers = [wrapperLayer sublayers]; - CALayer* pluginLayer = (CALayer*) [sublayers objectAtIndex:0]; - - // Create a transaction and disable animations - // to make the position update instant. - [CATransaction begin]; - NSMutableDictionary *newActions = - [[NSMutableDictionary alloc] initWithObjectsAndKeys: - [NSNull null], @"onOrderIn", - [NSNull null], @"onOrderOut", - [NSNull null], @"sublayers", - [NSNull null], @"contents", - [NSNull null], @"position", - [NSNull null], @"bounds", - nil]; - wrapperLayer.actions = newActions; - [newActions release]; - - // If we're in HiDPI mode, mContentsScaleFactor will (presumably) be 2.0. - // For some reason, to make things work properly in HiDPI mode we need to - // make caRenderer's 'bounds' and 'layer' different sizes -- to set 'bounds' - // to the size of 'layer's backing store. And to avoid this possibly - // confusing the plugin, we need to hide it's effects from the plugin by - // making pluginLayer (usually the CALayer* provided by the plugin) a - // sublayer of our own wrapperLayer (see bug 829284). - size_t intScaleFactor = ceil(mContentsScaleFactor); - [CATransaction setValue: [NSNumber numberWithFloat:0.0f] forKey: kCATransactionAnimationDuration]; - [CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions]; - [wrapperLayer setBounds:CGRectMake(0, 0, aWidth, aHeight)]; - [wrapperLayer setPosition:CGPointMake(aWidth/2.0, aHeight/2.0)]; - [pluginLayer setBounds:CGRectMake(0, 0, aWidth, aHeight)]; - [pluginLayer setFrame:CGRectMake(0, 0, aWidth, aHeight)]; - caRenderer.bounds = CGRectMake(0, 0, aWidth * intScaleFactor, aHeight * intScaleFactor); - if (mContentsScaleFactor != 1.0) { - CGAffineTransform affineTransform = [wrapperLayer affineTransform]; - affineTransform.a = mContentsScaleFactor; - affineTransform.d = mContentsScaleFactor; - affineTransform.tx = ((double)aWidth)/mContentsScaleFactor; - affineTransform.ty = ((double)aHeight)/mContentsScaleFactor; - [wrapperLayer setAffineTransform:affineTransform]; - } else { - // These settings are the default values. But they might have been - // changed as above if we were previously running in a HiDPI mode - // (i.e. if we just switched from that to a non-HiDPI mode). - [wrapperLayer setAffineTransform:CGAffineTransformIdentity]; - } - [CATransaction commit]; -} - -void nsCARenderer::SetViewport(int aWidth, int aHeight) { - size_t intScaleFactor = ceil(mContentsScaleFactor); - aWidth *= intScaleFactor; - aHeight *= intScaleFactor; - - ::glViewport(0.0, 0.0, aWidth, aHeight); - ::glMatrixMode(GL_PROJECTION); - ::glLoadIdentity(); - ::glOrtho (0.0, aWidth, 0.0, aHeight, -1, 1); - - // Render upside down to speed up CGContextDrawImage - ::glTranslatef(0.0f, aHeight, 0.0); - ::glScalef(1.0, -1.0, 1.0); -} - -void nsCARenderer::AttachIOSurface(MacIOSurface *aSurface) { - if (mIOSurface && - aSurface->GetIOSurfaceID() == mIOSurface->GetIOSurfaceID()) { - return; - } - - mIOSurface = aSurface; - - // Update the framebuffer and viewport - if (mCARenderer) { - CARenderer* caRenderer = (CARenderer*)mCARenderer; - size_t intScaleFactor = ceil(mContentsScaleFactor); - int width = caRenderer.bounds.size.width / intScaleFactor; - int height = caRenderer.bounds.size.height / intScaleFactor; - - CGLContextObj oldContext = ::CGLGetCurrentContext(); - ::CGLSetCurrentContext(mOpenGLContext); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mIOTexture); - MacIOSurfaceLib::CGLTexImageIOSurface2D(mOpenGLContext, GL_TEXTURE_RECTANGLE_ARB, - GL_RGBA, mIOSurface->GetDevicePixelWidth(), - mIOSurface->GetDevicePixelHeight(), - GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, - mIOSurface->mIOSurfacePtr, 0); - ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - - // Rebind the FBO to make it live - ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO); - - if (static_cast<int>(mIOSurface->GetWidth()) != width || - static_cast<int>(mIOSurface->GetHeight()) != height) { - width = mIOSurface->GetWidth(); - height = mIOSurface->GetHeight(); - SetBounds(width, height); - SetViewport(width, height); - } - - if (oldContext) { - ::CGLSetCurrentContext(oldContext); - } - } -} - -IOSurfaceID nsCARenderer::GetIOSurfaceID() { - if (!mIOSurface) { - return 0; - } - - return mIOSurface->GetIOSurfaceID(); -} - -nsresult nsCARenderer::Render(int aWidth, int aHeight, - double aContentsScaleFactor, - CGImageRef *aOutCGImage) { - if (!aOutCGImage && !mIOSurface) { - NS_ERROR("No target destination for rendering"); - } else if (aOutCGImage) { - // We are expected to return a CGImageRef, we will set - // it to nullptr in case we fail before the image is ready. - *aOutCGImage = nullptr; - } - - if (aWidth == 0 || aHeight == 0 || aContentsScaleFactor <= 0) - return NS_OK; - - if (!mCARenderer || !mWrapperCALayer) { - return NS_ERROR_FAILURE; - } - - CARenderer* caRenderer = (CARenderer*)mCARenderer; - CALayer* wrapperLayer = (CALayer*)mWrapperCALayer; - size_t intScaleFactor = ceil(aContentsScaleFactor); - int renderer_width = caRenderer.bounds.size.width / intScaleFactor; - int renderer_height = caRenderer.bounds.size.height / intScaleFactor; - - if (renderer_width != aWidth || renderer_height != aHeight || - mContentsScaleFactor != aContentsScaleFactor) { - // XXX: This should be optimized to not rescale the buffer - // if we are resizing down. - // caLayer may be the CALayer* provided by the plugin, so we need to - // preserve it across the call to Destroy(). - NSArray* sublayers = [wrapperLayer sublayers]; - CALayer* caLayer = (CALayer*) [sublayers objectAtIndex:0]; - // mIOSurface is set by AttachIOSurface(), not by SetupRenderer(). So - // since it may have been set by a prior call to AttachIOSurface(), we - // need to preserve it across the call to Destroy(). - RefPtr<MacIOSurface> ioSurface = mIOSurface; - Destroy(); - mIOSurface = ioSurface; - if (SetupRenderer(caLayer, aWidth, aHeight, aContentsScaleFactor, - mAllowOfflineRenderer) != NS_OK) { - return NS_ERROR_FAILURE; - } - - caRenderer = (CARenderer*)mCARenderer; - } - - CGLContextObj oldContext = ::CGLGetCurrentContext(); - ::CGLSetCurrentContext(mOpenGLContext); - if (!mIOSurface) { - // If no shared IOSurface is given render to our own - // texture for readback. - ::glGenTextures(1, &mFBOTexture); - } - - GLenum result = ::glGetError(); - if (result != GL_NO_ERROR) { - NS_ERROR("Unexpected OpenGL Error"); - Destroy(); - if (oldContext) - ::CGLSetCurrentContext(oldContext); - return NS_ERROR_FAILURE; - } - - ::glClearColor(0.0, 0.0, 0.0, 0.0); - ::glClear(GL_COLOR_BUFFER_BIT); - - [CATransaction commit]; - double caTime = ::CACurrentMediaTime(); - [caRenderer beginFrameAtTime:caTime timeStamp:nullptr]; - [caRenderer addUpdateRect:CGRectMake(0,0, aWidth * intScaleFactor, - aHeight * intScaleFactor)]; - [caRenderer render]; - [caRenderer endFrame]; - - // Read the data back either to the IOSurface or mCGImage. - if (mIOSurface) { - ::glFlush(); - } else { - ::glPixelStorei(GL_PACK_ALIGNMENT, 4); - ::glPixelStorei(GL_PACK_ROW_LENGTH, 0); - ::glPixelStorei(GL_PACK_SKIP_ROWS, 0); - ::glPixelStorei(GL_PACK_SKIP_PIXELS, 0); - - ::glReadPixels(0.0f, 0.0f, aWidth * intScaleFactor, - aHeight * intScaleFactor, - GL_BGRA, GL_UNSIGNED_BYTE, - mCGData); - - *aOutCGImage = mCGImage; - } - - if (oldContext) { - ::CGLSetCurrentContext(oldContext); - } - - return NS_OK; -} - -nsresult nsCARenderer::DrawSurfaceToCGContext(CGContextRef aContext, - MacIOSurface *surf, - CGColorSpaceRef aColorSpace, - int aX, int aY, - size_t aWidth, size_t aHeight) { - surf->Lock(); - size_t bytesPerRow = surf->GetBytesPerRow(); - size_t ioWidth = surf->GetWidth(); - size_t ioHeight = surf->GetHeight(); - - // We get rendering glitches if we use a width/height that falls - // outside of the IOSurface. - if (aWidth + aX > ioWidth) - aWidth = ioWidth - aX; - if (aHeight + aY > ioHeight) - aHeight = ioHeight - aY; - - if (aX < 0 || static_cast<size_t>(aX) >= ioWidth || - aY < 0 || static_cast<size_t>(aY) >= ioHeight) { - surf->Unlock(); - return NS_ERROR_FAILURE; - } - - void* ioData = surf->GetBaseAddress(); - double scaleFactor = surf->GetContentsScaleFactor(); - size_t intScaleFactor = ceil(surf->GetContentsScaleFactor()); - CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(ioData, - ioData, ioHeight*intScaleFactor*(bytesPerRow)*4, - nullptr); //No release callback - if (!dataProvider) { - surf->Unlock(); - return NS_ERROR_FAILURE; - } - - CGImageRef cgImage = ::CGImageCreate(ioWidth * intScaleFactor, - ioHeight * intScaleFactor, 8, 32, bytesPerRow, aColorSpace, - kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, - dataProvider, nullptr, true, kCGRenderingIntentDefault); - ::CGDataProviderRelease(dataProvider); - if (!cgImage) { - surf->Unlock(); - return NS_ERROR_FAILURE; - } - CGImageRef subImage = ::CGImageCreateWithImageInRect(cgImage, - ::CGRectMake(aX * scaleFactor, - aY * scaleFactor, - aWidth * scaleFactor, - aHeight * scaleFactor)); - if (!subImage) { - ::CGImageRelease(cgImage); - surf->Unlock(); - return NS_ERROR_FAILURE; - } - - ::CGContextScaleCTM(aContext, 1.0f, -1.0f); - ::CGContextDrawImage(aContext, - CGRectMake(aX * scaleFactor, - (-(CGFloat)aY - (CGFloat)aHeight) * scaleFactor, - aWidth * scaleFactor, - aHeight * scaleFactor), - subImage); - - ::CGImageRelease(subImage); - ::CGImageRelease(cgImage); - surf->Unlock(); - return NS_OK; -} - -void nsCARenderer::DetachCALayer() { - CALayer* wrapperLayer = (CALayer*)mWrapperCALayer; - NSArray* sublayers = [wrapperLayer sublayers]; - CALayer* oldLayer = (CALayer*) [sublayers objectAtIndex:0]; - [oldLayer removeFromSuperlayer]; -} - -void nsCARenderer::AttachCALayer(void *aCALayer) { - CALayer* wrapperLayer = (CALayer*)mWrapperCALayer; - NSArray* sublayers = [wrapperLayer sublayers]; - CALayer* oldLayer = (CALayer*) [sublayers objectAtIndex:0]; - [oldLayer removeFromSuperlayer]; - [wrapperLayer addSublayer:(CALayer*)aCALayer]; -} - -#ifdef DEBUG - -int sSaveToDiskSequence = 0; -void nsCARenderer::SaveToDisk(MacIOSurface *surf) { - surf->Lock(); - size_t bytesPerRow = surf->GetBytesPerRow(); - size_t ioWidth = surf->GetWidth(); - size_t ioHeight = surf->GetHeight(); - void* ioData = surf->GetBaseAddress(); - CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(ioData, - ioData, ioHeight*(bytesPerRow)*4, - nullptr); //No release callback - if (!dataProvider) { - surf->Unlock(); - return; - } - - CGColorSpaceRef colorSpace = CreateSystemColorSpace(); - CGImageRef cgImage = ::CGImageCreate(ioWidth, ioHeight, 8, 32, bytesPerRow, - colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, - dataProvider, nullptr, true, kCGRenderingIntentDefault); - ::CGDataProviderRelease(dataProvider); - ::CGColorSpaceRelease(colorSpace); - if (!cgImage) { - surf->Unlock(); - return; - } - - char cstr[1000]; - SprintfLiteral(cstr, "file:///Users/benoitgirard/debug/iosurface_%i.png", ++sSaveToDiskSequence); - - CFStringRef cfStr = ::CFStringCreateWithCString(kCFAllocatorDefault, cstr, kCFStringEncodingMacRoman); - - printf("Exporting: %s\n", cstr); - CFURLRef url = ::CFURLCreateWithString( nullptr, cfStr, nullptr); - ::CFRelease(cfStr); - - CFStringRef type = kUTTypePNG; - size_t count = 1; - CFDictionaryRef options = nullptr; - CGImageDestinationRef dest = ::CGImageDestinationCreateWithURL(url, type, count, options); - ::CFRelease(url); - - ::CGImageDestinationAddImage(dest, cgImage, nullptr); - - ::CGImageDestinationFinalize(dest); - ::CFRelease(dest); - ::CGImageRelease(cgImage); - - surf->Unlock(); - - return; - -} - -#endif diff --git a/gfx/2d/ScaledFontMac.cpp b/gfx/2d/ScaledFontMac.cpp deleted file mode 100644 index 6baf257826..0000000000 --- a/gfx/2d/ScaledFontMac.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * 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/. */ - -#include "ScaledFontMac.h" -#ifdef USE_SKIA -#include "PathSkia.h" -#include "skia/include/core/SkPaint.h" -#include "skia/include/core/SkPath.h" -#include "skia/include/ports/SkTypeface_mac.h" -#endif -#include <vector> -#include <dlfcn.h> -#ifdef MOZ_WIDGET_UIKIT -#include <CoreFoundation/CoreFoundation.h> -#endif - -#ifdef MOZ_WIDGET_COCOA -// prototype for private API -extern "C" { -CGPathRef CGFontGetGlyphPath(CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph); -}; -#endif - -#ifdef USE_CAIRO_SCALED_FONT -#include "cairo-quartz.h" -#endif - -namespace mozilla { -namespace gfx { - -ScaledFontMac::CTFontDrawGlyphsFuncT* ScaledFontMac::CTFontDrawGlyphsPtr = nullptr; -bool ScaledFontMac::sSymbolLookupDone = false; - -ScaledFontMac::ScaledFontMac(CGFontRef aFont, Float aSize) - : ScaledFontBase(aSize) -{ - if (!sSymbolLookupDone) { - CTFontDrawGlyphsPtr = - (CTFontDrawGlyphsFuncT*)dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs"); - sSymbolLookupDone = true; - } - - // XXX: should we be taking a reference - mFont = CGFontRetain(aFont); - if (CTFontDrawGlyphsPtr != nullptr) { - // only create mCTFont if we're going to be using the CTFontDrawGlyphs API - mCTFont = CTFontCreateWithGraphicsFont(aFont, aSize, nullptr, nullptr); - } else { - mCTFont = nullptr; - } -} - -ScaledFontMac::~ScaledFontMac() -{ - if (mCTFont) { - CFRelease(mCTFont); - } - CGFontRelease(mFont); -} - -#ifdef USE_SKIA -SkTypeface* ScaledFontMac::GetSkTypeface() -{ - if (!mTypeface) { - if (mCTFont) { - mTypeface = SkCreateTypefaceFromCTFont(mCTFont); - } else { - CTFontRef fontFace = CTFontCreateWithGraphicsFont(mFont, mSize, nullptr, nullptr); - mTypeface = SkCreateTypefaceFromCTFont(fontFace); - CFRelease(fontFace); - } - } - return mTypeface; -} -#endif - -// private API here are the public options on OS X -// CTFontCreatePathForGlyph -// ATSUGlyphGetCubicPaths -// we've used this in cairo sucessfully for some time. -// Note: cairo dlsyms it. We could do that but maybe it's -// safe just to use? - -already_AddRefed<Path> -ScaledFontMac::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) -{ - return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget); -} - -uint32_t -CalcTableChecksum(const uint32_t *tableStart, uint32_t length, bool skipChecksumAdjust = false) -{ - uint32_t sum = 0L; - const uint32_t *table = tableStart; - const uint32_t *end = table+((length+3) & ~3) / sizeof(uint32_t); - while (table < end) { - if (skipChecksumAdjust && (table - tableStart) == 2) { - table++; - } else { - sum += CFSwapInt32BigToHost(*table++); - } - } - return sum; -} - -struct TableRecord { - uint32_t tag; - uint32_t checkSum; - uint32_t offset; - uint32_t length; - CFDataRef data; -}; - -int maxPow2LessThan(int a) -{ - int x = 1; - int shift = 0; - while ((x<<(shift+1)) < a) { - shift++; - } - return shift; -} - -struct writeBuf -{ - explicit writeBuf(int size) - { - this->data = new unsigned char [size]; - this->offset = 0; - } - ~writeBuf() { - delete this->data; - } - - template <class T> - void writeElement(T a) - { - *reinterpret_cast<T*>(&this->data[this->offset]) = a; - this->offset += sizeof(T); - } - - void writeMem(const void *data, unsigned long length) - { - memcpy(&this->data[this->offset], data, length); - this->offset += length; - } - - void align() - { - while (this->offset & 3) { - this->data[this->offset] = 0; - this->offset++; - } - } - - unsigned char *data; - int offset; -}; - -bool -ScaledFontMac::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) -{ - // We'll reconstruct a TTF font from the tables we can get from the CGFont - CFArrayRef tags = CGFontCopyTableTags(mFont); - CFIndex count = CFArrayGetCount(tags); - - TableRecord *records = new TableRecord[count]; - uint32_t offset = 0; - offset += sizeof(uint32_t)*3; - offset += sizeof(uint32_t)*4*count; - bool CFF = false; - for (CFIndex i = 0; i<count; i++) { - uint32_t tag = (uint32_t)(uintptr_t)CFArrayGetValueAtIndex(tags, i); - if (tag == 0x43464620) // 'CFF ' - CFF = true; - CFDataRef data = CGFontCopyTableForTag(mFont, tag); - records[i].tag = tag; - records[i].offset = offset; - records[i].data = data; - records[i].length = CFDataGetLength(data); - bool skipChecksumAdjust = (tag == 0x68656164); // 'head' - records[i].checkSum = CalcTableChecksum(reinterpret_cast<const uint32_t*>(CFDataGetBytePtr(data)), - records[i].length, skipChecksumAdjust); - offset += records[i].length; - // 32 bit align the tables - offset = (offset + 3) & ~3; - } - CFRelease(tags); - - struct writeBuf buf(offset); - // write header/offset table - if (CFF) { - buf.writeElement(CFSwapInt32HostToBig(0x4f54544f)); - } else { - buf.writeElement(CFSwapInt32HostToBig(0x00010000)); - } - buf.writeElement(CFSwapInt16HostToBig(count)); - buf.writeElement(CFSwapInt16HostToBig((1<<maxPow2LessThan(count))*16)); - buf.writeElement(CFSwapInt16HostToBig(maxPow2LessThan(count))); - buf.writeElement(CFSwapInt16HostToBig(count*16-((1<<maxPow2LessThan(count))*16))); - - // write table record entries - for (CFIndex i = 0; i<count; i++) { - buf.writeElement(CFSwapInt32HostToBig(records[i].tag)); - buf.writeElement(CFSwapInt32HostToBig(records[i].checkSum)); - buf.writeElement(CFSwapInt32HostToBig(records[i].offset)); - buf.writeElement(CFSwapInt32HostToBig(records[i].length)); - } - - // write tables - int checkSumAdjustmentOffset = 0; - for (CFIndex i = 0; i<count; i++) { - if (records[i].tag == 0x68656164) { - checkSumAdjustmentOffset = buf.offset + 2*4; - } - buf.writeMem(CFDataGetBytePtr(records[i].data), CFDataGetLength(records[i].data)); - buf.align(); - CFRelease(records[i].data); - } - delete[] records; - - // clear the checksumAdjust field before checksumming the whole font - memset(&buf.data[checkSumAdjustmentOffset], 0, sizeof(uint32_t)); - uint32_t fontChecksum = CFSwapInt32HostToBig(0xb1b0afba - CalcTableChecksum(reinterpret_cast<const uint32_t*>(buf.data), offset)); - // set checkSumAdjust to the computed checksum - memcpy(&buf.data[checkSumAdjustmentOffset], &fontChecksum, sizeof(fontChecksum)); - - // we always use an index of 0 - aDataCallback(buf.data, buf.offset, 0, mSize, aBaton); - - return true; - -} - -#ifdef USE_CAIRO_SCALED_FONT -cairo_font_face_t* -ScaledFontMac::GetCairoFontFace() -{ - MOZ_ASSERT(mFont); - return cairo_quartz_font_face_create_for_cgfont(mFont); -} -#endif - -} // namespace gfx -} // namespace mozilla diff --git a/gfx/2d/ScaledFontMac.h b/gfx/2d/ScaledFontMac.h deleted file mode 100644 index c141f96b26..0000000000 --- a/gfx/2d/ScaledFontMac.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * 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/. */ - -#ifndef MOZILLA_GFX_SCALEDFONTMAC_H_ -#define MOZILLA_GFX_SCALEDFONTMAC_H_ - -#ifdef MOZ_WIDGET_COCOA -#include <ApplicationServices/ApplicationServices.h> -#else -#include <CoreGraphics/CoreGraphics.h> -#include <CoreText/CoreText.h> -#endif - -#include "2D.h" - -#include "ScaledFontBase.h" - -namespace mozilla { -namespace gfx { - -class GlyphRenderingOptionsCG : public GlyphRenderingOptions -{ -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GlyphRenderingOptionsCG, override) - - explicit GlyphRenderingOptionsCG(const Color &aFontSmoothingBackgroundColor) - : mFontSmoothingBackgroundColor(aFontSmoothingBackgroundColor) - {} - - const Color &FontSmoothingBackgroundColor() const { return mFontSmoothingBackgroundColor; } - - virtual FontType GetType() const override { return FontType::MAC; } - -private: - Color mFontSmoothingBackgroundColor; -}; - -class ScaledFontMac : public ScaledFontBase -{ -public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontMac) - ScaledFontMac(CGFontRef aFont, Float aSize); - virtual ~ScaledFontMac(); - - virtual FontType GetType() const { return FontType::MAC; } -#ifdef USE_SKIA - virtual SkTypeface* GetSkTypeface(); -#endif - virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget); - virtual bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton); - -#ifdef USE_CAIRO_SCALED_FONT - cairo_font_face_t* GetCairoFontFace(); -#endif - -private: - friend class DrawTargetSkia; - CGFontRef mFont; - CTFontRef mCTFont; // only created if CTFontDrawGlyphs is available, otherwise null - - typedef void (CTFontDrawGlyphsFuncT)(CTFontRef, - const CGGlyph[], const CGPoint[], - size_t, CGContextRef); - - static bool sSymbolLookupDone; - -public: - // function pointer for CTFontDrawGlyphs, if available; - // initialized the first time a ScaledFontMac is created, - // so it will be valid by the time DrawTargetCG wants to use it - static CTFontDrawGlyphsFuncT* CTFontDrawGlyphsPtr; -}; - -} // namespace gfx -} // namespace mozilla - -#endif /* MOZILLA_GFX_SCALEDFONTMAC_H_ */ diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build index 4f437d575a..7a80b1de2e 100644 --- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -58,16 +58,7 @@ EXPORTS.mozilla.gfx += [ EXPORTS.mozilla.gfx += ['ssse3-scaler.h'] -if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'uikit'): - EXPORTS.mozilla.gfx += [ - 'MacIOSurface.h', - ] - SOURCES += [ - 'NativeFontResourceMac.cpp', - 'PathCG.cpp', - 'ScaledFontMac.cpp', - ] -elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': +if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': SOURCES += [ 'DrawTargetD2D1.cpp', 'ExtendInputEffectD2D1.cpp', @@ -181,15 +172,6 @@ if CONFIG['CLANG_CXX']: if CONFIG['GNU_CXX']: CXXFLAGS += ['-Wno-error=shadow'] -if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': - EXPORTS.mozilla.gfx += [ - 'QuartzSupport.h', - ] - SOURCES += [ - 'MacIOSurface.cpp', - 'QuartzSupport.mm', - ] - if CONFIG['CPU_ARCH'] == 'arm' and CONFIG['BUILD_ARM_NEON']: SOURCES += ['BlurNEON.cpp'] SOURCES['BlurNEON.cpp'].flags += CONFIG['NEON_FLAGS'] |