bug 1170987 - Fix gfx/2d to build on iOS. r=jrmuizel

This commit is contained in:
Ted Mielczarek 2015-06-12 08:48:42 -04:00 committed by James Willcox
parent f79e1c0edd
commit 275b59ab6f
13 changed files with 101 additions and 21 deletions

View File

@ -1249,7 +1249,7 @@ public:
static bool DoesBackendSupportDataDrawtarget(BackendType aType);
#ifdef XP_MACOSX
#ifdef XP_DARWIN
static already_AddRefed<DrawTarget> CreateDrawTargetForCairoCGContext(CGContextRef cg, const IntSize& aSize);
static already_AddRefed<GlyphRenderingOptions>
CreateCGGlyphRenderingOptions(const Color &aFontSmoothingBackgroundColor);

View File

@ -137,7 +137,7 @@ private:
};
#endif
#ifdef XP_MACOSX
#ifdef XP_DARWIN
/* This is a helper class that let's you borrow a CGContextRef from a
* DrawTargetCG. This is used for drawing themed widgets.
*

View File

@ -3,6 +3,7 @@
* 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 <dlfcn.h>
#include "BorrowedContext.h"
#include "DataSurfaceHelpers.h"
#include "DrawTargetCG.h"
@ -177,6 +178,7 @@ DrawTargetCG::GetType() const
BackendType
DrawTargetCG::GetBackendType() const
{
#ifdef MOZ_WIDGET_COCOA
// It may be worth spliting Bitmap and IOSurface DrawTarget
// into seperate classes.
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
@ -184,15 +186,20 @@ DrawTargetCG::GetBackendType() const
} else {
return BackendType::COREGRAPHICS;
}
#else
return BackendType::COREGRAPHICS;
#endif
}
already_AddRefed<SourceSurface>
DrawTargetCG::Snapshot()
{
if (!mSnapshot) {
#ifdef MOZ_WIDGET_COCOA
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
return MakeAndAddRef<SourceSurfaceCGIOSurfaceContext>(this);
}
#endif
Flush();
mSnapshot = new SourceSurfaceCGBitmapContext(this);
}
@ -1717,12 +1724,14 @@ DrawTargetCG::Init(BackendType aType,
mSize = aSize;
#ifdef MOZ_WIDGET_COCOA
if (aType == BackendType::COREGRAPHICS_ACCELERATED) {
RefPtr<MacIOSurface> ioSurface = MacIOSurface::CreateIOSurface(aSize.width, aSize.height);
mCg = ioSurface->CreateIOSurfaceContext();
// If we don't have the symbol for 'CreateIOSurfaceContext' mCg will be null
// and we will fallback to software below
}
#endif
mFormat = SurfaceFormat::B8G8R8A8;
@ -1820,6 +1829,7 @@ EnsureValidPremultipliedData(CGContextRef aContext)
void
DrawTargetCG::Flush()
{
#ifdef MOZ_WIDGET_COCOA
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
CGContextFlush(mCg);
} else if (GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP &&
@ -1835,6 +1845,9 @@ DrawTargetCG::Flush()
EnsureValidPremultipliedData(mCg);
mMayContainInvalidPremultipliedData = false;
}
#else
//TODO
#endif
}
bool
@ -1874,7 +1887,9 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
mOriginalTransform = CGContextGetCTM(mCg);
mFormat = SurfaceFormat::B8G8R8A8;
#ifdef MOZ_WIDGET_COCOA
if (GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP) {
#endif
CGColorSpaceRef colorspace;
CGBitmapInfo bitinfo = CGBitmapContextGetBitmapInfo(mCg);
colorspace = CGBitmapContextGetColorSpace (mCg);
@ -1883,7 +1898,9 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
} else if ((bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst) {
mFormat = SurfaceFormat::B8G8R8X8;
}
#ifdef MOZ_WIDGET_COCOA
}
#endif
return true;
}
@ -1906,12 +1923,16 @@ DrawTargetCG::CreatePathBuilder(FillRule aFillRule) const
void*
DrawTargetCG::GetNativeSurface(NativeSurfaceType aType)
{
#ifdef MOZ_WIDGET_COCOA
if ((aType == NativeSurfaceType::CGCONTEXT && GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP) ||
(aType == NativeSurfaceType::CGCONTEXT_ACCELERATED && GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE)) {
return mCg;
} else {
return nullptr;
}
#else
return mCg;
#endif
}
void

View File

@ -6,7 +6,14 @@
#ifndef mozilla_gfx_DrawTargetCG_h
#define mozilla_gfx_DrawTargetCG_h
#ifdef MOZ_WIDGET_COCOA
#include <ApplicationServices/ApplicationServices.h>
#import <OpenGL/OpenGL.h>
#else
#include <CoreGraphics/CoreGraphics.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#endif
#include "2D.h"
#include "Rect.h"

View File

@ -24,8 +24,10 @@
#ifdef CAIRO_HAS_QUARTZ_SURFACE
#include "cairo-quartz.h"
#ifdef MOZ_WIDGET_COCOA
#include <ApplicationServices/ApplicationServices.h>
#endif
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
#include "cairo-xlib.h"

View File

@ -23,12 +23,12 @@
#include "ScaledFontWin.h"
#endif
#ifdef XP_MACOSX
#ifdef XP_DARWIN
#include "ScaledFontMac.h"
#endif
#ifdef XP_MACOSX
#ifdef XP_DARWIN
#include "DrawTargetCG.h"
#endif
@ -299,7 +299,7 @@ Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFor
}
break;
}
#elif defined XP_MACOSX
#elif defined XP_DARWIN
case BackendType::COREGRAPHICS:
case BackendType::COREGRAPHICS_ACCELERATED:
{
@ -382,7 +382,7 @@ Factory::CreateDrawTargetForData(BackendType aBackend,
break;
}
#endif
#ifdef XP_MACOSX
#ifdef XP_DARWIN
case BackendType::COREGRAPHICS:
{
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
@ -489,7 +489,7 @@ Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSiz
}
#endif
#endif
#ifdef XP_MACOSX
#ifdef XP_DARWIN
case NativeFontType::MAC_FONT_FACE:
{
return MakeAndAddRef<ScaledFontMac>(static_cast<CGFontRef>(aNativeFont.mFont), aSize);
@ -791,7 +791,7 @@ Factory::CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface, const IntSiz
return retVal.forget();
}
#ifdef XP_MACOSX
#ifdef XP_DARWIN
already_AddRefed<DrawTarget>
Factory::CreateDrawTargetForCairoCGContext(CGContextRef cg, const IntSize& aSize)
{

View File

@ -6,10 +6,23 @@
#ifndef MacIOSurface_h__
#define MacIOSurface_h__
#ifdef XP_MACOSX
#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;
#ifdef XP_IOS
typedef kern_return_t IOReturn;
typedef int CGLError;
#endif
typedef CFTypeRef IOSurfacePtr;
typedef IOSurfacePtr (*IOSurfaceCreateFunc) (CFDictionaryRef properties);
typedef IOSurfacePtr (*IOSurfaceLookupFunc) (uint32_t io_surface_id);
@ -42,18 +55,16 @@ typedef IOSurfacePtr (*CVPixelBufferGetIOSurfaceFunc)(
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"
struct _CGLContextObject;
typedef _CGLContextObject* CGLContextObj;
typedef struct CGContext* CGContextRef;
typedef struct CGImage* CGImageRef;
typedef uint32_t IOSurfaceID;
enum CGContextType {
CG_CONTEXT_TYPE_UNKNOWN = 0,
// These are found by inspection, it's possible they could be changed

View File

@ -6,7 +6,12 @@
#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 {

View File

@ -13,11 +13,16 @@
#include "DrawTargetCG.h"
#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
namespace mozilla {
@ -81,11 +86,12 @@ ScaledFontMac::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aT
{
if (aTarget->GetBackendType() == BackendType::COREGRAPHICS ||
aTarget->GetBackendType() == BackendType::COREGRAPHICS_ACCELERATED) {
#ifdef MOZ_WIDGET_COCOA
CGMutablePathRef path = CGPathCreateMutable();
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
// XXX: we could probably fold both of these transforms together to avoid extra work
CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
CGPathRef glyphPath = ::CGFontGetGlyphPath(mFont, &flip, 0, aBuffer.mGlyphs[i].mIndex);
CGAffineTransform matrix = CGAffineTransformMake(mSize, 0, 0, mSize,
@ -97,6 +103,10 @@ ScaledFontMac::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aT
RefPtr<Path> ret = new PathCG(path, FillRule::FILL_WINDING);
CGPathRelease(path);
return ret.forget();
#else
//TODO: probably want CTFontCreatePathForGlyph
MOZ_CRASH("This needs implemented");
#endif
}
return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget);
}
@ -108,7 +118,7 @@ ScaledFontMac::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBui
ScaledFontBase::CopyGlyphsToBuilder(aBuffer, aBuilder, aBackendType, aTransformHint);
return;
}
#ifdef MOZ_WIDGET_COCOA
PathBuilderCG *pathBuilderCG =
static_cast<PathBuilderCG*>(aBuilder);
// XXX: check builder type
@ -123,6 +133,10 @@ ScaledFontMac::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBui
CGPathAddPath(pathBuilderCG->mCGPath, &matrix, glyphPath);
CGPathRelease(glyphPath);
}
#else
//TODO: probably want CTFontCreatePathForGlyph
MOZ_CRASH("This needs implemented");
#endif
}
uint32_t

View File

@ -6,7 +6,13 @@
#ifndef MOZILLA_GFX_SCALEDFONTMAC_H_
#define MOZILLA_GFX_SCALEDFONTMAC_H_
#import <ApplicationServices/ApplicationServices.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"

View File

@ -9,7 +9,9 @@
#include "DataSurfaceHelpers.h"
#include "mozilla/Types.h" // for decltype
#ifdef MOZ_WIDGET_COCOA
#include "MacIOSurface.h"
#endif
#include "Tools.h"
namespace mozilla {
@ -384,6 +386,7 @@ SourceSurfaceCGBitmapContext::~SourceSurfaceCGBitmapContext()
CGImageRelease(mImage);
}
#ifdef MOZ_WIDGET_COCOA
SourceSurfaceCGIOSurfaceContext::SourceSurfaceCGIOSurfaceContext(DrawTargetCG *aDrawTarget)
{
CGContextRef cg = (CGContextRef)aDrawTarget->GetNativeSurface(NativeSurfaceType::CGCONTEXT_ACCELERATED);
@ -452,6 +455,7 @@ SourceSurfaceCGIOSurfaceContext::GetData()
{
return (unsigned char*)mData;
}
#endif
} // namespace gfx
} // namespace mozilla

View File

@ -6,11 +6,17 @@
#ifndef _MOZILLA_GFX_SOURCESURFACECG_H
#define _MOZILLA_GFX_SOURCESURFACECG_H
#ifdef MOZ_WIDGET_COCOA
#include <ApplicationServices/ApplicationServices.h>
#else
#include <CoreGraphics/CoreGraphics.h>
#endif
#include "2D.h"
#ifdef MOZ_WIDGET_COCOA
class MacIOSurface;
#endif
namespace mozilla {
namespace gfx {
@ -163,6 +169,7 @@ private:
IntSize mSize;
};
#ifdef MOZ_WIDGET_COCOA
class SourceSurfaceCGIOSurfaceContext : public SourceSurfaceCGContext
{
public:
@ -196,6 +203,7 @@ private:
IntSize mSize;
};
#endif
} // namespace gfx

View File

@ -48,10 +48,9 @@ EXPORTS.mozilla.gfx += [
'UserData.h',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'uikit'):
EXPORTS.mozilla.gfx += [
'MacIOSurface.h',
'QuartzSupport.h',
]
UNIFIED_SOURCES += [
'DrawTargetCG.cpp',
@ -160,6 +159,9 @@ SOURCES += [
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
EXPORTS.mozilla.gfx += [
'QuartzSupport.h',
]
SOURCES += [
'MacIOSurface.cpp',
'QuartzSupport.mm',