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.
--- 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);