Bug 874369 - Use normal memory instead of Shmem when only sharing between processes. r=Bas

This commit is contained in:
Matt Woodrow
2013-05-22 15:04:12 +08:00
parent 728d7ddf50
commit 7f17192cb8
7 changed files with 72 additions and 3 deletions

View File

@@ -97,6 +97,7 @@ TextureClientShmem::SetDescriptor(const SurfaceDescriptor& aDescriptor)
NS_ASSERTION(mDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc || NS_ASSERTION(mDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc ||
mDescriptor.type() == SurfaceDescriptor::TShmem || mDescriptor.type() == SurfaceDescriptor::TShmem ||
mDescriptor.type() == SurfaceDescriptor::TMemoryImage ||
mDescriptor.type() == SurfaceDescriptor::TRGBImage, mDescriptor.type() == SurfaceDescriptor::TRGBImage,
"Invalid surface descriptor"); "Invalid surface descriptor");
} }

View File

@@ -13,6 +13,7 @@
#include "mozilla/layers/LayersSurfaces.h" #include "mozilla/layers/LayersSurfaces.h"
#include "mozilla/layers/SharedPlanarYCbCrImage.h" #include "mozilla/layers/SharedPlanarYCbCrImage.h"
#include "mozilla/layers/SharedRGBImage.h" #include "mozilla/layers/SharedRGBImage.h"
#include "nsXULAppAPI.h"
#ifdef DEBUG #ifdef DEBUG
#include "prenv.h" #include "prenv.h"
@@ -85,6 +86,16 @@ ISurfaceAllocator::AllocSurfaceDescriptorWithCaps(const gfxIntSize& aSize,
return true; return true;
} }
if (XRE_GetProcessType() == GeckoProcessType_Default) {
gfxImageFormat format =
gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
int32_t stride = gfxASurface::FormatStrideForWidth(format, aSize.width);
uint8_t *data = new uint8_t[stride * aSize.height];
*aBuffer = MemoryImage((uintptr_t)data, aSize, stride, format);
return true;
}
nsRefPtr<gfxSharedImageSurface> buffer; nsRefPtr<gfxSharedImageSurface> buffer;
if (!AllocSharedImageSurface(aSize, aContent, if (!AllocSharedImageSurface(aSize, aContent,
getter_AddRefs(buffer))) { getter_AddRefs(buffer))) {
@@ -122,6 +133,9 @@ ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)
break; break;
case SurfaceDescriptor::TSurfaceDescriptorD3D10: case SurfaceDescriptor::TSurfaceDescriptorD3D10:
break; break;
case SurfaceDescriptor::TMemoryImage:
delete [] (unsigned char *)aSurface->get_MemoryImage().data();
break;
case SurfaceDescriptor::Tnull_t: case SurfaceDescriptor::Tnull_t:
case SurfaceDescriptor::T__None: case SurfaceDescriptor::T__None:
break; break;

View File

@@ -83,6 +83,13 @@ struct RGBImage {
uint64_t owner; uint64_t owner;
}; };
struct MemoryImage {
uintptr_t data;
gfxIntSize size;
uint32_t stride;
uint32_t format;
};
union SurfaceDescriptor { union SurfaceDescriptor {
Shmem; Shmem;
SurfaceDescriptorD3D10; SurfaceDescriptorD3D10;
@@ -92,6 +99,7 @@ union SurfaceDescriptor {
RGBImage; RGBImage;
SharedTextureDescriptor; SharedTextureDescriptor;
SurfaceStreamDescriptor; SurfaceStreamDescriptor;
MemoryImage;
null_t; null_t;
}; };

View File

@@ -32,10 +32,22 @@ ISurfaceAllocator::PlatformAllocSurfaceDescriptor(const gfxIntSize& aSize,
ShadowLayerForwarder::PlatformOpenDescriptor(OpenMode aMode, ShadowLayerForwarder::PlatformOpenDescriptor(OpenMode aMode,
const SurfaceDescriptor& aSurface) const SurfaceDescriptor& aSurface)
{ {
if (SurfaceDescriptor::TShmem != aSurface.type()) { if (aSurface.type() == SurfaceDescriptor::TShmem) {
return nullptr; return gfxSharedQuartzSurface::Open(aSurface.get_Shmem());
} else if (aSurface.type() == SurfaceDescriptor::TMemoryImage) {
const MemoryImage& image = aSurface.get_MemoryImage();
gfxASurface::gfxImageFormat format
= static_cast<gfxASurface::gfxImageFormat>(image.format());
nsRefPtr<gfxASurface> surf =
new gfxQuartzSurface((unsigned char*)image.data(),
image.size(),
image.stride(),
format);
return surf.forget();
} }
return gfxSharedQuartzSurface::Open(aSurface.get_Shmem()); return nullptr;
} }
/*static*/ bool /*static*/ bool

View File

@@ -530,6 +530,16 @@ ShadowLayerForwarder::OpenDescriptor(OpenMode aMode,
rgbFormat); rgbFormat);
return surf.forget(); return surf.forget();
} }
case SurfaceDescriptor::TMemoryImage: {
const MemoryImage& image = aSurface.get_MemoryImage();
gfxASurface::gfxImageFormat format
= static_cast<gfxASurface::gfxImageFormat>(image.format());
surf = new gfxImageSurface((unsigned char *)image.data(),
image.size(),
image.stride(),
format);
return surf.forget();
}
default: default:
NS_ERROR("unexpected SurfaceDescriptor type!"); NS_ERROR("unexpected SurfaceDescriptor type!");
return nullptr; return nullptr;

View File

@@ -125,6 +125,29 @@ gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
} }
} }
gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
const gfxIntSize& aSize,
long stride,
gfxImageFormat format,
bool aForPrinting)
: mCGContext(nullptr), mSize(aSize.width, aSize.height), mForPrinting(aForPrinting)
{
if (!CheckSurfaceSize(aSize))
MakeInvalid();
cairo_surface_t *surf = cairo_quartz_surface_create_for_data
(data, (cairo_format_t) format, aSize.width, aSize.height, stride);
mCGContext = cairo_quartz_surface_get_cg_context (surf);
CGContextRetain(mCGContext);
Init(surf);
if (mSurfaceValid) {
RecordMemoryUsed(mSize.height * stride + sizeof(gfxQuartzSurface));
}
}
already_AddRefed<gfxASurface> already_AddRefed<gfxASurface>
gfxQuartzSurface::CreateSimilarSurface(gfxContentType aType, gfxQuartzSurface::CreateSimilarSurface(gfxContentType aType,
const gfxIntSize& aSize) const gfxIntSize& aSize)

View File

@@ -20,6 +20,7 @@ public:
gfxQuartzSurface(CGContextRef context, const gfxIntSize& size, bool aForPrinting = false); gfxQuartzSurface(CGContextRef context, const gfxIntSize& size, bool aForPrinting = false);
gfxQuartzSurface(cairo_surface_t *csurf, bool aForPrinting = false); gfxQuartzSurface(cairo_surface_t *csurf, bool aForPrinting = false);
gfxQuartzSurface(unsigned char *data, const gfxSize& size, long stride, gfxImageFormat format, bool aForPrinting = false); gfxQuartzSurface(unsigned char *data, const gfxSize& size, long stride, gfxImageFormat format, bool aForPrinting = false);
gfxQuartzSurface(unsigned char *data, const gfxIntSize& size, long stride, gfxImageFormat format, bool aForPrinting = false);
virtual ~gfxQuartzSurface(); virtual ~gfxQuartzSurface();