mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 724666 - Part 2: Add CGIOSurfaceContext to azure. r=jmuizelaar
This commit is contained in:
parent
d38270d473
commit
be1e81f90f
@ -8,6 +8,7 @@
|
||||
#include "ScaledFontMac.h"
|
||||
#include "Tools.h"
|
||||
#include <vector>
|
||||
#include "QuartzSupport.h"
|
||||
|
||||
//CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode);
|
||||
|
||||
@ -92,11 +93,27 @@ DrawTargetCG::~DrawTargetCG()
|
||||
free(mData);
|
||||
}
|
||||
|
||||
BackendType
|
||||
DrawTargetCG::GetType() const
|
||||
{
|
||||
// It may be worth spliting Bitmap and IOSurface DrawTarget
|
||||
// into seperate classes.
|
||||
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
|
||||
return BACKEND_COREGRAPHICS_ACCELERATED;
|
||||
} else {
|
||||
return BACKEND_COREGRAPHICS;
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryRef<SourceSurface>
|
||||
DrawTargetCG::Snapshot()
|
||||
{
|
||||
if (!mSnapshot) {
|
||||
mSnapshot = new SourceSurfaceCGBitmapContext(this);
|
||||
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
|
||||
return new SourceSurfaceCGIOSurfaceContext(this);
|
||||
} else {
|
||||
mSnapshot = new SourceSurfaceCGBitmapContext(this);
|
||||
}
|
||||
}
|
||||
|
||||
return mSnapshot;
|
||||
@ -108,7 +125,7 @@ DrawTargetCG::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aForma
|
||||
// XXX: in thebes we use CGLayers to do this kind of thing. It probably makes sense
|
||||
// to add that in somehow, but at a higher level
|
||||
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
|
||||
if (newTarget->Init(aSize, aFormat)) {
|
||||
if (newTarget->Init(GetType(), aSize, aFormat)) {
|
||||
return newTarget;
|
||||
} else {
|
||||
return NULL;
|
||||
@ -136,7 +153,7 @@ GetImageFromSourceSurface(SourceSurface *aSurface)
|
||||
if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE)
|
||||
return static_cast<SourceSurfaceCG*>(aSurface)->GetImage();
|
||||
else if (aSurface->GetType() == SURFACE_COREGRAPHICS_CGCONTEXT)
|
||||
return static_cast<SourceSurfaceCGBitmapContext*>(aSurface)->GetImage();
|
||||
return static_cast<SourceSurfaceCGContext*>(aSurface)->GetImage();
|
||||
else if (aSurface->GetType() == SURFACE_DATA)
|
||||
return static_cast<DataSourceSurfaceCG*>(aSurface)->GetImage();
|
||||
abort();
|
||||
@ -277,6 +294,8 @@ class GradientStopsCG : public GradientStops
|
||||
virtual ~GradientStopsCG() {
|
||||
CGGradientRelease(mGradient);
|
||||
}
|
||||
// Will always report BACKEND_COREGRAPHICS, but it is compatible
|
||||
// with BACKEND_COREGRAPHICS_ACCELERATED
|
||||
BackendType GetBackendType() const { return BACKEND_COREGRAPHICS; }
|
||||
CGGradientRef mGradient;
|
||||
};
|
||||
@ -799,7 +818,8 @@ DrawTargetCG::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
|
||||
}
|
||||
|
||||
bool
|
||||
DrawTargetCG::Init(unsigned char* aData,
|
||||
DrawTargetCG::Init(BackendType aType,
|
||||
unsigned char* aData,
|
||||
const IntSize &aSize,
|
||||
int32_t aStride,
|
||||
SurfaceFormat aFormat)
|
||||
@ -821,7 +841,7 @@ DrawTargetCG::Init(unsigned char* aData,
|
||||
//XXX: we'd be better off reusing the Colorspace across draw targets
|
||||
mColorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
if (aData == NULL) {
|
||||
if (aData == NULL && aType != BACKEND_COREGRAPHICS_ACCELERATED) {
|
||||
// XXX: Currently, Init implicitly clears, that can often be a waste of time
|
||||
mData = calloc(aSize.height * aStride, 1);
|
||||
aData = static_cast<unsigned char*>(mData);
|
||||
@ -832,22 +852,30 @@ DrawTargetCG::Init(unsigned char* aData,
|
||||
}
|
||||
|
||||
mSize = aSize;
|
||||
|
||||
int bitsPerComponent = 8;
|
||||
|
||||
CGBitmapInfo bitinfo;
|
||||
if (aType == BACKEND_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
|
||||
mData = NULL;
|
||||
}
|
||||
|
||||
bitinfo = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
|
||||
if (!mCg || aType == BACKEND_COREGRAPHICS) {
|
||||
int bitsPerComponent = 8;
|
||||
|
||||
// XXX: what should we do if this fails?
|
||||
mCg = CGBitmapContextCreate (aData,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
bitsPerComponent,
|
||||
aStride,
|
||||
mColorSpace,
|
||||
bitinfo);
|
||||
CGBitmapInfo bitinfo;
|
||||
bitinfo = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
|
||||
|
||||
// XXX: what should we do if this fails?
|
||||
mCg = CGBitmapContextCreate (aData,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
bitsPerComponent,
|
||||
aStride,
|
||||
mColorSpace,
|
||||
bitinfo);
|
||||
}
|
||||
|
||||
assert(mCg);
|
||||
// CGContext's default to have the origin at the bottom left
|
||||
@ -866,9 +894,22 @@ DrawTargetCG::Init(unsigned char* aData,
|
||||
// XXX: set correct format
|
||||
mFormat = FORMAT_B8G8R8A8;
|
||||
|
||||
if (aType == BACKEND_COREGRAPHICS_ACCELERATED) {
|
||||
// The bitmap backend uses callac to clear, we can't do that without
|
||||
// reading back the surface. This should trigger something equivilent
|
||||
// to glClear.
|
||||
ClearRect(Rect(0, 0, mSize.width, mSize.height));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetCG::Flush()
|
||||
{
|
||||
CGContextFlush(mCg);
|
||||
}
|
||||
|
||||
bool
|
||||
DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
|
||||
{
|
||||
@ -905,12 +946,12 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize)
|
||||
}
|
||||
|
||||
bool
|
||||
DrawTargetCG::Init(const IntSize &aSize, SurfaceFormat &aFormat)
|
||||
DrawTargetCG::Init(BackendType aType, const IntSize &aSize, SurfaceFormat &aFormat)
|
||||
{
|
||||
int stride = aSize.width*4;
|
||||
|
||||
// Calling Init with aData == NULL will allocate.
|
||||
return Init(NULL, aSize, stride, aFormat);
|
||||
return Init(aType, NULL, aSize, stride, aFormat);
|
||||
}
|
||||
|
||||
TemporaryRef<PathBuilder>
|
||||
@ -923,7 +964,8 @@ DrawTargetCG::CreatePathBuilder(FillRule aFillRule) const
|
||||
void*
|
||||
DrawTargetCG::GetNativeSurface(NativeSurfaceType aType)
|
||||
{
|
||||
if (aType == NATIVE_SURFACE_CGCONTEXT) {
|
||||
if (aType == NATIVE_SURFACE_CGCONTEXT && GetContextType(mCg) == CG_CONTEXT_TYPE_BITMAP ||
|
||||
aType == NATIVE_SURFACE_CGCONTEXT_ACCELERATED && GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
|
||||
return mCg;
|
||||
} else {
|
||||
return NULL;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Rect.h"
|
||||
#include "PathCG.h"
|
||||
#include "SourceSurfaceCG.h"
|
||||
#include "GLDefs.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
@ -87,7 +88,7 @@ public:
|
||||
DrawTargetCG();
|
||||
virtual ~DrawTargetCG();
|
||||
|
||||
virtual BackendType GetType() const { return BACKEND_COREGRAPHICS; }
|
||||
virtual BackendType GetType() const;
|
||||
virtual TemporaryRef<SourceSurface> Snapshot();
|
||||
|
||||
virtual void DrawSurface(SourceSurface *aSurface,
|
||||
@ -102,12 +103,12 @@ public:
|
||||
|
||||
|
||||
//XXX: why do we take a reference to SurfaceFormat?
|
||||
bool Init(const IntSize &aSize, SurfaceFormat&);
|
||||
bool Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
|
||||
bool Init(BackendType aType, const IntSize &aSize, SurfaceFormat&);
|
||||
bool Init(BackendType aType, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
|
||||
bool Init(CGContextRef cgContext, const IntSize &aSize);
|
||||
|
||||
|
||||
virtual void Flush() {}
|
||||
// Flush if using IOSurface context
|
||||
virtual void Flush();
|
||||
|
||||
virtual void DrawSurfaceWithShadow(SourceSurface *, const Point &, const Color &, const Point &, Float, CompositionOp);
|
||||
virtual void ClearRect(const Rect &);
|
||||
@ -150,6 +151,8 @@ private:
|
||||
CGColorSpaceRef mColorSpace;
|
||||
CGContextRef mCg;
|
||||
|
||||
GLuint mIOSurfaceTexture;
|
||||
|
||||
/**
|
||||
* A pointer to the image buffer if the buffer is owned by this class (set to
|
||||
* NULL otherwise).
|
||||
@ -162,7 +165,7 @@ private:
|
||||
|
||||
SurfaceFormat mFormat;
|
||||
|
||||
RefPtr<SourceSurfaceCGBitmapContext> mSnapshot;
|
||||
RefPtr<SourceSurfaceCGContext> mSnapshot;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -173,10 +173,11 @@ Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFor
|
||||
}
|
||||
#elif defined XP_MACOSX
|
||||
case BACKEND_COREGRAPHICS:
|
||||
case BACKEND_COREGRAPHICS_ACCELERATED:
|
||||
{
|
||||
RefPtr<DrawTargetCG> newTarget;
|
||||
newTarget = new DrawTargetCG();
|
||||
if (newTarget->Init(aSize, aFormat)) {
|
||||
if (newTarget->Init(aBackend, aSize, aFormat)) {
|
||||
return newTarget;
|
||||
}
|
||||
break;
|
||||
@ -224,7 +225,7 @@ Factory::CreateDrawTargetForData(BackendType aBackend,
|
||||
case BACKEND_COREGRAPHICS:
|
||||
{
|
||||
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
|
||||
if (newTarget->Init(aData, aSize, aStride, aFormat))
|
||||
if (newTarget->Init(aBackend, aData, aSize, aStride, aFormat))
|
||||
return newTarget;
|
||||
break;
|
||||
}
|
||||
|
@ -52,6 +52,15 @@ CPPSRCS += \
|
||||
DrawTargetCG.cpp \
|
||||
PathCG.cpp \
|
||||
$(NULL)
|
||||
|
||||
CMMSRCS = \
|
||||
QuartzSupport.mm \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_mozilla/gfx += \
|
||||
QuartzSupport.h \
|
||||
MacIOSurface.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
DEFINES += -DMOZ_GFX -DUSE_CAIRO -DGFX2D_INTERNAL
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
}
|
||||
virtual ~PathCG() { CGPathRelease(mPath); }
|
||||
|
||||
// Paths will always return BACKEND_COREGRAPHICS, but note that they
|
||||
// are compatible with BACKEND_COREGRAPHICS_ACCELERATED backend.
|
||||
virtual BackendType GetBackendType() const { return BACKEND_COREGRAPHICS; }
|
||||
|
||||
virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FILL_WINDING) const;
|
||||
|
@ -56,7 +56,7 @@ SkTypeface* ScaledFontMac::GetSkTypeface()
|
||||
TemporaryRef<Path>
|
||||
ScaledFontMac::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
|
||||
{
|
||||
if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
|
||||
if (aTarget->GetType() == BACKEND_COREGRAPHICS || aTarget->GetType() == BACKEND_COREGRAPHICS_ACCELERATED) {
|
||||
CGMutablePathRef path = CGPathCreateMutable();
|
||||
|
||||
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "SourceSurfaceCG.h"
|
||||
#include "DrawTargetCG.h"
|
||||
|
||||
#include "QuartzSupport.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
@ -285,6 +287,8 @@ SourceSurfaceCGBitmapContext::SourceSurfaceCGBitmapContext(DrawTargetCG *aDrawTa
|
||||
{
|
||||
mDrawTarget = aDrawTarget;
|
||||
mCg = (CGContextRef)aDrawTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT);
|
||||
if (!mCg)
|
||||
abort();
|
||||
|
||||
mSize.width = CGBitmapContextGetWidth(mCg);
|
||||
mSize.height = CGBitmapContextGetHeight(mCg);
|
||||
@ -296,7 +300,7 @@ SourceSurfaceCGBitmapContext::SourceSurfaceCGBitmapContext(DrawTargetCG *aDrawTa
|
||||
|
||||
void SourceSurfaceCGBitmapContext::EnsureImage() const
|
||||
{
|
||||
// Instaed of using CGBitmapContextCreateImage we create
|
||||
// Instead of using CGBitmapContextCreateImage we create
|
||||
// a CGImage around the data associated with the CGBitmapContext
|
||||
// we do this to avoid the vm_copy that CGBitmapContextCreateImage.
|
||||
// vm_copy tends to cause all sorts of unexpected performance problems
|
||||
@ -326,6 +330,8 @@ void SourceSurfaceCGBitmapContext::EnsureImage() const
|
||||
info = mData;
|
||||
}
|
||||
|
||||
if (!mData) abort();
|
||||
|
||||
dataProvider = CGDataProviderCreateWithData (info,
|
||||
mData,
|
||||
mSize.height * mStride,
|
||||
@ -389,5 +395,102 @@ SourceSurfaceCGBitmapContext::~SourceSurfaceCGBitmapContext()
|
||||
CGImageRelease(mImage);
|
||||
}
|
||||
|
||||
SourceSurfaceCGIOSurfaceContext::SourceSurfaceCGIOSurfaceContext(DrawTargetCG *aDrawTarget)
|
||||
{
|
||||
CGContextRef cg = (CGContextRef)aDrawTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT_ACCELERATED);
|
||||
|
||||
RefPtr<MacIOSurface> surf = MacIOSurface::IOSurfaceContextGetSurface(cg);
|
||||
|
||||
mSize.width = surf->GetWidth();
|
||||
mSize.height = surf->GetHeight();
|
||||
|
||||
// TODO use CreateImageFromIOSurfaceContext instead of reading back the surface
|
||||
//mImage = MacIOSurface::CreateImageFromIOSurfaceContext(cg);
|
||||
mImage = NULL;
|
||||
|
||||
aDrawTarget->Flush();
|
||||
surf->Lock();
|
||||
size_t bytesPerRow = surf->GetBytesPerRow();
|
||||
size_t ioHeight = surf->GetHeight();
|
||||
void* ioData = surf->GetBaseAddress();
|
||||
// XXX If the width is much less then the stride maybe
|
||||
// we should repack the image?
|
||||
mData = malloc(ioHeight*bytesPerRow);
|
||||
memcpy(mData, ioData, ioHeight*(bytesPerRow));
|
||||
mStride = bytesPerRow;
|
||||
surf->Unlock();
|
||||
}
|
||||
|
||||
void SourceSurfaceCGIOSurfaceContext::EnsureImage() const
|
||||
{
|
||||
// TODO Use CreateImageFromIOSurfaceContext and remove this
|
||||
|
||||
// Instead of using CGBitmapContextCreateImage we create
|
||||
// a CGImage around the data associated with the CGBitmapContext
|
||||
// we do this to avoid the vm_copy that CGBitmapContextCreateImage.
|
||||
// vm_copy tends to cause all sorts of unexpected performance problems
|
||||
// because of the mm tricks that vm_copy does. Using a regular
|
||||
// memcpy when the bitmap context is modified gives us more predictable
|
||||
// performance characteristics.
|
||||
if (!mImage) {
|
||||
//XXX: we should avoid creating this colorspace everytime
|
||||
CGColorSpaceRef colorSpace = NULL;
|
||||
CGBitmapInfo bitinfo = 0;
|
||||
CGDataProviderRef dataProvider = NULL;
|
||||
int bitsPerComponent = 8;
|
||||
int bitsPerPixel = 32;
|
||||
|
||||
colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
|
||||
|
||||
void *info = mData;
|
||||
|
||||
dataProvider = CGDataProviderCreateWithData (info,
|
||||
mData,
|
||||
mSize.height * mStride,
|
||||
releaseCallback);
|
||||
|
||||
mImage = CGImageCreate (mSize.width, mSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
mStride,
|
||||
colorSpace,
|
||||
bitinfo,
|
||||
dataProvider,
|
||||
NULL,
|
||||
true,
|
||||
kCGRenderingIntentDefault);
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease (colorSpace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IntSize
|
||||
SourceSurfaceCGIOSurfaceContext::GetSize() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void
|
||||
SourceSurfaceCGIOSurfaceContext::DrawTargetWillChange()
|
||||
{
|
||||
}
|
||||
|
||||
SourceSurfaceCGIOSurfaceContext::~SourceSurfaceCGIOSurfaceContext()
|
||||
{
|
||||
if (mImage)
|
||||
CGImageRelease(mImage);
|
||||
else
|
||||
free(mData);
|
||||
}
|
||||
|
||||
unsigned char*
|
||||
SourceSurfaceCGIOSurfaceContext::GetData()
|
||||
{
|
||||
return (unsigned char*)mData;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "2D.h"
|
||||
|
||||
class MacIOSurface;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
@ -75,7 +77,14 @@ private:
|
||||
* for now we just store it in mFormat */
|
||||
};
|
||||
|
||||
class SourceSurfaceCGBitmapContext : public DataSourceSurface
|
||||
class SourceSurfaceCGContext : public DataSourceSurface
|
||||
{
|
||||
public:
|
||||
virtual void DrawTargetWillChange() = 0;
|
||||
virtual CGImageRef GetImage() = 0;
|
||||
};
|
||||
|
||||
class SourceSurfaceCGBitmapContext : public SourceSurfaceCGContext
|
||||
{
|
||||
public:
|
||||
SourceSurfaceCGBitmapContext(DrawTargetCG *);
|
||||
@ -94,7 +103,7 @@ public:
|
||||
private:
|
||||
//XXX: do the other backends friend their DrawTarget?
|
||||
friend class DrawTargetCG;
|
||||
void DrawTargetWillChange();
|
||||
virtual void DrawTargetWillChange();
|
||||
void EnsureImage() const;
|
||||
|
||||
// We hold a weak reference to these two objects.
|
||||
@ -112,6 +121,37 @@ private:
|
||||
IntSize mSize;
|
||||
};
|
||||
|
||||
class SourceSurfaceCGIOSurfaceContext : public SourceSurfaceCGContext
|
||||
{
|
||||
public:
|
||||
SourceSurfaceCGIOSurfaceContext(DrawTargetCG *);
|
||||
~SourceSurfaceCGIOSurfaceContext();
|
||||
|
||||
virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_CGCONTEXT; }
|
||||
virtual IntSize GetSize() const;
|
||||
virtual SurfaceFormat GetFormat() const { return FORMAT_B8G8R8A8; }
|
||||
|
||||
CGImageRef GetImage() { EnsureImage(); return mImage; }
|
||||
|
||||
virtual unsigned char *GetData();
|
||||
|
||||
virtual int32_t Stride() { return mStride; }
|
||||
|
||||
private:
|
||||
//XXX: do the other backends friend their DrawTarget?
|
||||
friend class DrawTargetCG;
|
||||
virtual void DrawTargetWillChange();
|
||||
void EnsureImage() const;
|
||||
|
||||
mutable CGImageRef mImage;
|
||||
MacIOSurface* mIOSurface;
|
||||
|
||||
void *mData;
|
||||
int32_t mStride;
|
||||
|
||||
IntSize mSize;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ enum BackendType
|
||||
BACKEND_NONE = 0,
|
||||
BACKEND_DIRECT2D,
|
||||
BACKEND_COREGRAPHICS,
|
||||
BACKEND_COREGRAPHICS_ACCELERATED,
|
||||
BACKEND_CAIRO,
|
||||
BACKEND_SKIA
|
||||
};
|
||||
@ -59,7 +60,8 @@ enum NativeSurfaceType
|
||||
{
|
||||
NATIVE_SURFACE_D3D10_TEXTURE,
|
||||
NATIVE_SURFACE_CAIRO_SURFACE,
|
||||
NATIVE_SURFACE_CGCONTEXT
|
||||
NATIVE_SURFACE_CGCONTEXT,
|
||||
NATIVE_SURFACE_CGCONTEXT_ACCELERATED
|
||||
};
|
||||
|
||||
enum NativeFontType
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "mozilla/layers/ImageContainerChild.h"
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
#include "nsCoreAnimationSupport.h"
|
||||
#include "mozilla/gfx/QuartzSupport.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
@ -26,6 +26,8 @@
|
||||
#endif
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
using mozilla::gfx::DataSourceSurface;
|
||||
using mozilla::gfx::SourceSurface;
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
@ -494,14 +496,31 @@ PlanarYCbCrImage::GetAsSurface()
|
||||
void
|
||||
MacIOSurfaceImage::SetData(const Data& aData)
|
||||
{
|
||||
mIOSurface = nsIOSurface::LookupSurface(aData.mIOSurface->GetIOSurfaceID());
|
||||
mIOSurface = MacIOSurface::LookupSurface(aData.mIOSurface->GetIOSurfaceID());
|
||||
mSize = gfxIntSize(mIOSurface->GetWidth(), mIOSurface->GetHeight());
|
||||
}
|
||||
|
||||
already_AddRefed<gfxASurface>
|
||||
MacIOSurfaceImage::GetAsSurface()
|
||||
{
|
||||
return mIOSurface->GetAsSurface();
|
||||
mIOSurface->Lock();
|
||||
size_t bytesPerRow = mIOSurface->GetBytesPerRow();
|
||||
size_t ioWidth = mIOSurface->GetWidth();
|
||||
size_t ioHeight = mIOSurface->GetHeight();
|
||||
|
||||
unsigned char* ioData = (unsigned char*)mIOSurface->GetBaseAddress();
|
||||
|
||||
nsRefPtr<gfxImageSurface> imgSurface =
|
||||
new gfxImageSurface(gfxIntSize(ioWidth, ioHeight), gfxASurface::ImageFormatARGB32);
|
||||
|
||||
for (int i = 0; i < ioHeight; i++) {
|
||||
memcpy(imgSurface->Data() + i * imgSurface->Stride(),
|
||||
ioData + i * bytesPerRow, ioWidth * 4);
|
||||
}
|
||||
|
||||
mIOSurface->Unlock();
|
||||
|
||||
return imgSurface.forget();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -117,6 +117,8 @@ BasicCanvasLayer::UpdateSurface(gfxASurface* aDestSurface, Layer* aMaskLayer)
|
||||
{
|
||||
if (mDrawTarget) {
|
||||
mDrawTarget->Flush();
|
||||
// TODO Fix me before turning accelerated quartz canvas by default
|
||||
//mSurface = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mDrawTarget);
|
||||
}
|
||||
|
||||
if (!mGLContext && aDestSurface) {
|
||||
|
@ -124,6 +124,43 @@ CanvasLayerOGL::Initialize(const Data& aData)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
static GLuint
|
||||
MakeIOSurfaceTexture(void* aCGIOSurfaceContext, mozilla::gl::GLContext* aGL)
|
||||
{
|
||||
GLuint ioSurfaceTexture;
|
||||
|
||||
aGL->fGenTextures(1, &ioSurfaceTexture);
|
||||
|
||||
aGL->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, ioSurfaceTexture);
|
||||
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
RefPtr<MacIOSurface> ioSurface = MacIOSurface::IOSurfaceContextGetSurface((CGContextRef)aCGIOSurfaceContext);
|
||||
void *nativeCtx = aGL->GetNativeData(GLContext::NativeGLContext);
|
||||
|
||||
ioSurface->CGLTexImageIOSurface2D(nativeCtx,
|
||||
LOCAL_GL_RGBA, LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV, 0);
|
||||
|
||||
aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
|
||||
return ioSurfaceTexture;
|
||||
}
|
||||
|
||||
#else
|
||||
static GLuint
|
||||
MakeIOSurfaceTexture(void* aCGIOSurfaceContext, mozilla::gl::GLContext* aGL)
|
||||
{
|
||||
NS_RUNTIMEABORT("Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Following UpdateSurface(), mTexture on context this->gl() should contain the data we want,
|
||||
* unless mDelayedUpdates is true because of a too-large surface.
|
||||
@ -203,7 +240,7 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
|
||||
if (mTexture) {
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
gl()->fBindTexture(mTextureTarget, mTexture);
|
||||
}
|
||||
|
||||
ShaderProgramOGL *program = nullptr;
|
||||
@ -244,6 +281,10 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
|
||||
gl()->ApplyFilterToBoundTexture(mFilter);
|
||||
|
||||
program->Activate();
|
||||
if (mLayerProgram == gl::RGBARectLayerProgramType) {
|
||||
// This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
|
||||
program->SetTexCoordMultiplier(mDrawTarget->GetSize().width, mDrawTarget->GetSize().height);
|
||||
}
|
||||
program->SetLayerQuadRect(drawRect);
|
||||
program->SetLayerTransform(GetEffectiveTransform());
|
||||
program->SetLayerOpacity(GetEffectiveOpacity());
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
: CanvasLayer(aManager, NULL),
|
||||
LayerOGL(aManager),
|
||||
mTexture(0),
|
||||
mTextureTarget(LOCAL_GL_TEXTURE_2D),
|
||||
mDelayedUpdates(false)
|
||||
#if defined(MOZ_WIDGET_GTK2) && !defined(MOZ_PLATFORM_MAEMO)
|
||||
,mPixmap(0)
|
||||
@ -54,6 +55,7 @@ protected:
|
||||
RefPtr<gfx::DrawTarget> mDrawTarget;
|
||||
|
||||
GLuint mTexture;
|
||||
GLenum mTextureTarget;
|
||||
|
||||
bool mDelayedUpdates;
|
||||
bool mGLBufferIsPremultiplied;
|
||||
|
@ -118,6 +118,8 @@ GetBackendName(mozilla::gfx::BackendType aBackend)
|
||||
switch (aBackend) {
|
||||
case mozilla::gfx::BACKEND_DIRECT2D:
|
||||
return "direct2d";
|
||||
case mozilla::gfx::BACKEND_COREGRAPHICS_ACCELERATED:
|
||||
return "quartz accelerated";
|
||||
case mozilla::gfx::BACKEND_COREGRAPHICS:
|
||||
return "quartz";
|
||||
case mozilla::gfx::BACKEND_CAIRO:
|
||||
|
@ -379,7 +379,17 @@ gfxPlatformMac::ReadAntiAliasingThreshold()
|
||||
already_AddRefed<gfxASurface>
|
||||
gfxPlatformMac::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
|
||||
{
|
||||
if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
|
||||
if (aTarget->GetType() == BACKEND_COREGRAPHICS_ACCELERATED) {
|
||||
RefPtr<SourceSurface> source = aTarget->Snapshot();
|
||||
RefPtr<DataSourceSurface> sourceData = source->GetDataSurface();
|
||||
unsigned char* data = sourceData->GetData();
|
||||
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(data, ThebesIntSize(sourceData->GetSize()), sourceData->Stride(),
|
||||
gfxImageSurface::ImageFormatARGB32);
|
||||
// We could fix this by telling gfxImageSurface it owns data.
|
||||
nsRefPtr<gfxImageSurface> cpy = new gfxImageSurface(ThebesIntSize(sourceData->GetSize()), gfxImageSurface::ImageFormatARGB32);
|
||||
cpy->CopyFrom(surf);
|
||||
return cpy.forget();
|
||||
} else if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
|
||||
CGContextRef cg = static_cast<CGContextRef>(aTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
|
||||
|
||||
//XXX: it would be nice to have an implicit conversion from IntSize to gfxIntSize
|
||||
@ -395,6 +405,12 @@ gfxPlatformMac::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
|
||||
return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
|
||||
}
|
||||
|
||||
bool
|
||||
gfxPlatformMac::UseAcceleratedCanvas()
|
||||
{
|
||||
// Lion or later is required
|
||||
return false && OSXVersion() >= 0x1070 && Preferences::GetBool("gfx.canvas.azure.accelerated", false);
|
||||
}
|
||||
|
||||
qcms_profile *
|
||||
gfxPlatformMac::GetPlatformCMSOutputProfile()
|
||||
|
@ -72,9 +72,11 @@ public:
|
||||
nsTArray<const char*>& aFontList);
|
||||
|
||||
// Returns the OS X version as returned from Gestalt(gestaltSystemVersion, ...)
|
||||
// Ex: Mac OS X 10.4.x ==> 0x104x
|
||||
// Ex: Mac OS X 10.4.x ==> 0x104x
|
||||
PRInt32 OSXVersion();
|
||||
|
||||
bool UseAcceleratedCanvas();
|
||||
|
||||
// lower threshold on font anti-aliasing
|
||||
PRUint32 GetAntiAliasingThreshold() { return mFontAntiAliasingThreshold; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user