2012-07-12 12:51:58 +00: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 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-12-20 16:46:30 +00:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2013-11-27 15:19:34 +00:00
|
|
|
#include "mozilla/layers/LayerTransactionChild.h"
|
2012-07-12 12:51:58 +00:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2013-04-25 22:25:33 +00:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
2013-12-12 01:44:44 +00:00
|
|
|
#include "mozilla/layers/TextureHost.h"
|
2014-05-01 01:52:00 +00:00
|
|
|
#include "mozilla/layers/SharedBufferManagerChild.h"
|
|
|
|
#include "mozilla/layers/SharedBufferManagerParent.h"
|
2012-07-12 12:51:58 +00:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
|
|
|
#include "ShadowLayerUtilsGralloc.h"
|
|
|
|
|
2012-11-22 13:39:56 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
#include "gfxPlatform.h"
|
2013-12-20 16:46:31 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2013-09-04 12:14:52 +00:00
|
|
|
#include "GLContext.h"
|
2012-07-12 12:51:58 +00:00
|
|
|
|
2013-03-18 14:25:50 +00:00
|
|
|
#include "GeckoProfiler.h"
|
2012-08-01 22:49:59 +00:00
|
|
|
|
2013-06-05 20:42:00 +00:00
|
|
|
#include "cutils/properties.h"
|
|
|
|
|
2013-09-24 22:09:20 +00:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
using namespace android;
|
|
|
|
using namespace mozilla::layers;
|
2012-10-25 20:12:59 +00:00
|
|
|
using namespace mozilla::gl;
|
2012-07-12 12:51:58 +00:00
|
|
|
|
2015-02-11 20:01:26 +00:00
|
|
|
using base::FileDescriptor;
|
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
namespace IPC {
|
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
void
|
|
|
|
ParamTraits<GrallocBufferRef>::Write(Message* aMsg,
|
|
|
|
const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteInt(aParam.mOwner);
|
2014-07-02 21:45:59 +00:00
|
|
|
aMsg->WriteInt64(aParam.mKey);
|
2014-05-01 01:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ParamTraits<GrallocBufferRef>::Read(const Message* aMsg, void** aIter,
|
|
|
|
paramType* aParam)
|
|
|
|
{
|
|
|
|
int owner;
|
2014-07-02 21:45:59 +00:00
|
|
|
int64_t index;
|
2014-05-01 01:52:00 +00:00
|
|
|
if (!aMsg->ReadInt(aIter, &owner) ||
|
2014-07-02 21:45:59 +00:00
|
|
|
!aMsg->ReadInt64(aIter, &index)) {
|
2014-06-30 23:36:52 +00:00
|
|
|
printf_stderr("ParamTraits<GrallocBufferRef>::Read() failed to read a message\n");
|
2014-05-01 01:52:00 +00:00
|
|
|
return false;
|
2014-06-30 23:36:52 +00:00
|
|
|
}
|
2014-05-01 01:52:00 +00:00
|
|
|
aParam->mOwner = owner;
|
|
|
|
aParam->mKey = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
void
|
|
|
|
ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
|
|
|
|
const paramType& aParam)
|
|
|
|
{
|
2014-01-09 10:42:54 +00:00
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
sp<GraphicBuffer> flattenable = aParam.mGraphicBuffer;
|
|
|
|
#else
|
2012-07-12 12:51:58 +00:00
|
|
|
Flattenable *flattenable = aParam.mGraphicBuffer.get();
|
2014-01-09 10:42:54 +00:00
|
|
|
#endif
|
2012-07-12 12:51:58 +00:00
|
|
|
size_t nbytes = flattenable->getFlattenedSize();
|
|
|
|
size_t nfds = flattenable->getFdCount();
|
|
|
|
|
|
|
|
char data[nbytes];
|
|
|
|
int fds[nfds];
|
2014-01-09 10:42:54 +00: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 12:51:58 +00:00
|
|
|
flattenable->flatten(data, nbytes, fds, nfds);
|
2014-01-09 10:42:54 +00:00
|
|
|
#endif
|
2014-05-01 01:52:00 +00:00
|
|
|
aMsg->WriteInt(aParam.mRef.mOwner);
|
2014-07-02 21:45:59 +00:00
|
|
|
aMsg->WriteInt64(aParam.mRef.mKey);
|
2012-07-12 12:51:58 +00:00
|
|
|
aMsg->WriteSize(nbytes);
|
|
|
|
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)
|
|
|
|
{
|
2015-03-24 22:40:00 +00:00
|
|
|
MOZ_ASSERT(!aResult->mGraphicBuffer.get());
|
|
|
|
MOZ_ASSERT(aResult->mRef.mOwner == 0);
|
|
|
|
MOZ_ASSERT(aResult->mRef.mKey == -1);
|
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
size_t nbytes;
|
|
|
|
const char* data;
|
2014-05-01 01:52:00 +00:00
|
|
|
int owner;
|
2014-07-02 21:45:59 +00:00
|
|
|
int64_t index;
|
2012-07-12 12:51:58 +00:00
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
if (!aMsg->ReadInt(aIter, &owner) ||
|
2014-07-02 21:45:59 +00:00
|
|
|
!aMsg->ReadInt64(aIter, &index) ||
|
2014-05-01 01:52:00 +00:00
|
|
|
!aMsg->ReadSize(aIter, &nbytes) ||
|
2012-07-12 12:51:58 +00:00
|
|
|
!aMsg->ReadBytes(aIter, &data, nbytes)) {
|
2014-06-30 23:36:52 +00:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read a message\n");
|
2012-07-12 12:51:58 +00: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 09:20:52 +00:00
|
|
|
|
2014-08-18 17:55:23 +00:00
|
|
|
size_t nfds = aMsg->num_fds();
|
2012-07-12 12:51:58 +00:00
|
|
|
int fds[nfds];
|
2015-03-24 22:40:00 +00:00
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
for (size_t n = 0; n < nfds; ++n) {
|
|
|
|
FileDescriptor fd;
|
|
|
|
if (!aMsg->ReadFileDescriptor(aIter, &fd)) {
|
2014-06-30 23:36:52 +00:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read file descriptors\n");
|
2012-07-12 12:51:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If the GraphicBuffer was shared cross-process, SCM_RIGHTS does
|
2014-06-30 23:36:52 +00: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 12:51:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
aResult->mRef.mOwner = owner;
|
|
|
|
aResult->mRef.mKey = index;
|
2015-06-24 18:11:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-03-24 22:40:00 +00:00
|
|
|
// If we are in chrome process, we can just get GraphicBuffer directly from
|
|
|
|
// SharedBufferManagerParent.
|
2014-05-01 01:52:00 +00:00
|
|
|
aResult->mGraphicBuffer = SharedBufferManagerParent::GetGraphicBuffer(aResult->mRef);
|
2014-07-09 01:35:42 +00:00
|
|
|
} else {
|
|
|
|
// Deserialize GraphicBuffer
|
2014-01-09 10:42:54 +00:00
|
|
|
#if ANDROID_VERSION >= 19
|
2014-07-09 01:35:42 +00:00
|
|
|
sp<GraphicBuffer> buffer(new GraphicBuffer());
|
|
|
|
const void* datap = (const void*)data;
|
|
|
|
const int* fdsp = &fds[0];
|
|
|
|
if (NO_ERROR != buffer->unflatten(datap, nbytes, fdsp, nfds)) {
|
|
|
|
buffer = nullptr;
|
|
|
|
}
|
2014-01-09 10:42:54 +00:00
|
|
|
#else
|
2014-07-09 01:35:42 +00:00
|
|
|
sp<GraphicBuffer> buffer(new GraphicBuffer());
|
|
|
|
Flattenable *flattenable = buffer.get();
|
|
|
|
if (NO_ERROR != flattenable->unflatten(data, nbytes, fds, nfds)) {
|
|
|
|
buffer = nullptr;
|
|
|
|
}
|
2014-01-09 10:42:54 +00:00
|
|
|
#endif
|
2015-03-24 22:40:00 +00:00
|
|
|
if (buffer.get()) {
|
2014-07-09 01:35:42 +00:00
|
|
|
aResult->mGraphicBuffer = buffer;
|
2014-05-01 01:52:00 +00:00
|
|
|
}
|
2012-07-12 12:51:58 +00:00
|
|
|
}
|
2014-05-01 01:52:00 +00:00
|
|
|
|
2014-07-09 01:35:42 +00:00
|
|
|
if (!aResult->mGraphicBuffer.get()) {
|
2014-06-30 23:36:52 +00:00
|
|
|
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to get gralloc buffer\n");
|
2014-05-01 01:52:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-07-12 12:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IPC
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref)
|
2012-07-12 12:51:58 +00:00
|
|
|
: mGraphicBuffer(aGraphicBuffer)
|
2014-05-01 01:52:00 +00:00
|
|
|
, mRef(ref)
|
2012-07-12 12:51:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Parent process
|
|
|
|
|
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 09:20:52 +00:00
|
|
|
/*static*/ bool
|
2013-04-25 22:25:33 +00: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 09:20:52 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-23 23:58:37 +00:00
|
|
|
/*static*/ void
|
2013-04-25 22:25:33 +00:00
|
|
|
LayerManagerComposite::PlatformSyncBeforeReplyUpdate()
|
2012-07-23 23:58:37 +00:00
|
|
|
{
|
|
|
|
// Nothing to be done for gralloc.
|
|
|
|
}
|
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-05-01 01:52:00 +00:00
|
|
|
// Both processes
|
2014-04-25 16:51:11 +00:00
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
/*static*/ sp<GraphicBuffer>
|
|
|
|
GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle)
|
2014-04-25 16:51:11 +00:00
|
|
|
{
|
2014-05-01 01:52:00 +00:00
|
|
|
if (aHandle.type() != MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
|
|
|
|
if (aHandle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
|
2015-06-24 18:11:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2014-05-01 01:52:00 +00:00
|
|
|
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-25 06:29:00 +00:00
|
|
|
}
|
2014-05-01 01:52:00 +00:00
|
|
|
return nullptr;
|
2014-04-25 16:51:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
android::sp<android::GraphicBuffer>
|
|
|
|
GetGraphicBufferFromDesc(SurfaceDescriptor aDesc)
|
2014-04-25 16:51:11 +00:00
|
|
|
{
|
2014-05-01 01:52:00 +00:00
|
|
|
MaybeMagicGrallocBufferHandle handle;
|
|
|
|
if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
|
|
|
|
handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer();
|
|
|
|
}
|
|
|
|
return GetGraphicBufferFrom(handle);
|
2013-08-09 15:23:46 +00:00
|
|
|
}
|
2012-07-12 12:51:58 +00:00
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ShadowLayerForwarder::PlatformSyncBeforeUpdate()
|
|
|
|
{
|
|
|
|
// Nothing to be done for gralloc.
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|