2012-12-12 14:47:28 -08:00
|
|
|
/* 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 "ShadowLayers.h"
|
|
|
|
#include "SharedRGBImage.h"
|
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 02:20:52 -07:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
2012-12-12 14:47:28 -08:00
|
|
|
#include "Shmem.h"
|
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 02:20:52 -07:00
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2012-12-12 14:47:28 -08:00
|
|
|
|
|
|
|
// Just big enough for a 1080p RGBA32 frame
|
|
|
|
#define MAX_FRAME_SIZE (16 * 1024 * 1024)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
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 02:20:52 -07:00
|
|
|
SharedRGBImage::SharedRGBImage(ISurfaceAllocator *aAllocator) :
|
2012-12-12 14:47:28 -08:00
|
|
|
Image(nullptr, SHARED_RGB),
|
|
|
|
mSize(0, 0),
|
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 02:20:52 -07:00
|
|
|
mSurfaceAllocator(aAllocator),
|
2012-12-12 14:47:28 -08:00
|
|
|
mAllocated(false),
|
|
|
|
mShmem(new ipc::Shmem())
|
|
|
|
{
|
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 02:20:52 -07:00
|
|
|
MOZ_COUNT_CTOR(SharedRGBImage);
|
2012-12-12 14:47:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedRGBImage::~SharedRGBImage()
|
|
|
|
{
|
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 02:20:52 -07:00
|
|
|
MOZ_COUNT_DTOR(SharedRGBImage);
|
|
|
|
|
|
|
|
if (mAllocated) {
|
|
|
|
SurfaceDescriptor desc;
|
|
|
|
DropToSurfaceDescriptor(desc);
|
|
|
|
mSurfaceAllocator->DestroySharedSurface(&desc);
|
|
|
|
}
|
2012-12-12 14:47:28 -08:00
|
|
|
delete mShmem;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SharedRGBImage>
|
|
|
|
SharedRGBImage::Create(ImageContainer *aImageContainer,
|
|
|
|
nsIntSize aSize,
|
|
|
|
gfxImageFormat aImageFormat)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aImageFormat == gfxASurface::ImageFormatARGB32 ||
|
|
|
|
aImageFormat == gfxASurface::ImageFormatRGB24 ||
|
|
|
|
aImageFormat == gfxASurface::ImageFormatRGB16_565,
|
|
|
|
"RGB formats supported only");
|
|
|
|
|
|
|
|
if (!aImageContainer) {
|
|
|
|
NS_WARNING("No ImageContainer to allocate SharedRGBImage");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageFormat format = SHARED_RGB;
|
|
|
|
nsRefPtr<Image> image = aImageContainer->CreateImage(&format, 1);
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
NS_WARNING("Failed to create SharedRGBImage");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<SharedRGBImage> rgbImage = static_cast<SharedRGBImage*>(image.get());
|
|
|
|
rgbImage->mSize = gfxIntSize(aSize.width, aSize.height);
|
|
|
|
rgbImage->mImageFormat = aImageFormat;
|
|
|
|
|
|
|
|
if (!rgbImage->AllocateBuffer(aSize, aImageFormat)) {
|
|
|
|
NS_WARNING("Failed to allocate shared memory for SharedRGBImage");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rgbImage.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *
|
|
|
|
SharedRGBImage::GetBuffer()
|
|
|
|
{
|
|
|
|
return mShmem->get<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SharedRGBImage::GetBufferSize()
|
|
|
|
{
|
|
|
|
return mSize.width * mSize.height * gfxASurface::BytesPerPixel(mImageFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize
|
|
|
|
SharedRGBImage::GetSize()
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SharedRGBImage::AllocateBuffer(nsIntSize aSize, gfxImageFormat aImageFormat)
|
|
|
|
{
|
|
|
|
if (mAllocated) {
|
|
|
|
NS_WARNING("Already allocated shmem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size = GetBufferSize();
|
|
|
|
|
|
|
|
if (size == 0 || size > MAX_FRAME_SIZE) {
|
|
|
|
NS_WARNING("Invalid frame size");
|
|
|
|
}
|
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 02:20:52 -07:00
|
|
|
if (mSurfaceAllocator->AllocUnsafeShmem(size, OptimalShmemType(), mShmem)) {
|
2012-12-12 14:47:28 -08:00
|
|
|
mAllocated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAllocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
SharedRGBImage::GetAsSurface()
|
|
|
|
{
|
|
|
|
return 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 02:20:52 -07:00
|
|
|
bool
|
|
|
|
SharedRGBImage::ToSurfaceDescriptor(SurfaceDescriptor& aResult)
|
|
|
|
{
|
|
|
|
if (!mAllocated) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->AddRef();
|
|
|
|
aResult = RGBImage(*mShmem,
|
|
|
|
nsIntRect(0, 0, mSize.width, mSize.height),
|
|
|
|
mImageFormat,
|
|
|
|
reinterpret_cast<uint64_t>(this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SharedRGBImage::DropToSurfaceDescriptor(SurfaceDescriptor& aResult)
|
2012-12-12 14:47:28 -08:00
|
|
|
{
|
|
|
|
if (!mAllocated) {
|
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 02:20:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aResult = RGBImage(*mShmem,
|
|
|
|
nsIntRect(0, 0, mSize.width, mSize.height),
|
|
|
|
mImageFormat,
|
|
|
|
0);
|
|
|
|
*mShmem = ipc::Shmem();
|
|
|
|
mAllocated = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedRGBImage*
|
|
|
|
SharedRGBImage::FromSurfaceDescriptor(const SurfaceDescriptor& aDescriptor)
|
|
|
|
{
|
|
|
|
if (aDescriptor.type() != SurfaceDescriptor::TRGBImage) {
|
2012-12-12 14:47:28 -08:00
|
|
|
return 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 02:20:52 -07:00
|
|
|
const RGBImage& rgb = aDescriptor.get_RGBImage();
|
|
|
|
if (rgb.owner() == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return reinterpret_cast<SharedRGBImage*>(rgb.owner());
|
2012-12-12 14:47:28 -08:00
|
|
|
}
|
|
|
|
|
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 02:20:52 -07:00
|
|
|
|
2012-12-12 14:47:28 -08:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|