Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1521774: Ensure a DC is available when using the generic dc on th…
Browse files Browse the repository at this point in the history
…e main thread. r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D19146
  • Loading branch information
Bas-moz committed Feb 8, 2019
1 parent 0cb87db commit 611d07f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions gfx/2d/DrawTargetD2D1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,16 @@ already_AddRefed<SourceSurface> DrawTargetD2D1::CreateSourceSurfaceFromData(
SurfaceFormat aFormat) const {
RefPtr<ID2D1Bitmap1> bitmap;

HRESULT hr = Factory::GetD2DDeviceContext()->CreateBitmap(
D2DIntSize(aSize), aData, aStride,
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE,
D2DPixelFormat(aFormat)),
getter_AddRefs(bitmap));
RefPtr<ID2D1DeviceContext> dc = Factory::GetD2DDeviceContext();
if (!dc) {
return nullptr;
}

HRESULT hr =
dc->CreateBitmap(D2DIntSize(aSize), aData, aStride,
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE,
D2DPixelFormat(aFormat)),
getter_AddRefs(bitmap));

if (FAILED(hr) || !bitmap) {
gfxCriticalError(
Expand All @@ -1062,8 +1067,8 @@ already_AddRefed<SourceSurface> DrawTargetD2D1::CreateSourceSurfaceFromData(
return nullptr;
}

return MakeAndAddRef<SourceSurfaceD2D1>(
bitmap.get(), Factory::GetD2DDeviceContext().get(), aFormat, aSize);
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), dc.get(), aFormat,
aSize);
}

already_AddRefed<DrawTarget> DrawTargetD2D1::CreateSimilarDrawTarget(
Expand All @@ -1080,6 +1085,9 @@ already_AddRefed<DrawTarget> DrawTargetD2D1::CreateSimilarDrawTarget(
bool DrawTargetD2D1::CanCreateSimilarDrawTarget(const IntSize &aSize,
SurfaceFormat aFormat) const {
RefPtr<ID2D1DeviceContext> dc = Factory::GetD2DDeviceContext();
if (!dc) {
return false;
}
return (dc->GetMaximumBitmapSize() >= UINT32(aSize.width) &&
dc->GetMaximumBitmapSize() >= UINT32(aSize.height));
}
Expand Down Expand Up @@ -2162,6 +2170,11 @@ already_AddRefed<SourceSurface> DrawTargetD2D1::OptimizeSourceSurface(
return surface.forget();
}

RefPtr<ID2D1DeviceContext> dc = Factory::GetD2DDeviceContext();
if (!dc) {
return nullptr;
}

// Special case captures so we don't resolve them to a data surface.
if (aSurface->GetType() == SurfaceType::CAPTURE) {
SourceSurfaceCapture *capture =
Expand All @@ -2183,7 +2196,7 @@ already_AddRefed<SourceSurface> DrawTargetD2D1::OptimizeSourceSurface(
return nullptr;
}

HRESULT hr = Factory::GetD2DDeviceContext()->CreateBitmap(
HRESULT hr = dc->CreateBitmap(
D2DIntSize(data->GetSize()), map.GetData(), map.GetStride(),
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE,
D2DPixelFormat(data->GetFormat())),
Expand All @@ -2201,8 +2214,7 @@ already_AddRefed<SourceSurface> DrawTargetD2D1::OptimizeSourceSurface(
return data.forget();
}

return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(),
Factory::GetD2DDeviceContext().get(),
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), dc.get(),
data->GetFormat(), data->GetSize());
}

Expand Down

0 comments on commit 611d07f

Please sign in to comment.