Bug 1057216 - Make DrawTargetCG hold a reference to DataSourceSurface when we're wrapping their data. r=jrmuizel

--HG--
extra : rebase_source : ad610592f69294caedcbca5d61c1644120cbec66
This commit is contained in:
Matt Woodrow 2014-08-27 10:20:18 +12:00
parent 437510eae5
commit afc9ab44bc
3 changed files with 33 additions and 2 deletions

View File

@ -215,6 +215,11 @@ DrawTargetCG::CreateSourceSurfaceFromData(unsigned char *aData,
return newSurf.forget();
}
static void releaseDataSurface(void* info, const void *data, size_t size)
{
static_cast<DataSourceSurface*>(info)->Release();
}
// This function returns a retained CGImage that needs to be released after
// use. The reason for this is that we want to either reuse an existing CGImage
// or create a new one.
@ -234,7 +239,9 @@ GetRetainedImageFromSourceSurface(SourceSurface *aSurface)
if (!data) {
MOZ_CRASH("unsupported source surface");
}
return CreateCGImage(nullptr, data->GetData(), data->GetSize(),
data->AddRef();
return CreateCGImage(releaseDataSurface, data.get(),
data->GetData(), data->GetSize(),
data->Stride(), data->GetFormat());
}
}

View File

@ -58,6 +58,22 @@ CreateCGImage(void *aInfo,
const IntSize &aSize,
int32_t aStride,
SurfaceFormat aFormat)
{
return CreateCGImage(releaseCallback,
aInfo,
aData,
aSize,
aStride,
aFormat);
}
CGImageRef
CreateCGImage(CGDataProviderReleaseDataCallback aCallback,
void *aInfo,
const void *aData,
const IntSize &aSize,
int32_t aStride,
SurfaceFormat aFormat)
{
//XXX: we should avoid creating this colorspace everytime
CGColorSpaceRef colorSpace = nullptr;
@ -97,7 +113,7 @@ CreateCGImage(void *aInfo,
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(aInfo,
aData,
bufLen,
releaseCallback);
aCallback);
CGImageRef image;
if (aFormat == SurfaceFormat::A8) {

View File

@ -15,6 +15,14 @@ class MacIOSurface;
namespace mozilla {
namespace gfx {
CGImageRef
CreateCGImage(CGDataProviderReleaseDataCallback aCallback,
void *aInfo,
const void *aData,
const IntSize &aSize,
int32_t aStride,
SurfaceFormat aFormat);
CGImageRef
CreateCGImage(void *aInfo,
const void *aData,