Bug 964442 - Make CreateImage just take a plain format parameter - r=jrmuizel

This commit is contained in:
Benoit Jacob 2014-01-30 17:58:51 -05:00
parent 3ee7a2d643
commit 4703621d85
20 changed files with 74 additions and 125 deletions

View File

@ -72,6 +72,7 @@ ValidatePlane(const VideoData::YCbCrBuffer::Plane& aPlane)
aPlane.mStride > 0;
}
#if 0
static bool
IsYV12Format(const VideoData::YCbCrBuffer::Plane& aYPlane,
const VideoData::YCbCrBuffer::Plane& aCbPlane,
@ -85,6 +86,7 @@ IsYV12Format(const VideoData::YCbCrBuffer::Plane& aYPlane,
aCbPlane.mWidth == aCrPlane.mWidth &&
aCbPlane.mHeight == aCrPlane.mHeight;
}
#endif
bool
VideoInfo::ValidateVideoRegion(const nsIntSize& aFrame,
@ -223,11 +225,13 @@ VideoData* VideoData::Create(VideoInfo& aInfo,
if (!aImage) {
// Currently our decoder only knows how to output to ImageFormat::PLANAR_YCBCR
// format.
ImageFormat format[2] = {ImageFormat::PLANAR_YCBCR, ImageFormat::GRALLOC_PLANAR_YCBCR};
#if 0
if (IsYV12Format(Y, Cb, Cr)) {
v->mImage = aContainer->CreateImage(format, 2);
} else {
v->mImage = aContainer->CreateImage(format, 1);
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
}
#endif
if (!v->mImage) {
v->mImage = aContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
}
} else {
v->mImage = aImage;
@ -363,8 +367,7 @@ VideoData* VideoData::Create(VideoInfo& aInfo,
aTimecode,
aInfo.mDisplay));
ImageFormat format = ImageFormat::GRALLOC_PLANAR_YCBCR;
v->mImage = aContainer->CreateImage(&format, 1);
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
if (!v->mImage) {
return nullptr;
}

View File

@ -955,9 +955,8 @@ MediaStreamGraphImpl::PlayVideo(MediaStream* aStream)
VideoFrameContainer* output = aStream->mVideoOutputs[i];
if (frame->GetForceBlack()) {
static const ImageFormat formats[1] = { ImageFormat::PLANAR_YCBCR };
nsRefPtr<Image> image =
output->GetImageContainer()->CreateImage(formats, 1);
output->GetImageContainer()->CreateImage(ImageFormat::PLANAR_YCBCR);
if (image) {
// Sets the image to a single black pixel, which will be scaled to fill
// the rendered size.

View File

@ -921,8 +921,9 @@ GstFlowReturn GStreamerReader::AllocateVideoBufferFull(GstPad* aPad,
{
/* allocate an image using the container */
ImageContainer* container = mDecoder->GetImageContainer();
ImageFormat format = ImageFormat::PLANAR_YCBCR;
PlanarYCbCrImage* img = reinterpret_cast<PlanarYCbCrImage*>(container->CreateImage(&format, 1).get());
PlanarYCbCrImage* img =
reinterpret_cast<PlanarYCbCrImage*>(
container->CreateImage(ImageFormat::PLANAR_YCBCR).get());
nsRefPtr<PlanarYCbCrImage> image = dont_AddRef(img);
/* prepare a GstBuffer pointing to the underlying PlanarYCbCrImage buffer */

View File

@ -373,9 +373,7 @@ uint8_t *
MediaPluginReader::ImageBufferCallback::CreateI420Image(size_t aWidth,
size_t aHeight)
{
ImageFormat format = ImageFormat::PLANAR_YCBCR;
mImage = mImageContainer->CreateImage(&format, 1 /* numFormats */);
mImage = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
PlanarYCbCrImage *yuvImage = static_cast<PlanarYCbCrImage *>(mImage.get());
if (!yuvImage) {

View File

@ -207,8 +207,7 @@ MediaEngineDefaultVideoSource::Notify(nsITimer* aTimer)
}
// Allocate a single solid color image
ImageFormat format = ImageFormat::PLANAR_YCBCR;
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(&format, 1);
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
nsRefPtr<layers::PlanarYCbCrImage> ycbcr_image =
static_cast<layers::PlanarYCbCrImage*>(image.get());
layers::PlanarYCbCrData data;

View File

@ -67,9 +67,7 @@ MediaEngineWebRTCVideoSource::DeliverFrame(
}
// Create a video frame and append it to the track.
ImageFormat format = ImageFormat::PLANAR_YCBCR;
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(&format, 1);
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(ImageFormat::PLANAR_YCBCR);
layers::PlanarYCbCrImage* videoImage = static_cast<layers::PlanarYCbCrImage*>(image.get());

View File

@ -154,8 +154,7 @@ D3D9DXVA2Manager::CopyToImage(IMFSample* aSample,
getter_AddRefs(surface));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
ImageFormat format = ImageFormat::D3D9_RGB32_TEXTURE;
nsRefPtr<Image> image = aImageContainer->CreateImage(&format, 1);
nsRefPtr<Image> image = aImageContainer->CreateImage(ImageFormat::D3D9_RGB32_TEXTURE);
NS_ENSURE_TRUE(image, E_FAIL);
NS_ASSERTION(image->GetFormat() == ImageFormat::D3D9_RGB32_TEXTURE,
"Wrong format?");

View File

@ -191,8 +191,7 @@ DOMCameraPreview::ReceiveFrame(void* aBuffer, ImageFormat aFormat, FrameBuilder
return false;
}
ImageFormat format = aFormat;
nsRefPtr<Image> image = mImageContainer->CreateImage(&format, 1);
nsRefPtr<Image> image = mImageContainer->CreateImage(aFormat);
aBuilder(image, aBuffer, mWidth, mHeight);
mInput->SetCurrentFrame(gfxIntSize(mWidth, mHeight), image);

View File

@ -179,8 +179,7 @@ nsPluginInstanceOwner::GetImageContainer()
container = LayerManager::CreateImageContainer();
ImageFormat format = ImageFormat::SHARED_TEXTURE;
nsRefPtr<Image> img = container->CreateImage(&format, 1);
nsRefPtr<Image> img = container->CreateImage(ImageFormat::SHARED_TEXTURE);
SharedTextureImage::Data data;
data.mSize = gfx::IntSize(r.width, r.height);
@ -1499,8 +1498,7 @@ already_AddRefed<ImageContainer> nsPluginInstanceOwner::GetImageContainerForVide
{
nsRefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
ImageFormat format = ImageFormat::SHARED_TEXTURE;
nsRefPtr<Image> img = container->CreateImage(&format, 1);
nsRefPtr<Image> img = container->CreateImage(ImageFormat::SHARED_TEXTURE);
SharedTextureImage::Data data;

View File

@ -638,8 +638,7 @@ PluginInstanceParent::RecvShow(const NPRect& updatedRect,
surface->MarkDirty(ur);
ImageContainer *container = GetImageContainer();
ImageFormat format = ImageFormat::CAIRO_SURFACE;
nsRefPtr<Image> image = container->CreateImage(&format, 1);
nsRefPtr<Image> image = container->CreateImage(ImageFormat::CAIRO_SURFACE);
NS_ASSERTION(image->GetFormat() == ImageFormat::CAIRO_SURFACE, "Wrong format?");
CairoImage* cairoImage = static_cast<CairoImage*>(image.get());
CairoImage::Data cairoData;
@ -719,8 +718,7 @@ PluginInstanceParent::GetImageContainer(ImageContainer** aContainer)
#ifdef XP_MACOSX
if (ioSurface) {
ImageFormat format = ImageFormat::MAC_IOSURFACE;
nsRefPtr<Image> image = container->CreateImage(&format, 1);
nsRefPtr<Image> image = container->CreateImage(ImageFormat::MAC_IOSURFACE);
if (!image) {
return NS_ERROR_FAILURE;
}

View File

@ -58,41 +58,37 @@ Image::GetAsSourceSurface()
}
already_AddRefed<Image>
ImageFactory::CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats,
ImageFactory::CreateImage(ImageFormat aFormat,
const gfx::IntSize &,
BufferRecycleBin *aRecycleBin)
{
if (!aNumFormats) {
return nullptr;
}
nsRefPtr<Image> img;
#ifdef MOZ_WIDGET_GONK
if (FormatInList(aFormats, aNumFormats, ImageFormat::GRALLOC_PLANAR_YCBCR)) {
if (aFormat == ImageFormat::GRALLOC_PLANAR_YCBCR) {
img = new GrallocImage();
return img.forget();
}
#endif
if (FormatInList(aFormats, aNumFormats, ImageFormat::PLANAR_YCBCR)) {
if (aFormat == ImageFormat::PLANAR_YCBCR) {
img = new PlanarYCbCrImage(aRecycleBin);
return img.forget();
}
if (FormatInList(aFormats, aNumFormats, ImageFormat::CAIRO_SURFACE)) {
if (aFormat == ImageFormat::CAIRO_SURFACE) {
img = new CairoImage();
return img.forget();
}
if (FormatInList(aFormats, aNumFormats, ImageFormat::SHARED_TEXTURE)) {
if (aFormat == ImageFormat::SHARED_TEXTURE) {
img = new SharedTextureImage();
return img.forget();
}
#ifdef XP_MACOSX
if (FormatInList(aFormats, aNumFormats, ImageFormat::MAC_IOSURFACE)) {
if (aFormat == ImageFormat::MAC_IOSURFACE) {
img = new MacIOSurfaceImage();
return img.forget();
}
#endif
#ifdef XP_WIN
if (FormatInList(aFormats, aNumFormats, ImageFormat::D3D9_RGB32_TEXTURE)) {
if (aFormat == ImageFormat::D3D9_RGB32_TEXTURE) {
img = new D3D9SurfaceImage();
return img.forget();
}
@ -162,18 +158,17 @@ ImageContainer::~ImageContainer()
}
already_AddRefed<Image>
ImageContainer::CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats)
ImageContainer::CreateImage(ImageFormat aFormat)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (mImageClient) {
nsRefPtr<Image> img = mImageClient->CreateImage(aFormats, aNumFormats);
nsRefPtr<Image> img = mImageClient->CreateImage(aFormat);
if (img) {
return img.forget();
}
}
return mImageFactory->CreateImage(aFormats, aNumFormats, mScaleHint, mRecycleBin);
return mImageFactory->CreateImage(aFormat, mScaleHint, mRecycleBin);
}
void

View File

@ -262,21 +262,6 @@ private:
uint32_t mRecycledBufferSize;
};
/**
* Returns true if aFormat is in the given format array.
*/
static inline bool
FormatInList(const ImageFormat* aFormats, uint32_t aNumFormats,
ImageFormat aFormat)
{
for (uint32_t i = 0; i < aNumFormats; ++i) {
if (aFormats[i] == aFormat) {
return true;
}
}
return false;
}
class CompositionNotifySink
{
public:
@ -309,8 +294,7 @@ protected:
ImageFactory() {}
virtual ~ImageFactory() {}
virtual already_AddRefed<Image> CreateImage(const ImageFormat* aFormats,
uint32_t aNumFormats,
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat,
const gfx::IntSize &aScaleHint,
BufferRecycleBin *aRecycleBin);
@ -411,8 +395,7 @@ public:
* Can be called on any thread. This method takes mReentrantMonitor
* when accessing thread-shared state.
*/
already_AddRefed<Image> CreateImage(const ImageFormat* aFormats,
uint32_t aNumFormats);
already_AddRefed<Image> CreateImage(ImageFormat aFormat);
/**
* Set an Image as the current image to display. The Image must have

View File

@ -67,22 +67,17 @@ class BasicImageFactory : public ImageFactory
public:
BasicImageFactory() {}
virtual already_AddRefed<Image> CreateImage(const ImageFormat* aFormats,
uint32_t aNumFormats,
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat,
const gfx::IntSize &aScaleHint,
BufferRecycleBin *aRecycleBin)
{
if (!aNumFormats) {
return nullptr;
}
nsRefPtr<Image> image;
if (aFormats[0] == ImageFormat::PLANAR_YCBCR) {
if (aFormat == ImageFormat::PLANAR_YCBCR) {
image = new BasicPlanarYCbCrImage(aScaleHint, gfxPlatform::GetPlatform()->GetOffscreenFormat(), aRecycleBin);
return image.forget();
}
return ImageFactory::CreateImage(aFormats, aNumFormats, aScaleHint, aRecycleBin);
return ImageFactory::CreateImage(aFormat, aScaleHint, aRecycleBin);
}
};

View File

@ -492,53 +492,45 @@ ImageClientBridge::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
}
already_AddRefed<Image>
ImageClientSingle::CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats)
ImageClientSingle::CreateImage(ImageFormat aFormat)
{
nsRefPtr<Image> img;
for (uint32_t i = 0; i < aNumFormats; i++) {
switch (aFormats[i]) {
case ImageFormat::PLANAR_YCBCR:
img = new SharedPlanarYCbCrImage(this);
return img.forget();
case ImageFormat::SHARED_RGB:
img = new SharedRGBImage(this);
return img.forget();
switch (aFormat) {
case ImageFormat::PLANAR_YCBCR:
img = new SharedPlanarYCbCrImage(this);
return img.forget();
case ImageFormat::SHARED_RGB:
img = new SharedRGBImage(this);
return img.forget();
#ifdef MOZ_WIDGET_GONK
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
#endif
default:
continue; // keep iterating over aFormats
}
default:
return nullptr;
}
return nullptr;
}
already_AddRefed<Image>
DeprecatedImageClientSingle::CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats)
DeprecatedImageClientSingle::CreateImage(ImageFormat aFormat)
{
nsRefPtr<Image> img;
for (uint32_t i = 0; i < aNumFormats; i++) {
switch (aFormats[i]) {
case ImageFormat::PLANAR_YCBCR:
img = new DeprecatedSharedPlanarYCbCrImage(GetForwarder());
return img.forget();
case ImageFormat::SHARED_RGB:
img = new DeprecatedSharedRGBImage(GetForwarder());
return img.forget();
switch (aFormat) {
case ImageFormat::PLANAR_YCBCR:
img = new DeprecatedSharedPlanarYCbCrImage(GetForwarder());
return img.forget();
case ImageFormat::SHARED_RGB:
img = new DeprecatedSharedRGBImage(GetForwarder());
return img.forget();
#ifdef MOZ_WIDGET_GONK
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
#endif
default:
continue; // keep iterating over aFormats
}
default:
return nullptr;
}
return nullptr;
}

View File

@ -59,8 +59,7 @@ public:
*/
virtual void UpdatePictureRect(nsIntRect aPictureRect);
virtual already_AddRefed<Image> CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats) = 0;
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) = 0;
/**
* Synchronously remove all the textures used by the image client.
@ -97,8 +96,7 @@ public:
virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE;
virtual already_AddRefed<Image> CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats) MOZ_OVERRIDE;
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE;
virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
@ -166,8 +164,7 @@ public:
return mTextureInfo;
}
virtual already_AddRefed<Image> CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats) MOZ_OVERRIDE;
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE;
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
@ -203,8 +200,7 @@ public:
MOZ_ASSERT(!aChild, "ImageClientBridge should not have IPDL actor");
}
virtual already_AddRefed<Image> CreateImage(const ImageFormat *aFormats,
uint32_t aNumFormats) MOZ_OVERRIDE
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE
{
NS_WARNING("Should not create an image through an ImageClientBridge");
return nullptr;

View File

@ -64,8 +64,7 @@ CreateSharedRGBImage(ImageContainer *aImageContainer,
return nullptr;
}
ImageFormat format = ImageFormat::SHARED_RGB;
nsRefPtr<Image> image = aImageContainer->CreateImage(&format, 1);
nsRefPtr<Image> image = aImageContainer->CreateImage(ImageFormat::SHARED_RGB);
if (!image) {
NS_WARNING("Failed to create DeprecatedSharedRGBImage");

View File

@ -958,11 +958,9 @@ RasterImage::GetCurrentImage()
GetHeight(&cairoData.mSize.height);
cairoData.mSourceSurface = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, imageSurface);
ImageFormat cairoFormat = ImageFormat::CAIRO_SURFACE;
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(&cairoFormat, 1);
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(ImageFormat::CAIRO_SURFACE);
NS_ASSERTION(image, "Failed to create Image");
NS_ASSERTION(image->GetFormat() == cairoFormat, "Wrong format");
static_cast<CairoImage*>(image.get())->SetData(cairoData);
return image.forget();

View File

@ -2990,7 +2990,7 @@ ChooseScaleAndSetTransform(FrameLayerBuilder* aLayerBuilder,
gfxSize scale;
// XXX Should we do something for 3D transforms?
if (canDraw2D) {
// If the container's transform is animated off main thread, then use the
// // If the container's transform is animated off main thread, then use the
// maximum scale.
if (aContainerFrame->GetContent() &&
nsLayoutUtils::HasAnimationsForCompositor(
@ -3868,8 +3868,7 @@ ContainerState::SetupMaskLayer(Layer *aLayer, const DisplayItemClip& aClip,
// build the image and container
container = aLayer->Manager()->CreateImageContainer();
NS_ASSERTION(container, "Could not create image container for mask layer.");
static const ImageFormat format = ImageFormat::CAIRO_SURFACE;
nsRefPtr<Image> image = container->CreateImage(&format, 1);
nsRefPtr<Image> image = container->CreateImage(ImageFormat::CAIRO_SURFACE);
NS_ASSERTION(image, "Could not create image container for mask layer.");
CairoImage::Data data;
data.mDeprecatedSurface = surface;

View File

@ -1203,7 +1203,7 @@ void MediaPipelineReceiveVideo::PipelineListener::RenderVideoFrame(
#else
ImageFormat format = ImageFormat::PLANAR_YCBCR;
#endif
nsRefPtr<layers::Image> image = image_container_->CreateImage(&format, 1);
nsRefPtr<layers::Image> image = image_container_->CreateImage(format);
layers::PlanarYCbCrImage* videoImage = static_cast<layers::PlanarYCbCrImage*>(image.get());
uint8_t* frame = const_cast<uint8_t*>(static_cast<const uint8_t*> (buffer));

View File

@ -118,11 +118,11 @@ class Fake_VideoGenerator {
const uint32_t HEIGHT = 480;
// Allocate a single blank Image
mozilla::ImageFormat format = mozilla::ImageFormat::PLANAR_YCBCR;
nsRefPtr<mozilla::layers::ImageContainer> container =
mozilla::layers::LayerManager::CreateImageContainer();
nsRefPtr<mozilla::layers::Image> image = container->CreateImage(&format, 1);
nsRefPtr<mozilla::layers::Image> image =
container->CreateImage(mozilla::ImageFormat::PLANAR_YCBCR);
int len = ((WIDTH * HEIGHT) * 3 / 2);
mozilla::layers::PlanarYCbCrImage* planar =