2012-07-12 05:51:58 -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/. */
|
|
|
|
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-12-20 08:46:30 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2013-11-27 07:19:34 -08:00
|
|
|
#include "mozilla/layers/LayerTransactionChild.h"
|
2012-07-12 05:51:58 -07:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2013-04-25 15:25:33 -07:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
2013-12-11 17:44:44 -08:00
|
|
|
#include "mozilla/layers/TextureHost.h"
|
2014-04-30 18:52:00 -07:00
|
|
|
#include "mozilla/layers/SharedBufferManagerChild.h"
|
|
|
|
#include "mozilla/layers/SharedBufferManagerParent.h"
|
2012-07-12 05:51:58 -07:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
|
|
|
#include "ShadowLayerUtilsGralloc.h"
|
|
|
|
|
2012-11-22 05:39:56 -08:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "gfxPlatform.h"
|
2013-12-20 08:46:31 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2012-07-12 05:51:58 -07:00
|
|
|
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-08-01 15:49:59 -07:00
|
|
|
|
2013-06-05 13:42:00 -07:00
|
|
|
#include "cutils/properties.h"
|
|
|
|
|
2013-09-24 15:09:20 -07:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
|
2012-07-12 05:51:58 -07:00
|
|
|
using namespace android;
|
|
|
|
using namespace base;
|
|
|
|
using namespace mozilla::layers;
|
2012-10-25 13:12:59 -07:00
|
|
|
using namespace mozilla::gl;
|
2012-07-12 05:51:58 -07:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
void
|
|
|
|
ParamTraits<GrallocBufferRef>::Write(Message* aMsg,
|
|
|
|
const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteInt(aParam.mOwner);
|
2014-07-02 14:45:59 -07:00
|
|
|
aMsg->WriteInt64(aParam.mKey);
|
2014-04-30 18:52:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ParamTraits<GrallocBufferRef>::Read(const Message* aMsg, void** aIter,
|
|
|
|
paramType* aParam)
|
|
|
|
{
|
|
|
|
int owner;
|
2014-07-02 14:45:59 -07:00
|
|
|
int64_t index;
|
2014-04-30 18:52:00 -07:00
|
|
|
if (!aMsg->ReadInt(aIter, &owner) ||
|
2014-07-02 14:45:59 -07:00
|
|
|
!aMsg->ReadInt64(aIter, &index)) {
|
2014-06-30 16:36:52 -07:00
|
|
|
printf_stderr("ParamTraits<GrallocBufferRef>::Read() failed to read a message\n");
|
2014-04-30 18:52:00 -07:00
|
|
|
return false;
|
2014-06-30 16:36:52 -07:00
|
|
|
}
|
2014-04-30 18:52:00 -07:00
|
|
|
aParam->mOwner = owner;
|
|
|
|
aParam->mKey = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-12 05:51:58 -07:00
|
|
|
void
|
|
|
|
ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
|
|
|
|
const paramType& aParam)
|
|
|
|
{
|
2014-01-09 02:42:54 -08:00
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
sp<GraphicBuffer> flattenable = aParam.mGraphicBuffer;
|
|
|
|
#else
|
2012-07-12 05:51:58 -07:00
|
|
|
Flattenable *flattenable = aParam.mGraphicBuffer.get();
|
2014-01-09 02:42:54 -08:00
|
|
|
#endif
|
2012-07-12 05:51:58 -07:00
|
|
|
size_t nbytes = flattenable->getFlattenedSize();
|
|
|
|
size_t nfds = flattenable->getFdCount();
|
|
|
|
|
|
|
|
char data[nbytes];
|
|
|
|
int fds[nfds];
|
2014-01-09 02:42:54 -08:00
|
|
|
|
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
// Make a copy of "data" and "fds" for flatten() to avoid casting problem
|
|
|
|
void *pdata = (void *)data;
|
|
|
|
int *pfds = fds;
|
|
|
|
|
|
|
|
flattenable->flatten(pdata, nbytes, pfds, nfds);
|
|
|
|
|
|
|
|
// In Kitkat, flatten() will change the value of nbytes and nfds, which dues
|
|
|
|
// to multiple parcelable object consumption. The actual size and fd count
|
|
|
|
// which returned by getFlattenedSize() and getFdCount() are not changed.
|
|
|
|
// So we change nbytes and nfds back by call corresponding calls.
|
|
|
|
nbytes = flattenable->getFlattenedSize();
|
|
|
|
nfds = flattenable->getFdCount();
|
|
|
|
#else
|
2012-07-12 05:51:58 -07:00
|
|
|
flattenable->flatten(data, nbytes, fds, nfds);
|
2014-01-09 02:42:54 -08:00
|
|
|
#endif
|
2014-04-30 18:52:00 -07:00
|
|
|
aMsg->WriteInt(aParam.mRef.mOwner);
|
2014-07-02 14:45:59 -07:00
|
|
|
aMsg->WriteInt64(aParam.mRef.mKey);
|
2012-07-12 05:51:58 -07:00
|
|
|
aMsg->WriteSize(nbytes);
|
|
|
|
aMsg->WriteSize(nfds);
|
|
|
|
|
|
|
|
aMsg->WriteBytes(data, nbytes);
|
|
|
|
for (size_t n = 0; n < nfds; ++n) {
|
|
|
|
// These buffers can't die in transit because they're created
|
|
|
|
// synchonously and the parent-side buffer can only be dropped if
|
|
|
|
// there's a crash.
|
|
|
|
aMsg->WriteFileDescriptor(FileDescriptor(fds[n], false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
|
|
|
|
void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
size_t nbytes;
|
|
|
|
size_t nfds;
|
|
|
|
const char* data;
|
2014-04-30 18:52:00 -07:00
|
|
|
int owner;
|
2014-07-02 14:45:59 -07:00
|
|
|
int64_t index;
|
2012-07-12 05:51:58 -07:00
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
if (!aMsg->ReadInt(aIter, &owner) ||
|
2014-07-02 14:45:59 -07:00
|
|
|
!aMsg->ReadInt64(aIter, &index) ||
|
2014-04-30 18:52:00 -07:00
|
|
|
!aMsg->ReadSize(aIter, &nbytes) ||
|
2012-07-12 05:51:58 -07:00
|
|
|
!aMsg->ReadSize(aIter, &nfds) ||
|
|
|
|
!aMsg->ReadBytes(aIter, &data, nbytes)) {
|
2014-06-30 16:36:52 -07:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read a message\n");
|
2012-07-12 05:51:58 -07:00
|
|
|
return false;
|
|
|
|
}
|
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-07-12 05:51:58 -07:00
|
|
|
int fds[nfds];
|
2014-04-30 18:52:00 -07:00
|
|
|
bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default);
|
2012-07-12 05:51:58 -07:00
|
|
|
for (size_t n = 0; n < nfds; ++n) {
|
|
|
|
FileDescriptor fd;
|
|
|
|
if (!aMsg->ReadFileDescriptor(aIter, &fd)) {
|
2014-06-30 16:36:52 -07:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read file descriptors\n");
|
2012-07-12 05:51:58 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If the GraphicBuffer was shared cross-process, SCM_RIGHTS does
|
2014-06-30 16:36:52 -07:00
|
|
|
// the right thing and dup's the fd. If it's shared cross-thread,
|
|
|
|
// SCM_RIGHTS doesn't dup the fd.
|
|
|
|
// But in shared cross-thread, dup fd is not necessary because we get
|
|
|
|
// a pointer to the GraphicBuffer directly from SharedBufferManagerParent
|
|
|
|
// and don't create a new GraphicBuffer around the fd.
|
|
|
|
fds[n] = fd.fd;
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
aResult->mRef.mOwner = owner;
|
|
|
|
aResult->mRef.mKey = index;
|
|
|
|
if (sameProcess)
|
|
|
|
aResult->mGraphicBuffer = SharedBufferManagerParent::GetGraphicBuffer(aResult->mRef);
|
|
|
|
else {
|
|
|
|
aResult->mGraphicBuffer = SharedBufferManagerChild::GetSingleton()->GetGraphicBuffer(index);
|
|
|
|
if (index >= 0 && aResult->mGraphicBuffer == nullptr) {
|
|
|
|
//Only newly created GraphicBuffer should deserialize
|
2014-01-09 02:42:54 -08:00
|
|
|
#if ANDROID_VERSION >= 19
|
2014-04-30 18:52:00 -07:00
|
|
|
sp<GraphicBuffer> flattenable(new GraphicBuffer());
|
|
|
|
const void* datap = (const void*)data;
|
|
|
|
const int* fdsp = &fds[0];
|
|
|
|
if (NO_ERROR == flattenable->unflatten(datap, nbytes, fdsp, nfds)) {
|
|
|
|
aResult->mGraphicBuffer = flattenable;
|
|
|
|
}
|
2014-01-09 02:42:54 -08:00
|
|
|
#else
|
2014-04-30 18:52:00 -07:00
|
|
|
sp<GraphicBuffer> buffer(new GraphicBuffer());
|
|
|
|
Flattenable *flattenable = buffer.get();
|
2012-07-12 05:51:58 -07:00
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) {
|
|
|
|
aResult->mGraphicBuffer = buffer;
|
|
|
|
}
|
2014-01-09 02:42:54 -08:00
|
|
|
#endif
|
2014-04-30 18:52:00 -07:00
|
|
|
}
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
2014-04-30 18:52:00 -07:00
|
|
|
|
|
|
|
if (aResult->mGraphicBuffer == nullptr) {
|
2014-06-30 16:36:52 -07:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to get gralloc buffer\n");
|
2014-04-30 18:52:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IPC
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref)
|
2012-07-12 05:51:58 -07:00
|
|
|
: mGraphicBuffer(aGraphicBuffer)
|
2014-04-30 18:52:00 -07:00
|
|
|
, mRef(ref)
|
2012-07-12 05:51:58 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Parent process
|
|
|
|
|
2013-09-24 13:45:13 -07:00
|
|
|
static gfxImageFormat
|
2012-07-12 05:51:58 -07:00
|
|
|
ImageFormatForPixelFormat(android::PixelFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aFormat) {
|
|
|
|
case PIXEL_FORMAT_RGBA_8888:
|
2014-01-23 10:26:40 -08:00
|
|
|
return gfxImageFormat::ARGB32;
|
2012-07-12 05:51:58 -07:00
|
|
|
case PIXEL_FORMAT_RGBX_8888:
|
2014-01-23 10:26:40 -08:00
|
|
|
return gfxImageFormat::RGB24;
|
2012-07-12 05:51:58 -07:00
|
|
|
case PIXEL_FORMAT_RGB_565:
|
2014-01-23 10:26:40 -08:00
|
|
|
return gfxImageFormat::RGB16_565;
|
2012-07-12 05:51:58 -07:00
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Unknown gralloc pixel format");
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
2014-01-23 10:26:40 -08:00
|
|
|
return gfxImageFormat::ARGB32;
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static android::PixelFormat
|
2013-09-24 13:45:13 -07:00
|
|
|
PixelFormatForImageFormat(gfxImageFormat aFormat)
|
2012-07-12 05:51:58 -07:00
|
|
|
{
|
|
|
|
switch (aFormat) {
|
2014-01-23 10:26:40 -08:00
|
|
|
case gfxImageFormat::ARGB32:
|
2012-07-12 05:51:58 -07:00
|
|
|
return android::PIXEL_FORMAT_RGBA_8888;
|
2014-01-23 10:26:40 -08:00
|
|
|
case gfxImageFormat::RGB24:
|
2012-07-12 05:51:58 -07:00
|
|
|
return android::PIXEL_FORMAT_RGBX_8888;
|
2014-01-23 10:26:40 -08:00
|
|
|
case gfxImageFormat::RGB16_565:
|
2012-07-12 05:51:58 -07:00
|
|
|
return android::PIXEL_FORMAT_RGB_565;
|
2014-01-30 08:17:10 -08:00
|
|
|
case gfxImageFormat::A8:
|
|
|
|
NS_WARNING("gralloc does not support gfxImageFormat::A8");
|
|
|
|
return android::PIXEL_FORMAT_UNKNOWN;
|
2012-07-12 05:51:58 -07:00
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Unknown gralloc pixel format");
|
2012-07-12 05:51:58 -07:00
|
|
|
}
|
2014-01-23 12:02:23 -08:00
|
|
|
return android::PIXEL_FORMAT_RGBA_8888;
|
2012-07-12 05:51:58 -07: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
|
|
|
/*static*/ bool
|
2013-04-25 15:25:33 -07:00
|
|
|
LayerManagerComposite::SupportsDirectTexturing()
|
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 true;
|
|
|
|
}
|
|
|
|
|
2012-07-23 16:58:37 -07:00
|
|
|
/*static*/ void
|
2013-04-25 15:25:33 -07:00
|
|
|
LayerManagerComposite::PlatformSyncBeforeReplyUpdate()
|
2012-07-23 16:58:37 -07:00
|
|
|
{
|
|
|
|
// Nothing to be done for gralloc.
|
|
|
|
}
|
|
|
|
|
2012-07-12 05:51:58 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-04-30 18:52:00 -07:00
|
|
|
// Both processes
|
2014-04-25 09:51:11 -07:00
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
/*static*/ sp<GraphicBuffer>
|
|
|
|
GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle)
|
2014-04-25 09:51:11 -07:00
|
|
|
{
|
2014-04-30 18:52:00 -07:00
|
|
|
if (aHandle.type() != MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
|
|
|
|
if (aHandle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
return SharedBufferManagerParent::GetGraphicBuffer(aHandle.get_GrallocBufferRef());
|
|
|
|
}
|
|
|
|
return SharedBufferManagerChild::GetSingleton()->GetGraphicBuffer(aHandle.get_GrallocBufferRef().mKey);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MagicGrallocBufferHandle realHandle = aHandle.get_MagicGrallocBufferHandle();
|
|
|
|
return realHandle.mGraphicBuffer;
|
2014-04-24 23:29:00 -07:00
|
|
|
}
|
2014-04-30 18:52:00 -07:00
|
|
|
return nullptr;
|
2014-04-25 09:51:11 -07:00
|
|
|
}
|
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
android::sp<android::GraphicBuffer>
|
|
|
|
GetGraphicBufferFromDesc(SurfaceDescriptor aDesc)
|
2014-04-25 09:51:11 -07:00
|
|
|
{
|
2014-04-30 18:52:00 -07:00
|
|
|
MaybeMagicGrallocBufferHandle handle;
|
|
|
|
if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
|
|
|
|
handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer();
|
|
|
|
}
|
|
|
|
return GetGraphicBufferFrom(handle);
|
2013-08-09 08:23:46 -07:00
|
|
|
}
|
2012-07-12 05:51:58 -07:00
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ShadowLayerForwarder::PlatformSyncBeforeUpdate()
|
|
|
|
{
|
|
|
|
// Nothing to be done for gralloc.
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|