2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-07-17 16:12:22 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-02-12 13:59:05 +04:00
|
|
|
#include <initguid.h>
|
2013-07-17 16:12:22 +04:00
|
|
|
#include "DrawTargetD2D1.h"
|
2013-11-27 15:22:56 +04:00
|
|
|
#include "FilterNodeSoftware.h"
|
2013-07-17 16:12:22 +04:00
|
|
|
#include "GradientStopsD2D.h"
|
2017-10-31 22:02:31 +03:00
|
|
|
#include "SourceSurfaceCapture.h"
|
2013-07-17 16:12:22 +04:00
|
|
|
#include "SourceSurfaceD2D1.h"
|
2017-04-17 18:41:42 +03:00
|
|
|
#include "SourceSurfaceDual.h"
|
2013-07-17 16:12:22 +04:00
|
|
|
#include "RadialGradientEffectD2D1.h"
|
|
|
|
|
|
|
|
#include "HelpersD2D.h"
|
2013-11-27 15:25:16 +04:00
|
|
|
#include "FilterNodeD2D1.h"
|
2016-02-13 16:33:28 +03:00
|
|
|
#include "ExtendInputEffectD2D1.h"
|
2013-07-17 16:12:22 +04:00
|
|
|
#include "Tools.h"
|
2017-06-29 20:09:14 +03:00
|
|
|
#include "nsAppRunner.h"
|
2017-07-18 22:15:44 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
using namespace std;
|
|
|
|
|
2016-02-13 16:33:28 +03:00
|
|
|
// decltype is not usable for overloaded functions.
|
|
|
|
typedef HRESULT (WINAPI*D2D1CreateFactoryFunc)(
|
|
|
|
D2D1_FACTORY_TYPE factoryType,
|
|
|
|
REFIID iid,
|
|
|
|
CONST D2D1_FACTORY_OPTIONS *pFactoryOptions,
|
|
|
|
void **factory
|
|
|
|
);
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
uint64_t DrawTargetD2D1::mVRAMUsageDT;
|
|
|
|
uint64_t DrawTargetD2D1::mVRAMUsageSS;
|
2017-07-18 22:15:39 +03:00
|
|
|
StaticRefPtr<ID2D1Factory1> DrawTargetD2D1::mFactory;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2017-07-18 22:15:39 +03:00
|
|
|
RefPtr<ID2D1Factory1> D2DFactory()
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
return DrawTargetD2D1::factory();
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetD2D1::DrawTargetD2D1()
|
2016-01-05 11:03:08 +03:00
|
|
|
: mPushedLayers(1)
|
2017-12-05 10:35:16 +03:00
|
|
|
, mSnapshotLock(make_shared<Mutex>("DrawTargetD2D1::mSnapshotLock"))
|
2016-02-11 23:35:07 +03:00
|
|
|
, mUsedCommandListsSincePurge(0)
|
2017-09-22 20:37:02 +03:00
|
|
|
, mComplexBlendsWithListInList(0)
|
2017-05-10 11:22:08 +03:00
|
|
|
, mDeviceSeq(0)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetD2D1::~DrawTargetD2D1()
|
|
|
|
{
|
|
|
|
PopAllClips();
|
|
|
|
|
2014-09-15 01:51:28 +04:00
|
|
|
if (mSnapshot) {
|
2017-11-21 18:52:38 +03:00
|
|
|
MutexAutoLock lock(*mSnapshotLock);
|
2014-09-15 01:51:28 +04:00
|
|
|
// We may hold the only reference. MarkIndependent will clear mSnapshot;
|
|
|
|
// keep the snapshot object alive so it doesn't get destroyed while
|
|
|
|
// MarkIndependent is running.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurfaceD2D1> deathGrip = mSnapshot;
|
2014-09-15 01:51:28 +04:00
|
|
|
// mSnapshot can be treated as independent of this DrawTarget since we know
|
|
|
|
// this DrawTarget won't change again.
|
|
|
|
deathGrip->MarkIndependent();
|
|
|
|
// mSnapshot will be cleared now.
|
|
|
|
}
|
|
|
|
|
2017-05-10 11:22:08 +03:00
|
|
|
if (mDC && IsDeviceContextValid()) {
|
2015-07-06 18:57:03 +03:00
|
|
|
// The only way mDC can be null is if Init failed, but it can happen and the
|
|
|
|
// destructor is the only place where we need to check for it since the
|
|
|
|
// DrawTarget will destroyed right after Init fails.
|
|
|
|
mDC->EndDraw();
|
|
|
|
}
|
2014-09-15 01:51:28 +04:00
|
|
|
|
|
|
|
// Targets depending on us can break that dependency, since we're obviously not going to
|
|
|
|
// be modified in the future.
|
|
|
|
for (auto iter = mDependentTargets.begin();
|
|
|
|
iter != mDependentTargets.end(); iter++) {
|
|
|
|
(*iter)->mDependingOnTargets.erase(this);
|
|
|
|
}
|
|
|
|
// Our dependencies on other targets no longer matter.
|
|
|
|
for (TargetSet::iterator iter = mDependingOnTargets.begin();
|
|
|
|
iter != mDependingOnTargets.end(); iter++) {
|
|
|
|
(*iter)->mDependentTargets.erase(this);
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::Snapshot()
|
|
|
|
{
|
2017-12-05 10:35:16 +03:00
|
|
|
MutexAutoLock lock(*mSnapshotLock);
|
2013-07-17 16:12:22 +04:00
|
|
|
if (mSnapshot) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> snapshot(mSnapshot);
|
2015-05-01 16:14:16 +03:00
|
|
|
return snapshot.forget();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
PopAllClips();
|
|
|
|
|
2016-03-31 22:45:36 +03:00
|
|
|
Flush();
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mSnapshot = new SourceSurfaceD2D1(mBitmap, mDC, mFormat, mSize, this);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> snapshot(mSnapshot);
|
2015-05-01 16:14:16 +03:00
|
|
|
return snapshot.forget();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2017-06-22 20:15:37 +03:00
|
|
|
bool
|
2017-06-02 21:13:36 +03:00
|
|
|
DrawTargetD2D1::EnsureLuminanceEffect()
|
|
|
|
{
|
|
|
|
if (mLuminanceEffect.get()) {
|
2017-06-22 20:15:37 +03:00
|
|
|
return true;
|
2017-06-02 21:13:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = mDC->CreateEffect(CLSID_D2D1LuminanceToAlpha,
|
|
|
|
getter_AddRefs(mLuminanceEffect));
|
|
|
|
if (FAILED(hr)) {
|
2017-06-22 20:15:37 +03:00
|
|
|
gfxCriticalError() << "Failed to create luminance effect. Code: " << hexa(hr);
|
|
|
|
return false;
|
2017-06-02 21:13:36 +03:00
|
|
|
}
|
2017-06-22 20:15:37 +03:00
|
|
|
|
|
|
|
return true;
|
2017-06-02 21:13:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SourceSurface>
|
|
|
|
DrawTargetD2D1::IntoLuminanceSource(LuminanceType aLuminanceType, float aOpacity)
|
|
|
|
{
|
2017-06-29 20:09:14 +03:00
|
|
|
if ((aLuminanceType != LuminanceType::LUMINANCE) ||
|
|
|
|
// See bug 1372577, some race condition where we get invalid
|
|
|
|
// results with D2D in the parent process. Fallback in that case.
|
|
|
|
XRE_IsParentProcess()) {
|
2017-06-02 21:13:36 +03:00
|
|
|
return DrawTarget::IntoLuminanceSource(aLuminanceType, aOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the luminance effect
|
2017-06-22 20:15:37 +03:00
|
|
|
if (!EnsureLuminanceEffect()) {
|
|
|
|
return DrawTarget::IntoLuminanceSource(aLuminanceType, aOpacity);
|
|
|
|
}
|
|
|
|
|
2017-06-02 21:13:36 +03:00
|
|
|
mLuminanceEffect->SetInput(0, mBitmap);
|
|
|
|
|
|
|
|
RefPtr<ID2D1Image> luminanceOutput;
|
|
|
|
mLuminanceEffect->GetOutput(getter_AddRefs(luminanceOutput));
|
|
|
|
|
|
|
|
return MakeAndAddRef<SourceSurfaceD2D1>(luminanceOutput, mDC, SurfaceFormat::A8, mSize);
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:38:10 +03:00
|
|
|
// Command lists are kept around by device contexts until EndDraw is called,
|
|
|
|
// this can cause issues with memory usage (see bug 1238328). EndDraw/BeginDraw
|
|
|
|
// are expensive though, especially relatively when little work is done, so
|
|
|
|
// we try to reduce the amount of times we execute these purges.
|
|
|
|
static const uint32_t kPushedLayersBeforePurge = 25;
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::Flush()
|
|
|
|
{
|
2017-05-10 11:22:08 +03:00
|
|
|
if (IsDeviceContextValid()) {
|
|
|
|
if ((mUsedCommandListsSincePurge >= kPushedLayersBeforePurge) &&
|
|
|
|
mPushedLayers.size() == 1) {
|
|
|
|
// It's important to pop all clips as otherwise layers can forget about
|
|
|
|
// their clip when doing an EndDraw. When we have layers pushed we cannot
|
|
|
|
// easily pop all underlying clips to delay the purge until we have no
|
|
|
|
// layers pushed.
|
|
|
|
PopAllClips();
|
|
|
|
mUsedCommandListsSincePurge = 0;
|
|
|
|
mDC->EndDraw();
|
|
|
|
mDC->BeginDraw();
|
|
|
|
} else {
|
|
|
|
mDC->Flush();
|
|
|
|
}
|
2016-01-11 18:38:10 +03:00
|
|
|
}
|
2014-09-15 01:51:28 +04:00
|
|
|
|
|
|
|
// We no longer depend on any target.
|
|
|
|
for (TargetSet::iterator iter = mDependingOnTargets.begin();
|
|
|
|
iter != mDependingOnTargets.end(); iter++) {
|
|
|
|
(*iter)->mDependentTargets.erase(this);
|
|
|
|
}
|
|
|
|
mDependingOnTargets.clear();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2014-09-15 01:51:28 +04:00
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
D2D1_RECT_F samplingBounds;
|
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aSurfOptions.mSamplingBounds == SamplingBounds::BOUNDED) {
|
2013-07-17 16:12:22 +04:00
|
|
|
samplingBounds = D2DRect(aSource);
|
|
|
|
} else {
|
|
|
|
samplingBounds = D2D1::RectF(0, 0, Float(aSurface->GetSize().width), Float(aSurface->GetSize().height));
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:29:28 +03:00
|
|
|
Float xScale = aDest.Width() / aSource.Width();
|
|
|
|
Float yScale = aDest.Height() / aSource.Height();
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1ImageBrush> brush;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
// Here we scale the source pattern up to the size and position where we want
|
|
|
|
// it to be.
|
|
|
|
Matrix transform;
|
2017-12-19 23:48:39 +03:00
|
|
|
transform.PreTranslate(aDest.X() - aSource.X() * xScale, aDest.Y() - aSource.Y() * yScale);
|
2014-09-10 21:29:35 +04:00
|
|
|
transform.PreScale(xScale, yScale);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, transform, ExtendMode::CLAMP);
|
2014-09-15 01:52:46 +04:00
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
gfxWarning() << *this << ": Unable to get D2D image for surface.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2017-05-31 01:59:19 +03:00
|
|
|
HRESULT hr;
|
2014-11-12 01:09:31 +03:00
|
|
|
if (aSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
|
|
|
|
// If this is called with a DataSourceSurface it might do a partial upload
|
|
|
|
// that our DrawBitmap call doesn't support.
|
2017-05-31 01:59:19 +03:00
|
|
|
hr = image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
2014-11-12 01:09:31 +03:00
|
|
|
}
|
|
|
|
|
2017-05-31 01:59:19 +03:00
|
|
|
if (SUCCEEDED(hr) && bitmap && aSurfOptions.mSamplingBounds == SamplingBounds::UNBOUNDED) {
|
2016-05-25 19:01:18 +03:00
|
|
|
mDC->DrawBitmap(bitmap, D2DRect(aDest), aOptions.mAlpha,
|
|
|
|
D2DFilter(aSurfOptions.mSamplingFilter), D2DRect(aSource));
|
2014-11-12 01:09:31 +03:00
|
|
|
} else {
|
|
|
|
// This has issues ignoring the alpha channel on windows 7 with images marked opaque.
|
|
|
|
MOZ_ASSERT(aSurface->GetFormat() != SurfaceFormat::B8G8R8X8);
|
2016-09-08 21:30:00 +03:00
|
|
|
|
|
|
|
// Bug 1275478 - D2D1 cannot draw A8 surface correctly.
|
|
|
|
MOZ_ASSERT(aSurface->GetFormat() != SurfaceFormat::A8);
|
|
|
|
|
2014-11-12 01:09:31 +03:00
|
|
|
mDC->CreateImageBrush(image,
|
|
|
|
D2D1::ImageBrushProperties(samplingBounds,
|
|
|
|
D2D1_EXTEND_MODE_CLAMP,
|
|
|
|
D2D1_EXTEND_MODE_CLAMP,
|
2016-05-25 19:01:18 +03:00
|
|
|
D2DInterpolationMode(aSurfOptions.mSamplingFilter)),
|
2014-11-12 01:09:31 +03:00
|
|
|
D2D1::BrushProperties(aOptions.mAlpha, D2DMatrix(transform)),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(brush));
|
2014-11-12 01:09:31 +03:00
|
|
|
mDC->FillRectangle(D2DRect(aDest), brush);
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2017-09-20 15:57:25 +03:00
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:22:56 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2013-11-27 15:25:16 +04:00
|
|
|
if (aNode->GetBackendType() != FILTER_BACKEND_DIRECT2D1_1) {
|
|
|
|
gfxWarning() << *this << ": Incompatible filter passed to DrawFilter.";
|
2013-11-27 15:22:56 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:16 +04:00
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
|
2014-09-15 01:52:47 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2014-09-25 23:18:29 +04:00
|
|
|
FilterNodeD2D1* node = static_cast<FilterNodeD2D1*>(aNode);
|
|
|
|
node->WillDraw(this);
|
|
|
|
|
|
|
|
mDC->DrawImage(node->OutputEffect(), D2DPoint(aDestPoint), D2DRect(aSourceRect));
|
2014-09-15 01:52:47 +04:00
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
2013-11-27 15:22:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
|
|
|
Float aSigma,
|
|
|
|
CompositionOp aOperator)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
|
|
|
Matrix mat;
|
2017-03-15 05:17:47 +03:00
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP, nullptr, false);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-11-20 23:48:01 +03:00
|
|
|
if (!image) {
|
|
|
|
gfxWarning() << "Couldn't get image for surface.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
if (!mat.IsIdentity()) {
|
|
|
|
gfxDebug() << *this << ": At this point complex partial uploads are not supported for Shadow surfaces.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 1, create the shadow effect.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Effect> shadowEffect;
|
2016-11-21 21:17:09 +03:00
|
|
|
HRESULT hr = mDC->CreateEffect(mFormat == SurfaceFormat::A8 ? CLSID_D2D1GaussianBlur : CLSID_D2D1Shadow,
|
|
|
|
getter_AddRefs(shadowEffect));
|
2015-05-28 22:46:16 +03:00
|
|
|
if (FAILED(hr) || !shadowEffect) {
|
|
|
|
gfxWarning() << "Failed to create shadow effect. Code: " << hexa(hr);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
shadowEffect->SetInput(0, image);
|
2016-11-21 21:17:09 +03:00
|
|
|
if (mFormat == SurfaceFormat::A8) {
|
|
|
|
shadowEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, aSigma);
|
|
|
|
shadowEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_BORDER_MODE, D2D1_BORDER_MODE_HARD);
|
|
|
|
} else {
|
|
|
|
shadowEffect->SetValue(D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, aSigma);
|
|
|
|
D2D1_VECTOR_4F color = { aColor.r, aColor.g, aColor.b, aColor.a };
|
|
|
|
shadowEffect->SetValue(D2D1_SHADOW_PROP_COLOR, color);
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-09-15 01:51:35 +04:00
|
|
|
D2D1_POINT_2F shadowPoint = D2DPoint(aDest + aOffset);
|
|
|
|
mDC->DrawImage(shadowEffect, &shadowPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
|
|
|
|
|
2016-11-21 21:17:09 +03:00
|
|
|
if (aSurface->GetFormat() != SurfaceFormat::A8) {
|
|
|
|
D2D1_POINT_2F imgPoint = D2DPoint(aDest);
|
|
|
|
mDC->DrawImage(image, &imgPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::ClearRect(const Rect &aRect)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
|
2014-09-15 01:51:29 +04:00
|
|
|
PopAllClips();
|
|
|
|
|
|
|
|
PushClipRect(aRect);
|
|
|
|
|
|
|
|
if (mTransformDirty ||
|
|
|
|
!mTransform.IsIdentity()) {
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_RECT_F clipRect;
|
|
|
|
bool isPixelAligned;
|
|
|
|
if (mTransform.IsRectilinear() &&
|
|
|
|
GetDeviceSpaceClipRect(clipRect, isPixelAligned)) {
|
|
|
|
mDC->PushAxisAlignedClip(clipRect, isPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
|
|
mDC->Clear();
|
|
|
|
mDC->PopAxisAlignedClip();
|
|
|
|
|
|
|
|
PopClip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-12 19:00:52 +03:00
|
|
|
RefPtr<ID2D1CommandList> list;
|
2016-02-11 23:35:07 +03:00
|
|
|
mUsedCommandListsSincePurge++;
|
2015-11-12 19:00:52 +03:00
|
|
|
mDC->CreateCommandList(getter_AddRefs(list));
|
|
|
|
mDC->SetTarget(list);
|
2014-09-15 01:51:29 +04:00
|
|
|
|
|
|
|
IntRect addClipRect;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(&addClipRect);
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
2015-10-18 07:40:10 +03:00
|
|
|
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), getter_AddRefs(brush));
|
2017-12-19 23:48:39 +03:00
|
|
|
mDC->PushAxisAlignedClip(D2D1::RectF(addClipRect.X(), addClipRect.Y(), addClipRect.XMost(), addClipRect.YMost()), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
2014-09-15 01:51:29 +04:00
|
|
|
mDC->FillGeometry(geom, brush);
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->PopAxisAlignedClip();
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
mDC->SetTarget(CurrentTarget());
|
2015-11-12 19:00:52 +03:00
|
|
|
list->Close();
|
|
|
|
|
|
|
|
mDC->DrawImage(list, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_DESTINATION_OUT);
|
2014-09-15 01:51:29 +04:00
|
|
|
|
|
|
|
PopClip();
|
|
|
|
|
|
|
|
return;
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2014-11-20 23:48:01 +03:00
|
|
|
MarkChanged();
|
2014-09-15 01:51:28 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-11-05 02:05:26 +03:00
|
|
|
Matrix mat = Matrix::Translation(aOffset);
|
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aMask, mat, ExtendMode::CLAMP, nullptr);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mat.HasNonTranslation());
|
|
|
|
aOffset.x = mat._31;
|
|
|
|
aOffset.y = mat._32;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-11-20 23:48:01 +03:00
|
|
|
if (!image) {
|
|
|
|
gfxWarning() << "Failed to get image for surface.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
|
2017-06-02 21:13:36 +03:00
|
|
|
IntSize size = IntSize::Truncate(aMask->GetSize().width, aMask->GetSize().height);
|
|
|
|
Rect dest = Rect(aOffset.x, aOffset.y, Float(size.width), Float(size.height));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2017-06-02 21:13:36 +03:00
|
|
|
HRESULT hr = image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
|
|
if (!bitmap || FAILED(hr)) {
|
|
|
|
// D2D says if we have an actual ID2D1Image and not a bitmap underlying the object,
|
|
|
|
// we can't query for a bitmap. Instead, Push/PopLayer
|
|
|
|
gfxWarning() << "FillOpacityMask only works with Bitmap source surfaces. Falling back to push/pop layer";
|
|
|
|
|
|
|
|
RefPtr<ID2D1Brush> source = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1ImageBrush> maskBrush;
|
|
|
|
hr = mDC->CreateImageBrush(image,
|
|
|
|
D2D1::ImageBrushProperties(D2D1::RectF(0, 0, size.width, size.height)),
|
|
|
|
D2D1::BrushProperties(1.0f, D2D1::IdentityMatrix()),
|
|
|
|
getter_AddRefs(maskBrush));
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
|
|
mDC->PushLayer(D2D1::LayerParameters1(D2D1::InfiniteRect(), nullptr,
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
|
|
|
D2D1::IdentityMatrix(),
|
|
|
|
1.0f, maskBrush, D2D1_LAYER_OPTIONS1_NONE),
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
mDC->FillRectangle(D2DRect(dest), source);
|
|
|
|
mDC->PopLayer();
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aSource);
|
2013-07-17 16:12:22 +04:00
|
|
|
return;
|
2017-06-02 21:13:36 +03:00
|
|
|
} else {
|
|
|
|
// If this is a data source surface, we might have created a partial bitmap
|
|
|
|
// for this surface and only uploaded part of the mask. In that case,
|
|
|
|
// we have to fixup our sizes here.
|
|
|
|
size.width = bitmap->GetSize().width;
|
|
|
|
size.height = bitmap->GetSize().height;
|
2017-08-14 15:29:28 +03:00
|
|
|
dest.SetWidth(size.width);
|
|
|
|
dest.SetHeight(size.height);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2017-06-02 21:13:36 +03:00
|
|
|
// FillOpacityMask only works if the antialias mode is MODE_ALIASED
|
|
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
2015-11-05 02:05:26 +03:00
|
|
|
|
|
|
|
Rect maskRect = Rect(0.f, 0.f, Float(size.width), Float(size.height));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS, D2DRect(dest), D2DRect(maskRect));
|
|
|
|
|
|
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
|
|
|
const IntPoint &aDestination)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
|
2014-09-15 01:51:31 +04:00
|
|
|
PopAllClips();
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
2017-12-19 23:48:39 +03:00
|
|
|
Matrix mat = Matrix::Translation(aDestination.x - aSourceRect.X(), aDestination.y - aSourceRect.Y());
|
2017-03-15 05:17:47 +03:00
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP, nullptr, false);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-11-20 23:48:01 +03:00
|
|
|
if (!image) {
|
|
|
|
gfxWarning() << "Couldn't get image for surface.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:22:31 +03:00
|
|
|
if (mat.HasNonIntegerTranslation()) {
|
|
|
|
gfxDebug() << *this << ": At this point scaled partial uploads are not supported for CopySurface.";
|
2013-07-17 16:12:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:22:31 +03:00
|
|
|
IntRect sourceRect = aSourceRect;
|
2017-12-19 23:48:39 +03:00
|
|
|
sourceRect.SetLeftEdge(sourceRect.X() + (aDestination.x - aSourceRect.X()) - mat._31);
|
|
|
|
sourceRect.SetTopEdge(sourceRect.Y() + (aDestination.y - aSourceRect.Y()) - mat._32);
|
2016-04-28 16:22:31 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2017-05-31 01:59:19 +03:00
|
|
|
HRESULT hr = image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
2014-09-15 01:51:31 +04:00
|
|
|
|
2017-05-31 01:59:19 +03:00
|
|
|
if (SUCCEEDED(hr) && bitmap && mFormat == SurfaceFormat::A8) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
2014-09-15 01:51:31 +04:00
|
|
|
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),
|
2015-10-18 07:40:10 +03:00
|
|
|
D2D1::BrushProperties(), getter_AddRefs(brush));
|
2014-09-15 01:51:31 +04:00
|
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
2015-06-19 23:05:51 +03:00
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_COPY);
|
2014-09-15 01:51:31 +04:00
|
|
|
mDC->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
|
|
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
2015-06-19 23:05:51 +03:00
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-19 23:48:39 +03:00
|
|
|
Rect srcRect(Float(sourceRect.X()), Float(sourceRect.Y()),
|
2017-08-14 15:29:28 +03:00
|
|
|
Float(aSourceRect.Width()), Float(aSourceRect.Height()));
|
2015-06-19 23:05:51 +03:00
|
|
|
|
|
|
|
Rect dstRect(Float(aDestination.x), Float(aDestination.y),
|
2017-08-14 15:29:28 +03:00
|
|
|
Float(aSourceRect.Width()), Float(aSourceRect.Height()));
|
2015-06-19 23:05:51 +03:00
|
|
|
|
2017-05-31 01:59:19 +03:00
|
|
|
if (SUCCEEDED(hr) && bitmap) {
|
2015-06-19 23:05:51 +03:00
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_COPY);
|
|
|
|
mDC->DrawBitmap(bitmap, D2DRect(dstRect), 1.0f,
|
|
|
|
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
|
|
|
|
D2DRect(srcRect));
|
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
2014-09-15 01:51:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->DrawImage(image, D2D1::Point2F(Float(aDestination.x), Float(aDestination.y)),
|
2015-06-19 23:05:51 +03:00
|
|
|
D2DRect(srcRect), D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
|
|
|
|
D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
2014-09-15 01:51:32 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->FillRectangle(D2DRect(aRect), brush);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
2014-09-15 01:51:32 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->DrawRectangle(D2DRect(aRect), brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
2014-09-15 01:51:32 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->DrawLine(D2DPoint(aStart), D2DPoint(aEnd), brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2015-01-08 03:10:48 +03:00
|
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
2013-07-17 16:12:22 +04:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
2014-09-15 01:51:32 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->DrawGeometry(d2dPath->mGeometry, brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2017-01-16 21:21:36 +03:00
|
|
|
if (!aPath || aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
2013-07-17 16:12:22 +04:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
2014-09-15 01:51:32 +04:00
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->FillGeometry(d2dPath->mGeometry, brush);
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
2017-11-03 04:42:56 +03:00
|
|
|
const DrawOptions &aOptions)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
2014-01-10 23:06:16 +04:00
|
|
|
if (aFont->GetType() != FontType::DWRITE) {
|
2013-07-17 16:12:22 +04:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible font.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScaledFontDWrite *font = static_cast<ScaledFontDWrite*>(aFont);
|
|
|
|
|
2017-06-30 21:09:05 +03:00
|
|
|
IDWriteRenderingParams *params = font->mParams;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
AntialiasMode aaMode = font->GetDefaultAAMode();
|
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aOptions.mAntialiasMode != AntialiasMode::DEFAULT) {
|
2013-07-17 16:12:22 +04:00
|
|
|
aaMode = aOptions.mAntialiasMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
|
|
|
bool forceClearType = false;
|
2016-01-05 11:03:08 +03:00
|
|
|
if (!CurrentLayer().mIsOpaque && mPermitSubpixelAA &&
|
2014-01-10 23:06:17 +04:00
|
|
|
aOptions.mCompositionOp == CompositionOp::OP_OVER && aaMode == AntialiasMode::SUBPIXEL) {
|
2013-07-17 16:12:22 +04:00
|
|
|
forceClearType = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D2D1_TEXT_ANTIALIAS_MODE d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
|
|
|
|
|
|
switch (aaMode) {
|
2014-01-10 23:06:17 +04:00
|
|
|
case AntialiasMode::NONE:
|
2013-07-17 16:12:22 +04:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
|
|
|
|
break;
|
2014-01-10 23:06:17 +04:00
|
|
|
case AntialiasMode::GRAY:
|
2013-07-17 16:12:22 +04:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
|
|
break;
|
2014-01-10 23:06:17 +04:00
|
|
|
case AntialiasMode::SUBPIXEL:
|
2013-07-17 16:12:22 +04:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d2dAAMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE &&
|
2016-01-05 11:03:08 +03:00
|
|
|
!CurrentLayer().mIsOpaque && !forceClearType) {
|
2013-07-17 16:12:22 +04:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDC->SetTextAntialiasMode(d2dAAMode);
|
|
|
|
|
|
|
|
if (params != mTextRenderingParams) {
|
|
|
|
mDC->SetTextRenderingParams(params);
|
|
|
|
mTextRenderingParams = params;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
AutoDWriteGlyphRun autoRun;
|
|
|
|
DWriteGlyphRunFromGlyphs(aBuffer, font, &autoRun);
|
|
|
|
|
2015-05-29 15:49:19 +03:00
|
|
|
bool needsRepushedLayers = false;
|
2016-01-05 11:03:08 +03:00
|
|
|
if (forceClearType) {
|
2015-05-29 15:49:19 +03:00
|
|
|
D2D1_RECT_F rect;
|
|
|
|
bool isAligned;
|
2016-01-05 11:03:08 +03:00
|
|
|
needsRepushedLayers = CurrentLayer().mPushedClips.size() && !GetDeviceSpaceClipRect(rect, isAligned);
|
2015-05-29 15:49:19 +03:00
|
|
|
|
|
|
|
// If we have a complex clip in our stack and we have a transparent
|
|
|
|
// background, and subpixel AA is permitted, we need to repush our layer
|
|
|
|
// stack limited by the glyph run bounds initializing our layers for
|
|
|
|
// subpixel AA.
|
|
|
|
if (needsRepushedLayers) {
|
|
|
|
mDC->GetGlyphRunWorldBounds(D2D1::Point2F(), &autoRun,
|
|
|
|
DWRITE_MEASURING_MODE_NATURAL, &rect);
|
|
|
|
rect.left = std::floor(rect.left);
|
|
|
|
rect.right = std::ceil(rect.right);
|
|
|
|
rect.top = std::floor(rect.top);
|
|
|
|
rect.bottom = std::ceil(rect.bottom);
|
|
|
|
|
|
|
|
PopAllClips();
|
|
|
|
|
|
|
|
if (!mTransform.IsRectilinear()) {
|
|
|
|
// We must limit the pixels we touch to the -user space- bounds of
|
|
|
|
// the glyphs being drawn. In order not to get transparent pixels
|
|
|
|
// copied up in our pushed layer stack.
|
|
|
|
D2D1_RECT_F userRect;
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mDC->GetGlyphRunWorldBounds(D2D1::Point2F(), &autoRun,
|
|
|
|
DWRITE_MEASURING_MODE_NATURAL, &userRect);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
2016-02-13 16:33:28 +03:00
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(path));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 07:40:10 +03:00
|
|
|
path->Open(getter_AddRefs(sink));
|
2016-01-06 02:23:29 +03:00
|
|
|
AddRectToSink(sink, userRect);
|
2015-05-29 15:49:19 +03:00
|
|
|
sink->Close();
|
|
|
|
|
|
|
|
mDC->PushLayer(D2D1::LayerParameters1(D2D1::InfiniteRect(), path, D2D1_ANTIALIAS_MODE_ALIASED,
|
|
|
|
D2DMatrix(mTransform), 1.0f, nullptr,
|
|
|
|
D2D1_LAYER_OPTIONS1_INITIALIZE_FROM_BACKGROUND |
|
|
|
|
D2D1_LAYER_OPTIONS1_IGNORE_ALPHA), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PushClipsToDC(mDC, true, rect);
|
|
|
|
mDC->SetTransform(D2DMatrix(mTransform));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
if (brush) {
|
|
|
|
mDC->DrawGlyphRun(D2D1::Point2F(), &autoRun, brush);
|
|
|
|
}
|
|
|
|
|
2015-05-29 15:49:19 +03:00
|
|
|
if (needsRepushedLayers) {
|
|
|
|
PopClipsFromDC(mDC);
|
|
|
|
|
|
|
|
if (!mTransform.IsRectilinear()) {
|
|
|
|
mDC->PopLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Brush> source = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1Brush> mask = CreateBrushForPattern(aMask, 1.0f);
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->PushLayer(D2D1::LayerParameters(D2D1::InfiniteRect(), nullptr,
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
|
|
|
D2D1::IdentityMatrix(),
|
|
|
|
1.0f, mask),
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
Rect rect(0, 0, (Float)mSize.width, (Float)mSize.height);
|
|
|
|
Matrix mat = mTransform;
|
|
|
|
mat.Invert();
|
|
|
|
|
|
|
|
mDC->FillRectangle(D2DRect(mat.TransformBounds(rect)), source);
|
|
|
|
|
|
|
|
mDC->PopLayer();
|
|
|
|
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-22 00:03:20 +03:00
|
|
|
DrawTargetD2D1::PushClipGeometry(ID2D1Geometry* aGeometry,
|
|
|
|
const D2D1_MATRIX_3X2_F& aTransform,
|
|
|
|
bool aPixelAligned)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
2014-09-15 01:51:29 +04:00
|
|
|
mCurrentClippedGeometry = nullptr;
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
PushedClip clip;
|
2016-09-22 00:03:20 +03:00
|
|
|
clip.mGeometry = aGeometry;
|
|
|
|
clip.mTransform = aTransform;
|
|
|
|
clip.mIsPixelAligned = aPixelAligned;
|
|
|
|
|
|
|
|
aGeometry->GetBounds(aTransform, &clip.mBounds);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mPushedClips.push_back(clip);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
// The transform of clips is relative to the world matrix, since we use the total
|
|
|
|
// transform for the clips, make the world matrix identity.
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
2016-09-22 00:03:20 +03:00
|
|
|
PushD2DLayer(mDC, clip.mGeometry, clip.mTransform, clip.mIsPixelAligned);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PushClip(const Path *aPath)
|
|
|
|
{
|
|
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
|
|
|
gfxDebug() << *this << ": Ignoring clipping call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PathD2D> pathD2D = static_cast<PathD2D*>(const_cast<Path*>(aPath));
|
|
|
|
|
|
|
|
PushClipGeometry(pathD2D->GetGeometry(), D2DMatrix(mTransform));
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PushClipRect(const Rect &aRect)
|
|
|
|
{
|
|
|
|
if (!mTransform.IsRectilinear()) {
|
|
|
|
// Whoops, this isn't a rectangle in device space, Direct2D will not deal
|
|
|
|
// with this transform the way we want it to.
|
|
|
|
// See remarks: http://msdn.microsoft.com/en-us/library/dd316860%28VS.85%29.aspx
|
2016-09-22 00:03:20 +03:00
|
|
|
RefPtr<ID2D1Geometry> geom = ConvertRectToGeometry(D2DRect(aRect));
|
|
|
|
return PushClipGeometry(geom, D2DMatrix(mTransform));
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2014-09-15 01:51:29 +04:00
|
|
|
mCurrentClippedGeometry = nullptr;
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
PushedClip clip;
|
|
|
|
Rect rect = mTransform.TransformBounds(aRect);
|
|
|
|
IntRect intRect;
|
|
|
|
clip.mIsPixelAligned = rect.ToIntRect(&intRect);
|
|
|
|
|
|
|
|
// Do not store the transform, just store the device space rectangle directly.
|
|
|
|
clip.mBounds = D2DRect(rect);
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mPushedClips.push_back(clip);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->PushAxisAlignedClip(clip.mBounds, clip.mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PushDeviceSpaceClipRects(const IntRect* aRects, uint32_t aCount)
|
|
|
|
{
|
|
|
|
// Build a path for the union of the rects.
|
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(path));
|
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
|
|
|
path->Open(getter_AddRefs(sink));
|
|
|
|
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
|
|
|
|
for (uint32_t i = 0; i < aCount; i++) {
|
|
|
|
const IntRect& rect = aRects[i];
|
|
|
|
sink->BeginFigure(D2DPoint(rect.TopLeft()), D2D1_FIGURE_BEGIN_FILLED);
|
|
|
|
D2D1_POINT_2F lines[3] = { D2DPoint(rect.TopRight()), D2DPoint(rect.BottomRight()), D2DPoint(rect.BottomLeft()) };
|
|
|
|
sink->AddLines(lines, 3);
|
|
|
|
sink->EndFigure(D2D1_FIGURE_END_CLOSED);
|
|
|
|
}
|
|
|
|
sink->Close();
|
|
|
|
|
|
|
|
// The path is in device-space, so there is no transform needed,
|
|
|
|
// and all rects are pixel aligned.
|
|
|
|
PushClipGeometry(path, D2D1::IdentityMatrix(), true);
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PopClip()
|
|
|
|
{
|
2014-09-15 01:51:29 +04:00
|
|
|
mCurrentClippedGeometry = nullptr;
|
2016-08-24 12:06:45 +03:00
|
|
|
if (CurrentLayer().mPushedClips.empty()) {
|
|
|
|
gfxDevCrash(LogReason::UnbalancedClipStack) << "DrawTargetD2D1::PopClip: No clip to pop.";
|
|
|
|
return;
|
|
|
|
}
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
2016-09-22 00:03:20 +03:00
|
|
|
if (CurrentLayer().mPushedClips.back().mGeometry) {
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->PopLayer();
|
|
|
|
} else {
|
|
|
|
mDC->PopAxisAlignedClip();
|
|
|
|
}
|
|
|
|
}
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mPushedClips.pop_back();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform, const IntRect& aBounds,
|
|
|
|
bool aCopyBackground)
|
|
|
|
{
|
|
|
|
D2D1_LAYER_OPTIONS1 options = D2D1_LAYER_OPTIONS1_NONE;
|
|
|
|
|
|
|
|
if (aOpaque) {
|
|
|
|
options |= D2D1_LAYER_OPTIONS1_IGNORE_ALPHA;
|
|
|
|
}
|
|
|
|
if (aCopyBackground) {
|
|
|
|
options |= D2D1_LAYER_OPTIONS1_INITIALIZE_FROM_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
2017-05-30 19:31:02 +03:00
|
|
|
RefPtr<ID2D1ImageBrush> mask;
|
2016-01-06 02:23:29 +03:00
|
|
|
Matrix maskTransform = aMaskTransform;
|
2017-05-29 01:45:42 +03:00
|
|
|
RefPtr<ID2D1PathGeometry> clip;
|
2017-05-30 19:31:02 +03:00
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
if (aMask) {
|
2017-05-30 19:31:02 +03:00
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aMask, maskTransform, ExtendMode::CLAMP);
|
2016-01-06 02:23:29 +03:00
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
|
|
|
// The mask is given in user space. Our layer will apply it in device space.
|
|
|
|
maskTransform = maskTransform * mTransform;
|
|
|
|
|
|
|
|
if (image) {
|
2017-05-30 19:31:02 +03:00
|
|
|
IntSize maskSize = aMask->GetSize();
|
|
|
|
HRESULT hr = mDC->CreateImageBrush(image,
|
|
|
|
D2D1::ImageBrushProperties(D2D1::RectF(0, 0, maskSize.width, maskSize.height)),
|
|
|
|
D2D1::BrushProperties(1.0f, D2DMatrix(maskTransform)),
|
|
|
|
getter_AddRefs(mask));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() <<"[D2D1.1] Failed to create a ImageBrush, code: " << hexa(hr);
|
|
|
|
}
|
2016-01-06 02:23:29 +03:00
|
|
|
|
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(clip));
|
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
|
|
|
clip->Open(getter_AddRefs(sink));
|
|
|
|
AddRectToSink(sink, D2D1::RectF(0, 0, aMask->GetSize().width, aMask->GetSize().height));
|
|
|
|
sink->Close();
|
|
|
|
} else {
|
|
|
|
gfxCriticalError() << "Failed to get image for mask surface!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PushAllClips();
|
|
|
|
|
|
|
|
mDC->PushLayer(D2D1::LayerParameters1(D2D1::InfiniteRect(), clip, D2D1_ANTIALIAS_MODE_ALIASED, D2DMatrix(maskTransform), aOpacity, mask, options), nullptr);
|
|
|
|
PushedLayer pushedLayer;
|
|
|
|
pushedLayer.mClipsArePushed = false;
|
|
|
|
pushedLayer.mIsOpaque = aOpaque;
|
2016-01-06 02:23:33 +03:00
|
|
|
pushedLayer.mOldPermitSubpixelAA = mPermitSubpixelAA;
|
|
|
|
mPermitSubpixelAA = aOpaque;
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
mDC->CreateCommandList(getter_AddRefs(pushedLayer.mCurrentList));
|
|
|
|
mPushedLayers.push_back(pushedLayer);
|
|
|
|
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
2016-01-11 18:38:10 +03:00
|
|
|
|
2016-02-11 23:35:07 +03:00
|
|
|
mUsedCommandListsSincePurge++;
|
2016-01-06 02:23:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::PopLayer()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(CurrentLayer().mPushedClips.size() == 0);
|
|
|
|
|
|
|
|
RefPtr<ID2D1CommandList> list = CurrentLayer().mCurrentList;
|
2016-01-06 02:23:33 +03:00
|
|
|
mPermitSubpixelAA = CurrentLayer().mOldPermitSubpixelAA;
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
mPushedLayers.pop_back();
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
|
|
|
|
|
|
list->Close();
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
|
|
|
DCCommandSink sink(mDC);
|
|
|
|
list->Stream(&sink);
|
|
|
|
|
2017-09-22 20:37:02 +03:00
|
|
|
mComplexBlendsWithListInList = 0;
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
mDC->PopLayer();
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap1> bitmap;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
HRESULT hr = mDC->CreateBitmap(D2DIntSize(aSize), aData, aStride,
|
|
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(aFormat)),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(bitmap));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-11-26 23:05:01 +03:00
|
|
|
if (FAILED(hr) || !bitmap) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(aSize))) << "[D2D1.1] 1CreateBitmap failure " << aSize << " Code: " << hexa(hr) << " format " << (int)aFormat;
|
2013-07-17 16:12:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, aFormat, aSize);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTargetD2D1> dt = new DrawTargetD2D1();
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
if (!dt->Init(aSize, aFormat)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return dt.forget();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<PathBuilder>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::CreatePathBuilder(FillRule aFillRule) const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
2015-10-18 07:40:10 +03:00
|
|
|
HRESULT hr = factory()->CreatePathGeometry(getter_AddRefs(path));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << *this << ": Failed to create Direct2D Path Geometry. Code: " << hexa(hr);
|
2013-07-17 16:12:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = path->Open(getter_AddRefs(sink));
|
2013-07-17 16:12:22 +04:00
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << *this << ": Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
|
2013-07-17 16:12:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aFillRule == FillRule::FILL_WINDING) {
|
2013-07-17 16:12:22 +04:00
|
|
|
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<PathBuilderD2D>(sink, path, aFillRule, BackendType::DIRECT2D1_1);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<GradientStops>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
|
|
|
|
{
|
2014-09-15 01:51:34 +04:00
|
|
|
if (aNumStops == 0) {
|
|
|
|
gfxWarning() << *this << ": Failed to create GradientStopCollection with no stops.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops];
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
|
|
|
stops[i].position = rawStops[i].offset;
|
|
|
|
stops[i].color = D2DColor(rawStops[i].color);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GradientStopCollection> stopCollection;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
HRESULT hr =
|
|
|
|
mDC->CreateGradientStopCollection(stops, aNumStops,
|
2015-11-23 19:17:35 +03:00
|
|
|
D2D1_GAMMA_2_2, D2DExtend(aExtendMode, Axis::BOTH),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(stopCollection));
|
2013-07-17 16:12:22 +04:00
|
|
|
delete [] stops;
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 19:35:39 +04:00
|
|
|
gfxWarning() << *this << ": Failed to create GradientStopCollection. Code: " << hexa(hr);
|
2013-07-17 16:12:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:39 +03:00
|
|
|
RefPtr<ID3D11Device> device = Factory::GetDirect3D11Device();
|
|
|
|
return MakeAndAddRef<GradientStopsD2D>(stopCollection, device);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<FilterNode>
|
2013-11-27 15:22:56 +04:00
|
|
|
DrawTargetD2D1::CreateFilter(FilterType aType)
|
|
|
|
{
|
2014-09-25 23:18:29 +04:00
|
|
|
return FilterNodeD2D1::Create(mDC, aType);
|
2013-11-27 15:22:56 +04:00
|
|
|
}
|
|
|
|
|
2016-08-10 02:41:03 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::GetGlyphRasterizationMetrics(ScaledFont *aScaledFont, const uint16_t* aGlyphIndices,
|
|
|
|
uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aScaledFont->GetType() == FontType::DWRITE);
|
|
|
|
|
|
|
|
aScaledFont->GetGlyphDesignMetrics(aGlyphIndices, aNumGlyphs, aGlyphMetrics);
|
|
|
|
|
|
|
|
// GetDesignGlyphMetrics returns 'ideal' glyph metrics, we need to pad to
|
|
|
|
// account for antialiasing.
|
|
|
|
for (uint32_t i = 0; i < aNumGlyphs; i++) {
|
|
|
|
if (aGlyphMetrics[i].mWidth > 0 && aGlyphMetrics[i].mHeight > 0) {
|
|
|
|
aGlyphMetrics[i].mWidth += 2.0f;
|
|
|
|
aGlyphMetrics[i].mXBearing -= 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 01:51:27 +04:00
|
|
|
bool
|
|
|
|
DrawTargetD2D1::Init(ID3D11Texture2D* aTexture, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2014-09-18 02:35:48 +04:00
|
|
|
|
2017-07-18 22:15:44 +03:00
|
|
|
RefPtr<ID2D1Device> device = Factory::GetD2D1Device(&mDeviceSeq);
|
2015-04-22 13:02:01 +03:00
|
|
|
if (!device) {
|
2016-07-07 06:43:03 +03:00
|
|
|
gfxCriticalNote << "[D2D1.1] Failed to obtain a device for DrawTargetD2D1::Init(ID3D11Texture2D*, SurfaceFormat).";
|
2015-04-22 13:02:01 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, getter_AddRefs(mDC));
|
2014-09-15 01:51:27 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError() <<"[D2D1.1] 1Failed to create a DeviceContext, code: " << hexa(hr) << " format " << (int)aFormat;
|
2014-09-15 01:51:27 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDXGISurface> dxgiSurface;
|
2014-09-15 01:51:27 +04:00
|
|
|
aTexture->QueryInterface(__uuidof(IDXGISurface),
|
2015-10-18 07:40:10 +03:00
|
|
|
(void**)((IDXGISurface**)getter_AddRefs(dxgiSurface)));
|
2014-09-15 01:51:27 +04:00
|
|
|
if (!dxgiSurface) {
|
2014-11-26 23:05:01 +03:00
|
|
|
gfxCriticalError() <<"[D2D1.1] Failed to obtain a DXGI surface.";
|
2014-09-15 01:51:27 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_BITMAP_PROPERTIES1 props;
|
|
|
|
props.dpiX = 96;
|
|
|
|
props.dpiY = 96;
|
|
|
|
props.pixelFormat = D2DPixelFormat(aFormat);
|
|
|
|
props.colorContext = nullptr;
|
|
|
|
props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)getter_AddRefs(mBitmap));
|
2014-09-15 01:51:27 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError() << "[D2D1.1] CreateBitmapFromDxgiSurface failure Code: " << hexa(hr) << " format " << (int)aFormat;
|
2014-09-15 01:51:27 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
aTexture->GetDesc(&desc);
|
|
|
|
mSize.width = desc.Width;
|
|
|
|
mSize.height = desc.Height;
|
|
|
|
|
2015-05-07 03:38:10 +03:00
|
|
|
// This single solid color brush system is not very 'threadsafe', however,
|
|
|
|
// issueing multiple drawing commands simultaneously to a single drawtarget
|
|
|
|
// from multiple threads is unexpected since there's no way to guarantee
|
|
|
|
// ordering in that situation anyway.
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = mDC->CreateSolidColorBrush(D2D1::ColorF(0, 0), getter_AddRefs(mSolidColorBrush));
|
2015-05-07 03:38:10 +03:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-12-29 22:03:58 +03:00
|
|
|
gfxCriticalError() << "[D2D1.1] Failure creating solid color brush (I1).";
|
2015-05-07 03:38:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
mDC->SetTarget(CurrentTarget());
|
2014-09-15 01:51:27 +04:00
|
|
|
|
|
|
|
mDC->BeginDraw();
|
2015-05-07 03:38:10 +03:00
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mIsOpaque = aFormat == SurfaceFormat::B8G8R8X8;
|
|
|
|
|
2014-09-15 01:51:27 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
bool
|
|
|
|
DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2014-09-15 01:51:33 +04:00
|
|
|
|
2017-07-18 22:15:44 +03:00
|
|
|
RefPtr<ID2D1Device> device = Factory::GetD2D1Device(&mDeviceSeq);
|
2015-04-22 13:02:01 +03:00
|
|
|
if (!device) {
|
2016-07-07 06:43:03 +03:00
|
|
|
gfxCriticalNote << "[D2D1.1] Failed to obtain a device for DrawTargetD2D1::Init(IntSize, SurfaceFormat).";
|
2015-04-22 13:02:01 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, getter_AddRefs(mDC));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError() <<"[D2D1.1] 2Failed to create a DeviceContext, code: " << hexa(hr) << " format " << (int)aFormat;
|
2013-07-17 16:12:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-15 01:51:33 +04:00
|
|
|
if (mDC->GetMaximumBitmapSize() < UINT32(aSize.width) ||
|
|
|
|
mDC->GetMaximumBitmapSize() < UINT32(aSize.height)) {
|
2014-12-18 01:54:04 +03:00
|
|
|
// This is 'ok', so don't assert
|
2015-10-21 15:34:00 +03:00
|
|
|
gfxCriticalNote << "[D2D1.1] Attempt to use unsupported surface size " << aSize;
|
2014-09-15 01:51:33 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
D2D1_BITMAP_PROPERTIES1 props;
|
|
|
|
props.dpiX = 96;
|
|
|
|
props.dpiY = 96;
|
|
|
|
props.pixelFormat = D2DPixelFormat(aFormat);
|
|
|
|
props.colorContext = nullptr;
|
|
|
|
props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = mDC->CreateBitmap(D2DIntSize(aSize), nullptr, 0, props, (ID2D1Bitmap1**)getter_AddRefs(mBitmap));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError() << "[D2D1.1] 3CreateBitmap failure " << aSize << " Code: " << hexa(hr) << " format " << (int)aFormat;
|
2013-07-17 16:12:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
mDC->SetTarget(CurrentTarget());
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
hr = mDC->CreateSolidColorBrush(D2D1::ColorF(0, 0), getter_AddRefs(mSolidColorBrush));
|
2015-05-07 03:38:10 +03:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-12-29 22:03:58 +03:00
|
|
|
gfxCriticalError() << "[D2D1.1] Failure creating solid color brush (I2).";
|
2015-05-07 03:38:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->BeginDraw();
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mIsOpaque = aFormat == SurfaceFormat::B8G8R8X8;
|
|
|
|
|
2014-09-15 01:51:33 +04:00
|
|
|
mDC->Clear();
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
mFormat = aFormat;
|
|
|
|
mSize = aSize;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helpers.
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
DrawTargetD2D1::GetByteSize() const
|
|
|
|
{
|
|
|
|
return mSize.width * mSize.height * BytesPerPixel(mFormat);
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:39 +03:00
|
|
|
RefPtr<ID2D1Factory1>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::factory()
|
|
|
|
{
|
2017-07-18 22:15:44 +03:00
|
|
|
StaticMutexAutoLock lock(Factory::mDeviceLock);
|
|
|
|
|
|
|
|
if (mFactory || !NS_IsMainThread()) {
|
2013-07-17 16:12:22 +04:00
|
|
|
return mFactory;
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:44 +03:00
|
|
|
// We don't allow initializing the factory off the main thread.
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-02-13 16:33:28 +03:00
|
|
|
RefPtr<ID2D1Factory> factory;
|
|
|
|
D2D1CreateFactoryFunc createD2DFactory;
|
|
|
|
HMODULE d2dModule = LoadLibraryW(L"d2d1.dll");
|
|
|
|
createD2DFactory = (D2D1CreateFactoryFunc)
|
|
|
|
GetProcAddress(d2dModule, "D2D1CreateFactory");
|
|
|
|
|
|
|
|
if (!createD2DFactory) {
|
|
|
|
gfxWarning() << "Failed to locate D2D1CreateFactory function.";
|
2015-01-20 00:56:59 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-13 16:33:28 +03:00
|
|
|
D2D1_FACTORY_OPTIONS options;
|
|
|
|
#ifdef _DEBUG
|
|
|
|
options.debugLevel = D2D1_DEBUG_LEVEL_WARNING;
|
|
|
|
#else
|
|
|
|
options.debugLevel = D2D1_DEBUG_LEVEL_NONE;
|
|
|
|
#endif
|
|
|
|
//options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
|
2016-02-12 04:11:50 +03:00
|
|
|
|
2016-02-13 16:33:28 +03:00
|
|
|
HRESULT hr = createD2DFactory(D2D1_FACTORY_TYPE_MULTI_THREADED,
|
|
|
|
__uuidof(ID2D1Factory),
|
|
|
|
&options,
|
|
|
|
getter_AddRefs(factory));
|
|
|
|
|
|
|
|
if (FAILED(hr) || !factory) {
|
2016-02-16 10:59:24 +03:00
|
|
|
gfxCriticalNote << "Failed to create a D2D1 content device: " << hexa(hr);
|
2016-02-13 16:33:28 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:39 +03:00
|
|
|
RefPtr<ID2D1Factory1> factory1;
|
|
|
|
hr = factory->QueryInterface(__uuidof(ID2D1Factory1), getter_AddRefs(factory1));
|
|
|
|
if (FAILED(hr) || !factory1) {
|
2013-07-17 16:12:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:39 +03:00
|
|
|
mFactory = factory1;
|
|
|
|
|
2016-02-13 16:33:28 +03:00
|
|
|
ExtendInputEffectD2D1::Register(mFactory);
|
2013-07-17 16:12:22 +04:00
|
|
|
RadialGradientEffectD2D1::Register(mFactory);
|
|
|
|
|
|
|
|
return mFactory;
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:16:48 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::CleanupD2D()
|
|
|
|
{
|
2017-07-18 22:15:44 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
Factory::mDeviceLock.AssertCurrentThreadOwns();
|
|
|
|
|
2014-11-20 03:16:48 +03:00
|
|
|
if (mFactory) {
|
|
|
|
RadialGradientEffectD2D1::Unregister(mFactory);
|
2016-02-13 16:33:28 +03:00
|
|
|
ExtendInputEffectD2D1::Unregister(mFactory);
|
2014-11-20 03:16:48 +03:00
|
|
|
mFactory = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::MarkChanged()
|
|
|
|
{
|
|
|
|
if (mSnapshot) {
|
2017-11-21 18:52:38 +03:00
|
|
|
MutexAutoLock lock(*mSnapshotLock);
|
2013-07-17 16:12:22 +04:00
|
|
|
if (mSnapshot->hasOneRef()) {
|
|
|
|
// Just destroy it, since no-one else knows about it.
|
|
|
|
mSnapshot = nullptr;
|
|
|
|
} else {
|
|
|
|
mSnapshot->DrawTargetWillChange();
|
|
|
|
// The snapshot will no longer depend on this target.
|
|
|
|
MOZ_ASSERT(!mSnapshot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDependentTargets.size()) {
|
|
|
|
// Copy mDependentTargets since the Flush()es below will modify it.
|
|
|
|
TargetSet tmpTargets = mDependentTargets;
|
|
|
|
for (TargetSet::iterator iter = tmpTargets.begin();
|
|
|
|
iter != tmpTargets.end(); iter++) {
|
|
|
|
(*iter)->Flush();
|
|
|
|
}
|
|
|
|
// The Flush() should have broken all dependencies on this target.
|
|
|
|
MOZ_ASSERT(!mDependentTargets.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-20 21:51:46 +03:00
|
|
|
bool
|
|
|
|
DrawTargetD2D1::ShouldClipTemporarySurfaceDrawing(CompositionOp aOp,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
bool aClipIsComplex)
|
|
|
|
{
|
|
|
|
bool patternSupported = IsPatternSupportedByD2D(aPattern);
|
|
|
|
return patternSupported && !CurrentLayer().mIsOpaque && D2DSupportsCompositeMode(aOp) &&
|
|
|
|
IsOperatorBoundByMask(aOp) && aClipIsComplex;
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PrepareForDrawing(CompositionOp aOp, const Pattern &aPattern)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
|
2016-03-20 21:51:46 +03:00
|
|
|
bool patternSupported = IsPatternSupportedByD2D(aPattern);
|
|
|
|
|
|
|
|
if (D2DSupportsPrimitiveBlendMode(aOp) && patternSupported) {
|
2015-04-10 08:09:31 +03:00
|
|
|
// It's important to do this before FlushTransformToDC! As this will cause
|
|
|
|
// the transform to become dirty.
|
|
|
|
PushAllClips();
|
|
|
|
|
|
|
|
FlushTransformToDC();
|
2015-05-11 15:47:00 +03:00
|
|
|
|
|
|
|
if (aOp != CompositionOp::OP_OVER)
|
|
|
|
mDC->SetPrimitiveBlend(D2DPrimitiveBlendMode(aOp));
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:11:00 +03:00
|
|
|
HRESULT result = mDC->CreateCommandList(getter_AddRefs(mCommandList));
|
2015-11-12 19:00:52 +03:00
|
|
|
mDC->SetTarget(mCommandList);
|
2016-02-11 23:35:07 +03:00
|
|
|
mUsedCommandListsSincePurge++;
|
2015-04-10 08:09:31 +03:00
|
|
|
|
2016-04-20 19:11:00 +03:00
|
|
|
// This is where we should have a valid command list. If we don't, something is
|
|
|
|
// wrong, and it's likely an OOM.
|
|
|
|
if (!mCommandList) {
|
|
|
|
gfxDevCrash(LogReason::InvalidCommandList) << "Invalid D2D1.1 command list on creation " << mUsedCommandListsSincePurge << ", " << gfx::hexa(result);
|
|
|
|
}
|
|
|
|
|
2016-03-20 21:51:46 +03:00
|
|
|
D2D1_RECT_F rect;
|
|
|
|
bool isAligned;
|
|
|
|
bool clipIsComplex = CurrentLayer().mPushedClips.size() && !GetDeviceSpaceClipRect(rect, isAligned);
|
|
|
|
|
|
|
|
if (ShouldClipTemporarySurfaceDrawing(aOp, aPattern, clipIsComplex)) {
|
|
|
|
PushClipsToDC(mDC);
|
|
|
|
}
|
|
|
|
|
2015-04-10 08:09:31 +03:00
|
|
|
FlushTransformToDC();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-20 15:57:25 +03:00
|
|
|
DrawTargetD2D1::FinalizeDrawing(CompositionOp aOp, const Pattern &aPattern)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
bool patternSupported = IsPatternSupportedByD2D(aPattern);
|
|
|
|
|
2015-05-11 15:47:00 +03:00
|
|
|
if (D2DSupportsPrimitiveBlendMode(aOp) && patternSupported) {
|
|
|
|
if (aOp != CompositionOp::OP_OVER)
|
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
2013-07-17 16:12:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-20 21:51:46 +03:00
|
|
|
D2D1_RECT_F rect;
|
|
|
|
bool isAligned;
|
|
|
|
bool clipIsComplex = CurrentLayer().mPushedClips.size() && !GetDeviceSpaceClipRect(rect, isAligned);
|
|
|
|
|
|
|
|
if (ShouldClipTemporarySurfaceDrawing(aOp, aPattern, clipIsComplex)) {
|
|
|
|
PopClipsFromDC(mDC);
|
|
|
|
}
|
2015-04-10 08:09:31 +03:00
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
mDC->SetTarget(CurrentTarget());
|
2016-04-20 19:11:00 +03:00
|
|
|
if (!mCommandList) {
|
|
|
|
gfxDevCrash(LogReason::InvalidCommandList) << "Invalid D21.1 command list on finalize";
|
|
|
|
return;
|
|
|
|
}
|
2015-11-12 19:00:52 +03:00
|
|
|
mCommandList->Close();
|
|
|
|
|
|
|
|
RefPtr<ID2D1CommandList> source = mCommandList;
|
|
|
|
mCommandList = nullptr;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2014-09-15 01:51:29 +04:00
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
if (patternSupported) {
|
2014-09-15 01:51:31 +04:00
|
|
|
if (D2DSupportsCompositeMode(aOp)) {
|
2016-01-06 02:23:29 +03:00
|
|
|
RefPtr<ID2D1Image> tmpImage;
|
2015-04-10 08:09:31 +03:00
|
|
|
if (clipIsComplex) {
|
2016-03-20 21:51:46 +03:00
|
|
|
PopAllClips();
|
2015-04-10 08:09:31 +03:00
|
|
|
if (!IsOperatorBoundByMask(aOp)) {
|
2016-01-06 02:23:29 +03:00
|
|
|
tmpImage = GetImageForLayerContent();
|
2015-04-10 08:09:31 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-12 19:00:52 +03:00
|
|
|
mDC->DrawImage(source, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2DCompositionMode(aOp));
|
2015-04-10 08:09:31 +03:00
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
if (tmpImage) {
|
|
|
|
RefPtr<ID2D1ImageBrush> brush;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> inverseGeom = GetInverseClippedGeometry();
|
2016-01-06 02:23:29 +03:00
|
|
|
mDC->CreateImageBrush(tmpImage, D2D1::ImageBrushProperties(D2D1::RectF(0, 0, mSize.width, mSize.height)),
|
|
|
|
getter_AddRefs(brush));
|
2015-04-10 08:09:31 +03:00
|
|
|
|
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_COPY);
|
|
|
|
mDC->FillGeometry(inverseGeom, brush);
|
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
|
|
|
}
|
2014-09-15 01:51:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
RefPtr<ID2D1Effect> blendEffect;
|
|
|
|
HRESULT hr = mDC->CreateEffect(CLSID_D2D1Blend, getter_AddRefs(blendEffect));
|
2014-09-15 01:51:31 +04:00
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
if (FAILED(hr) || !blendEffect) {
|
|
|
|
gfxWarning() << "Failed to create blend effect!";
|
2015-08-12 00:07:49 +03:00
|
|
|
return;
|
2015-02-26 01:44:56 +03:00
|
|
|
}
|
2014-09-15 01:51:31 +04:00
|
|
|
|
2017-09-20 15:57:25 +03:00
|
|
|
// We don't need to preserve the current content of this layer as the output
|
2016-09-12 19:41:10 +03:00
|
|
|
// of the blend effect should completely replace it.
|
2017-09-20 15:57:25 +03:00
|
|
|
RefPtr<ID2D1Image> tmpImage = GetImageForLayerContent(false);
|
2017-02-21 01:14:49 +03:00
|
|
|
if (!tmpImage) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-15 01:51:31 +04:00
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
blendEffect->SetInput(0, tmpImage);
|
|
|
|
blendEffect->SetInput(1, source);
|
|
|
|
blendEffect->SetValue(D2D1_BLEND_PROP_MODE, D2DBlendMode(aOp));
|
2014-09-15 01:51:31 +04:00
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
mDC->DrawImage(blendEffect, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
|
2016-08-22 14:22:01 +03:00
|
|
|
|
2017-09-22 20:37:02 +03:00
|
|
|
mComplexBlendsWithListInList++;
|
2013-07-17 16:12:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-12 18:05:13 +03:00
|
|
|
const RadialGradientPattern *pat = static_cast<const RadialGradientPattern*>(&aPattern);
|
|
|
|
if (pat->mCenter1 == pat->mCenter2 && pat->mRadius1 == pat->mRadius2) {
|
|
|
|
// Draw nothing!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-16 08:55:22 +03:00
|
|
|
if (!pat->mStops) {
|
|
|
|
// Draw nothing because of no color stops
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Effect> radialGradientEffect;
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
HRESULT hr = mDC->CreateEffect(CLSID_RadialGradientEffect, getter_AddRefs(radialGradientEffect));
|
2015-05-28 22:46:16 +03:00
|
|
|
if (FAILED(hr) || !radialGradientEffect) {
|
|
|
|
gfxWarning() << "Failed to create radial gradient effect. Code: " << hexa(hr);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_STOP_COLLECTION,
|
|
|
|
static_cast<const GradientStopsD2D*>(pat->mStops.get())->mStopCollection);
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_CENTER_1, D2D1::Vector2F(pat->mCenter1.x, pat->mCenter1.y));
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_CENTER_2, D2D1::Vector2F(pat->mCenter2.x, pat->mCenter2.y));
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_RADIUS_1, pat->mRadius1);
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_RADIUS_2, pat->mRadius2);
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_RADIUS_2, pat->mRadius2);
|
|
|
|
radialGradientEffect->SetValue(RADIAL_PROP_TRANSFORM, D2DMatrix(pat->mMatrix * mTransform));
|
2015-11-12 19:00:52 +03:00
|
|
|
radialGradientEffect->SetInput(0, source);
|
2013-07-17 16:12:22 +04:00
|
|
|
|
|
|
|
mDC->DrawImage(radialGradientEffect, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2DCompositionMode(aOp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::AddDependencyOnSource(SourceSurfaceD2D1* aSource)
|
|
|
|
{
|
|
|
|
if (aSource->mDrawTarget && !mDependingOnTargets.count(aSource->mDrawTarget)) {
|
|
|
|
aSource->mDrawTarget->mDependentTargets.insert(this);
|
|
|
|
mDependingOnTargets.insert(aSource->mDrawTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 01:51:29 +04:00
|
|
|
static D2D1_RECT_F
|
|
|
|
IntersectRect(const D2D1_RECT_F& aRect1, const D2D1_RECT_F& aRect2)
|
|
|
|
{
|
|
|
|
D2D1_RECT_F result;
|
|
|
|
result.left = max(aRect1.left, aRect2.left);
|
|
|
|
result.top = max(aRect1.top, aRect2.top);
|
|
|
|
result.right = min(aRect1.right, aRect2.right);
|
|
|
|
result.bottom = min(aRect1.bottom, aRect2.bottom);
|
|
|
|
|
|
|
|
result.right = max(result.right, result.left);
|
|
|
|
result.bottom = max(result.bottom, result.top);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetD2D1::GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned)
|
|
|
|
{
|
2016-01-05 11:03:08 +03:00
|
|
|
if (!CurrentLayer().mPushedClips.size()) {
|
2014-09-15 01:51:29 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-29 21:18:33 +03:00
|
|
|
aIsPixelAligned = true;
|
2014-09-15 01:51:29 +04:00
|
|
|
aClipRect = D2D1::RectF(0, 0, mSize.width, mSize.height);
|
2016-01-05 11:03:08 +03:00
|
|
|
for (auto iter = CurrentLayer().mPushedClips.begin();iter != CurrentLayer().mPushedClips.end(); iter++) {
|
2016-09-22 00:03:20 +03:00
|
|
|
if (iter->mGeometry) {
|
2014-09-15 01:51:29 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aClipRect = IntersectRect(aClipRect, iter->mBounds);
|
|
|
|
if (!iter->mIsPixelAligned) {
|
|
|
|
aIsPixelAligned = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:37:02 +03:00
|
|
|
static const uint32_t sComplexBlendsWithListAllowedInList = 4;
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
already_AddRefed<ID2D1Image>
|
2017-09-20 15:57:25 +03:00
|
|
|
DrawTargetD2D1::GetImageForLayerContent(bool aShouldPreserveContent)
|
2016-01-06 02:23:29 +03:00
|
|
|
{
|
2016-09-27 18:11:39 +03:00
|
|
|
PopAllClips();
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
if (!CurrentLayer().mCurrentList) {
|
|
|
|
RefPtr<ID2D1Bitmap> tmpBitmap;
|
|
|
|
HRESULT hr = mDC->CreateBitmap(D2DIntSize(mSize), D2D1::BitmapProperties(D2DPixelFormat(mFormat)), getter_AddRefs(tmpBitmap));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(mSize))) << "[D2D1.1] 6CreateBitmap failure " << mSize << " Code: " << hexa(hr) << " format " << (int)mFormat;
|
2017-02-21 01:14:49 +03:00
|
|
|
// If it's a recreate target error, return and handle it elsewhere.
|
|
|
|
if (hr == D2DERR_RECREATE_TARGET) {
|
|
|
|
mDC->Flush();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// For now, crash in other scenarios; this should happen because tmpBitmap is
|
2016-01-06 02:23:29 +03:00
|
|
|
// null and CopyFromBitmap call below dereferences it.
|
|
|
|
}
|
|
|
|
mDC->Flush();
|
|
|
|
|
|
|
|
tmpBitmap->CopyFromBitmap(nullptr, mBitmap, nullptr);
|
|
|
|
return tmpBitmap.forget();
|
|
|
|
} else {
|
|
|
|
RefPtr<ID2D1CommandList> list = CurrentLayer().mCurrentList;
|
|
|
|
mDC->CreateCommandList(getter_AddRefs(CurrentLayer().mCurrentList));
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
|
|
list->Close();
|
|
|
|
|
2016-08-22 14:22:01 +03:00
|
|
|
RefPtr<ID2D1Bitmap1> tmpBitmap;
|
2017-09-22 20:37:02 +03:00
|
|
|
if (mComplexBlendsWithListInList >= sComplexBlendsWithListAllowedInList) {
|
2016-08-29 17:31:25 +03:00
|
|
|
D2D1_BITMAP_PROPERTIES1 props =
|
|
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET,
|
|
|
|
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
D2D1_ALPHA_MODE_PREMULTIPLIED));
|
2017-09-20 15:57:25 +03:00
|
|
|
mDC->CreateBitmap(mBitmap->GetPixelSize(), nullptr, 0, &props, getter_AddRefs(tmpBitmap));
|
2016-08-22 14:22:01 +03:00
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mDC->SetTarget(tmpBitmap);
|
2017-09-20 15:57:25 +03:00
|
|
|
mDC->DrawImage(list, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
|
2016-08-22 14:22:01 +03:00
|
|
|
mDC->SetTarget(CurrentTarget());
|
2017-09-22 20:37:02 +03:00
|
|
|
mComplexBlendsWithListInList = 0;
|
2016-08-22 14:22:01 +03:00
|
|
|
}
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
DCCommandSink sink(mDC);
|
|
|
|
|
2016-09-12 19:41:10 +03:00
|
|
|
if (aShouldPreserveContent) {
|
|
|
|
list->Stream(&sink);
|
|
|
|
PushAllClips();
|
|
|
|
}
|
2016-03-20 21:51:46 +03:00
|
|
|
|
2017-09-22 20:37:02 +03:00
|
|
|
if (tmpBitmap) {
|
2016-08-22 14:22:01 +03:00
|
|
|
return tmpBitmap.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-06 02:23:29 +03:00
|
|
|
return list.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1Geometry>
|
2014-09-15 01:51:29 +04:00
|
|
|
DrawTargetD2D1::GetClippedGeometry(IntRect *aClipBounds)
|
|
|
|
{
|
|
|
|
if (mCurrentClippedGeometry) {
|
|
|
|
*aClipBounds = mCurrentClipBounds;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
2015-05-01 16:14:16 +03:00
|
|
|
return clippedGeometry.forget();
|
2014-09-15 01:51:29 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
MOZ_ASSERT(CurrentLayer().mPushedClips.size());
|
2015-04-10 08:09:31 +03:00
|
|
|
|
2014-09-15 01:51:29 +04:00
|
|
|
mCurrentClipBounds = IntRect(IntPoint(0, 0), mSize);
|
|
|
|
|
|
|
|
// if pathGeom is null then pathRect represents the path.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> pathGeom;
|
2014-09-15 01:51:29 +04:00
|
|
|
D2D1_RECT_F pathRect;
|
|
|
|
bool pathRectIsAxisAligned = false;
|
2016-01-05 11:03:08 +03:00
|
|
|
auto iter = CurrentLayer().mPushedClips.begin();
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
if (iter->mGeometry) {
|
|
|
|
pathGeom = GetTransformedGeometry(iter->mGeometry, iter->mTransform);
|
2014-09-15 01:51:29 +04:00
|
|
|
} else {
|
|
|
|
pathRect = iter->mBounds;
|
|
|
|
pathRectIsAxisAligned = iter->mIsPixelAligned;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter++;
|
2016-01-05 11:03:08 +03:00
|
|
|
for (;iter != CurrentLayer().mPushedClips.end(); iter++) {
|
2014-09-15 01:51:29 +04:00
|
|
|
// Do nothing but add it to the current clip bounds.
|
2016-09-22 00:03:20 +03:00
|
|
|
if (!iter->mGeometry && iter->mIsPixelAligned) {
|
2014-09-15 01:51:29 +04:00
|
|
|
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
|
|
|
|
IntRect(int32_t(iter->mBounds.left), int32_t(iter->mBounds.top),
|
|
|
|
int32_t(iter->mBounds.right - iter->mBounds.left),
|
|
|
|
int32_t(iter->mBounds.bottom - iter->mBounds.top)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pathGeom) {
|
|
|
|
if (pathRectIsAxisAligned) {
|
|
|
|
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
|
|
|
|
IntRect(int32_t(pathRect.left), int32_t(pathRect.top),
|
|
|
|
int32_t(pathRect.right - pathRect.left),
|
|
|
|
int32_t(pathRect.bottom - pathRect.top)));
|
|
|
|
}
|
2016-09-22 00:03:20 +03:00
|
|
|
if (iter->mGeometry) {
|
2014-09-15 01:51:29 +04:00
|
|
|
// See if pathRect needs to go into the path geometry.
|
|
|
|
if (!pathRectIsAxisAligned) {
|
|
|
|
pathGeom = ConvertRectToGeometry(pathRect);
|
|
|
|
} else {
|
2016-09-22 00:03:20 +03:00
|
|
|
pathGeom = GetTransformedGeometry(iter->mGeometry, iter->mTransform);
|
2014-09-15 01:51:29 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pathRect = IntersectRect(pathRect, iter->mBounds);
|
|
|
|
pathRectIsAxisAligned = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1PathGeometry> newGeom;
|
2015-10-18 07:40:10 +03:00
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(newGeom));
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GeometrySink> currentSink;
|
2015-10-18 07:40:10 +03:00
|
|
|
newGeom->Open(getter_AddRefs(currentSink));
|
2014-09-15 01:51:29 +04:00
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
if (iter->mGeometry) {
|
|
|
|
pathGeom->CombineWithGeometry(iter->mGeometry, D2D1_COMBINE_MODE_INTERSECT,
|
2014-09-15 01:51:29 +04:00
|
|
|
iter->mTransform, currentSink);
|
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> rectGeom = ConvertRectToGeometry(iter->mBounds);
|
2014-09-15 01:51:29 +04:00
|
|
|
pathGeom->CombineWithGeometry(rectGeom, D2D1_COMBINE_MODE_INTERSECT,
|
|
|
|
D2D1::IdentityMatrix(), currentSink);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentSink->Close();
|
|
|
|
|
|
|
|
pathGeom = newGeom.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now we need mCurrentClippedGeometry to always be non-nullptr. This
|
|
|
|
// method might seem a little strange but it is just fine, if pathGeom is
|
|
|
|
// nullptr pathRect will always still contain 1 clip unaccounted for
|
|
|
|
// regardless of mCurrentClipBounds.
|
|
|
|
if (!pathGeom) {
|
|
|
|
pathGeom = ConvertRectToGeometry(pathRect);
|
|
|
|
}
|
|
|
|
mCurrentClippedGeometry = pathGeom.forget();
|
|
|
|
*aClipBounds = mCurrentClipBounds;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
2015-05-01 16:14:16 +03:00
|
|
|
return clippedGeometry.forget();
|
2014-09-15 01:51:29 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1Geometry>
|
2015-04-10 08:09:31 +03:00
|
|
|
DrawTargetD2D1::GetInverseClippedGeometry()
|
|
|
|
{
|
|
|
|
IntRect bounds;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(&bounds);
|
|
|
|
RefPtr<ID2D1RectangleGeometry> rectGeom;
|
|
|
|
RefPtr<ID2D1PathGeometry> inverseGeom;
|
2015-10-18 07:40:10 +03:00
|
|
|
|
|
|
|
factory()->CreateRectangleGeometry(D2D1::RectF(0, 0, mSize.width, mSize.height), getter_AddRefs(rectGeom));
|
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(inverseGeom));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 07:40:10 +03:00
|
|
|
inverseGeom->Open(getter_AddRefs(sink));
|
2015-04-10 08:09:31 +03:00
|
|
|
rectGeom->CombineWithGeometry(geom, D2D1_COMBINE_MODE_EXCLUDE, D2D1::IdentityMatrix(), sink);
|
|
|
|
sink->Close();
|
|
|
|
|
2015-05-01 16:14:16 +03:00
|
|
|
return inverseGeom.forget();
|
2015-04-10 08:09:31 +03:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PopAllClips()
|
|
|
|
{
|
2016-01-05 11:03:08 +03:00
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
2013-07-17 16:12:22 +04:00
|
|
|
PopClipsFromDC(mDC);
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mClipsArePushed = false;
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-10 08:09:31 +03:00
|
|
|
void
|
|
|
|
DrawTargetD2D1::PushAllClips()
|
|
|
|
{
|
2016-01-05 11:03:08 +03:00
|
|
|
if (!CurrentLayer().mClipsArePushed) {
|
2015-04-10 08:09:31 +03:00
|
|
|
PushClipsToDC(mDC);
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
CurrentLayer().mClipsArePushed = true;
|
2015-04-10 08:09:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
2015-05-29 15:49:19 +03:00
|
|
|
DrawTargetD2D1::PushClipsToDC(ID2D1DeviceContext *aDC, bool aForceIgnoreAlpha, const D2D1_RECT_F& aMaxRect)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
2016-01-05 11:03:08 +03:00
|
|
|
for (auto iter = CurrentLayer().mPushedClips.begin(); iter != CurrentLayer().mPushedClips.end(); iter++) {
|
2016-09-22 00:03:20 +03:00
|
|
|
if (iter->mGeometry) {
|
|
|
|
PushD2DLayer(aDC, iter->mGeometry, iter->mTransform, iter->mIsPixelAligned, aForceIgnoreAlpha, aMaxRect);
|
2013-07-17 16:12:22 +04:00
|
|
|
} else {
|
|
|
|
mDC->PushAxisAlignedClip(iter->mBounds, iter->mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D1::PopClipsFromDC(ID2D1DeviceContext *aDC)
|
|
|
|
{
|
2016-01-05 11:03:08 +03:00
|
|
|
for (int i = CurrentLayer().mPushedClips.size() - 1; i >= 0; i--) {
|
2016-09-22 00:03:20 +03:00
|
|
|
if (CurrentLayer().mPushedClips[i].mGeometry) {
|
2013-07-17 16:12:22 +04:00
|
|
|
aDC->PopLayer();
|
|
|
|
} else {
|
|
|
|
aDC->PopAxisAlignedClip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1Brush>
|
2014-09-15 01:51:34 +04:00
|
|
|
DrawTargetD2D1::CreateTransparentBlackBrush()
|
|
|
|
{
|
2015-05-07 03:38:10 +03:00
|
|
|
return GetSolidColorBrush(D2D1::ColorF(0, 0));
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1SolidColorBrush>
|
2015-05-07 03:38:10 +03:00
|
|
|
DrawTargetD2D1::GetSolidColorBrush(const D2D_COLOR_F& aColor)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1SolidColorBrush> brush = mSolidColorBrush;
|
2015-05-07 03:38:10 +03:00
|
|
|
brush->SetColor(aColor);
|
2015-05-01 16:14:16 +03:00
|
|
|
return brush.forget();
|
2014-09-15 01:51:34 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1Brush>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
|
|
|
|
{
|
|
|
|
if (!IsPatternSupportedByD2D(aPattern)) {
|
2015-05-07 03:38:10 +03:00
|
|
|
return GetSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f));
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aPattern.GetType() == PatternType::COLOR) {
|
2013-07-17 16:12:22 +04:00
|
|
|
Color color = static_cast<const ColorPattern*>(&aPattern)->mColor;
|
2015-05-07 03:38:10 +03:00
|
|
|
return GetSolidColorBrush(D2D1::ColorF(color.r, color.g, color.b, color.a * aAlpha));
|
2014-06-13 20:09:23 +04:00
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::LINEAR_GRADIENT) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1LinearGradientBrush> gradBrush;
|
2013-07-17 16:12:22 +04:00
|
|
|
const LinearGradientPattern *pat =
|
|
|
|
static_cast<const LinearGradientPattern*>(&aPattern);
|
|
|
|
|
|
|
|
GradientStopsD2D *stops = static_cast<GradientStopsD2D*>(pat->mStops.get());
|
|
|
|
|
|
|
|
if (!stops) {
|
|
|
|
gfxDebug() << "No stops specified for gradient pattern.";
|
2014-09-15 01:51:34 +04:00
|
|
|
return CreateTransparentBlackBrush();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pat->mBegin == pat->mEnd) {
|
|
|
|
uint32_t stopCount = stops->mStopCollection->GetGradientStopCount();
|
|
|
|
vector<D2D1_GRADIENT_STOP> d2dStops(stopCount);
|
|
|
|
stops->mStopCollection->GetGradientStops(&d2dStops.front(), stopCount);
|
2015-05-07 03:38:10 +03:00
|
|
|
d2dStops.back().color.a *= aAlpha;
|
|
|
|
return GetSolidColorBrush(d2dStops.back().color);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDC->CreateLinearGradientBrush(D2D1::LinearGradientBrushProperties(D2DPoint(pat->mBegin),
|
|
|
|
D2DPoint(pat->mEnd)),
|
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(pat->mMatrix)),
|
|
|
|
stops->mStopCollection,
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(gradBrush));
|
2015-01-28 03:54:19 +03:00
|
|
|
|
|
|
|
if (!gradBrush) {
|
|
|
|
gfxWarning() << "Couldn't create gradient brush.";
|
|
|
|
return CreateTransparentBlackBrush();
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return gradBrush.forget();
|
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::RADIAL_GRADIENT) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1RadialGradientBrush> gradBrush;
|
2013-07-17 16:12:22 +04:00
|
|
|
const RadialGradientPattern *pat =
|
|
|
|
static_cast<const RadialGradientPattern*>(&aPattern);
|
|
|
|
|
|
|
|
GradientStopsD2D *stops = static_cast<GradientStopsD2D*>(pat->mStops.get());
|
|
|
|
|
|
|
|
if (!stops) {
|
|
|
|
gfxDebug() << "No stops specified for gradient pattern.";
|
2014-09-15 01:51:34 +04:00
|
|
|
return CreateTransparentBlackBrush();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This will not be a complex radial gradient brush.
|
|
|
|
mDC->CreateRadialGradientBrush(
|
|
|
|
D2D1::RadialGradientBrushProperties(D2DPoint(pat->mCenter2),
|
|
|
|
D2DPoint(pat->mCenter1 - pat->mCenter2),
|
|
|
|
pat->mRadius2, pat->mRadius2),
|
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(pat->mMatrix)),
|
2014-06-13 20:09:23 +04:00
|
|
|
stops->mStopCollection,
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(gradBrush));
|
2013-07-17 16:12:22 +04:00
|
|
|
|
2015-01-28 03:54:19 +03:00
|
|
|
if (!gradBrush) {
|
|
|
|
gfxWarning() << "Couldn't create gradient brush.";
|
|
|
|
return CreateTransparentBlackBrush();
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return gradBrush.forget();
|
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::SURFACE) {
|
2013-07-17 16:12:22 +04:00
|
|
|
const SurfacePattern *pat =
|
|
|
|
static_cast<const SurfacePattern*>(&aPattern);
|
|
|
|
|
|
|
|
if (!pat->mSurface) {
|
|
|
|
gfxDebug() << "No source surface specified for surface pattern";
|
2014-09-15 01:51:34 +04:00
|
|
|
return CreateTransparentBlackBrush();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 09:18:22 +04:00
|
|
|
D2D1_RECT_F samplingBounds;
|
2014-10-01 21:50:24 +04:00
|
|
|
Matrix mat = pat->mMatrix;
|
2014-10-30 01:40:38 +03:00
|
|
|
|
2015-01-28 03:54:19 +03:00
|
|
|
MOZ_ASSERT(pat->mSurface->IsValid());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(pat->mSurface, mat, pat->mExtendMode, !pat->mSamplingRect.IsEmpty() ? &pat->mSamplingRect : nullptr);
|
2014-11-20 23:48:01 +03:00
|
|
|
|
2016-03-18 16:47:11 +03:00
|
|
|
if (pat->mSurface->GetFormat() == SurfaceFormat::A8) {
|
|
|
|
// See bug 1251431, at least FillOpacityMask does not appear to allow a source bitmapbrush
|
|
|
|
// with source format A8. This creates a BGRA surface with the same alpha values that
|
|
|
|
// the A8 surface has.
|
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2017-05-31 01:59:19 +03:00
|
|
|
HRESULT hr = image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
|
|
if (SUCCEEDED(hr) && bitmap) {
|
2016-03-18 16:47:11 +03:00
|
|
|
RefPtr<ID2D1Image> oldTarget;
|
|
|
|
RefPtr<ID2D1Bitmap1> tmpBitmap;
|
|
|
|
mDC->CreateBitmap(D2D1::SizeU(pat->mSurface->GetSize().width, pat->mSurface->GetSize().height), nullptr, 0,
|
2016-03-21 15:16:29 +03:00
|
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)),
|
2016-03-18 16:47:11 +03:00
|
|
|
getter_AddRefs(tmpBitmap));
|
|
|
|
mDC->GetTarget(getter_AddRefs(oldTarget));
|
|
|
|
mDC->SetTarget(tmpBitmap);
|
|
|
|
|
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
|
|
|
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), getter_AddRefs(brush));
|
|
|
|
mDC->FillOpacityMask(bitmap, brush);
|
|
|
|
mDC->SetTarget(oldTarget);
|
|
|
|
image = tmpBitmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 23:48:01 +03:00
|
|
|
if (!image) {
|
|
|
|
return CreateTransparentBlackBrush();
|
|
|
|
}
|
|
|
|
|
2015-06-13 00:28:25 +03:00
|
|
|
if (pat->mSamplingRect.IsEmpty()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2017-05-31 01:59:19 +03:00
|
|
|
HRESULT hr = image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
|
|
if (SUCCEEDED(hr) && bitmap) {
|
2015-11-23 19:17:35 +03:00
|
|
|
/**
|
|
|
|
* Create the brush with the proper repeat modes.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1BitmapBrush> bitmapBrush;
|
2015-11-23 19:17:35 +03:00
|
|
|
D2D1_EXTEND_MODE xRepeat = D2DExtend(pat->mExtendMode, Axis::X_AXIS);
|
|
|
|
D2D1_EXTEND_MODE yRepeat = D2DExtend(pat->mExtendMode, Axis::Y_AXIS);
|
|
|
|
|
2015-06-13 00:28:25 +03:00
|
|
|
mDC->CreateBitmapBrush(bitmap,
|
2015-11-23 19:17:35 +03:00
|
|
|
D2D1::BitmapBrushProperties(xRepeat, yRepeat,
|
2016-05-25 19:01:18 +03:00
|
|
|
D2DFilter(pat->mSamplingFilter)),
|
2015-06-13 00:28:25 +03:00
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(bitmapBrush));
|
2015-06-13 00:28:25 +03:00
|
|
|
if (!bitmapBrush) {
|
|
|
|
gfxWarning() << "Couldn't create bitmap brush!";
|
|
|
|
return CreateTransparentBlackBrush();
|
|
|
|
}
|
|
|
|
return bitmapBrush.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1ImageBrush> imageBrush;
|
2015-06-13 00:28:25 +03:00
|
|
|
if (pat->mSamplingRect.IsEmpty()) {
|
|
|
|
samplingBounds = D2D1::RectF(0, 0,
|
|
|
|
Float(pat->mSurface->GetSize().width),
|
|
|
|
Float(pat->mSurface->GetSize().height));
|
|
|
|
} else if (pat->mSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
|
|
|
|
samplingBounds = D2DRect(pat->mSamplingRect);
|
2017-12-19 23:48:39 +03:00
|
|
|
mat.PreTranslate(pat->mSamplingRect.X(), pat->mSamplingRect.Y());
|
2015-06-13 00:28:25 +03:00
|
|
|
} else {
|
|
|
|
// We will do a partial upload of the sampling restricted area from GetImageForSurface.
|
2017-08-14 15:29:28 +03:00
|
|
|
samplingBounds = D2D1::RectF(0, 0, pat->mSamplingRect.Width(), pat->mSamplingRect.Height());
|
2015-06-13 00:28:25 +03:00
|
|
|
}
|
2015-11-23 19:17:35 +03:00
|
|
|
|
|
|
|
D2D1_EXTEND_MODE xRepeat = D2DExtend(pat->mExtendMode, Axis::X_AXIS);
|
|
|
|
D2D1_EXTEND_MODE yRepeat = D2DExtend(pat->mExtendMode, Axis::Y_AXIS);
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
mDC->CreateImageBrush(image,
|
2014-09-12 09:18:22 +04:00
|
|
|
D2D1::ImageBrushProperties(samplingBounds,
|
2015-11-23 19:17:35 +03:00
|
|
|
xRepeat,
|
|
|
|
yRepeat,
|
2016-05-25 19:01:18 +03:00
|
|
|
D2DInterpolationMode(pat->mSamplingFilter)),
|
2013-07-17 16:12:22 +04:00
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(imageBrush));
|
2015-05-07 03:38:10 +03:00
|
|
|
|
|
|
|
if (!imageBrush) {
|
|
|
|
gfxWarning() << "Couldn't create image brush!";
|
|
|
|
return CreateTransparentBlackBrush();
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return imageBrush.forget();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxWarning() << "Invalid pattern type detected.";
|
2014-09-15 01:51:34 +04:00
|
|
|
return CreateTransparentBlackBrush();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ID2D1Image>
|
2013-07-17 16:12:22 +04:00
|
|
|
DrawTargetD2D1::GetImageForSurface(SourceSurface *aSurface, Matrix &aSourceTransform,
|
2017-03-15 05:17:47 +03:00
|
|
|
ExtendMode aExtendMode, const IntRect* aSourceRect,
|
|
|
|
bool aUserSpace)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Image> image;
|
2013-07-17 16:12:22 +04:00
|
|
|
switch (aSurface->GetType()) {
|
2017-10-31 22:02:31 +03:00
|
|
|
case SurfaceType::CAPTURE:
|
|
|
|
{
|
|
|
|
SourceSurfaceCapture* capture = static_cast<SourceSurfaceCapture*>(aSurface);
|
|
|
|
RefPtr<SourceSurface> resolved = capture->Resolve(GetBackendType());
|
|
|
|
if (!resolved) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(resolved->GetType() != SurfaceType::CAPTURE);
|
|
|
|
return GetImageForSurface(resolved, aSourceTransform, aExtendMode, aSourceRect, aUserSpace);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 22:55:24 +04:00
|
|
|
case SurfaceType::D2D1_1_IMAGE:
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
SourceSurfaceD2D1 *surf = static_cast<SourceSurfaceD2D1*>(aSurface);
|
|
|
|
image = surf->GetImage();
|
|
|
|
AddDependencyOnSource(surf);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-17 18:41:42 +03:00
|
|
|
case SurfaceType::DUAL_DT:
|
|
|
|
{
|
|
|
|
// Sometimes we have a dual drawtarget but the underlying targets
|
|
|
|
// are d2d surfaces. Let's not readback and reupload in those cases.
|
|
|
|
SourceSurfaceDual* surface = static_cast<SourceSurfaceDual*>(aSurface);
|
|
|
|
SourceSurface* first = surface->GetFirstSurface();
|
|
|
|
if (first->GetType() == SurfaceType::D2D1_1_IMAGE) {
|
|
|
|
MOZ_ASSERT(surface->SameSurfaceTypes());
|
|
|
|
SourceSurfaceD2D1* d2dSurface = static_cast<SourceSurfaceD2D1*>(first);
|
|
|
|
image = d2dSurface->GetImage();
|
|
|
|
AddDependencyOnSource(d2dSurface);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Otherwise fall through
|
|
|
|
}
|
2013-07-17 16:12:22 +04:00
|
|
|
default:
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> dataSurf = aSurface->GetDataSurface();
|
2013-07-17 16:12:22 +04:00
|
|
|
if (!dataSurf) {
|
|
|
|
gfxWarning() << "Invalid surface type.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-03-15 05:17:47 +03:00
|
|
|
Matrix transform = aUserSpace ? mTransform : Matrix();
|
|
|
|
return CreatePartialBitmapForSurface(dataSurf, transform, mSize, aExtendMode,
|
2014-10-30 01:40:38 +03:00
|
|
|
aSourceTransform, mDC, aSourceRect);
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return image.forget();
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2014-04-17 04:45:25 +04:00
|
|
|
DrawTargetD2D1::OptimizeSourceSurface(SourceSurface* aSurface) const
|
|
|
|
{
|
|
|
|
if (aSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
2015-04-30 22:20:30 +03:00
|
|
|
return surface.forget();
|
2014-04-17 04:45:25 +04:00
|
|
|
}
|
|
|
|
|
2017-10-31 22:02:31 +03:00
|
|
|
// Special case captures so we don't resolve them to a data surface.
|
|
|
|
if (aSurface->GetType() == SurfaceType::CAPTURE) {
|
|
|
|
SourceSurfaceCapture* capture = static_cast<SourceSurfaceCapture*>(aSurface);
|
|
|
|
RefPtr<SourceSurface> resolved = capture->Resolve(GetBackendType());
|
|
|
|
if (!resolved) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(resolved->GetType() != SurfaceType::CAPTURE);
|
|
|
|
return OptimizeSourceSurface(resolved);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
|
2014-04-17 04:45:25 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID2D1Bitmap1> bitmap;
|
2015-06-10 14:01:00 +03:00
|
|
|
{
|
|
|
|
DataSourceSurface::ScopedMap map(data, DataSourceSurface::READ);
|
|
|
|
if (MOZ2D_WARN_IF(!map.IsMapped())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-17 04:45:25 +04:00
|
|
|
|
2015-06-10 14:01:00 +03:00
|
|
|
HRESULT hr = mDC->CreateBitmap(D2DIntSize(data->GetSize()), map.GetData(), map.GetStride(),
|
|
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(data->GetFormat())),
|
2015-10-18 07:40:10 +03:00
|
|
|
getter_AddRefs(bitmap));
|
2014-09-18 01:23:09 +04:00
|
|
|
|
2015-06-10 14:01:00 +03:00
|
|
|
if (FAILED(hr)) {
|
2015-07-14 22:22:29 +03:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(data->GetSize()))) << "[D2D1.1] 4CreateBitmap failure " << data->GetSize() << " Code: " << hexa(hr) << " format " << (int)data->GetFormat();
|
2015-06-10 14:01:00 +03:00
|
|
|
}
|
|
|
|
}
|
2014-04-17 04:45:25 +04:00
|
|
|
|
|
|
|
if (!bitmap) {
|
2014-06-13 20:09:23 +04:00
|
|
|
return data.forget();
|
2014-04-17 04:45:25 +04:00
|
|
|
}
|
|
|
|
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, data->GetFormat(), data->GetSize());
|
2014-04-17 04:45:25 +04:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
void
|
2015-05-29 15:49:19 +03:00
|
|
|
DrawTargetD2D1::PushD2DLayer(ID2D1DeviceContext *aDC, ID2D1Geometry *aGeometry, const D2D1_MATRIX_3X2_F &aTransform,
|
2016-09-22 00:03:20 +03:00
|
|
|
bool aPixelAligned, bool aForceIgnoreAlpha, const D2D1_RECT_F& aMaxRect)
|
2013-07-17 16:12:22 +04:00
|
|
|
{
|
|
|
|
D2D1_LAYER_OPTIONS1 options = D2D1_LAYER_OPTIONS1_NONE;
|
|
|
|
|
2016-03-20 21:51:46 +03:00
|
|
|
if (CurrentLayer().mIsOpaque || aForceIgnoreAlpha) {
|
2013-07-17 16:12:22 +04:00
|
|
|
options = D2D1_LAYER_OPTIONS1_IGNORE_ALPHA | D2D1_LAYER_OPTIONS1_INITIALIZE_FROM_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
D2D1_ANTIALIAS_MODE antialias =
|
|
|
|
aPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE;
|
|
|
|
|
|
|
|
mDC->PushLayer(D2D1::LayerParameters1(aMaxRect, aGeometry, antialias, aTransform,
|
2013-07-17 16:12:22 +04:00
|
|
|
1.0, nullptr, options), nullptr);
|
|
|
|
}
|
|
|
|
|
2017-05-10 11:22:08 +03:00
|
|
|
bool
|
|
|
|
DrawTargetD2D1::IsDeviceContextValid() {
|
2017-07-18 22:15:44 +03:00
|
|
|
uint32_t seqNo;
|
|
|
|
return Factory::GetD2D1Device(&seqNo) && seqNo == mDeviceSeq;
|
2017-05-10 11:22:08 +03:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:12:22 +04:00
|
|
|
}
|
|
|
|
}
|