mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 839383 - part 2 - factor out CGImageRef creation code in SourceSurfaceCG.cpp; r=jrmuizel
This commit is contained in:
parent
9612c3dcdb
commit
155fdc5155
@ -79,8 +79,9 @@ AssignSurfaceParametersFromFormat(SurfaceFormat aFormat,
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
SourceSurfaceCG::InitFromData(unsigned char *aData,
|
||||
static CGImageRef
|
||||
CreateCGImage(void *aInfo,
|
||||
const void *aData,
|
||||
const IntSize &aSize,
|
||||
int32_t aStride,
|
||||
SurfaceFormat aFormat)
|
||||
@ -88,37 +89,29 @@ SourceSurfaceCG::InitFromData(unsigned char *aData,
|
||||
//XXX: we should avoid creating this colorspace everytime
|
||||
CGColorSpaceRef colorSpace = nullptr;
|
||||
CGBitmapInfo bitinfo = 0;
|
||||
CGDataProviderRef dataProvider = nullptr;
|
||||
int bitsPerComponent = 0;
|
||||
int bitsPerPixel = 0;
|
||||
|
||||
assert(aSize.width >= 0 && aSize.height >= 0);
|
||||
|
||||
AssignSurfaceParametersFromFormat(aFormat, colorSpace, bitinfo,
|
||||
bitsPerComponent, bitsPerPixel);
|
||||
|
||||
void *data = malloc(aStride * aSize.height);
|
||||
memcpy(data, aData, aStride * aSize.height);
|
||||
|
||||
mFormat = aFormat;
|
||||
|
||||
dataProvider = CGDataProviderCreateWithData (data,
|
||||
data,
|
||||
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(aInfo,
|
||||
aData,
|
||||
aSize.height * aStride,
|
||||
releaseCallback);
|
||||
|
||||
CGImageRef image;
|
||||
if (aFormat == FORMAT_A8) {
|
||||
CGFloat decode[] = {1.0, 0.0};
|
||||
mImage = CGImageMaskCreate (aSize.width, aSize.height,
|
||||
image = CGImageMaskCreate (aSize.width, aSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
aStride,
|
||||
dataProvider,
|
||||
decode,
|
||||
true);
|
||||
|
||||
} else {
|
||||
mImage = CGImageCreate (aSize.width, aSize.height,
|
||||
image = CGImageCreate (aSize.width, aSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
aStride,
|
||||
@ -131,7 +124,24 @@ SourceSurfaceCG::InitFromData(unsigned char *aData,
|
||||
}
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease (colorSpace);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
bool
|
||||
SourceSurfaceCG::InitFromData(unsigned char *aData,
|
||||
const IntSize &aSize,
|
||||
int32_t aStride,
|
||||
SurfaceFormat aFormat)
|
||||
{
|
||||
assert(aSize.width >= 0 && aSize.height >= 0);
|
||||
|
||||
void *data = malloc(aStride * aSize.height);
|
||||
memcpy(data, aData, aStride * aSize.height);
|
||||
|
||||
mFormat = aFormat;
|
||||
mImage = CreateCGImage(data, data, aSize, aStride, aFormat);
|
||||
|
||||
return mImage != nullptr;
|
||||
}
|
||||
@ -158,51 +168,10 @@ DataSourceSurfaceCG::InitFromData(unsigned char *aData,
|
||||
int32_t aStride,
|
||||
SurfaceFormat aFormat)
|
||||
{
|
||||
//XXX: we should avoid creating this colorspace everytime
|
||||
CGColorSpaceRef colorSpace = nullptr;
|
||||
CGBitmapInfo bitinfo = 0;
|
||||
CGDataProviderRef dataProvider = nullptr;
|
||||
int bitsPerComponent = 0;
|
||||
int bitsPerPixel = 0;
|
||||
|
||||
AssignSurfaceParametersFromFormat(aFormat, colorSpace, bitinfo,
|
||||
bitsPerComponent, bitsPerPixel);
|
||||
|
||||
void *data = malloc(aStride * aSize.height);
|
||||
memcpy(data, aData, aStride * aSize.height);
|
||||
|
||||
//mFormat = aFormat;
|
||||
|
||||
dataProvider = CGDataProviderCreateWithData (data,
|
||||
data,
|
||||
aSize.height * aStride,
|
||||
releaseCallback);
|
||||
|
||||
if (aFormat == FORMAT_A8) {
|
||||
CGFloat decode[] = {1.0, 0.0};
|
||||
mImage = CGImageMaskCreate (aSize.width, aSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
aStride,
|
||||
dataProvider,
|
||||
decode,
|
||||
true);
|
||||
|
||||
} else {
|
||||
mImage = CGImageCreate (aSize.width, aSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
aStride,
|
||||
colorSpace,
|
||||
bitinfo,
|
||||
dataProvider,
|
||||
nullptr,
|
||||
true,
|
||||
kCGRenderingIntentDefault);
|
||||
}
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease (colorSpace);
|
||||
mImage = CreateCGImage(data, data, aSize, aStride, aFormat);
|
||||
|
||||
return mImage;
|
||||
}
|
||||
@ -305,16 +274,6 @@ void SourceSurfaceCGBitmapContext::EnsureImage() const
|
||||
// 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 = nullptr;
|
||||
CGBitmapInfo bitinfo = 0;
|
||||
CGDataProviderRef dataProvider = nullptr;
|
||||
int bitsPerComponent = 8;
|
||||
int bitsPerPixel = 32;
|
||||
|
||||
colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
|
||||
|
||||
void *info;
|
||||
if (mCg) {
|
||||
// if we have an mCg than it owns the data
|
||||
@ -329,24 +288,7 @@ void SourceSurfaceCGBitmapContext::EnsureImage() const
|
||||
|
||||
if (!mData) abort();
|
||||
|
||||
dataProvider = CGDataProviderCreateWithData (info,
|
||||
mData,
|
||||
mSize.height * mStride,
|
||||
releaseCallback);
|
||||
|
||||
mImage = CGImageCreate (mSize.width, mSize.height,
|
||||
bitsPerComponent,
|
||||
bitsPerPixel,
|
||||
mStride,
|
||||
colorSpace,
|
||||
bitinfo,
|
||||
dataProvider,
|
||||
nullptr,
|
||||
true,
|
||||
kCGRenderingIntentDefault);
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease (colorSpace);
|
||||
mImage = CreateCGImage(info, mData, mSize, mStride, FORMAT_B8G8R8A8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,36 +372,7 @@ void SourceSurfaceCGIOSurfaceContext::EnsureImage() const
|
||||
// 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 = nullptr;
|
||||
CGBitmapInfo bitinfo = 0;
|
||||
CGDataProviderRef dataProvider = nullptr;
|
||||
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,
|
||||
nullptr,
|
||||
true,
|
||||
kCGRenderingIntentDefault);
|
||||
|
||||
CGDataProviderRelease(dataProvider);
|
||||
CGColorSpaceRelease (colorSpace);
|
||||
mImage = CreateCGImage(mData, mData, mSize, mStride, FORMAT_B8G8R8A8);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user