DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (dcc6d7a0dc00)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/* -*- 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/. */

#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#pragma GCC visibility push(default)
#include "sync/sync.h"       // for sync_merge
#pragma GCC visibility pop
#endif

#include "FenceUtils.h"

using namespace mozilla::layers;

namespace IPC {

void
ParamTraits<FenceHandle>::Write(Message* aMsg,
                                const paramType& aParam)
{
  FenceHandle handle = aParam;

  MOZ_ASSERT(handle.IsValid());

#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
  RefPtr<FenceHandle::FdObj> fence = handle.GetAndResetFdObj();
  aMsg->WriteFileDescriptor(base::FileDescriptor(fence->GetAndResetFd(), true));
#endif
}

bool
ParamTraits<FenceHandle>::Read(const Message* aMsg,
                               void** aIter, paramType* aResult)
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
  base::FileDescriptor fd;
  if (aMsg->ReadFileDescriptor(aIter, &fd)) {
    aResult->Merge(FenceHandle(new FenceHandle::FdObj(fd.fd)));
  }
#endif
  return true;
}

} // namespace IPC

namespace mozilla {
namespace layers {

FenceHandle::FenceHandle()
  : mFence(new FdObj())
{
}

FenceHandle::FenceHandle(FdObj* aFdObj)
  : mFence(aFdObj)
{
  MOZ_ASSERT(aFdObj);
}

void
FenceHandle::Merge(const FenceHandle& aFenceHandle)
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
  if (!aFenceHandle.IsValid()) {
    return;
  }

  if (!IsValid()) {
    mFence = aFenceHandle.mFence;
  } else {
    int result = sync_merge("FenceHandle", mFence->mFd, aFenceHandle.mFence->mFd);
    if (result == -1) {
      mFence = aFenceHandle.mFence;
    } else {
      mFence = new FdObj(result);
    }
  }
#endif
}

void
FenceHandle::TransferToAnotherFenceHandle(FenceHandle& aFenceHandle)
{
  aFenceHandle.mFence = this->GetAndResetFdObj();
}

already_AddRefed<FenceHandle::FdObj>
FenceHandle::GetAndResetFdObj()
{
  RefPtr<FdObj> fence = mFence;
  mFence = new FdObj();
  return fence.forget();
}

already_AddRefed<FenceHandle::FdObj>
FenceHandle::GetDupFdObj()
{
  RefPtr<FdObj> fdObj;
  if (IsValid()) {
    fdObj = new FenceHandle::FdObj(dup(mFence->mFd));
  } else {
    fdObj = new FenceHandle::FdObj();
  }
  return fdObj.forget();
}

} // namespace layers
} // namespace mozilla