Bug 980436 - Fix widget/windows/nsDragService.cpp's use of DataSourceSurface::Map(), and fix up the conversion to Moz2D. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-03-07 16:52:38 +00:00
Родитель fe8411d692
Коммит 392dd90572
1 изменённых файлов: 26 добавлений и 16 удалений

Просмотреть файл

@ -41,6 +41,8 @@
#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;
@ -94,27 +96,33 @@ nsDragService::CreateDragImage(nsIDOMNode *aDOMNode,
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)
return false;
RefPtr<DrawTarget> dt =
gfxPlatform::GetPlatform()->
CreateDrawTargetForSurface(imgSurface, IntSize(bmWidth, bmHeight));
if (!dt)
Factory::CreateDrawTargetForData(BackendType::CAIRO,
map.mData,
dataSurface->GetSize(),
map.mStride,
dataSurface->GetFormat());
if (!dt) {
dataSurface->Unmap();
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));
@ -136,7 +144,9 @@ nsDragService::CreateDragImage(nsIDOMNode *aDOMNode,
::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;
@ -156,7 +166,7 @@ nsDragService::CreateDragImage(nsIDOMNode *aDOMNode,
DeleteDC(hdcSrc);
}
data->Unmap();
dataSurface->Unmap();
return psdi->hbmpDragImage != nullptr;
}