Bug 1265902 - part 1 - be more efficient when using nsContentUtils::GetSurfaceData(); r=mccr8
authorNathan Froyd <froydnj.com>
Wed, 20 Apr 2016 11:50:45 -0400
changeset 354474 c7c25fa27b435024a5a29f8a63a2d14540f040d7
parent 354473 2d966e084cdd4ae510dff1f3ce4d538dafc6cd5d
child 354475 01c33b05600eefb26ea30af54848335a6899a76d
push id16088
push usergkruglov@mozilla.com
push dateWed, 20 Apr 2016 23:45:23 +0000
reviewersmccr8
bugs1265902
milestone48.0a1
Bug 1265902 - part 1 - be more efficient when using nsContentUtils::GetSurfaceData(); r=mccr8 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
@@ -7401,17 +7401,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
@@ -983,17 +983,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);