Bug 1265902 - Be more efficient when using nsContentUtils::GetSurfaceData(). r=mccr8, a=ritu
authorNathan Froyd <froydnj.com>
Wed, 20 Apr 2016 11:50:45 -0400
changeset 324137 6bf374e42b5ed6bf8f424ec39354e0868c7d1222
parent 324136 0ee49a42aee51d7234cac1ee9d799393b3754d85
child 324138 5ee8c003df7bb339b39a8145911dc79c291c800f
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, ritu
bugs1265902
milestone47.0a2
Bug 1265902 - Be more efficient when using nsContentUtils::GetSurfaceData(). r=mccr8, a=ritu nsContenUtils::GetSurfaceData() returns an allocated buffer; the uses of it in PuppetWidget and nsContentUtils::TransferableToIPCTransferable copy the allocated buffer again. We can do better than this. In the PuppetWidgetCase, we can simply construct an nsDependentCString for sending the IPC message. In the TransferableToIPCTransferable case, we can transfer ownership of the buffer into the IPCDataTransferItem we are creating.
dom/base/nsContentUtils.cpp
widget/PuppetWidget.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7578,17 +7578,19 @@ nsContentUtils::TransferableToIPCTransfe
                 surface->GetDataSurface();
               size_t length;
               int32_t stride;
               mozilla::UniquePtr<char[]> surfaceData =
                 nsContentUtils::GetSurfaceData(dataSurface, &length, &stride);
 
               IPCDataTransferItem* item = aIPCDataTransfer->items().AppendElement();
               item->flavor() = nsCString(flavorStr);
-              item->data() = nsCString(surfaceData.get(), length);
+              // Turn item->data() into an nsCString prior to accessing it.
+              item->data() = EmptyCString();
+              item->data().get_nsCString().Adopt(surfaceData.release(), length);
 
               IPCDataTransferImage& imageDetails = item->imageDetails();
               mozilla::gfx::IntSize size = dataSurface->GetSize();
               imageDetails.width() = size.width;
               imageDetails.height() = size.height;
               imageDetails.stride() = stride;
               imageDetails.format() = static_cast<uint8_t>(dataSurface->GetFormat());
             }
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -1001,17 +1001,17 @@ PuppetWidget::SetCursor(imgIContainer* a
 
   RefPtr<mozilla::gfx::DataSourceSurface> dataSurface =
     surface->GetDataSurface();
   size_t length;
   int32_t stride;
   mozilla::UniquePtr<char[]> surfaceData =
     nsContentUtils::GetSurfaceData(dataSurface, &length, &stride);
 
-  nsCString cursorData = nsCString(surfaceData.get(), length);
+  nsDependentCString cursorData(surfaceData.get(), length);
   mozilla::gfx::IntSize size = dataSurface->GetSize();
   if (!mTabChild->SendSetCustomCursor(cursorData, size.width, size.height, stride,
                                       static_cast<uint8_t>(dataSurface->GetFormat()),
                                       aHotspotX, aHotspotY, mUpdateCursor)) {
     return NS_ERROR_FAILURE;
   }
 
   mCursor = nsCursor(-1);