Bug 980436 - Fix widget/windows/nsDragService.cpp's use of DataSourceSurface::Map(), and fix up the conversion to Moz2D. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Fri, 07 Mar 2014 18:15:51 +0000
changeset 172587 4528bce55006e736340d870b97bc59a228f3c5a3
parent 172586 b0406a8daedd93c302d50a45121d2ac96927f6d8
child 172588 d1c54bc2bb7183795827426dd8fd6ec4f2986cf5
push id26365
push userryanvm@gmail.com
push dateFri, 07 Mar 2014 20:37:53 +0000
treeherdermozilla-central@cd67334b34c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs980436
milestone30.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 980436 - Fix widget/windows/nsDragService.cpp's use of DataSourceSurface::Map(), and fix up the conversion to Moz2D. r=mattwoodrow
widget/windows/nsDragService.cpp
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -36,16 +36,18 @@
 #include "nsDirectoryServiceDefs.h"
 #include "nsUnicharUtils.h"
 #include "gfxASurface.h"
 #include "gfxContext.h"
 #include "nsRect.h"
 #include "nsMathUtils.h"
 #include "gfxWindowsPlatform.h"
 #include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/DataSurfaceHelpers.h"
+#include "mozilla/gfx/Tools.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 //-------------------------------------------------------------------------
 //
 // DragService constructor
 //
@@ -89,37 +91,43 @@ nsDragService::CreateDragImage(nsIDOMNod
 
   uint32_t bmWidth = dragRect.width, bmHeight = dragRect.height;
 
   if (bmWidth == 0 || bmHeight == 0)
     return false;
 
   psdi->crColorKey = CLR_NONE;
 
-  RefPtr<DataSourceSurface> data = surface->GetDataSurface();
+  RefPtr<DataSourceSurface> dataSurface =
+    Factory::CreateDataSourceSurface(IntSize(bmWidth, bmHeight),
+                                     SurfaceFormat::B8G8R8A8);
+  NS_ENSURE_TRUE(dataSurface, false);
+
   DataSourceSurface::MappedSurface map;
-  if (!data->Map(DataSourceSurface::READ, &map)) {
+  if (!dataSurface->Map(DataSourceSurface::MapType::READ_WRITE, &map)) {
     return false;
   }
 
-  nsRefPtr<gfxImageSurface> imgSurface = new gfxImageSurface(
-    gfxIntSize(bmWidth, bmHeight), 
-    gfxImageFormat::ARGB32);
-  if (!imgSurface)
+  RefPtr<DrawTarget> dt =
+    Factory::CreateDrawTargetForData(BackendType::CAIRO,
+                                     map.mData,
+                                     dataSurface->GetSize(),
+                                     map.mStride,
+                                     dataSurface->GetFormat());
+  if (!dt) {
+    dataSurface->Unmap();
     return false;
+  }
 
-  RefPtr<DrawTarget> dt =
-    gfxPlatform::GetPlatform()->
-      CreateDrawTargetForSurface(imgSurface, IntSize(bmWidth, bmHeight));
-  if (!dt)
-    return false;
-
-  dt->FillRect(Rect(0, 0, bmWidth, bmHeight),
-               SurfacePattern(surface, ExtendMode::CLAMP),
-               DrawOptions(1.0f, CompositionOp::OP_SOURCE));
+  dt->DrawSurface(surface,
+                  Rect(0, 0, dataSurface->GetSize().width, dataSurface->GetSize().height),
+                  Rect(0, 0, surface->GetSize().width, surface->GetSize().height),
+                  DrawSurfaceOptions(),
+                  DrawOptions(1.0f, CompositionOp::OP_SOURCE));
+  dt->Flush();
 
   BITMAPV5HEADER bmih;
   memset((void*)&bmih, 0, sizeof(BITMAPV5HEADER));
   bmih.bV5Size        = sizeof(BITMAPV5HEADER);
   bmih.bV5Width       = bmWidth;
   bmih.bV5Height      = -(int32_t)bmHeight; // flip vertical
   bmih.bV5Planes      = 1;
   bmih.bV5BitCount    = 32;
@@ -131,17 +139,19 @@ nsDragService::CreateDragImage(nsIDOMNod
 
   HDC hdcSrc = CreateCompatibleDC(nullptr);
   void *lpBits = nullptr;
   if (hdcSrc) {
     psdi->hbmpDragImage = 
     ::CreateDIBSection(hdcSrc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
                        (void**)&lpBits, nullptr, 0);
     if (psdi->hbmpDragImage && lpBits) {
-      memcpy(lpBits,imgSurface->Data(),(bmWidth*bmHeight*4));
+      CopySurfaceDataToPackedArray(map.mData, static_cast<uint8_t*>(lpBits),
+                                   dataSurface->GetSize(), map.mStride,
+                                   BytesPerPixel(dataSurface->GetFormat()));
     }
 
     psdi->sizeDragImage.cx = bmWidth;
     psdi->sizeDragImage.cy = bmHeight;
 
     // Mouse position in center
     if (mScreenX == -1 || mScreenY == -1) {
       psdi->ptOffset.x = (uint32_t)((float)bmWidth/2.0f);
@@ -151,17 +161,17 @@ nsDragService::CreateDragImage(nsIDOMNod
       ConvertToUnscaledDevPixels(pc, &sx, &sy);
       psdi->ptOffset.x = sx - dragRect.x;
       psdi->ptOffset.y = sy - dragRect.y;
     }
 
     DeleteDC(hdcSrc);
   }
 
-  data->Unmap();
+  dataSurface->Unmap();
 
   return psdi->hbmpDragImage != nullptr;
 }
 
 //-------------------------------------------------------------------------
 NS_IMETHODIMP
 nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
                                  nsISupportsArray *anArrayTransferables,