Remove Gonk usage of ImageContainer::CreateImage. (bug 1222910, r=sotaro)

This commit is contained in:
David Anderson 2015-11-17 00:09:01 -08:00
parent 27bfc27d62
commit 8e086a182c
14 changed files with 62 additions and 116 deletions

View File

@ -2388,15 +2388,11 @@ void
nsGonkCameraControl::OnNewPreviewFrame(layers::TextureClient* aBuffer)
{
#ifdef MOZ_WIDGET_GONK
RefPtr<Image> frame = mImageContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
RefPtr<GrallocImage> frame = new GrallocImage();
GrallocImage* videoImage = static_cast<GrallocImage*>(frame.get());
GrallocImage::GrallocData data;
data.mGraphicBuffer = aBuffer;
data.mPicSize = IntSize(mCurrentConfiguration.mPreviewSize.width,
mCurrentConfiguration.mPreviewSize.height);
videoImage->SetData(data);
IntSize picSize(mCurrentConfiguration.mPreviewSize.width,
mCurrentConfiguration.mPreviewSize.height);
frame->SetData(aBuffer, picSize);
if (mCapturePoster.exchange(false)) {
CreatePoster(frame,

View File

@ -1044,10 +1044,9 @@ DOMHwMediaStream::DOMHwMediaStream()
{
#ifdef MOZ_WIDGET_GONK
mImageContainer = LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS_OVERLAY);
RefPtr<Image> img = mImageContainer->CreateImage(ImageFormat::OVERLAY_IMAGE);
mOverlayImage = static_cast<layers::OverlayImage*>(img.get());
mOverlayImage = mImageContainer->CreateOverlayImage();
nsAutoTArray<ImageContainer::NonOwningImage,1> images;
images.AppendElement(ImageContainer::NonOwningImage(img));
images.AppendElement(ImageContainer::NonOwningImage(mOverlayImage));
mImageContainer->SetCurrentImages(images);
#endif
}

View File

@ -312,7 +312,7 @@ VideoData::Create(const VideoInfo& aInfo,
// format.
#ifdef MOZ_WIDGET_GONK
if (IsYV12Format(Y, Cb, Cr) && !IsInEmulator()) {
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
v->mImage = new layers::GrallocImage();
}
#endif
if (!v->mImage) {
@ -461,22 +461,9 @@ VideoData::Create(const VideoInfo& aInfo,
aInfo.mDisplay,
0));
v->mImage = aContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
if (!v->mImage) {
return nullptr;
}
NS_ASSERTION(v->mImage->GetFormat() == ImageFormat::GRALLOC_PLANAR_YCBCR,
"Wrong format?");
typedef mozilla::layers::GrallocImage GrallocImage;
GrallocImage* videoImage = static_cast<GrallocImage*>(v->mImage.get());
GrallocImage::GrallocData data;
data.mPicSize = aPicture.Size();
data.mGraphicBuffer = aBuffer;
if (!videoImage->SetData(data)) {
return nullptr;
}
RefPtr<layers::GrallocImage> image = new layers::GrallocImage();
image->SetData(aBuffer, aPicture.Size());
v->mImage = image;
return v.forget();
}

View File

@ -738,9 +738,9 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
graphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_MASK, &pMem);
uint8_t* srcPtr = static_cast<uint8_t*>(pMem);
// Create a video frame and append it to the track.
ImageFormat format = ImageFormat::GONK_CAMERA_IMAGE;
RefPtr<layers::Image> image = mImageContainer->CreateImage(format);
RefPtr<layers::PlanarYCbCrImage> image = new GonkCameraImage();
uint32_t dstWidth;
uint32_t dstHeight;
@ -763,8 +763,7 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
layers::TextureFlags::DEFAULT,
layers::ALLOC_DISALLOW_BUFFERTEXTURECLIENT);
if (textureClient) {
RefPtr<layers::GrallocTextureClientOGL> grallocTextureClient =
static_cast<layers::GrallocTextureClientOGL*>(textureClient.get());
RefPtr<layers::GrallocTextureClientOGL> grallocTextureClient = textureClient->AsGrallocTextureClientOGL();
android::sp<android::GraphicBuffer> destBuffer = grallocTextureClient->GetGraphicBuffer();
@ -787,11 +786,7 @@ MediaEngineGonkVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth,
libyuv::FOURCC_NV21);
destBuffer->unlock();
layers::GrallocImage::GrallocData data;
data.mPicSize = gfx::IntSize(dstWidth, dstHeight);
data.mGraphicBuffer = textureClient;
image->AsGrallocImage()->SetData(data);
image->AsGrallocImage()->SetData(textureClient, gfx::IntSize(dstWidth, dstHeight));
} else {
// Handle out of gralloc case.
image = mImageContainer->CreatePlanarYCbCrImage();

View File

@ -147,11 +147,12 @@ GrallocImage::SetData(const Data& aData)
return true;
}
bool GrallocImage::SetData(const GrallocData& aData)
void
GrallocImage::SetData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize)
{
mTextureClient = static_cast<GrallocTextureClientOGL*>(aData.mGraphicBuffer.get());
mSize = aData.mPicSize;
return true;
MOZ_ASSERT(aGraphicBuffer->AsGrallocTextureClientOGL());
mTextureClient = aGraphicBuffer->AsGrallocTextureClientOGL();
mSize = aSize;
}
/**

View File

@ -53,11 +53,6 @@ class GrallocImage : public RecyclingPlanarYCbCrImage
typedef PlanarYCbCrData Data;
static int32_t sColorIdMap[];
public:
struct GrallocData {
RefPtr<TextureClient> mGraphicBuffer;
gfx::IntSize mPicSize;
};
GrallocImage();
virtual ~GrallocImage();
@ -72,7 +67,7 @@ public:
* Share the SurfaceDescriptor without making the copy, in order
* to support functioning in all different layer managers.
*/
virtual bool SetData(const GrallocData& aData);
void SetData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize);
// From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
enum {

View File

@ -55,23 +55,6 @@ ImageFactory::CreateImage(ImageFormat aFormat,
const gfx::IntSize &,
BufferRecycleBin *aRecycleBin)
{
RefPtr<Image> img;
#ifdef MOZ_WIDGET_GONK
if (aFormat == ImageFormat::GRALLOC_PLANAR_YCBCR) {
img = new GrallocImage();
return img.forget();
}
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
img = new OverlayImage();
return img.forget();
}
#endif
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_CAMERA) && defined(MOZ_WEBRTC)
if (aFormat == ImageFormat::GONK_CAMERA_IMAGE) {
img = new GonkCameraImage();
return img.forget();
}
#endif
return nullptr;
}
@ -183,19 +166,6 @@ already_AddRefed<Image>
ImageContainer::CreateImage(ImageFormat aFormat)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
#ifdef MOZ_WIDGET_GONK
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
// If this ImageContainer is async but the image type mismatch, fix it here
if (ImageBridgeChild::IsCreated()) {
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(
CompositableType::IMAGE_OVERLAY, this).take();
}
}
}
#endif
if (mImageClient) {
RefPtr<Image> img = mImageClient->CreateImage(aFormat);
if (img) {
@ -225,6 +195,23 @@ ImageContainer::CreateSharedRGBImage()
return new SharedRGBImage(mImageClient);
}
#ifdef MOZ_WIDGET_GONK
RefPtr<OverlayImage>
ImageContainer::CreateOverlayImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
// If this ImageContainer is async but the image type mismatch, fix it here
if (ImageBridgeChild::IsCreated()) {
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(
CompositableType::IMAGE_OVERLAY, this).take();
}
}
return new OverlayImage();
}
#endif
void
ImageContainer::SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages)
{

View File

@ -118,13 +118,14 @@ protected:
/* Forward declarations for Image derivatives. */
class EGLImageImage;
class SharedRGBImage;
#ifdef MOZ_WIDGET_ANDROID
class SurfaceTextureImage;
#endif
#ifdef XP_MACOSX
#elif defined(XP_MACOSX)
class MacIOSurfaceImage;
#elif defined(MOZ_WIDGET_GONK)
class OverlayImage;
#endif
class SharedRGBImage;
/**
* A class representing a buffer of pixel data. The data can be in one
@ -332,6 +333,10 @@ public:
// Factory methods for shared image types.
RefPtr<SharedRGBImage> CreateSharedRGBImage();
#ifdef MOZ_WIDGET_GONK
RefPtr<OverlayImage> CreateOverlayImage();
#endif
struct NonOwningImage {
explicit NonOwningImage(Image* aImage = nullptr,
TimeStamp aTimeStamp = TimeStamp(),

View File

@ -320,16 +320,7 @@ ImageClientBridge::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
already_AddRefed<Image>
ImageClientSingle::CreateImage(ImageFormat aFormat)
{
RefPtr<Image> img;
switch (aFormat) {
#ifdef MOZ_WIDGET_GONK
case ImageFormat::GRALLOC_PLANAR_YCBCR:
img = new GrallocImage();
return img.forget();
#endif
default:
return nullptr;
}
return nullptr;
}
#ifdef MOZ_WIDGET_GONK
@ -366,20 +357,6 @@ ImageClientOverlay::UpdateImage(ImageContainer* aContainer, uint32_t aContentFla
}
return true;
}
already_AddRefed<Image>
ImageClientOverlay::CreateImage(ImageFormat aFormat)
{
RefPtr<Image> img;
switch (aFormat) {
case ImageFormat::OVERLAY_IMAGE:
img = new OverlayImage();
return img.forget();
default:
return nullptr;
}
}
#endif
} // namespace layers
} // namespace mozilla

View File

@ -165,11 +165,14 @@ public:
TextureFlags aFlags);
virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat);
TextureInfo GetTextureInfo() const override
{
return TextureInfo(CompositableType::IMAGE_OVERLAY);
}
already_AddRefed<Image> CreateImage(ImageFormat aFormat) override {
return nullptr;
}
};
#endif

View File

@ -56,6 +56,7 @@ class TextureClientRecycleAllocator;
class TextureClientPool;
#endif
class KeepAlive;
class GrallocTextureClientOGL;
/**
* TextureClient is the abstraction that allows us to share data between the
@ -234,6 +235,7 @@ public:
}
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
virtual GrallocTextureClientOGL* AsGrallocTextureClientOGL() { return nullptr; }
/**
* Locks the shared data, allowing the caller to get access to it.

View File

@ -64,6 +64,10 @@ public:
virtual void WaitForBufferOwnership(bool aWaitReleaseFence = true) override;
GrallocTextureClientOGL* AsGrallocTextureClientOGL() override {
return this;
}
void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); }
gfx::IntSize GetSize() const override { return mSize; }

View File

@ -524,12 +524,9 @@ public:
return;
}
layers::GrallocImage::GrallocData grallocData;
grallocData.mPicSize = buffer->GetSize();
grallocData.mGraphicBuffer = buffer;
gfx::IntSize picSize(buffer->GetSize());
nsAutoPtr<layers::GrallocImage> grallocImage(new layers::GrallocImage());
grallocImage->SetData(grallocData);
grallocImage->SetData(buffer, picSize);
// Get timestamp of the frame about to render.
int64_t timestamp = -1;
@ -547,12 +544,12 @@ public:
MOZ_ASSERT(timestamp >= 0 && renderTimeMs >= 0);
CODEC_LOGD("Decoder NewFrame: %dx%d, timestamp %lld, renderTimeMs %lld",
grallocData.mPicSize.width, grallocData.mPicSize.height, timestamp, renderTimeMs);
picSize.width, picSize.height, timestamp, renderTimeMs);
nsAutoPtr<webrtc::I420VideoFrame> videoFrame(
new webrtc::TextureVideoFrame(new ImageNativeHandle(grallocImage.forget()),
grallocData.mPicSize.width,
grallocData.mPicSize.height,
picSize.width,
picSize.height,
timestamp,
renderTimeMs));
if (videoFrame != nullptr) {

View File

@ -1481,9 +1481,7 @@ void MediaPipelineReceiveVideo::PipelineListener::RenderVideoFrame(
if (buffer) {
// Create a video frame using |buffer|.
#ifdef MOZ_WIDGET_GONK
ImageFormat format = ImageFormat::GRALLOC_PLANAR_YCBCR;
RefPtr<Image> image = image_container_->CreateImage(format);
PlanarYCbCrImage* yuvImage = static_cast<PlanarYCbCrImage*>(image.get());
RefPtr<PlanarYCbCrImage> yuvImage = new GrallocImage();
#else
RefPtr<PlanarYCbCrImage> yuvImage = image_container_->CreatePlanarYCbCrImage();
#endif