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
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* 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 "ISurfaceAllocator.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include <sys/types.h> // for int32_t
|
|
|
|
#include "gfxASurface.h" // for gfxASurface, etc
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform, gfxImageFormat
|
|
|
|
#include "gfxSharedImageSurface.h" // for gfxSharedImageSurface
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
|
|
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
|
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
|
|
|
|
#include "ShadowLayerUtils.h"
|
|
|
|
#include "mozilla/mozalloc.h" // for operator delete[], etc
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
|
|
|
|
#include "nsDebug.h" // for NS_RUNTIMEABORT
|
|
|
|
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
|
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
|
|
|
#ifdef DEBUG
|
|
|
|
#include "prenv.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
SharedMemory::SharedMemoryType OptimalShmemType()
|
|
|
|
{
|
|
|
|
return SharedMemory::TYPE_BASIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface)
|
|
|
|
{
|
|
|
|
return aSurface.type() != SurfaceDescriptor::T__None &&
|
|
|
|
aSurface.type() != SurfaceDescriptor::Tnull_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ISurfaceAllocator::AllocSharedImageSurface(const gfxIntSize& aSize,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxContentType aContent,
|
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
|
|
|
gfxSharedImageSurface** aBuffer)
|
|
|
|
{
|
|
|
|
SharedMemory::SharedMemoryType shmemType = OptimalShmemType();
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
|
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
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> back =
|
|
|
|
gfxSharedImageSurface::CreateUnsafe(this, aSize, format, shmemType);
|
|
|
|
if (!back)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*aBuffer = nullptr;
|
|
|
|
back.swap(*aBuffer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ISurfaceAllocator::AllocSurfaceDescriptor(const gfxIntSize& aSize,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxContentType aContent,
|
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
|
|
|
SurfaceDescriptor* aBuffer)
|
|
|
|
{
|
|
|
|
return AllocSurfaceDescriptorWithCaps(aSize, aContent, DEFAULT_BUFFER_CAPS, aBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ISurfaceAllocator::AllocSurfaceDescriptorWithCaps(const gfxIntSize& aSize,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxContentType aContent,
|
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
|
|
|
uint32_t aCaps,
|
|
|
|
SurfaceDescriptor* aBuffer)
|
|
|
|
{
|
|
|
|
bool tryPlatformSurface = true;
|
|
|
|
#ifdef DEBUG
|
|
|
|
tryPlatformSurface = !PR_GetEnv("MOZ_LAYERS_FORCE_SHMEM_SURFACES");
|
|
|
|
#endif
|
|
|
|
if (tryPlatformSurface &&
|
|
|
|
PlatformAllocSurfaceDescriptor(aSize, aContent, aCaps, aBuffer)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-22 00:04:12 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
gfxImageFormat format =
|
|
|
|
gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
|
|
|
|
int32_t stride = gfxASurface::FormatStrideForWidth(format, aSize.width);
|
2013-08-04 00:46:17 -07:00
|
|
|
uint8_t *data = new (std::nothrow) uint8_t[stride * aSize.height];
|
|
|
|
if (!data) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-09 14:52:30 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Workaround a bug in Quartz where drawing an a8 surface to another a8
|
|
|
|
// surface with OPERATOR_SOURCE still requires the destination to be clear.
|
2013-09-24 13:45:13 -07:00
|
|
|
if (format == gfxImageFormatA8) {
|
2013-07-09 18:12:23 -07:00
|
|
|
memset(data, 0, stride * aSize.height);
|
2013-07-09 14:52:30 -07:00
|
|
|
}
|
|
|
|
#endif
|
2013-05-22 00:04:12 -07:00
|
|
|
*aBuffer = MemoryImage((uintptr_t)data, aSize, stride, format);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsRefPtr<gfxSharedImageSurface> buffer;
|
|
|
|
if (!AllocSharedImageSurface(aSize, aContent,
|
|
|
|
getter_AddRefs(buffer))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBuffer = buffer->GetShmem();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
if (!aSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (PlatformDestroySharedSurface(aSurface)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (aSurface->type()) {
|
|
|
|
case SurfaceDescriptor::TShmem:
|
|
|
|
DeallocShmem(aSurface->get_Shmem());
|
|
|
|
break;
|
|
|
|
case SurfaceDescriptor::TYCbCrImage:
|
|
|
|
DeallocShmem(aSurface->get_YCbCrImage().data());
|
|
|
|
break;
|
|
|
|
case SurfaceDescriptor::TRGBImage:
|
|
|
|
DeallocShmem(aSurface->get_RGBImage().data());
|
|
|
|
break;
|
2013-08-04 00:46:17 -07:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D9:
|
2013-09-23 18:14:11 -07:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDIB:
|
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
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D10:
|
|
|
|
break;
|
2013-05-22 00:04:12 -07:00
|
|
|
case SurfaceDescriptor::TMemoryImage:
|
2013-09-24 08:49:11 -07:00
|
|
|
delete [] (unsigned char *)aSurface->get_MemoryImage().data();
|
2013-05-22 00:04:12 -07:00
|
|
|
break;
|
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
|
|
|
case SurfaceDescriptor::Tnull_t:
|
|
|
|
case SurfaceDescriptor::T__None:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("surface type not implemented!");
|
|
|
|
}
|
|
|
|
*aSurface = SurfaceDescriptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
|
|
|
|
bool
|
|
|
|
ISurfaceAllocator::PlatformAllocSurfaceDescriptor(const gfxIntSize&,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxContentType,
|
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
|
|
|
uint32_t,
|
|
|
|
SurfaceDescriptor*)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|