2012-08-19 12:33:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
|
|
|
#include "mozilla/layers/ImageContainerChild.h"
|
|
|
|
|
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "GonkIOSurfaceImage.h"
|
2012-08-21 03:22:58 -07:00
|
|
|
#include "GrallocImages.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "mozilla/ipc/Shmem.h"
|
|
|
|
#include "mozilla/ipc/CrossProcessMutex.h"
|
|
|
|
#include "SharedTextureImage.h"
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxSharedImageSurface.h"
|
|
|
|
#include "yuv_convert.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxD2DSurface.h"
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include <d3d10_1.h>
|
|
|
|
|
|
|
|
#include "d3d10/ImageLayerD3D10.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
2012-08-21 03:22:58 -07:00
|
|
|
using namespace android;
|
2012-08-19 12:33:25 -07:00
|
|
|
using mozilla::gfx::DataSourceSurface;
|
|
|
|
using mozilla::gfx::SourceSurface;
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-08-22 19:02:51 -07:00
|
|
|
int32_t Image::sSerialCounter = 0;
|
2012-08-22 17:08:26 -07:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
already_AddRefed<Image>
|
|
|
|
ImageFactory::CreateImage(const ImageFormat *aFormats,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNumFormats,
|
2012-08-19 12:33:25 -07:00
|
|
|
const gfxIntSize &,
|
|
|
|
BufferRecycleBin *aRecycleBin)
|
|
|
|
{
|
|
|
|
if (!aNumFormats) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsRefPtr<Image> img;
|
2012-08-21 03:22:58 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (FormatInList(aFormats, aNumFormats, GRALLOC_PLANAR_YCBCR)) {
|
|
|
|
img = new GrallocPlanarYCbCrImage();
|
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-19 19:39:10 -07:00
|
|
|
if (FormatInList(aFormats, aNumFormats, PLANAR_YCBCR)) {
|
2012-08-19 12:33:25 -07:00
|
|
|
img = new PlanarYCbCrImage(aRecycleBin);
|
2012-08-21 03:22:58 -07:00
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
if (FormatInList(aFormats, aNumFormats, CAIRO_SURFACE)) {
|
2012-08-19 12:33:25 -07:00
|
|
|
img = new CairoImage();
|
2012-08-21 03:22:58 -07:00
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
if (FormatInList(aFormats, aNumFormats, SHARED_TEXTURE)) {
|
2012-08-19 12:33:25 -07:00
|
|
|
img = new SharedTextureImage();
|
2012-08-21 03:22:58 -07:00
|
|
|
return img.forget();
|
|
|
|
}
|
2012-08-19 12:33:25 -07:00
|
|
|
#ifdef XP_MACOSX
|
2012-08-21 03:22:58 -07:00
|
|
|
if (FormatInList(aFormats, aNumFormats, MAC_IO_SURFACE)) {
|
2012-08-19 12:33:25 -07:00
|
|
|
img = new MacIOSurfaceImage();
|
2012-08-21 03:22:58 -07:00
|
|
|
return img.forget();
|
|
|
|
}
|
2012-08-19 12:33:25 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-08-21 03:22:58 -07:00
|
|
|
if (FormatInList(aFormats, aNumFormats, GONK_IO_SURFACE)) {
|
2012-08-19 12:33:25 -07:00
|
|
|
img = new GonkIOSurfaceImage();
|
2012-08-21 03:22:58 -07:00
|
|
|
return img.forget();
|
2012-08-21 02:55:02 -07:00
|
|
|
}
|
2012-08-21 03:22:58 -07:00
|
|
|
#endif
|
|
|
|
return nullptr;
|
2012-08-19 12:33:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BufferRecycleBin::BufferRecycleBin()
|
|
|
|
: mLock("mozilla.layers.BufferRecycleBin.mLock")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
BufferRecycleBin::RecycleBuffer(uint8_t* aBuffer, uint32_t aSize)
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
if (!mRecycledBuffers.IsEmpty() && aSize != mRecycledBufferSize) {
|
|
|
|
mRecycledBuffers.Clear();
|
|
|
|
}
|
|
|
|
mRecycledBufferSize = aSize;
|
|
|
|
mRecycledBuffers.AppendElement(aBuffer);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t*
|
|
|
|
BufferRecycleBin::GetBuffer(uint32_t aSize)
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
if (mRecycledBuffers.IsEmpty() || mRecycledBufferSize != aSize)
|
2012-08-22 08:56:38 -07:00
|
|
|
return new uint8_t[aSize];
|
2012-08-19 12:33:25 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t last = mRecycledBuffers.Length() - 1;
|
|
|
|
uint8_t* result = mRecycledBuffers[last].forget();
|
2012-08-19 12:33:25 -07:00
|
|
|
mRecycledBuffers.RemoveElementAt(last);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageContainer::ImageContainer(int flag)
|
|
|
|
: mReentrantMonitor("ImageContainer.mReentrantMonitor"),
|
|
|
|
mPaintCount(0),
|
|
|
|
mPreviousImagePainted(false),
|
|
|
|
mImageFactory(new ImageFactory()),
|
|
|
|
mRecycleBin(new BufferRecycleBin()),
|
|
|
|
mRemoteData(nullptr),
|
|
|
|
mRemoteDataMutex(nullptr),
|
|
|
|
mCompositionNotifySink(nullptr),
|
|
|
|
mImageContainerChild(nullptr)
|
|
|
|
{
|
|
|
|
if (flag == ENABLE_ASYNC && ImageBridgeChild::IsCreated()) {
|
|
|
|
mImageContainerChild =
|
|
|
|
ImageBridgeChild::GetSingleton()->CreateImageContainerChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageContainer::~ImageContainer()
|
|
|
|
{
|
|
|
|
if (mImageContainerChild) {
|
|
|
|
mImageContainerChild->DispatchStop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Image>
|
|
|
|
ImageContainer::CreateImage(const ImageFormat *aFormats,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNumFormats)
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-05 02:38:03 -08:00
|
|
|
if (mImageContainerChild) {
|
2012-11-08 09:44:11 -08:00
|
|
|
nsRefPtr<Image> img = mImageContainerChild->CreateImage((uint32_t*)aFormats,
|
|
|
|
aNumFormats);
|
2012-11-05 02:38:03 -08:00
|
|
|
if (img) {
|
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
}
|
2012-08-19 12:33:25 -07:00
|
|
|
return mImageFactory->CreateImage(aFormats, aNumFormats, mScaleHint, mRecycleBin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::SetCurrentImageInternal(Image *aImage)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
NS_ASSERTION(mRemoteDataMutex, "Should have remote data mutex when having remote data!");
|
|
|
|
mRemoteDataMutex->Lock();
|
|
|
|
// This is important since it ensures we won't change the active image
|
|
|
|
// when we currently have a locked image that depends on mRemoteData.
|
|
|
|
}
|
|
|
|
|
|
|
|
mActiveImage = aImage;
|
|
|
|
CurrentImageChanged();
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
mRemoteDataMutex->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::SetCurrentImage(Image *aImage)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mImageContainerChild) {
|
|
|
|
if (aImage) {
|
|
|
|
mImageContainerChild->SendImageAsync(this, aImage);
|
|
|
|
} else {
|
2013-01-14 17:15:03 -08:00
|
|
|
mImageContainerChild->SetIdle();
|
2012-08-19 12:33:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCurrentImageInternal(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::SetCurrentImageInTransaction(Image *aImage)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
NS_ASSERTION(!mImageContainerChild, "Should use async image transfer with ImageBridge.");
|
|
|
|
|
|
|
|
SetCurrentImageInternal(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageContainer::IsAsync() const {
|
|
|
|
return mImageContainerChild != nullptr;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t ImageContainer::GetAsyncContainerID() const
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IsAsync(),"Shared image ID is only relevant to async ImageContainers");
|
|
|
|
if (IsAsync()) {
|
|
|
|
return mImageContainerChild->GetID();
|
|
|
|
} else {
|
|
|
|
return 0; // zero is always an invalid SharedImageID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ImageContainer::HasCurrentImage()
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
CrossProcessMutexAutoLock autoLock(*mRemoteDataMutex);
|
|
|
|
|
|
|
|
EnsureActiveImage();
|
|
|
|
|
|
|
|
return !!mActiveImage.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!mActiveImage.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Image>
|
|
|
|
ImageContainer::LockCurrentImage()
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
NS_ASSERTION(mRemoteDataMutex, "Should have remote data mutex when having remote data!");
|
|
|
|
mRemoteDataMutex->Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsureActiveImage();
|
|
|
|
|
|
|
|
nsRefPtr<Image> retval = mActiveImage;
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
ImageContainer::LockCurrentAsSurface(gfxIntSize *aSize, Image** aCurrentImage)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
NS_ASSERTION(mRemoteDataMutex, "Should have remote data mutex when having remote data!");
|
|
|
|
mRemoteDataMutex->Lock();
|
|
|
|
|
|
|
|
EnsureActiveImage();
|
|
|
|
|
|
|
|
if (aCurrentImage) {
|
|
|
|
NS_IF_ADDREF(mActiveImage);
|
|
|
|
*aCurrentImage = mActiveImage.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActiveImage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-08-19 19:39:10 -07:00
|
|
|
if (mActiveImage->GetFormat() == REMOTE_IMAGE_BITMAP) {
|
2012-08-19 12:33:25 -07:00
|
|
|
nsRefPtr<gfxImageSurface> newSurf =
|
|
|
|
new gfxImageSurface(mRemoteData->mBitmap.mData, mRemoteData->mSize, mRemoteData->mBitmap.mStride,
|
|
|
|
mRemoteData->mFormat == RemoteImageData::BGRX32 ?
|
|
|
|
gfxASurface::ImageFormatARGB32 :
|
|
|
|
gfxASurface::ImageFormatRGB24);
|
|
|
|
|
|
|
|
*aSize = newSurf->GetSize();
|
|
|
|
|
|
|
|
return newSurf.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSize = mActiveImage->GetSize();
|
|
|
|
return mActiveImage->GetAsSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCurrentImage) {
|
|
|
|
NS_IF_ADDREF(mActiveImage);
|
|
|
|
*aCurrentImage = mActiveImage.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActiveImage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSize = mActiveImage->GetSize();
|
|
|
|
return mActiveImage->GetAsSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::UnlockCurrentImage()
|
|
|
|
{
|
|
|
|
if (mRemoteData) {
|
|
|
|
NS_ASSERTION(mRemoteDataMutex, "Should have remote data mutex when having remote data!");
|
|
|
|
mRemoteDataMutex->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
ImageContainer::GetCurrentAsSurface(gfxIntSize *aSize)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
CrossProcessMutexAutoLock autoLock(*mRemoteDataMutex);
|
|
|
|
EnsureActiveImage();
|
|
|
|
|
|
|
|
if (!mActiveImage)
|
|
|
|
return nullptr;
|
|
|
|
*aSize = mRemoteData->mSize;
|
|
|
|
} else {
|
|
|
|
if (!mActiveImage)
|
|
|
|
return nullptr;
|
|
|
|
*aSize = mActiveImage->GetSize();
|
|
|
|
}
|
|
|
|
return mActiveImage->GetAsSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize
|
|
|
|
ImageContainer::GetCurrentSize()
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mRemoteData) {
|
|
|
|
CrossProcessMutexAutoLock autoLock(*mRemoteDataMutex);
|
|
|
|
|
|
|
|
// We don't need to ensure we have an active image here, as we need to
|
|
|
|
// be in the mutex anyway, and this is easiest to return from there.
|
|
|
|
return mRemoteData->mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActiveImage) {
|
|
|
|
return gfxIntSize(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mActiveImage->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::SetRemoteImageData(RemoteImageData *aData, CrossProcessMutex *aMutex)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
NS_ASSERTION(!mActiveImage || !aData, "No active image expected when SetRemoteImageData is called with non-NULL aData.");
|
|
|
|
NS_ASSERTION(!mRemoteData || !aData, "No remote data expected when SetRemoteImageData is called with non-NULL aData.");
|
|
|
|
|
|
|
|
mRemoteData = aData;
|
|
|
|
|
|
|
|
if (aData) {
|
|
|
|
memset(aData, 0, sizeof(RemoteImageData));
|
|
|
|
} else {
|
|
|
|
mActiveImage = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRemoteDataMutex = aMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::EnsureActiveImage()
|
|
|
|
{
|
|
|
|
if (mRemoteData) {
|
|
|
|
if (mRemoteData->mWasUpdated) {
|
|
|
|
mActiveImage = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mRemoteData->mType == RemoteImageData::RAW_BITMAP &&
|
|
|
|
mRemoteData->mBitmap.mData && !mActiveImage) {
|
|
|
|
nsRefPtr<RemoteBitmapImage> newImg = new RemoteBitmapImage();
|
|
|
|
|
|
|
|
newImg->mFormat = mRemoteData->mFormat;
|
|
|
|
newImg->mData = mRemoteData->mBitmap.mData;
|
|
|
|
newImg->mSize = mRemoteData->mSize;
|
|
|
|
newImg->mStride = mRemoteData->mBitmap.mStride;
|
|
|
|
mRemoteData->mWasUpdated = false;
|
|
|
|
|
|
|
|
mActiveImage = newImg;
|
|
|
|
}
|
|
|
|
#ifdef XP_WIN
|
|
|
|
else if (mRemoteData->mType == RemoteImageData::DXGI_TEXTURE_HANDLE &&
|
|
|
|
mRemoteData->mTextureHandle && !mActiveImage) {
|
|
|
|
nsRefPtr<RemoteDXGITextureImage> newImg = new RemoteDXGITextureImage();
|
|
|
|
newImg->mSize = mRemoteData->mSize;
|
|
|
|
newImg->mHandle = mRemoteData->mTextureHandle;
|
|
|
|
newImg->mFormat = mRemoteData->mFormat;
|
|
|
|
mRemoteData->mWasUpdated = false;
|
|
|
|
|
|
|
|
mActiveImage = newImg;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlanarYCbCrImage::PlanarYCbCrImage(BufferRecycleBin *aRecycleBin)
|
|
|
|
: Image(nullptr, PLANAR_YCBCR)
|
|
|
|
, mBufferSize(0)
|
2012-12-17 03:21:56 -08:00
|
|
|
, mOffscreenFormat(gfxASurface::ImageFormatUnknown)
|
2012-08-19 12:33:25 -07:00
|
|
|
, mRecycleBin(aRecycleBin)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrImage::~PlanarYCbCrImage()
|
|
|
|
{
|
|
|
|
if (mBuffer) {
|
|
|
|
mRecycleBin->RecycleBuffer(mBuffer.forget(), mBufferSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t*
|
|
|
|
PlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
return mRecycleBin->GetBuffer(aSize);
|
|
|
|
}
|
|
|
|
|
2012-08-23 10:01:14 -07:00
|
|
|
static void
|
2012-09-04 10:10:06 -07:00
|
|
|
CopyPlane(uint8_t *aDst, const uint8_t *aSrc,
|
2012-08-25 20:22:51 -07:00
|
|
|
const gfxIntSize &aSize, int32_t aStride, int32_t aSkip)
|
2012-08-23 10:01:14 -07:00
|
|
|
{
|
2012-08-25 20:22:51 -07:00
|
|
|
if (!aSkip) {
|
2012-08-23 10:01:14 -07:00
|
|
|
// Fast path: planar input.
|
|
|
|
memcpy(aDst, aSrc, aSize.height * aStride);
|
|
|
|
} else {
|
|
|
|
int32_t height = aSize.height;
|
|
|
|
int32_t width = aSize.width;
|
|
|
|
for (int y = 0; y < height; ++y) {
|
2012-09-04 10:10:06 -07:00
|
|
|
const uint8_t *src = aSrc;
|
2012-08-23 10:01:14 -07:00
|
|
|
uint8_t *dst = aDst;
|
2012-08-25 20:22:51 -07:00
|
|
|
// Slow path
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
src += aSkip;
|
2012-08-23 10:01:14 -07:00
|
|
|
}
|
2012-09-04 10:10:06 -07:00
|
|
|
aSrc += aStride;
|
|
|
|
aDst += aStride;
|
2012-08-23 10:01:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlanarYCbCrImage::CopyData(const Data& aData)
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
2012-08-23 10:01:14 -07:00
|
|
|
mData = aData;
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
// update buffer size
|
2012-08-23 10:01:14 -07:00
|
|
|
mBufferSize = mData.mCbCrStride * mData.mCbCrSize.height * 2 +
|
|
|
|
mData.mYStride * mData.mYSize.height;
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
// get new buffer
|
2012-08-23 10:01:14 -07:00
|
|
|
mBuffer = AllocateBuffer(mBufferSize);
|
|
|
|
if (!mBuffer)
|
2012-08-19 12:33:25 -07:00
|
|
|
return;
|
|
|
|
|
2012-08-23 10:01:14 -07:00
|
|
|
mData.mYChannel = mBuffer;
|
|
|
|
mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height;
|
|
|
|
mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height;
|
|
|
|
|
|
|
|
CopyPlane(mData.mYChannel, aData.mYChannel,
|
2012-08-25 20:22:51 -07:00
|
|
|
mData.mYSize, mData.mYStride, mData.mYSkip);
|
2012-08-23 10:01:14 -07:00
|
|
|
CopyPlane(mData.mCbChannel, aData.mCbChannel,
|
2012-08-25 20:22:51 -07:00
|
|
|
mData.mCbCrSize, mData.mCbCrStride, mData.mCbSkip);
|
2012-08-23 10:01:14 -07:00
|
|
|
CopyPlane(mData.mCrChannel, aData.mCrChannel,
|
2012-08-25 20:22:51 -07:00
|
|
|
mData.mCbCrSize, mData.mCbCrStride, mData.mCrSkip);
|
2012-08-23 10:01:14 -07:00
|
|
|
|
|
|
|
mSize = aData.mPicSize;
|
2012-08-19 12:33:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlanarYCbCrImage::SetData(const Data &aData)
|
|
|
|
{
|
2012-08-23 10:01:14 -07:00
|
|
|
CopyData(aData);
|
2012-08-19 12:33:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PlanarYCbCrImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
|
|
|
nsRefPtr<gfxASurface> result = mSurface.get();
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface::gfxImageFormat format = GetOffscreenFormat();
|
|
|
|
|
|
|
|
gfxIntSize size(mSize);
|
|
|
|
gfxUtils::GetYCbCrToRGBDestFormatAndSize(mData, format, size);
|
|
|
|
if (size.width > PlanarYCbCrImage::MAX_DIMENSION ||
|
|
|
|
size.height > PlanarYCbCrImage::MAX_DIMENSION) {
|
|
|
|
NS_ERROR("Illegal image dest width or height");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurface =
|
|
|
|
new gfxImageSurface(mSize, format);
|
|
|
|
|
|
|
|
gfxUtils::ConvertYCbCrToRGB(mData, format, mSize,
|
|
|
|
imageSurface->Data(),
|
|
|
|
imageSurface->Stride());
|
|
|
|
|
|
|
|
mSurface = imageSurface;
|
|
|
|
|
|
|
|
return imageSurface.forget().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
void
|
|
|
|
MacIOSurfaceImage::SetData(const Data& aData)
|
|
|
|
{
|
|
|
|
mIOSurface = MacIOSurface::LookupSurface(aData.mIOSurface->GetIOSurfaceID());
|
|
|
|
mSize = gfxIntSize(mIOSurface->GetWidth(), mIOSurface->GetHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
MacIOSurfaceImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
mIOSurface->Lock();
|
|
|
|
size_t bytesPerRow = mIOSurface->GetBytesPerRow();
|
|
|
|
size_t ioWidth = mIOSurface->GetWidth();
|
|
|
|
size_t ioHeight = mIOSurface->GetHeight();
|
|
|
|
|
|
|
|
unsigned char* ioData = (unsigned char*)mIOSurface->GetBaseAddress();
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurface =
|
|
|
|
new gfxImageSurface(gfxIntSize(ioWidth, ioHeight), gfxASurface::ImageFormatARGB32);
|
|
|
|
|
|
|
|
for (int i = 0; i < ioHeight; i++) {
|
|
|
|
memcpy(imgSurface->Data() + i * imgSurface->Stride(),
|
|
|
|
ioData + i * bytesPerRow, ioWidth * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
mIOSurface->Unlock();
|
|
|
|
|
|
|
|
return imgSurface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MacIOSurfaceImage::Update(ImageContainer* aContainer)
|
|
|
|
{
|
|
|
|
if (mUpdateCallback) {
|
|
|
|
mUpdateCallback(aContainer, mPluginInstanceOwner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
RemoteBitmapImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxImageSurface> newSurf =
|
|
|
|
new gfxImageSurface(mSize,
|
|
|
|
mFormat == RemoteImageData::BGRX32 ? gfxASurface::ImageFormatRGB24 : gfxASurface::ImageFormatARGB32);
|
|
|
|
|
|
|
|
for (int y = 0; y < mSize.height; y++) {
|
|
|
|
memcpy(newSurf->Data() + newSurf->Stride() * y,
|
|
|
|
mData + mStride * y,
|
|
|
|
mSize.width * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newSurf.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2012-08-19 19:39:10 -07:00
|
|
|
} // namespace
|