2012-08-19 23:33:25 +04: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 "ImageContainer.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <string.h> // for memcpy, memset
|
|
|
|
#include "SharedTextureImage.h" // for SharedTextureImage
|
|
|
|
#include "gfxImageSurface.h" // for gfxImageSurface
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
|
|
#include "gfxUtils.h" // for gfxUtils
|
|
|
|
#include "mozilla/RefPtr.h" // for TemporaryRef
|
|
|
|
#include "mozilla/ipc/CrossProcessMutex.h" // for CrossProcessMutex, etc
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "mozilla/layers/ImageBridgeChild.h" // for ImageBridgeChild
|
|
|
|
#include "mozilla/layers/ImageClient.h" // for ImageClient
|
|
|
|
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-08-21 14:22:58 +04:00
|
|
|
#include "GrallocImages.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#endif
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
2013-11-01 05:54:14 +04:00
|
|
|
#include "MacIOSurfaceImage.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxD2DSurface.h"
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include <d3d10_1.h>
|
|
|
|
#include "d3d10/ImageLayerD3D10.h"
|
2013-05-04 14:12:40 +04:00
|
|
|
#include "D3D9SurfaceImage.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
2012-08-21 14:22:58 +04:00
|
|
|
using namespace android;
|
2012-08-19 23:33:25 +04:00
|
|
|
using mozilla::gfx::DataSourceSurface;
|
|
|
|
using mozilla::gfx::SourceSurface;
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
class DataSourceSurface;
|
|
|
|
class SourceSurface;
|
|
|
|
|
2013-08-12 13:51:49 +04:00
|
|
|
Atomic<int32_t> Image::sSerialCounter(0);
|
2012-08-23 04:08:26 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
already_AddRefed<Image>
|
|
|
|
ImageFactory::CreateImage(const ImageFormat *aFormats,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aNumFormats,
|
2012-08-19 23:33:25 +04:00
|
|
|
const gfxIntSize &,
|
|
|
|
BufferRecycleBin *aRecycleBin)
|
|
|
|
{
|
|
|
|
if (!aNumFormats) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsRefPtr<Image> img;
|
2012-08-21 14:22:58 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (FormatInList(aFormats, aNumFormats, GRALLOC_PLANAR_YCBCR)) {
|
2013-07-25 06:13:35 +04:00
|
|
|
img = new GrallocImage();
|
2012-08-21 14:22:58 +04:00
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-20 06:39:10 +04:00
|
|
|
if (FormatInList(aFormats, aNumFormats, PLANAR_YCBCR)) {
|
2012-08-19 23:33:25 +04:00
|
|
|
img = new PlanarYCbCrImage(aRecycleBin);
|
2012-08-21 14:22:58 +04:00
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
if (FormatInList(aFormats, aNumFormats, CAIRO_SURFACE)) {
|
2012-08-19 23:33:25 +04:00
|
|
|
img = new CairoImage();
|
2012-08-21 14:22:58 +04:00
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
if (FormatInList(aFormats, aNumFormats, SHARED_TEXTURE)) {
|
2012-08-19 23:33:25 +04:00
|
|
|
img = new SharedTextureImage();
|
2012-08-21 14:22:58 +04:00
|
|
|
return img.forget();
|
|
|
|
}
|
2013-11-01 05:54:14 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (FormatInList(aFormats, aNumFormats, MAC_IOSURFACE)) {
|
|
|
|
img = new MacIOSurfaceImage();
|
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-04 14:12:40 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (FormatInList(aFormats, aNumFormats, D3D9_RGB32_TEXTURE)) {
|
|
|
|
img = new D3D9SurfaceImage();
|
|
|
|
return img.forget();
|
|
|
|
}
|
2012-08-21 14:22:58 +04:00
|
|
|
#endif
|
|
|
|
return nullptr;
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BufferRecycleBin::BufferRecycleBin()
|
|
|
|
: mLock("mozilla.layers.BufferRecycleBin.mLock")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
BufferRecycleBin::RecycleBuffer(uint8_t* aBuffer, uint32_t aSize)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
if (!mRecycledBuffers.IsEmpty() && aSize != mRecycledBufferSize) {
|
|
|
|
mRecycledBuffers.Clear();
|
|
|
|
}
|
|
|
|
mRecycledBufferSize = aSize;
|
|
|
|
mRecycledBuffers.AppendElement(aBuffer);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t*
|
|
|
|
BufferRecycleBin::GetBuffer(uint32_t aSize)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
if (mRecycledBuffers.IsEmpty() || mRecycledBufferSize != aSize)
|
2012-08-22 19:56:38 +04:00
|
|
|
return new uint8_t[aSize];
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t last = mRecycledBuffers.Length() - 1;
|
|
|
|
uint8_t* result = mRecycledBuffers[last].forget();
|
2012-08-19 23:33:25 +04:00
|
|
|
mRecycledBuffers.RemoveElementAt(last);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
ImageContainer::ImageContainer(int flag)
|
2012-08-19 23:33:25 +04:00
|
|
|
: mReentrantMonitor("ImageContainer.mReentrantMonitor"),
|
|
|
|
mPaintCount(0),
|
|
|
|
mPreviousImagePainted(false),
|
|
|
|
mImageFactory(new ImageFactory()),
|
|
|
|
mRecycleBin(new BufferRecycleBin()),
|
|
|
|
mRemoteData(nullptr),
|
|
|
|
mRemoteDataMutex(nullptr),
|
|
|
|
mCompositionNotifySink(nullptr),
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
mImageClient(nullptr)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
if (flag == ENABLE_ASYNC && ImageBridgeChild::IsCreated()) {
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
// the refcount of this ImageClient is 1. we don't use a RefPtr here because the refcount
|
|
|
|
// of this class must be done on the ImageBridge thread.
|
2013-11-06 21:32:12 +04:00
|
|
|
if (gfxPlatform::GetPlatform()->UseDeprecatedTextures()) {
|
|
|
|
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(BUFFER_IMAGE_BUFFERED).drop();
|
|
|
|
} else {
|
|
|
|
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(BUFFER_IMAGE_SINGLE).drop();
|
|
|
|
}
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
MOZ_ASSERT(mImageClient);
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageContainer::~ImageContainer()
|
|
|
|
{
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
if (IsAsync()) {
|
|
|
|
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Image>
|
|
|
|
ImageContainer::CreateImage(const ImageFormat *aFormats,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aNumFormats)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
|
|
|
if (mImageClient) {
|
|
|
|
nsRefPtr<Image> img = mImageClient->CreateImage((uint32_t*)aFormats,
|
2012-11-08 21:44:11 +04:00
|
|
|
aNumFormats);
|
2012-11-05 14:38:03 +04:00
|
|
|
if (img) {
|
|
|
|
return img.forget();
|
|
|
|
}
|
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
return mImageFactory->CreateImage(aFormats, aNumFormats, mScaleHint, mRecycleBin);
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
void
|
2012-08-19 23:33:25 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:50:28 +04:00
|
|
|
void
|
|
|
|
ImageContainer::ClearCurrentImage()
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
SetCurrentImageInternal(nullptr);
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
void
|
|
|
|
ImageContainer::SetCurrentImage(Image *aImage)
|
|
|
|
{
|
2013-10-17 19:09:15 +04:00
|
|
|
if (!aImage) {
|
|
|
|
ClearAllImages();
|
2013-09-12 18:50:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
if (IsAsync()) {
|
2013-09-12 18:50:28 +04:00
|
|
|
ImageBridgeChild::DispatchImageClientUpdate(mImageClient, this);
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
SetCurrentImageInternal(aImage);
|
|
|
|
}
|
|
|
|
|
2013-10-17 19:09:15 +04:00
|
|
|
void
|
|
|
|
ImageContainer::ClearAllImages()
|
|
|
|
{
|
|
|
|
if (IsAsync()) {
|
|
|
|
// Let ImageClient release all TextureClients.
|
|
|
|
ImageBridgeChild::FlushAllImages(mImageClient, this, false);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2013-10-17 19:09:15 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
SetCurrentImageInternal(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageContainer::ClearAllImagesExceptFront()
|
|
|
|
{
|
|
|
|
if (IsAsync()) {
|
|
|
|
// Let ImageClient release all TextureClients except front one.
|
|
|
|
ImageBridgeChild::FlushAllImages(mImageClient, this, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
void
|
|
|
|
ImageContainer::SetCurrentImageInTransaction(Image *aImage)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
NS_ASSERTION(!mImageClient, "Should use async image transfer with ImageBridge.");
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
SetCurrentImageInternal(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageContainer::IsAsync() const {
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
return mImageClient != nullptr;
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t ImageContainer::GetAsyncContainerID() const
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IsAsync(),"Shared image ID is only relevant to async ImageContainers");
|
|
|
|
if (IsAsync()) {
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
return mImageClient->GetAsyncID();
|
2012-08-19 23:33:25 +04:00
|
|
|
} else {
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
return 0; // zero is always an invalid AsyncID
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-20 06:39:10 +04:00
|
|
|
if (mActiveImage->GetFormat() == REMOTE_IMAGE_BITMAP) {
|
2012-08-19 23:33:25 +04:00
|
|
|
nsRefPtr<gfxImageSurface> newSurf =
|
|
|
|
new gfxImageSurface(mRemoteData->mBitmap.mData, mRemoteData->mSize, mRemoteData->mBitmap.mStride,
|
|
|
|
mRemoteData->mFormat == RemoteImageData::BGRX32 ?
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormatARGB32 :
|
|
|
|
gfxImageFormatRGB24);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
*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)
|
2013-09-25 00:45:13 +04:00
|
|
|
, mOffscreenFormat(gfxImageFormatUnknown)
|
2012-08-19 23:33:25 +04:00
|
|
|
, mRecycleBin(aRecycleBin)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrImage::~PlanarYCbCrImage()
|
|
|
|
{
|
|
|
|
if (mBuffer) {
|
|
|
|
mRecycleBin->RecycleBuffer(mBuffer.forget(), mBufferSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t*
|
|
|
|
PlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
return mRecycleBin->GetBuffer(aSize);
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:01:14 +04:00
|
|
|
static void
|
2012-09-04 21:10:06 +04:00
|
|
|
CopyPlane(uint8_t *aDst, const uint8_t *aSrc,
|
2012-08-26 07:22:51 +04:00
|
|
|
const gfxIntSize &aSize, int32_t aStride, int32_t aSkip)
|
2012-08-23 21:01:14 +04:00
|
|
|
{
|
2012-08-26 07:22:51 +04:00
|
|
|
if (!aSkip) {
|
2012-08-23 21:01:14 +04: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 21:10:06 +04:00
|
|
|
const uint8_t *src = aSrc;
|
2012-08-23 21:01:14 +04:00
|
|
|
uint8_t *dst = aDst;
|
2012-08-26 07:22:51 +04:00
|
|
|
// Slow path
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
src += aSkip;
|
2012-08-23 21:01:14 +04:00
|
|
|
}
|
2012-09-04 21:10:06 +04:00
|
|
|
aSrc += aStride;
|
|
|
|
aDst += aStride;
|
2012-08-23 21:01:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlanarYCbCrImage::CopyData(const Data& aData)
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
2012-08-23 21:01:14 +04:00
|
|
|
mData = aData;
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
// update buffer size
|
2013-12-11 10:58:51 +04:00
|
|
|
size_t size = mData.mCbCrStride * mData.mCbCrSize.height * 2 +
|
2012-08-23 21:01:14 +04:00
|
|
|
mData.mYStride * mData.mYSize.height;
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
// get new buffer
|
2013-12-11 10:58:51 +04:00
|
|
|
mBuffer = AllocateBuffer(size);
|
2012-08-23 21:01:14 +04:00
|
|
|
if (!mBuffer)
|
2012-08-19 23:33:25 +04:00
|
|
|
return;
|
|
|
|
|
2013-12-11 10:58:51 +04:00
|
|
|
// update buffer size
|
|
|
|
mBufferSize = size;
|
|
|
|
|
2012-08-23 21:01:14 +04: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-26 07:22:51 +04:00
|
|
|
mData.mYSize, mData.mYStride, mData.mYSkip);
|
2012-08-23 21:01:14 +04:00
|
|
|
CopyPlane(mData.mCbChannel, aData.mCbChannel,
|
2012-08-26 07:22:51 +04:00
|
|
|
mData.mCbCrSize, mData.mCbCrStride, mData.mCbSkip);
|
2012-08-23 21:01:14 +04:00
|
|
|
CopyPlane(mData.mCrChannel, aData.mCrChannel,
|
2012-08-26 07:22:51 +04:00
|
|
|
mData.mCbCrSize, mData.mCbCrStride, mData.mCrSkip);
|
2012-08-23 21:01:14 +04:00
|
|
|
|
|
|
|
mSize = aData.mPicSize;
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlanarYCbCrImage::SetData(const Data &aData)
|
|
|
|
{
|
2012-08-23 21:01:14 +04:00
|
|
|
CopyData(aData);
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormat
|
2013-01-24 03:08:16 +04:00
|
|
|
PlanarYCbCrImage::GetOffscreenFormat()
|
|
|
|
{
|
2013-09-25 00:45:13 +04:00
|
|
|
return mOffscreenFormat == gfxImageFormatUnknown ?
|
2013-01-24 03:08:16 +04:00
|
|
|
gfxPlatform::GetPlatform()->GetOffscreenFormat() :
|
|
|
|
mOffscreenFormat;
|
|
|
|
}
|
|
|
|
|
2013-03-14 00:11:15 +04:00
|
|
|
void
|
|
|
|
PlanarYCbCrImage::SetDataNoCopy(const Data &aData)
|
|
|
|
{
|
|
|
|
mData = aData;
|
|
|
|
mSize = aData.mPicSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
PlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
|
|
|
|
{
|
|
|
|
// get new buffer
|
2013-12-11 10:58:51 +04:00
|
|
|
mBuffer = AllocateBuffer(aSize);
|
|
|
|
if (mBuffer) {
|
|
|
|
// update buffer size
|
|
|
|
mBufferSize = aSize;
|
|
|
|
}
|
2013-03-14 00:11:15 +04:00
|
|
|
return mBuffer;
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
PlanarYCbCrImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
|
|
|
nsRefPtr<gfxASurface> result = mSurface.get();
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormat format = GetOffscreenFormat();
|
2012-08-19 23:33:25 +04:00
|
|
|
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;
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return imageSurface.forget();
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
RemoteBitmapImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxImageSurface> newSurf =
|
|
|
|
new gfxImageSurface(mSize,
|
2013-09-25 00:45:13 +04:00
|
|
|
mFormat == RemoteImageData::BGRX32 ? gfxImageFormatRGB24 : gfxImageFormatARGB32);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
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-20 06:39:10 +04:00
|
|
|
} // namespace
|