Skip to content

Commit

Permalink
Bug 1808632 - TaskbarPreviewCallback::Done(): modernization and error…
Browse files Browse the repository at this point in the history
…-checking r=cmartin

Properly test for and handle errors in target-surface creation and
mapping.

(Additionally, perform some drive-by cleanup/modernization.)

Differential Revision: https://phabricator.services.mozilla.com/D166126
  • Loading branch information
selenography committed Jan 10, 2023
1 parent 603bebe commit 53e4063
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions widget/windows/TaskbarPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,37 +345,43 @@ TaskbarPreviewCallback::Done(nsISupports* aCanvas, bool aDrawBorder) {
}
RefPtr<gfxWindowsSurface> target = new gfxWindowsSurface(
source->GetSize(), gfx::SurfaceFormat::A8R8G8B8_UINT32);
if (!target) {
if (target->CairoStatus() != CAIRO_STATUS_SUCCESS) {
return NS_ERROR_FAILURE;
}

RefPtr<gfx::DataSourceSurface> srcSurface = source->GetDataSurface();
using DataSrcSurf = gfx::DataSourceSurface;
RefPtr<DataSrcSurf> srcSurface = source->GetDataSurface();
RefPtr<gfxImageSurface> imageSurface = target->GetAsImageSurface();
if (!srcSurface || !imageSurface) {
return NS_ERROR_FAILURE;
}

gfx::DataSourceSurface::MappedSurface sourceMap;
srcSurface->Map(gfx::DataSourceSurface::READ, &sourceMap);
mozilla::gfx::CopySurfaceDataToPackedArray(
sourceMap.mData, imageSurface->Data(), srcSurface->GetSize(),
sourceMap.mStride, BytesPerPixel(srcSurface->GetFormat()));
srcSurface->Unmap();
if (DataSrcSurf::ScopedMap const sourceMap(srcSurface, DataSrcSurf::READ);
sourceMap.IsMapped()) {
mozilla::gfx::CopySurfaceDataToPackedArray(
sourceMap.GetData(), imageSurface->Data(), srcSurface->GetSize(),
sourceMap.GetStride(), BytesPerPixel(srcSurface->GetFormat()));
} else if (source->GetSize().IsEmpty()) {
// A zero-size source-surface probably shouldn't happen, but is harmless
// here. Fall through.
} else {
return NS_ERROR_FAILURE;
}

HDC hDC = target->GetDC();
HBITMAP hBitmap = (HBITMAP)GetCurrentObject(hDC, OBJ_BITMAP);

DWORD flags = aDrawBorder ? DWM_SIT_DISPLAYFRAME : 0;
POINT pptClient = {0, 0};
HRESULT hr;
if (!mIsThumbnail) {
POINT pptClient = {0, 0};
hr = DwmSetIconicLivePreviewBitmap(mPreview->PreviewWindow(), hBitmap,
&pptClient, flags);
} else {
hr = DwmSetIconicThumbnail(mPreview->PreviewWindow(), hBitmap, flags);
}
MOZ_ASSERT(SUCCEEDED(hr));
(void)hr;
mozilla::Unused << hr;
return NS_OK;
}

Expand Down

0 comments on commit 53e4063

Please sign in to comment.