mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
b0cbe263c6
- Bug 1238964 Part 1: Hold new printable page sizes in print nsIPrintSettingsWin. r=jimm (b5e4d012ba) - Bug 1238964 Part 2: Move separate DEVMODE to nsIPrintSettings copying into nsPrintSettingsWin. r=jimm (cb7bb66037) - Bug 1218029 - Adds SRICheckDataVerifier for progressing data handling. r=francois (8331afc1a7) - Bug 1218029 - Implements progressive Unicode chars decoding in nsScriptLoader. r=djvj (2c32ca259a) - Bug 1237201 part 1 - Use MOZ_ALWAYS_TRUE in nsScriptLoadHandler::TryDecodeRawData. r=yury (8f7496be23) - Bug 1237201 part 2 - Handle Vector OOM in gfx/. r=jrmuizel,kats (d5e8bd3383) - Bug 1237201 part 3 - Handle Vector OOM in StreamingLexer. r=njn (be383e35b4) - Bug 1237201 part 4 - Handle Vector OOM in ipc/. r=billm (fe9a3bf25a) - Bug 1237201 part 5 - Ignore Vector OOM in JSMainRuntimeCompartmentsReporter. r=njn (d0070c0636) - Bug 1237201 part 6 - Handle Vector OOM in media/webrtc/. r=jesup (eab4e00735) - Bug 1186491 - Splitting nsIPerformanceStats in two;r=froydnj (006b578345) - Bug 1186491 - An API for watching slow performance alerts (xpcom-level);r=froydnj (4fcefd66f5) - Bug 1237201 part 7 - Handle Vector OOM in nsPerformanceStats, telemetry. r=Yoric (6021b583ff) - Bug 1237201 part 8 - Make fallible Vector methods MOZ_WARN_UNUSED_RESULT. r=jwalden (90144c2d35) - Bug 1237201 part 9 - Fix remaining issues. r=nfroyd (25b86adb6d) - Bug 1186491 - An API for watching slow performance alerts (js-level); r=felipe (f04d277c80) - Bug 1200172 - AddonWatcher now discards data if the system is apparently too busy/just back from hibernation. r=mossop (66a3840b73) - Bug 1205840 - Typo fixes in AddonWatcher.jsm. r=felipe (760df6764c) - Bug 1186491 - Reworking AddonWatcher to use low-level performance watch API;r=mossop (81cc64263e) - Bug 1200169 - Making the slow add-on watcher more tolerant;r=Felipe (fcf988d985) - Bug 1157009 - Redesign about:performance. r=felipe (cacc590716) - Bug 1189513 - Get rid of separation between e10s and non-e10s probes; r=felipe (7a6d996c93) - Bug 1191327 - Recapitulates alerts in about:performance now. r=felipe (53ecc02da9) - Bug 1189799 - Make sure that about:performance displays each add-on only once (front-end);r=felipe (1ee53a0410) - Bug 1208747 - Move most of Stopwatch-related code to XPCOM-land (JS-level);r=felipe (84af14c20e) - Bug 1229519: Fix miscellaneous parts of toolkit to pass eslint checks. r=MattN (00ce3585c5) - Bug 1230735 - AddonWatcher.alerts is now a map;r=Felipe (81bbafbbd4) - Bug 1241838 - Removing erroneous CPOW suffix, reworking buggy jank suffix;r=Felipe (020d6928e6) - Bug 1175098 - Fix double-loading of PerformanceStats content script. r=mconley (fb1c499343) - Bug 1189799 - Make sure that about:performance displays each add-on only once (back-end);r=felipe (1eac8258df) - Bug 1221761 - Probe.prototype.release() now swallows NS_ERROR_NOT_AVAILABLE. r=felipe (ba1d0032a9) - Bug 1142937 - AddonWatcher now communicates through nsIObserverService. r=felipe (ea2e7ccdaa) - Bug 967873 - Test changes for async removeTab (r=Gijs) (dae5cbf835) - more missing parts of Bug 1132072 - Tab switch refactoring (r=mconley) (dc5e310537) - Bug 1191460 Rebased patch and added userContextId to origin attributes. (r=tanvi,r=sicking) (723999e7fa) - Bug 1239040 - Cleanup of DrawTargetSkia GetBitmapForSurface to use installPixels. r=jrmuizel (4016f4d734) - Bug 1239040 - Cleanup of DrawTargetSkia Mask and MaskSurface. r=jrmuizel (908a44d47e) - Bug 1239040 - Implement PushLayer for DrawTargetSkia. r=Bas (ae74697559) - Bug 1246756 - part 1 - fix moz2d Skia usage for Skia m49 update. r=jrmuizel (5e4b0f41e3) - Bug 1239040 - Allow usage of SkCanvas::getTopDevice in Skia. r=jrmuizel (19bdd2cecb) - Bug 1239040 - Fix DrawTargetCairo/DrawTargetSkia LockBits and BorrowedXlibDrawable to work inside PushLayer. r=jrmuizel (b9ba04009b) - Bug 1239040 - Cleanup of DrawTargetSkia CopySurface to avoid accessing bottom layer directly. r=jrmuizel (6690702507) - Bug 1240437: Implement PushLayer and PopLayer for DrawTargetRecording. r=bas (22673a1b52) - Bug 1220629 - Part 1: Add PushLayer/PopLayer API to DrawTarget baseclass. r=jrmuizel (c4b4315749) - Bug 1220629 - Part 2: Prepare DrawTargetD2D1 for the possibilities of layers existing inside it. r=jrmuizel (f2a74151a8) - Bug 1220629 - Part 3: Implement PushLayer/PopLayer API in cairo. r=jrmuizel (9a52965141) - Bug 1220629 - Part 4: Allow gfxContext to use the native pushlayer implementations based on a pref. r=jrmuizel (f13b773ff3) - Bug 1220629 - Part 5: Implement PushLayer/PopLayer API for Direct2D 1.1. r=jrmuizel (8a040648a2) - Bug 1220629 - Part 6: Implement PushLayer/PopLayer API in several wrapper DT types. r=jrmuizel (cf76723216) - Bug 1220629 - Part 7: Mark several reftests fuzzy. r=jrmuizel (a6deab2300) - Bug 1220629 - Part 8: Enable native PushLayer/PopLayer by default on Windows and Linux. r=jrmuizel (eef18e1e3e) - Bug 1234494 - part 1 - don't build in Skia GPU code if support is disabled, r=jrmuizel (4c74813077) - Bug 1234494 - part 2 - disable Skia GPU support by default on certain *BSDs, r=glandium (6184133b33) - Bug 1246756 - part 2 - update Skia moz.build for m49 update. r=jrmuizel (e0cf4ab953) - Bug 1244454 - Fixed skia compilation on mingw. r=lsalzman (064a56e56e) - Bug 1242044 - "layout/reftests/css-gradients/linear-zero-length-1 fails under Skia content". r=jmuizelaar (bee8f76e72) - Bug 1242751 - fix assertion in SkLinearGradient. r=jmuizelaar (f5df5ed88f) - Bug 1238795 - Fix SkGpuDevice::drawBitmapRect to always update clips. r=jrmuizel (05a9a6b10a) - Bug 1230096 - fix GrAAConvexTessellator assertion. r=jrmuizel (18aef9bdcc) - Bug 1237983 - Investigate and remove the Bagheera Client Implementation. r=gfritzsche (6de39c0e32) - Bug 1246756 - part 3 - update Skia to m49 branch. r=jrmuizel (a02a53e368) - Bug 1234526 - Remove services/healthreport. r=gfritzsche (bb0c567255) - Bug 1234522 - Remove services/datareporting. r=gfritzsche (c7bfec7784) - Bug 1211166 - Use AppConstants in SessionRecorder.jsm r=ted (4434996c34) - Bug 1246756 - Cross compilation fixup. r=upstream (99e3e40ba1) - Bug 1248228 - Build fix for SkOSFile_stdio on OpenBSD. r=jmuizelaar (bbb1eb7ac0) - Bug 1250196 - Part 1: Import mozilla::Forward and mozilla::UniqePtr into the std namespace in a way that is compatible with libc++; r=lsalzman (ffeebcc133) - Bug 1248851 part 4 - Mark UniquePtr::release() MOZ_WARN_UNUSED_RESULT. r=Waldo (f43cced74c) - Bug 1250196 - Part 2: Rename UniquePtr::getDeleter() to get_deleter() in order to make it compatible with std::unique_ptr; r=froydnj (f8aeabfc9a) - Bug 1248851 part 3 - Fix a potential double-free issue in indexedDB. r=sicking (4d13f5047b) - Bug 1248851 part 2 - Remove redundant release() calls in indexedDB code. r=sicking (86d67ffad8) - Bug 1239702 - Fix SK_ARM_HAS_NEON build config r=lsalzman (4233a57122) - Bug 1245979 - make mfbt Function reference-counted so that it can be cheaply copied for compatibility with Skia. r=froydnj (bd69e9c07b) - Bug 1245055 - Remove gfx/skia/Makefile.in. r=mshal (bf2c611f38) - Bug 1232694 - fix typo in Compiler.h; r=botond (2b5abb9d2d) - Bug 1228641 - Rename begin/size to aBegin/aSize to avoid shadow warnings; r=botond (9222809505) - Bug 1248784 - Rename the existing AddRefTraits to ConstRemovingRefPtrTraits. r=froydnj (99d7b0ae1f) - Bug 1248784 - Extract the AddRef/Release calls into a non-inner helper trait. r=froydnj (37243b6235) - Bug 1248784 - Followup to add requested comment. r=froydnj DONTBUILD (0e870b586b) - Bug 1242794 - make SkGrPixelRef::deepCopy preserve alpha type. r=jmuizelaar (0fb454c326) - Bug 1201037 - (Linux) squash network-change events during 1000ms, r=mcmanus (087f57c44d) - Bug 1235509 - Link monitor should not fire link change events for the refresh of the ipv6 lifetime. r=bagder (c507a319c4) - Bug 1234548 - Don't send network change events if routes are changed. r=mcmanus, r=bagder (5cd0bc582e) - Bug 1234548 - Remove unused variables. r=bustage (42df135fbf) - Bug 1240515 - change allocator for addr and localaddr from malloc to new, since the smart pointer that is used uses delete operator. r=dragana (02f5d5433c) - Bug 1241901 part 1 - Remove nsAutoPtr uses in nsNotifyAddrListener on Linux. r=bagder (f8696ad190) - Bug 1241901 part 2 - Use intptr_t to pass bluetooth service class instead of a pointer to heap. r=shawnjohnjr (5c86a164fa) - Bug 1241901 part 3 - Add IsMemberPointer and IsScalar type traits. r=froydnj (80747268bd) - Bug 1243876 - fix ConvertibleTester to not cause incomplete type errors with UniquePtr and Skia. r=nfroyd (c5588dd270) - Bug 1234736 - IonMonkey: Recover Math.imul as an int32 operation. r=h4writer (459b92c618) - Bug 1228571 - Fix GenerateSeed to not leave seed uninitialized if reading from /dev/urandom fails. r=cpeterson (3be0a2816b) - Bug 1233302: Don't crash if we can't open /dev/urandom; just fall back to PRMJ_Now. (d83ae5540a) - Bug 1167248 - Call RtlGenRandom() instead of rand_s() to workaround crashes from injected third-party hooks. r=jandem (678e7a0056) - Bug 1236619 Fix compilation failure with warnings-as-errors with some compilers. r=njn (043956881d) - Bug 1167248 - Cross compilation fixup. (f4a34fb229)
1694 lines
53 KiB
C++
1694 lines
53 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
#include <initguid.h>
|
|
#include "DrawTargetD2D1.h"
|
|
#include "DrawTargetD2D.h"
|
|
#include "FilterNodeSoftware.h"
|
|
#include "GradientStopsD2D.h"
|
|
#include "SourceSurfaceD2D1.h"
|
|
#include "SourceSurfaceD2D.h"
|
|
#include "RadialGradientEffectD2D1.h"
|
|
|
|
#include "HelpersD2D.h"
|
|
#include "FilterNodeD2D1.h"
|
|
#include "Tools.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace mozilla {
|
|
namespace gfx {
|
|
|
|
uint64_t DrawTargetD2D1::mVRAMUsageDT;
|
|
uint64_t DrawTargetD2D1::mVRAMUsageSS;
|
|
ID2D1Factory1* DrawTargetD2D1::mFactory = nullptr;
|
|
|
|
ID2D1Factory1 *D2DFactory1()
|
|
{
|
|
return DrawTargetD2D1::factory();
|
|
}
|
|
|
|
DrawTargetD2D1::DrawTargetD2D1()
|
|
: mPushedLayers(1)
|
|
{
|
|
}
|
|
|
|
DrawTargetD2D1::~DrawTargetD2D1()
|
|
{
|
|
PopAllClips();
|
|
|
|
if (mSnapshot) {
|
|
// 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.
|
|
RefPtr<SourceSurfaceD2D1> deathGrip = mSnapshot;
|
|
// 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.
|
|
}
|
|
|
|
if (mDC) {
|
|
// 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();
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
DrawTargetD2D1::Snapshot()
|
|
{
|
|
if (mSnapshot) {
|
|
RefPtr<SourceSurface> snapshot(mSnapshot);
|
|
return snapshot.forget();
|
|
}
|
|
PopAllClips();
|
|
|
|
mDC->Flush();
|
|
|
|
mSnapshot = new SourceSurfaceD2D1(mBitmap, mDC, mFormat, mSize, this);
|
|
|
|
RefPtr<SourceSurface> snapshot(mSnapshot);
|
|
return snapshot.forget();
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::Flush()
|
|
{
|
|
mDC->Flush();
|
|
|
|
// We no longer depend on any target.
|
|
for (TargetSet::iterator iter = mDependingOnTargets.begin();
|
|
iter != mDependingOnTargets.end(); iter++) {
|
|
(*iter)->mDependentTargets.erase(this);
|
|
}
|
|
mDependingOnTargets.clear();
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::DrawSurface(SourceSurface *aSurface,
|
|
const Rect &aDest,
|
|
const Rect &aSource,
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
D2D1_RECT_F samplingBounds;
|
|
|
|
if (aSurfOptions.mSamplingBounds == SamplingBounds::BOUNDED) {
|
|
samplingBounds = D2DRect(aSource);
|
|
} else {
|
|
samplingBounds = D2D1::RectF(0, 0, Float(aSurface->GetSize().width), Float(aSurface->GetSize().height));
|
|
}
|
|
|
|
Float xScale = aDest.width / aSource.width;
|
|
Float yScale = aDest.height / aSource.height;
|
|
|
|
RefPtr<ID2D1ImageBrush> brush;
|
|
|
|
// Here we scale the source pattern up to the size and position where we want
|
|
// it to be.
|
|
Matrix transform;
|
|
transform.PreTranslate(aDest.x - aSource.x * xScale, aDest.y - aSource.y * yScale);
|
|
transform.PreScale(xScale, yScale);
|
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, transform, ExtendMode::CLAMP);
|
|
|
|
if (!image) {
|
|
gfxWarning() << *this << ": Unable to get D2D image for surface.";
|
|
return;
|
|
}
|
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
|
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.
|
|
image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
}
|
|
|
|
if (bitmap && aSurfOptions.mSamplingBounds == SamplingBounds::UNBOUNDED) {
|
|
mDC->DrawBitmap(bitmap, D2DRect(aDest), aOptions.mAlpha, D2DFilter(aSurfOptions.mFilter), D2DRect(aSource));
|
|
} else {
|
|
// This has issues ignoring the alpha channel on windows 7 with images marked opaque.
|
|
MOZ_ASSERT(aSurface->GetFormat() != SurfaceFormat::B8G8R8X8);
|
|
mDC->CreateImageBrush(image,
|
|
D2D1::ImageBrushProperties(samplingBounds,
|
|
D2D1_EXTEND_MODE_CLAMP,
|
|
D2D1_EXTEND_MODE_CLAMP,
|
|
D2DInterpolationMode(aSurfOptions.mFilter)),
|
|
D2D1::BrushProperties(aOptions.mAlpha, D2DMatrix(transform)),
|
|
getter_AddRefs(brush));
|
|
mDC->FillRectangle(D2DRect(aDest), brush);
|
|
}
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::DrawFilter(FilterNode *aNode,
|
|
const Rect &aSourceRect,
|
|
const Point &aDestPoint,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
if (aNode->GetBackendType() != FILTER_BACKEND_DIRECT2D1_1) {
|
|
gfxWarning() << *this << ": Incompatible filter passed to DrawFilter.";
|
|
return;
|
|
}
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
FilterNodeD2D1* node = static_cast<FilterNodeD2D1*>(aNode);
|
|
node->WillDraw(this);
|
|
|
|
mDC->DrawImage(node->OutputEffect(), D2DPoint(aDestPoint), D2DRect(aSourceRect));
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
}
|
|
|
|
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;
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP);
|
|
|
|
if (!image) {
|
|
gfxWarning() << "Couldn't get image for surface.";
|
|
return;
|
|
}
|
|
|
|
if (!mat.IsIdentity()) {
|
|
gfxDebug() << *this << ": At this point complex partial uploads are not supported for Shadow surfaces.";
|
|
return;
|
|
}
|
|
|
|
// Step 1, create the shadow effect.
|
|
RefPtr<ID2D1Effect> shadowEffect;
|
|
HRESULT hr = mDC->CreateEffect(CLSID_D2D1Shadow, getter_AddRefs(shadowEffect));
|
|
if (FAILED(hr) || !shadowEffect) {
|
|
gfxWarning() << "Failed to create shadow effect. Code: " << hexa(hr);
|
|
return;
|
|
}
|
|
shadowEffect->SetInput(0, image);
|
|
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);
|
|
|
|
D2D1_POINT_2F shadowPoint = D2DPoint(aDest + aOffset);
|
|
mDC->DrawImage(shadowEffect, &shadowPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
|
|
|
|
D2D1_POINT_2F imgPoint = D2DPoint(aDest);
|
|
mDC->DrawImage(image, &imgPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::ClearRect(const Rect &aRect)
|
|
{
|
|
MarkChanged();
|
|
|
|
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;
|
|
}
|
|
|
|
RefPtr<ID2D1CommandList> list;
|
|
mDC->CreateCommandList(getter_AddRefs(list));
|
|
mDC->SetTarget(list);
|
|
|
|
IntRect addClipRect;
|
|
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(&addClipRect);
|
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
|
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), getter_AddRefs(brush));
|
|
mDC->PushAxisAlignedClip(D2D1::RectF(addClipRect.x, addClipRect.y, addClipRect.XMost(), addClipRect.YMost()), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
mDC->FillGeometry(geom, brush);
|
|
mDC->PopAxisAlignedClip();
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
list->Close();
|
|
|
|
mDC->DrawImage(list, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_DESTINATION_OUT);
|
|
|
|
PopClip();
|
|
|
|
return;
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::MaskSurface(const Pattern &aSource,
|
|
SourceSurface *aMask,
|
|
Point aOffset,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
MarkChanged();
|
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
|
|
|
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;
|
|
|
|
if (!image) {
|
|
gfxWarning() << "Failed to get image for surface.";
|
|
return;
|
|
}
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
// FillOpacityMask only works if the antialias mode is MODE_ALIASED
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
|
|
|
image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
if (!bitmap) {
|
|
gfxWarning() << "FillOpacityMask only works with Bitmap source surfaces.";
|
|
return;
|
|
}
|
|
|
|
IntSize size = IntSize(bitmap->GetSize().width, bitmap->GetSize().height);
|
|
|
|
Rect maskRect = Rect(0.f, 0.f, Float(size.width), Float(size.height));
|
|
|
|
Rect dest = Rect(aOffset.x, aOffset.y, Float(size.width), Float(size.height));
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
|
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();
|
|
|
|
PopAllClips();
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
Matrix mat;
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP);
|
|
|
|
if (!image) {
|
|
gfxWarning() << "Couldn't get image for surface.";
|
|
return;
|
|
}
|
|
|
|
if (!mat.IsIdentity()) {
|
|
gfxDebug() << *this << ": At this point complex partial uploads are not supported for CopySurface.";
|
|
return;
|
|
}
|
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
|
image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
|
|
if (bitmap && mFormat == SurfaceFormat::A8) {
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
|
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),
|
|
D2D1::BrushProperties(), getter_AddRefs(brush));
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_COPY);
|
|
mDC->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
|
|
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
|
return;
|
|
}
|
|
|
|
Rect srcRect(Float(aSourceRect.x), Float(aSourceRect.y),
|
|
Float(aSourceRect.width), Float(aSourceRect.height));
|
|
|
|
Rect dstRect(Float(aDestination.x), Float(aDestination.y),
|
|
Float(aSourceRect.width), Float(aSourceRect.height));
|
|
|
|
if (bitmap) {
|
|
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);
|
|
return;
|
|
}
|
|
|
|
mDC->DrawImage(image, D2D1::Point2F(Float(aDestination.x), Float(aDestination.y)),
|
|
D2DRect(srcRect), D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
|
|
D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::FillRect(const Rect &aRect,
|
|
const Pattern &aPattern,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
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);
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
|
|
|
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);
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
|
|
|
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)
|
|
{
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
return;
|
|
}
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
|
|
|
mDC->DrawGeometry(d2dPath->mGeometry, brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::Fill(const Path *aPath,
|
|
const Pattern &aPattern,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
return;
|
|
}
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
|
|
mDC->FillGeometry(d2dPath->mGeometry, brush);
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::FillGlyphs(ScaledFont *aFont,
|
|
const GlyphBuffer &aBuffer,
|
|
const Pattern &aPattern,
|
|
const DrawOptions &aOptions,
|
|
const GlyphRenderingOptions *aRenderingOptions)
|
|
{
|
|
if (aFont->GetType() != FontType::DWRITE) {
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible font.";
|
|
return;
|
|
}
|
|
|
|
ScaledFontDWrite *font = static_cast<ScaledFontDWrite*>(aFont);
|
|
|
|
IDWriteRenderingParams *params = nullptr;
|
|
if (aRenderingOptions) {
|
|
if (aRenderingOptions->GetType() != FontType::DWRITE) {
|
|
gfxDebug() << *this << ": Ignoring incompatible GlyphRenderingOptions.";
|
|
// This should never happen.
|
|
MOZ_ASSERT(false);
|
|
} else {
|
|
params = static_cast<const GlyphRenderingOptionsDWrite*>(aRenderingOptions)->mParams;
|
|
}
|
|
}
|
|
|
|
AntialiasMode aaMode = font->GetDefaultAAMode();
|
|
|
|
if (aOptions.mAntialiasMode != AntialiasMode::DEFAULT) {
|
|
aaMode = aOptions.mAntialiasMode;
|
|
}
|
|
|
|
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
|
|
|
|
bool forceClearType = false;
|
|
if (!CurrentLayer().mIsOpaque && mPermitSubpixelAA &&
|
|
aOptions.mCompositionOp == CompositionOp::OP_OVER && aaMode == AntialiasMode::SUBPIXEL) {
|
|
forceClearType = true;
|
|
}
|
|
|
|
|
|
D2D1_TEXT_ANTIALIAS_MODE d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
|
|
switch (aaMode) {
|
|
case AntialiasMode::NONE:
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
|
|
break;
|
|
case AntialiasMode::GRAY:
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
break;
|
|
case AntialiasMode::SUBPIXEL:
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
|
break;
|
|
default:
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
}
|
|
|
|
if (d2dAAMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE &&
|
|
!CurrentLayer().mIsOpaque && !forceClearType) {
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
}
|
|
|
|
mDC->SetTextAntialiasMode(d2dAAMode);
|
|
|
|
if (params != mTextRenderingParams) {
|
|
mDC->SetTextRenderingParams(params);
|
|
mTextRenderingParams = params;
|
|
}
|
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
|
|
|
AutoDWriteGlyphRun autoRun;
|
|
DWriteGlyphRunFromGlyphs(aBuffer, font, &autoRun);
|
|
|
|
bool needsRepushedLayers = false;
|
|
if (forceClearType) {
|
|
D2D1_RECT_F rect;
|
|
bool isAligned;
|
|
needsRepushedLayers = CurrentLayer().mPushedClips.size() && !GetDeviceSpaceClipRect(rect, isAligned);
|
|
|
|
// 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);
|
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
|
D2DFactory()->CreatePathGeometry(getter_AddRefs(path));
|
|
RefPtr<ID2D1GeometrySink> sink;
|
|
path->Open(getter_AddRefs(sink));
|
|
AddRectToSink(sink, userRect);
|
|
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));
|
|
}
|
|
}
|
|
|
|
if (brush) {
|
|
mDC->DrawGlyphRun(D2D1::Point2F(), &autoRun, brush);
|
|
}
|
|
|
|
if (needsRepushedLayers) {
|
|
PopClipsFromDC(mDC);
|
|
|
|
if (!mTransform.IsRectilinear()) {
|
|
mDC->PopLayer();
|
|
}
|
|
}
|
|
|
|
FinalizeDrawing(aOptions.mCompositionOp, aPattern);
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::Mask(const Pattern &aSource,
|
|
const Pattern &aMask,
|
|
const DrawOptions &aOptions)
|
|
{
|
|
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
|
|
|
RefPtr<ID2D1Brush> source = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
|
RefPtr<ID2D1Brush> mask = CreateBrushForPattern(aMask, 1.0f);
|
|
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
|
|
DrawTargetD2D1::PushClip(const Path *aPath)
|
|
{
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D1_1) {
|
|
gfxDebug() << *this << ": Ignoring clipping call for incompatible path.";
|
|
return;
|
|
}
|
|
|
|
mCurrentClippedGeometry = nullptr;
|
|
|
|
RefPtr<PathD2D> pathD2D = static_cast<PathD2D*>(const_cast<Path*>(aPath));
|
|
|
|
PushedClip clip;
|
|
clip.mTransform = D2DMatrix(mTransform);
|
|
clip.mPath = pathD2D;
|
|
|
|
pathD2D->mGeometry->GetBounds(clip.mTransform, &clip.mBounds);
|
|
|
|
CurrentLayer().mPushedClips.push_back(clip);
|
|
|
|
// 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;
|
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
|
PushD2DLayer(mDC, pathD2D->mGeometry, clip.mTransform);
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
RefPtr<PathBuilder> pathBuilder = CreatePathBuilder();
|
|
pathBuilder->MoveTo(aRect.TopLeft());
|
|
pathBuilder->LineTo(aRect.TopRight());
|
|
pathBuilder->LineTo(aRect.BottomRight());
|
|
pathBuilder->LineTo(aRect.BottomLeft());
|
|
pathBuilder->Close();
|
|
RefPtr<Path> path = pathBuilder->Finish();
|
|
return PushClip(path);
|
|
}
|
|
|
|
mCurrentClippedGeometry = nullptr;
|
|
|
|
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);
|
|
|
|
CurrentLayer().mPushedClips.push_back(clip);
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
|
mDC->PushAxisAlignedClip(clip.mBounds, clip.mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PopClip()
|
|
{
|
|
mCurrentClippedGeometry = nullptr;
|
|
|
|
if (CurrentLayer().mClipsArePushed) {
|
|
if (CurrentLayer().mPushedClips.back().mPath) {
|
|
mDC->PopLayer();
|
|
} else {
|
|
mDC->PopAxisAlignedClip();
|
|
}
|
|
}
|
|
CurrentLayer().mPushedClips.pop_back();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
RefPtr<ID2D1BitmapBrush> mask;
|
|
|
|
Matrix maskTransform = aMaskTransform;
|
|
|
|
RefPtr<ID2D1PathGeometry> clip;
|
|
if (aMask) {
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(aMask, maskTransform, ExtendMode::CLAMP);
|
|
|
|
// The mask is given in user space. Our layer will apply it in device space.
|
|
maskTransform = maskTransform * mTransform;
|
|
|
|
if (image) {
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
|
image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
|
|
mDC->CreateBitmapBrush(bitmap, D2D1::BitmapBrushProperties(), D2D1::BrushProperties(1.0f, D2DMatrix(maskTransform)), getter_AddRefs(mask));
|
|
MOZ_ASSERT(bitmap); // This should always be true since it was created for a surface.
|
|
|
|
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;
|
|
pushedLayer.mOldPermitSubpixelAA = mPermitSubpixelAA;
|
|
mPermitSubpixelAA = aOpaque;
|
|
|
|
mDC->CreateCommandList(getter_AddRefs(pushedLayer.mCurrentList));
|
|
mPushedLayers.push_back(pushedLayer);
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PopLayer()
|
|
{
|
|
MOZ_ASSERT(CurrentLayer().mPushedClips.size() == 0);
|
|
|
|
RefPtr<ID2D1CommandList> list = CurrentLayer().mCurrentList;
|
|
mPermitSubpixelAA = CurrentLayer().mOldPermitSubpixelAA;
|
|
|
|
mPushedLayers.pop_back();
|
|
mDC->SetTarget(CurrentTarget());
|
|
|
|
list->Close();
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
DCCommandSink sink(mDC);
|
|
list->Stream(&sink);
|
|
|
|
mDC->PopLayer();
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
DrawTargetD2D1::CreateSourceSurfaceFromData(unsigned char *aData,
|
|
const IntSize &aSize,
|
|
int32_t aStride,
|
|
SurfaceFormat aFormat) const
|
|
{
|
|
RefPtr<ID2D1Bitmap1> bitmap;
|
|
|
|
HRESULT hr = mDC->CreateBitmap(D2DIntSize(aSize), aData, aStride,
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(aFormat)),
|
|
getter_AddRefs(bitmap));
|
|
|
|
if (FAILED(hr) || !bitmap) {
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(aSize))) << "[D2D1.1] 1CreateBitmap failure " << aSize << " Code: " << hexa(hr) << " format " << (int)aFormat;
|
|
return nullptr;
|
|
}
|
|
|
|
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, aFormat, aSize);
|
|
}
|
|
|
|
already_AddRefed<DrawTarget>
|
|
DrawTargetD2D1::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
|
|
{
|
|
RefPtr<DrawTargetD2D1> dt = new DrawTargetD2D1();
|
|
|
|
if (!dt->Init(aSize, aFormat)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return dt.forget();
|
|
}
|
|
|
|
already_AddRefed<PathBuilder>
|
|
DrawTargetD2D1::CreatePathBuilder(FillRule aFillRule) const
|
|
{
|
|
RefPtr<ID2D1PathGeometry> path;
|
|
HRESULT hr = factory()->CreatePathGeometry(getter_AddRefs(path));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxWarning() << *this << ": Failed to create Direct2D Path Geometry. Code: " << hexa(hr);
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
|
hr = path->Open(getter_AddRefs(sink));
|
|
if (FAILED(hr)) {
|
|
gfxWarning() << *this << ": Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
|
|
return nullptr;
|
|
}
|
|
|
|
if (aFillRule == FillRule::FILL_WINDING) {
|
|
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
|
|
}
|
|
|
|
return MakeAndAddRef<PathBuilderD2D>(sink, path, aFillRule, BackendType::DIRECT2D1_1);
|
|
}
|
|
|
|
already_AddRefed<GradientStops>
|
|
DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
|
|
{
|
|
if (aNumStops == 0) {
|
|
gfxWarning() << *this << ": Failed to create GradientStopCollection with no stops.";
|
|
return nullptr;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
RefPtr<ID2D1GradientStopCollection> stopCollection;
|
|
|
|
HRESULT hr =
|
|
mDC->CreateGradientStopCollection(stops, aNumStops,
|
|
D2D1_GAMMA_2_2, D2DExtend(aExtendMode, Axis::BOTH),
|
|
getter_AddRefs(stopCollection));
|
|
delete [] stops;
|
|
|
|
if (FAILED(hr)) {
|
|
gfxWarning() << *this << ": Failed to create GradientStopCollection. Code: " << hexa(hr);
|
|
return nullptr;
|
|
}
|
|
|
|
return MakeAndAddRef<GradientStopsD2D>(stopCollection, Factory::GetDirect3D11Device());
|
|
}
|
|
|
|
already_AddRefed<FilterNode>
|
|
DrawTargetD2D1::CreateFilter(FilterType aType)
|
|
{
|
|
return FilterNodeD2D1::Create(mDC, aType);
|
|
}
|
|
|
|
bool
|
|
DrawTargetD2D1::Init(ID3D11Texture2D* aTexture, SurfaceFormat aFormat)
|
|
{
|
|
HRESULT hr;
|
|
|
|
ID2D1Device* device = Factory::GetD2D1Device();
|
|
if (!device) {
|
|
return false;
|
|
}
|
|
|
|
hr = device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, getter_AddRefs(mDC));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() <<"[D2D1.1] 1Failed to create a DeviceContext, code: " << hexa(hr) << " format " << (int)aFormat;
|
|
return false;
|
|
}
|
|
|
|
RefPtr<IDXGISurface> dxgiSurface;
|
|
aTexture->QueryInterface(__uuidof(IDXGISurface),
|
|
(void**)((IDXGISurface**)getter_AddRefs(dxgiSurface)));
|
|
if (!dxgiSurface) {
|
|
gfxCriticalError() <<"[D2D1.1] Failed to obtain a DXGI surface.";
|
|
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;
|
|
hr = mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)getter_AddRefs(mBitmap));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() << "[D2D1.1] CreateBitmapFromDxgiSurface failure Code: " << hexa(hr) << " format " << (int)aFormat;
|
|
return false;
|
|
}
|
|
|
|
mFormat = aFormat;
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
aTexture->GetDesc(&desc);
|
|
mSize.width = desc.Width;
|
|
mSize.height = desc.Height;
|
|
|
|
// 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.
|
|
hr = mDC->CreateSolidColorBrush(D2D1::ColorF(0, 0), getter_AddRefs(mSolidColorBrush));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() << "[D2D1.1] Failure creating solid color brush.";
|
|
return false;
|
|
}
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
|
|
mDC->BeginDraw();
|
|
|
|
CurrentLayer().mIsOpaque = aFormat == SurfaceFormat::B8G8R8X8;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
|
|
{
|
|
HRESULT hr;
|
|
|
|
ID2D1Device* device = Factory::GetD2D1Device();
|
|
if (!device) {
|
|
return false;
|
|
}
|
|
|
|
hr = device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, getter_AddRefs(mDC));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() <<"[D2D1.1] 2Failed to create a DeviceContext, code: " << hexa(hr) << " format " << (int)aFormat;
|
|
return false;
|
|
}
|
|
|
|
if (mDC->GetMaximumBitmapSize() < UINT32(aSize.width) ||
|
|
mDC->GetMaximumBitmapSize() < UINT32(aSize.height)) {
|
|
// This is 'ok', so don't assert
|
|
gfxCriticalNote << "[D2D1.1] Attempt to use unsupported surface size " << aSize;
|
|
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;
|
|
hr = mDC->CreateBitmap(D2DIntSize(aSize), nullptr, 0, props, (ID2D1Bitmap1**)getter_AddRefs(mBitmap));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() << "[D2D1.1] 3CreateBitmap failure " << aSize << " Code: " << hexa(hr) << " format " << (int)aFormat;
|
|
return false;
|
|
}
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
|
|
hr = mDC->CreateSolidColorBrush(D2D1::ColorF(0, 0), getter_AddRefs(mSolidColorBrush));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError() << "[D2D1.1] Failure creating solid color brush.";
|
|
return false;
|
|
}
|
|
|
|
mDC->BeginDraw();
|
|
|
|
CurrentLayer().mIsOpaque = aFormat == SurfaceFormat::B8G8R8X8;
|
|
|
|
mDC->Clear();
|
|
|
|
mFormat = aFormat;
|
|
mSize = aSize;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Private helpers.
|
|
*/
|
|
uint32_t
|
|
DrawTargetD2D1::GetByteSize() const
|
|
{
|
|
return mSize.width * mSize.height * BytesPerPixel(mFormat);
|
|
}
|
|
|
|
ID2D1Factory1*
|
|
DrawTargetD2D1::factory()
|
|
{
|
|
if (mFactory) {
|
|
return mFactory;
|
|
}
|
|
|
|
ID2D1Factory* d2dFactory = D2DFactory();
|
|
if (!d2dFactory) {
|
|
return nullptr;
|
|
}
|
|
|
|
HRESULT hr = d2dFactory->QueryInterface((ID2D1Factory1**)&mFactory);
|
|
|
|
if (FAILED(hr)) {
|
|
return nullptr;
|
|
}
|
|
|
|
RadialGradientEffectD2D1::Register(mFactory);
|
|
|
|
return mFactory;
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::CleanupD2D()
|
|
{
|
|
if (mFactory) {
|
|
RadialGradientEffectD2D1::Unregister(mFactory);
|
|
mFactory->Release();
|
|
mFactory = nullptr;
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::MarkChanged()
|
|
{
|
|
if (mSnapshot) {
|
|
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());
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PrepareForDrawing(CompositionOp aOp, const Pattern &aPattern)
|
|
{
|
|
MarkChanged();
|
|
|
|
if (D2DSupportsPrimitiveBlendMode(aOp) && IsPatternSupportedByD2D(aPattern)) {
|
|
// It's important to do this before FlushTransformToDC! As this will cause
|
|
// the transform to become dirty.
|
|
PushAllClips();
|
|
|
|
FlushTransformToDC();
|
|
|
|
if (aOp != CompositionOp::OP_OVER)
|
|
mDC->SetPrimitiveBlend(D2DPrimitiveBlendMode(aOp));
|
|
|
|
return;
|
|
}
|
|
|
|
PopAllClips();
|
|
|
|
mDC->CreateCommandList(getter_AddRefs(mCommandList));
|
|
mDC->SetTarget(mCommandList);
|
|
|
|
PushAllClips();
|
|
FlushTransformToDC();
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::FinalizeDrawing(CompositionOp aOp, const Pattern &aPattern)
|
|
{
|
|
bool patternSupported = IsPatternSupportedByD2D(aPattern);
|
|
|
|
if (D2DSupportsPrimitiveBlendMode(aOp) && patternSupported) {
|
|
if (aOp != CompositionOp::OP_OVER)
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
|
return;
|
|
}
|
|
|
|
PopAllClips();
|
|
|
|
mDC->SetTarget(CurrentTarget());
|
|
mCommandList->Close();
|
|
|
|
RefPtr<ID2D1CommandList> source = mCommandList;
|
|
mCommandList = nullptr;
|
|
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
if (patternSupported) {
|
|
if (D2DSupportsCompositeMode(aOp)) {
|
|
D2D1_RECT_F rect;
|
|
bool isAligned;
|
|
RefPtr<ID2D1Image> tmpImage;
|
|
bool clipIsComplex = CurrentLayer().mPushedClips.size() && !GetDeviceSpaceClipRect(rect, isAligned);
|
|
|
|
if (clipIsComplex) {
|
|
if (!IsOperatorBoundByMask(aOp)) {
|
|
tmpImage = GetImageForLayerContent();
|
|
}
|
|
} else {
|
|
PushAllClips();
|
|
}
|
|
mDC->DrawImage(source, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2DCompositionMode(aOp));
|
|
|
|
if (tmpImage) {
|
|
RefPtr<ID2D1ImageBrush> brush;
|
|
RefPtr<ID2D1Geometry> inverseGeom = GetInverseClippedGeometry();
|
|
mDC->CreateImageBrush(tmpImage, D2D1::ImageBrushProperties(D2D1::RectF(0, 0, mSize.width, mSize.height)),
|
|
getter_AddRefs(brush));
|
|
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_COPY);
|
|
mDC->FillGeometry(inverseGeom, brush);
|
|
mDC->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_SOURCE_OVER);
|
|
}
|
|
return;
|
|
}
|
|
|
|
RefPtr<ID2D1Effect> blendEffect;
|
|
HRESULT hr = mDC->CreateEffect(CLSID_D2D1Blend, getter_AddRefs(blendEffect));
|
|
|
|
if (FAILED(hr) || !blendEffect) {
|
|
gfxWarning() << "Failed to create blend effect!";
|
|
return;
|
|
}
|
|
|
|
RefPtr<ID2D1Image> tmpImage = GetImageForLayerContent();
|
|
|
|
blendEffect->SetInput(0, tmpImage);
|
|
blendEffect->SetInput(1, source);
|
|
blendEffect->SetValue(D2D1_BLEND_PROP_MODE, D2DBlendMode(aOp));
|
|
|
|
PushAllClips();
|
|
|
|
mDC->DrawImage(blendEffect, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
|
|
return;
|
|
}
|
|
|
|
const RadialGradientPattern *pat = static_cast<const RadialGradientPattern*>(&aPattern);
|
|
if (pat->mCenter1 == pat->mCenter2 && pat->mRadius1 == pat->mRadius2) {
|
|
// Draw nothing!
|
|
return;
|
|
}
|
|
|
|
PushAllClips();
|
|
|
|
RefPtr<ID2D1Effect> radialGradientEffect;
|
|
|
|
HRESULT hr = mDC->CreateEffect(CLSID_RadialGradientEffect, getter_AddRefs(radialGradientEffect));
|
|
if (FAILED(hr) || !radialGradientEffect) {
|
|
gfxWarning() << "Failed to create radial gradient effect. Code: " << hexa(hr);
|
|
return;
|
|
}
|
|
|
|
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));
|
|
radialGradientEffect->SetInput(0, source);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (!CurrentLayer().mPushedClips.size()) {
|
|
return false;
|
|
}
|
|
|
|
aClipRect = D2D1::RectF(0, 0, mSize.width, mSize.height);
|
|
for (auto iter = CurrentLayer().mPushedClips.begin();iter != CurrentLayer().mPushedClips.end(); iter++) {
|
|
if (iter->mPath) {
|
|
return false;
|
|
}
|
|
aClipRect = IntersectRect(aClipRect, iter->mBounds);
|
|
if (!iter->mIsPixelAligned) {
|
|
aIsPixelAligned = false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
already_AddRefed<ID2D1Image>
|
|
DrawTargetD2D1::GetImageForLayerContent()
|
|
{
|
|
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;
|
|
// For now, crash in this scenario; this should happen because tmpBitmap is
|
|
// null and CopyFromBitmap call below dereferences it.
|
|
// return;
|
|
}
|
|
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();
|
|
|
|
DCCommandSink sink(mDC);
|
|
list->Stream(&sink);
|
|
|
|
return list.forget();
|
|
}
|
|
}
|
|
|
|
already_AddRefed<ID2D1Geometry>
|
|
DrawTargetD2D1::GetClippedGeometry(IntRect *aClipBounds)
|
|
{
|
|
if (mCurrentClippedGeometry) {
|
|
*aClipBounds = mCurrentClipBounds;
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
|
return clippedGeometry.forget();
|
|
}
|
|
|
|
MOZ_ASSERT(CurrentLayer().mPushedClips.size());
|
|
|
|
mCurrentClipBounds = IntRect(IntPoint(0, 0), mSize);
|
|
|
|
// if pathGeom is null then pathRect represents the path.
|
|
RefPtr<ID2D1Geometry> pathGeom;
|
|
D2D1_RECT_F pathRect;
|
|
bool pathRectIsAxisAligned = false;
|
|
auto iter = CurrentLayer().mPushedClips.begin();
|
|
|
|
if (iter->mPath) {
|
|
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
|
|
} else {
|
|
pathRect = iter->mBounds;
|
|
pathRectIsAxisAligned = iter->mIsPixelAligned;
|
|
}
|
|
|
|
iter++;
|
|
for (;iter != CurrentLayer().mPushedClips.end(); iter++) {
|
|
// Do nothing but add it to the current clip bounds.
|
|
if (!iter->mPath && iter->mIsPixelAligned) {
|
|
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)));
|
|
}
|
|
if (iter->mPath) {
|
|
// See if pathRect needs to go into the path geometry.
|
|
if (!pathRectIsAxisAligned) {
|
|
pathGeom = ConvertRectToGeometry(pathRect);
|
|
} else {
|
|
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
|
|
}
|
|
} else {
|
|
pathRect = IntersectRect(pathRect, iter->mBounds);
|
|
pathRectIsAxisAligned = false;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
RefPtr<ID2D1PathGeometry> newGeom;
|
|
factory()->CreatePathGeometry(getter_AddRefs(newGeom));
|
|
|
|
RefPtr<ID2D1GeometrySink> currentSink;
|
|
newGeom->Open(getter_AddRefs(currentSink));
|
|
|
|
if (iter->mPath) {
|
|
pathGeom->CombineWithGeometry(iter->mPath->GetGeometry(), D2D1_COMBINE_MODE_INTERSECT,
|
|
iter->mTransform, currentSink);
|
|
} else {
|
|
RefPtr<ID2D1Geometry> rectGeom = ConvertRectToGeometry(iter->mBounds);
|
|
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;
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
|
return clippedGeometry.forget();
|
|
}
|
|
|
|
already_AddRefed<ID2D1Geometry>
|
|
DrawTargetD2D1::GetInverseClippedGeometry()
|
|
{
|
|
IntRect bounds;
|
|
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(&bounds);
|
|
RefPtr<ID2D1RectangleGeometry> rectGeom;
|
|
RefPtr<ID2D1PathGeometry> inverseGeom;
|
|
|
|
factory()->CreateRectangleGeometry(D2D1::RectF(0, 0, mSize.width, mSize.height), getter_AddRefs(rectGeom));
|
|
factory()->CreatePathGeometry(getter_AddRefs(inverseGeom));
|
|
RefPtr<ID2D1GeometrySink> sink;
|
|
inverseGeom->Open(getter_AddRefs(sink));
|
|
rectGeom->CombineWithGeometry(geom, D2D1_COMBINE_MODE_EXCLUDE, D2D1::IdentityMatrix(), sink);
|
|
sink->Close();
|
|
|
|
return inverseGeom.forget();
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PopAllClips()
|
|
{
|
|
if (CurrentLayer().mClipsArePushed) {
|
|
PopClipsFromDC(mDC);
|
|
|
|
CurrentLayer().mClipsArePushed = false;
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PushAllClips()
|
|
{
|
|
if (!CurrentLayer().mClipsArePushed) {
|
|
PushClipsToDC(mDC);
|
|
|
|
CurrentLayer().mClipsArePushed = true;
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PushClipsToDC(ID2D1DeviceContext *aDC, bool aForceIgnoreAlpha, const D2D1_RECT_F& aMaxRect)
|
|
{
|
|
mDC->SetTransform(D2D1::IdentityMatrix());
|
|
mTransformDirty = true;
|
|
|
|
for (auto iter = CurrentLayer().mPushedClips.begin(); iter != CurrentLayer().mPushedClips.end(); iter++) {
|
|
if (iter->mPath) {
|
|
PushD2DLayer(aDC, iter->mPath->mGeometry, iter->mTransform, aForceIgnoreAlpha, aMaxRect);
|
|
} else {
|
|
mDC->PushAxisAlignedClip(iter->mBounds, iter->mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PopClipsFromDC(ID2D1DeviceContext *aDC)
|
|
{
|
|
for (int i = CurrentLayer().mPushedClips.size() - 1; i >= 0; i--) {
|
|
if (CurrentLayer().mPushedClips[i].mPath) {
|
|
aDC->PopLayer();
|
|
} else {
|
|
aDC->PopAxisAlignedClip();
|
|
}
|
|
}
|
|
}
|
|
|
|
already_AddRefed<ID2D1Brush>
|
|
DrawTargetD2D1::CreateTransparentBlackBrush()
|
|
{
|
|
return GetSolidColorBrush(D2D1::ColorF(0, 0));
|
|
}
|
|
|
|
already_AddRefed<ID2D1SolidColorBrush>
|
|
DrawTargetD2D1::GetSolidColorBrush(const D2D_COLOR_F& aColor)
|
|
{
|
|
RefPtr<ID2D1SolidColorBrush> brush = mSolidColorBrush;
|
|
brush->SetColor(aColor);
|
|
return brush.forget();
|
|
}
|
|
|
|
already_AddRefed<ID2D1Brush>
|
|
DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
|
|
{
|
|
if (!IsPatternSupportedByD2D(aPattern)) {
|
|
return GetSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f));
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::COLOR) {
|
|
Color color = static_cast<const ColorPattern*>(&aPattern)->mColor;
|
|
return GetSolidColorBrush(D2D1::ColorF(color.r, color.g, color.b, color.a * aAlpha));
|
|
}
|
|
if (aPattern.GetType() == PatternType::LINEAR_GRADIENT) {
|
|
RefPtr<ID2D1LinearGradientBrush> gradBrush;
|
|
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.";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
if (pat->mBegin == pat->mEnd) {
|
|
uint32_t stopCount = stops->mStopCollection->GetGradientStopCount();
|
|
vector<D2D1_GRADIENT_STOP> d2dStops(stopCount);
|
|
stops->mStopCollection->GetGradientStops(&d2dStops.front(), stopCount);
|
|
d2dStops.back().color.a *= aAlpha;
|
|
return GetSolidColorBrush(d2dStops.back().color);
|
|
}
|
|
|
|
mDC->CreateLinearGradientBrush(D2D1::LinearGradientBrushProperties(D2DPoint(pat->mBegin),
|
|
D2DPoint(pat->mEnd)),
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(pat->mMatrix)),
|
|
stops->mStopCollection,
|
|
getter_AddRefs(gradBrush));
|
|
|
|
if (!gradBrush) {
|
|
gfxWarning() << "Couldn't create gradient brush.";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
return gradBrush.forget();
|
|
}
|
|
if (aPattern.GetType() == PatternType::RADIAL_GRADIENT) {
|
|
RefPtr<ID2D1RadialGradientBrush> gradBrush;
|
|
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.";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
// 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)),
|
|
stops->mStopCollection,
|
|
getter_AddRefs(gradBrush));
|
|
|
|
if (!gradBrush) {
|
|
gfxWarning() << "Couldn't create gradient brush.";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
return gradBrush.forget();
|
|
}
|
|
if (aPattern.GetType() == PatternType::SURFACE) {
|
|
const SurfacePattern *pat =
|
|
static_cast<const SurfacePattern*>(&aPattern);
|
|
|
|
if (!pat->mSurface) {
|
|
gfxDebug() << "No source surface specified for surface pattern";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
D2D1_RECT_F samplingBounds;
|
|
Matrix mat = pat->mMatrix;
|
|
|
|
MOZ_ASSERT(pat->mSurface->IsValid());
|
|
|
|
RefPtr<ID2D1Image> image = GetImageForSurface(pat->mSurface, mat, pat->mExtendMode, !pat->mSamplingRect.IsEmpty() ? &pat->mSamplingRect : nullptr);
|
|
|
|
if (!image) {
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
if (pat->mSamplingRect.IsEmpty()) {
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
|
image->QueryInterface((ID2D1Bitmap**)getter_AddRefs(bitmap));
|
|
if (bitmap) {
|
|
/**
|
|
* Create the brush with the proper repeat modes.
|
|
*/
|
|
RefPtr<ID2D1BitmapBrush> bitmapBrush;
|
|
D2D1_EXTEND_MODE xRepeat = D2DExtend(pat->mExtendMode, Axis::X_AXIS);
|
|
D2D1_EXTEND_MODE yRepeat = D2DExtend(pat->mExtendMode, Axis::Y_AXIS);
|
|
|
|
mDC->CreateBitmapBrush(bitmap,
|
|
D2D1::BitmapBrushProperties(xRepeat, yRepeat,
|
|
D2DFilter(pat->mFilter)),
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
|
|
getter_AddRefs(bitmapBrush));
|
|
if (!bitmapBrush) {
|
|
gfxWarning() << "Couldn't create bitmap brush!";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
return bitmapBrush.forget();
|
|
}
|
|
}
|
|
|
|
RefPtr<ID2D1ImageBrush> imageBrush;
|
|
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);
|
|
mat.PreTranslate(pat->mSamplingRect.x, pat->mSamplingRect.y);
|
|
} else {
|
|
// We will do a partial upload of the sampling restricted area from GetImageForSurface.
|
|
samplingBounds = D2D1::RectF(0, 0, pat->mSamplingRect.width, pat->mSamplingRect.height);
|
|
}
|
|
|
|
D2D1_EXTEND_MODE xRepeat = D2DExtend(pat->mExtendMode, Axis::X_AXIS);
|
|
D2D1_EXTEND_MODE yRepeat = D2DExtend(pat->mExtendMode, Axis::Y_AXIS);
|
|
|
|
mDC->CreateImageBrush(image,
|
|
D2D1::ImageBrushProperties(samplingBounds,
|
|
xRepeat,
|
|
yRepeat,
|
|
D2DInterpolationMode(pat->mFilter)),
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
|
|
getter_AddRefs(imageBrush));
|
|
|
|
if (!imageBrush) {
|
|
gfxWarning() << "Couldn't create image brush!";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
return imageBrush.forget();
|
|
}
|
|
|
|
gfxWarning() << "Invalid pattern type detected.";
|
|
return CreateTransparentBlackBrush();
|
|
}
|
|
|
|
already_AddRefed<ID2D1Image>
|
|
DrawTargetD2D1::GetImageForSurface(SourceSurface *aSurface, Matrix &aSourceTransform,
|
|
ExtendMode aExtendMode, const IntRect* aSourceRect)
|
|
{
|
|
RefPtr<ID2D1Image> image;
|
|
|
|
switch (aSurface->GetType()) {
|
|
case SurfaceType::D2D1_1_IMAGE:
|
|
{
|
|
SourceSurfaceD2D1 *surf = static_cast<SourceSurfaceD2D1*>(aSurface);
|
|
image = surf->GetImage();
|
|
AddDependencyOnSource(surf);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
RefPtr<DataSourceSurface> dataSurf = aSurface->GetDataSurface();
|
|
if (!dataSurf) {
|
|
gfxWarning() << "Invalid surface type.";
|
|
return nullptr;
|
|
}
|
|
return CreatePartialBitmapForSurface(dataSurf, mTransform, mSize, aExtendMode,
|
|
aSourceTransform, mDC, aSourceRect);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return image.forget();
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
DrawTargetD2D1::OptimizeSourceSurface(SourceSurface* aSurface) const
|
|
{
|
|
if (aSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
|
|
RefPtr<SourceSurface> surface(aSurface);
|
|
return surface.forget();
|
|
}
|
|
|
|
RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
|
|
|
|
RefPtr<ID2D1Bitmap1> bitmap;
|
|
{
|
|
DataSourceSurface::ScopedMap map(data, DataSourceSurface::READ);
|
|
if (MOZ2D_WARN_IF(!map.IsMapped())) {
|
|
return nullptr;
|
|
}
|
|
|
|
HRESULT hr = mDC->CreateBitmap(D2DIntSize(data->GetSize()), map.GetData(), map.GetStride(),
|
|
D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(data->GetFormat())),
|
|
getter_AddRefs(bitmap));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(data->GetSize()))) << "[D2D1.1] 4CreateBitmap failure " << data->GetSize() << " Code: " << hexa(hr) << " format " << (int)data->GetFormat();
|
|
}
|
|
}
|
|
|
|
if (!bitmap) {
|
|
return data.forget();
|
|
}
|
|
|
|
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, data->GetFormat(), data->GetSize());
|
|
}
|
|
|
|
void
|
|
DrawTargetD2D1::PushD2DLayer(ID2D1DeviceContext *aDC, ID2D1Geometry *aGeometry, const D2D1_MATRIX_3X2_F &aTransform,
|
|
bool aForceIgnoreAlpha, const D2D1_RECT_F& aMaxRect)
|
|
{
|
|
D2D1_LAYER_OPTIONS1 options = D2D1_LAYER_OPTIONS1_NONE;
|
|
|
|
if (aDC->GetPixelFormat().alphaMode == D2D1_ALPHA_MODE_IGNORE || aForceIgnoreAlpha) {
|
|
options = D2D1_LAYER_OPTIONS1_IGNORE_ALPHA | D2D1_LAYER_OPTIONS1_INITIALIZE_FROM_BACKGROUND;
|
|
}
|
|
|
|
mDC->PushLayer(D2D1::LayerParameters1(aMaxRect, aGeometry,
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, aTransform,
|
|
1.0, nullptr, options), nullptr);
|
|
}
|
|
|
|
}
|
|
}
|