Bug 1240659 - Add GonkNativeHandle::CreateDupNhObj() r=nical
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Wed, 20 Jan 2016 21:36:00 -0800
changeset 280891 a24d6c2b7525f4e1f5a32c3d54444f01c09e82fe
parent 280890 f87d296b05288411bce7a722e232e71ffe088962
child 280892 b578a9def3278b66b4ff63d167e5d9c1eff05a7b
push id29922
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:51:00 +0000
treeherdermozilla-central@977d78a8dd78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1240659
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1240659 - Add GonkNativeHandle::CreateDupNhObj() r=nical
gfx/layers/ipc/GonkNativeHandle.cpp
gfx/layers/ipc/GonkNativeHandle.h
--- a/gfx/layers/ipc/GonkNativeHandle.cpp
+++ b/gfx/layers/ipc/GonkNativeHandle.cpp
@@ -38,28 +38,41 @@ GonkNativeHandle::GetAndResetNhObj()
   RefPtr<NhObj> nhObj = mNhObj;
   mNhObj = new NhObj();
   return nhObj.forget();
 }
 
 already_AddRefed<GonkNativeHandle::NhObj>
 GonkNativeHandle::GetDupNhObj()
 {
+  if (!IsValid()) {
+    return GonkNativeHandle::CreateDupNhObj(nullptr);
+  }
+  return GonkNativeHandle::CreateDupNhObj(mNhObj->mHandle);
+}
+
+/* static */ already_AddRefed<GonkNativeHandle::NhObj>
+GonkNativeHandle::CreateDupNhObj(native_handle_t* aHandle)
+{
   RefPtr<NhObj> nhObj;
-  if (IsValid()) {
+  if (aHandle) {
     native_handle* nativeHandle =
-      native_handle_create(mNhObj->mHandle->numFds, mNhObj->mHandle->numInts);
+      native_handle_create(aHandle->numFds, aHandle->numInts);
+    if (!nativeHandle) {
+      nhObj = new GonkNativeHandle::NhObj();
+      return nhObj.forget();
+    }
 
-    for (int i = 0; i < mNhObj->mHandle->numFds; ++i) {
-        nativeHandle->data[i] = dup(mNhObj->mHandle->data[i]);
+    for (int i = 0; i < aHandle->numFds; ++i) {
+      nativeHandle->data[i] = dup(aHandle->data[i]);
     }
 
     memcpy(nativeHandle->data + nativeHandle->numFds,
-           mNhObj->mHandle->data + mNhObj->mHandle->numFds,
-           sizeof(int) * mNhObj->mHandle->numInts);
+           aHandle->data + aHandle->numFds,
+           sizeof(int) * aHandle->numInts);
 
     nhObj = new GonkNativeHandle::NhObj(nativeHandle);
   } else {
     nhObj = new GonkNativeHandle::NhObj();
   }
   return nhObj.forget();
 }
 
--- a/gfx/layers/ipc/GonkNativeHandle.h
+++ b/gfx/layers/ipc/GonkNativeHandle.h
@@ -66,16 +66,18 @@ public:
   }
 
   void TransferToAnother(GonkNativeHandle& aHandle);
 
   already_AddRefed<NhObj> GetAndResetNhObj();
 
   already_AddRefed<NhObj> GetDupNhObj();
 
+  static already_AddRefed<NhObj> CreateDupNhObj(native_handle_t* aHandle);
+
   // Return non owning handle.
   native_handle_t* GetRawNativeHandle() const
   {
     if (mNhObj) {
       return mNhObj->mHandle;
     }
     return nullptr;
   }