2011-06-24 17:41:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2014-02-28 15:42:23 +00:00
|
|
|
#include <initguid.h>
|
2011-06-24 17:41:16 +00:00
|
|
|
#include "DrawTargetD2D.h"
|
|
|
|
#include "SourceSurfaceD2D.h"
|
2014-04-15 22:45:11 +00:00
|
|
|
#include "SourceSurfaceD2D1.h"
|
2011-06-24 17:41:16 +00:00
|
|
|
#include "SourceSurfaceD2DTarget.h"
|
|
|
|
#include "ShadersD2D.h"
|
|
|
|
#include "PathD2D.h"
|
|
|
|
#include "GradientStopsD2D.h"
|
|
|
|
#include "ScaledFontDWrite.h"
|
2012-05-10 04:31:14 +00:00
|
|
|
#include "ImageScaling.h"
|
2011-06-24 17:41:16 +00:00
|
|
|
#include "Logging.h"
|
|
|
|
#include "Tools.h"
|
2011-11-25 02:12:40 +00:00
|
|
|
#include <algorithm>
|
2012-08-06 20:32:11 +00:00
|
|
|
#include "mozilla/Constants.h"
|
2013-11-27 11:22:56 +00:00
|
|
|
#include "FilterNodeSoftware.h"
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2013-11-27 11:25:16 +00:00
|
|
|
#include "FilterNodeD2D1.h"
|
2015-02-09 19:04:11 +00:00
|
|
|
#include "ExtendInputEffectD2D1.h"
|
2013-11-27 11:25:16 +00:00
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
#include <dwrite.h>
|
|
|
|
|
2014-02-17 22:32:52 +00:00
|
|
|
// decltype is not usable for overloaded functions.
|
2011-06-24 17:41:16 +00:00
|
|
|
typedef HRESULT (WINAPI*D2D1CreateFactoryFunc)(
|
2011-08-23 15:35:13 +00:00
|
|
|
D2D1_FACTORY_TYPE factoryType,
|
|
|
|
REFIID iid,
|
|
|
|
CONST D2D1_FACTORY_OPTIONS *pFactoryOptions,
|
|
|
|
void **factory
|
2011-06-24 17:41:16 +00:00
|
|
|
);
|
|
|
|
|
2011-06-29 21:34:58 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
|
|
|
|
|
|
|
ID2D1Factory *DrawTargetD2D::mFactory;
|
2012-05-15 14:57:51 +00:00
|
|
|
IDWriteFactory *DrawTargetD2D::mDWriteFactory;
|
2012-06-20 21:41:16 +00:00
|
|
|
uint64_t DrawTargetD2D::mVRAMUsageDT;
|
|
|
|
uint64_t DrawTargetD2D::mVRAMUsageSS;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
// Helper class to restore surface contents that was clipped out but may have
|
|
|
|
// been altered by a drawing call.
|
|
|
|
class AutoSaveRestoreClippedOut
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSaveRestoreClippedOut(DrawTargetD2D *aDT)
|
|
|
|
: mDT(aDT)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Save() {
|
|
|
|
if (!mDT->mPushedClips.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDT->Flush();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tmpTexture;
|
2011-06-24 17:41:16 +00:00
|
|
|
IntSize size = mDT->mSize;
|
|
|
|
SurfaceFormat format = mDT->mFormat;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGIFormat(format), size.width, size.height,
|
|
|
|
1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mDT->mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(tmpTexture));
|
2011-06-24 17:41:16 +00:00
|
|
|
if (FAILED(hr)) {
|
2015-07-14 19:22:29 +00:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(size))) << "[D2D] 1 CreateTexture2D failure " << size << " Code: " << hexa(hr) << " format " << (int)format;
|
2014-09-11 15:27:48 +00:00
|
|
|
return;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
mDT->mDevice->CopyResource(tmpTexture, mDT->mTexture);
|
|
|
|
|
2013-11-20 16:20:50 +00:00
|
|
|
D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(D2DPixelFormat(format));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDXGISurface> surf;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
tmpTexture->QueryInterface((IDXGISurface**)getter_AddRefs(surf));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
hr = mDT->mRT->CreateSharedBitmap(IID_IDXGISurface, surf,
|
2015-10-18 04:40:10 +00:00
|
|
|
&props, getter_AddRefs(mOldSurfBitmap));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxCriticalError() << "[D2D] CreateSharedBitmap failure " << size << " Code: " << hexa(hr);
|
2014-09-11 15:27:48 +00:00
|
|
|
return;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
IntRect clipBounds;
|
|
|
|
mClippedArea = mDT->GetClippedGeometry(&clipBounds);
|
|
|
|
|
|
|
|
if (!clipBounds.IsEqualEdges(IntRect(IntPoint(0, 0), mDT->mSize))) {
|
|
|
|
// We still need to take into account clipBounds if it contains additional
|
|
|
|
// clipping information.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1RectangleGeometry> rectGeom;
|
2013-01-28 15:09:29 +00:00
|
|
|
factory()->CreateRectangleGeometry(D2D1::Rect(Float(clipBounds.x),
|
|
|
|
Float(clipBounds.y),
|
|
|
|
Float(clipBounds.XMost()),
|
|
|
|
Float(clipBounds.YMost())),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(rectGeom));
|
2012-09-18 23:04:42 +00:00
|
|
|
|
2013-06-19 20:48:40 +00:00
|
|
|
mClippedArea = IntersectGeometry(mClippedArea, rectGeom);
|
2012-09-18 23:04:42 +00:00
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ID2D1Factory *factory() { return mDT->factory(); }
|
|
|
|
|
|
|
|
~AutoSaveRestoreClippedOut()
|
|
|
|
{
|
|
|
|
if (!mOldSurfBitmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID2D1RenderTarget *rt = mDT->mRT;
|
|
|
|
|
|
|
|
// Write the area that was clipped out back to the surface. This all
|
|
|
|
// happens in device space.
|
|
|
|
rt->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mDT->mTransformDirty = true;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1RectangleGeometry> rectGeom;
|
2011-07-05 06:28:20 +00:00
|
|
|
factory()->CreateRectangleGeometry(
|
|
|
|
D2D1::RectF(0, 0, float(mDT->mSize.width), float(mDT->mSize.height)),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(rectGeom));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1PathGeometry> invClippedArea;
|
2015-10-18 04:40:10 +00:00
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(invClippedArea));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 04:40:10 +00:00
|
|
|
invClippedArea->Open(getter_AddRefs(sink));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
rectGeom->CombineWithGeometry(mClippedArea, D2D1_COMBINE_MODE_EXCLUDE, nullptr, sink);
|
2011-06-24 17:41:16 +00:00
|
|
|
sink->Close();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1BitmapBrush> brush;
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = rt->CreateBitmapBrush(mOldSurfBitmap, D2D1::BitmapBrushProperties(), D2D1::BrushProperties(), getter_AddRefs(brush));
|
2015-02-25 22:44:56 +00:00
|
|
|
if (FAILED(hr)) {
|
2015-10-21 12:34:00 +00:00
|
|
|
gfxCriticalNote << "[D2D] CreateBitmapBrush failure " << hexa(hr);
|
2015-02-25 22:44:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
rt->FillGeometry(invClippedArea, brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-02-25 22:44:56 +00:00
|
|
|
DrawTargetD2D *mDT;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
// If we have an operator unbound by the source, this will contain a bitmap
|
|
|
|
// with the old dest surface data.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> mOldSurfBitmap;
|
2011-06-24 17:41:16 +00:00
|
|
|
// This contains the area drawing is clipped to.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> mClippedArea;
|
2011-06-24 17:41:16 +00:00
|
|
|
};
|
|
|
|
|
2013-06-19 20:48:40 +00:00
|
|
|
ID2D1Factory *D2DFactory()
|
|
|
|
{
|
|
|
|
return DrawTargetD2D::factory();
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::DrawTargetD2D()
|
2012-06-20 21:41:16 +00:00
|
|
|
: mCurrentCachedLayer(0)
|
|
|
|
, mClipsArePushed(false)
|
2012-08-14 18:06:12 +00:00
|
|
|
, mPrivateData(nullptr)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetD2D::~DrawTargetD2D()
|
|
|
|
{
|
|
|
|
if (mRT) {
|
|
|
|
PopAllClips();
|
|
|
|
|
|
|
|
mRT->EndDraw();
|
2012-06-20 21:41:16 +00:00
|
|
|
|
|
|
|
mVRAMUsageDT -= GetByteSize();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
if (mTempRT) {
|
|
|
|
mTempRT->EndDraw();
|
2012-06-20 21:41:16 +00:00
|
|
|
|
|
|
|
mVRAMUsageDT -= GetByteSize();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2011-11-25 02:12:40 +00:00
|
|
|
|
2011-12-09 09:51:57 +00:00
|
|
|
if (mSnapshot) {
|
|
|
|
// We may hold the only reference. MarkIndependent will clear mSnapshot;
|
2012-06-20 21:41:16 +00:00
|
|
|
// keep the snapshot object alive so it doesn't get destroyed while
|
|
|
|
// MarkIndependent is running.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurfaceD2DTarget> deathGrip = mSnapshot;
|
2012-06-20 21:41:16 +00: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.
|
2011-12-09 09:51:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 21:41:16 +00:00
|
|
|
for (int i = 0; i < kLayerCacheSize; i++) {
|
|
|
|
if (mCachedLayers[i]) {
|
2012-08-14 18:06:12 +00:00
|
|
|
mCachedLayers[i] = nullptr;
|
2012-06-20 21:41:16 +00:00
|
|
|
mVRAMUsageDT -= GetByteSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-25 02:12:40 +00:00
|
|
|
// Targets depending on us can break that dependency, since we're obviously not going to
|
|
|
|
// be modified in the future.
|
2011-12-09 09:51:57 +00:00
|
|
|
for (TargetSet::iterator iter = mDependentTargets.begin();
|
2011-11-25 02:12:40 +00:00
|
|
|
iter != mDependentTargets.end(); iter++) {
|
2011-12-09 09:51:57 +00:00
|
|
|
(*iter)->mDependingOnTargets.erase(this);
|
2011-11-25 02:12:40 +00:00
|
|
|
}
|
|
|
|
// Our dependencies on other targets no longer matter.
|
2011-12-09 09:51:57 +00:00
|
|
|
for (TargetSet::iterator iter = mDependingOnTargets.begin();
|
2011-11-25 02:12:40 +00:00
|
|
|
iter != mDependingOnTargets.end(); iter++) {
|
2011-12-09 09:51:57 +00:00
|
|
|
(*iter)->mDependentTargets.erase(this);
|
2011-11-25 02:12:40 +00:00
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DrawTarget Implementation
|
|
|
|
*/
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::Snapshot()
|
|
|
|
{
|
2011-12-09 09:51:57 +00:00
|
|
|
if (!mSnapshot) {
|
|
|
|
mSnapshot = new SourceSurfaceD2DTarget(this, mTexture, mFormat);
|
|
|
|
Flush();
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface> snapshot(mSnapshot);
|
2015-05-01 13:14:16 +00:00
|
|
|
return snapshot.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::Flush()
|
|
|
|
{
|
|
|
|
PopAllClips();
|
|
|
|
|
|
|
|
HRESULT hr = mRT->Flush();
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Error reported when trying to flush D2D rendertarget. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2011-11-25 02:12:40 +00:00
|
|
|
|
|
|
|
// We no longer depend on any target.
|
2011-12-09 09:51:57 +00:00
|
|
|
for (TargetSet::iterator iter = mDependingOnTargets.begin();
|
2011-11-25 02:12:40 +00:00
|
|
|
iter != mDependingOnTargets.end(); iter++) {
|
2011-12-09 09:51:57 +00:00
|
|
|
(*iter)->mDependentTargets.erase(this);
|
2011-11-25 02:12:40 +00:00
|
|
|
}
|
|
|
|
mDependingOnTargets.clear();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:51:57 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::AddDependencyOnSource(SourceSurfaceD2DTarget* aSource)
|
|
|
|
{
|
2011-12-09 09:53:14 +00:00
|
|
|
if (aSource->mDrawTarget && !mDependingOnTargets.count(aSource->mDrawTarget)) {
|
2011-12-09 09:51:57 +00:00
|
|
|
aSource->mDrawTarget->mDependentTargets.insert(this);
|
|
|
|
mDependingOnTargets.insert(aSource->mDrawTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1Bitmap>
|
2013-06-13 03:57:51 +00:00
|
|
|
DrawTargetD2D::GetBitmapForSurface(SourceSurface *aSurface,
|
|
|
|
Rect &aSource)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
switch (aSurface->GetType()) {
|
|
|
|
|
2014-01-10 18:55:24 +00:00
|
|
|
case SurfaceType::D2D1_BITMAP:
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
|
|
|
SourceSurfaceD2D *srcSurf = static_cast<SourceSurfaceD2D*>(aSurface);
|
|
|
|
bitmap = srcSurf->GetBitmap();
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 18:55:24 +00:00
|
|
|
case SurfaceType::D2D1_DRAWTARGET:
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
|
|
|
SourceSurfaceD2DTarget *srcSurf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
|
|
|
|
bitmap = srcSurf->GetBitmap(mRT);
|
2011-12-09 09:51:57 +00:00
|
|
|
AddDependencyOnSource(srcSurf);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-09-20 21:24:12 +00:00
|
|
|
default:
|
2012-05-21 15:27:30 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();
|
2012-09-20 21:24:12 +00:00
|
|
|
|
|
|
|
if (!srcSurf) {
|
|
|
|
gfxDebug() << "Not able to deal with non-data source surface.";
|
2013-06-13 03:57:51 +00:00
|
|
|
return nullptr;
|
2012-09-20 21:24:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 09:58:22 +00:00
|
|
|
// We need to include any pixels that are overlapped by aSource
|
|
|
|
Rect sourceRect(aSource);
|
|
|
|
sourceRect.RoundOut();
|
|
|
|
|
|
|
|
if (sourceRect.IsEmpty()) {
|
|
|
|
gfxDebug() << "Bitmap source is empty. DrawBitmap will silently fail.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceRect.width > mRT->GetMaximumBitmapSize() ||
|
|
|
|
sourceRect.height > mRT->GetMaximumBitmapSize()) {
|
2012-05-21 15:27:30 +00:00
|
|
|
gfxDebug() << "Bitmap source larger than texture size specified. DrawBitmap will silently fail.";
|
|
|
|
// Don't know how to deal with this yet.
|
2013-06-13 03:57:51 +00:00
|
|
|
return nullptr;
|
2012-05-21 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 11:01:00 +00:00
|
|
|
HRESULT hr;
|
|
|
|
{
|
|
|
|
DataSourceSurface::ScopedMap srcMap(srcSurf, DataSourceSurface::READ);
|
|
|
|
if (MOZ2D_WARN_IF(!srcMap.IsMapped())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int stride = srcMap.GetStride();
|
|
|
|
unsigned char *data = srcMap.GetData() +
|
|
|
|
(uint32_t)sourceRect.y * stride +
|
|
|
|
(uint32_t)sourceRect.x * BytesPerPixel(srcSurf->GetFormat());
|
|
|
|
|
|
|
|
D2D1_BITMAP_PROPERTIES props =
|
|
|
|
D2D1::BitmapProperties(D2DPixelFormat(srcSurf->GetFormat()));
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mRT->CreateBitmap(D2D1::SizeU(UINT32(sourceRect.width), UINT32(sourceRect.height)), data, stride, props, getter_AddRefs(bitmap));
|
2015-06-10 11:01:00 +00:00
|
|
|
}
|
2015-02-25 22:44:56 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
IntSize size(sourceRect.width, sourceRect.height);
|
2015-07-14 19:22:29 +00:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(size))) << "[D2D] 1CreateBitmap failure " << size << " Code: " << hexa(hr) << " format " << (int)srcSurf->GetFormat();
|
2015-02-25 22:44:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-21 15:27:30 +00:00
|
|
|
|
2013-06-13 03:57:51 +00:00
|
|
|
// subtract the integer part leaving the fractional part
|
|
|
|
aSource.x -= (uint32_t)aSource.x;
|
|
|
|
aSource.y -= (uint32_t)aSource.y;
|
2012-05-21 15:27:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-05-01 13:14:16 +00:00
|
|
|
return bitmap.forget();
|
2013-06-13 03:57:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1Image>
|
2014-04-15 22:45:11 +00:00
|
|
|
DrawTargetD2D::GetImageForSurface(SourceSurface *aSurface)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Image> image;
|
2014-04-15 22:45:11 +00:00
|
|
|
|
2014-09-14 21:51:34 +00:00
|
|
|
Rect r(Point(), Size(aSurface->GetSize()));
|
|
|
|
image = GetBitmapForSurface(aSurface, r);
|
2014-04-15 22:45:11 +00:00
|
|
|
|
2015-05-01 13:14:16 +00:00
|
|
|
return image.forget();
|
2014-04-15 22:45:11 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 03:57:51 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2013-06-13 03:57:51 +00:00
|
|
|
|
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
|
|
|
Rect srcRect = aSource;
|
|
|
|
|
|
|
|
bitmap = GetBitmapForSurface(aSurface, srcRect);
|
|
|
|
if (!bitmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
rt->DrawBitmap(bitmap, D2DRect(aDest), aOptions.mAlpha, D2DFilter(aSurfOptions.mFilter), D2DRect(srcRect));
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()), aDest);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 11:22:56 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1DeviceContext> dc;
|
2013-11-27 11:25:16 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mRT->QueryInterface((ID2D1DeviceContext**)getter_AddRefs(dc));
|
2013-11-27 11:25:16 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && aNode->GetBackendType() == FILTER_BACKEND_DIRECT2D1_1) {
|
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = rt->QueryInterface((ID2D1DeviceContext**)getter_AddRefs(dc));
|
2013-11-27 11:25:16 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
2014-09-25 19:18:29 +00:00
|
|
|
FilterNodeD2D1* node = static_cast<FilterNodeD2D1*>(aNode);
|
|
|
|
node->WillDraw(this);
|
|
|
|
|
|
|
|
dc->DrawImage(node->OutputEffect(), D2DPoint(aDestPoint), D2DRect(aSourceRect));
|
2013-11-27 11:25:16 +00:00
|
|
|
|
|
|
|
Rect destRect = aSourceRect;
|
|
|
|
destRect.MoveBy(aDestPoint);
|
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()), destRect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 11:22:56 +00:00
|
|
|
if (aNode->GetBackendType() != FILTER_BACKEND_SOFTWARE) {
|
|
|
|
gfxWarning() << "Invalid filter backend passed to DrawTargetD2D!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterNodeSoftware* filter = static_cast<FilterNodeSoftware*>(aNode);
|
|
|
|
filter->Draw(this, aSourceRect, aDestPoint, aOptions);
|
|
|
|
}
|
|
|
|
|
2013-06-13 03:57:51 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2013-06-13 03:57:51 +00:00
|
|
|
|
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()));
|
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
|
|
|
// FillOpacityMask only works if the antialias mode is MODE_ALIASED
|
|
|
|
rt->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
|
|
|
|
|
|
|
IntSize size = aMask->GetSize();
|
|
|
|
Rect maskRect = Rect(0.f, 0.f, size.width, size.height);
|
|
|
|
bitmap = GetBitmapForSurface(aMask, maskRect);
|
|
|
|
if (!bitmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect dest = Rect(aOffset.x, aOffset.y, size.width, size.height);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
2013-06-13 03:57:51 +00:00
|
|
|
rt->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS, D2DRect(dest), D2DRect(maskRect));
|
|
|
|
|
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, ColorPattern(Color()), dest);
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
2011-07-05 06:28:14 +00:00
|
|
|
Float aSigma,
|
|
|
|
CompositionOp aOperator)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10ShaderResourceView> srView = nullptr;
|
2014-01-10 18:55:24 +00:00
|
|
|
if (aSurface->GetType() != SurfaceType::D2D1_DRAWTARGET) {
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
SetScissorToRect(nullptr);
|
|
|
|
|
2011-07-13 00:34:43 +00:00
|
|
|
// XXX - This function is way too long, it should be split up soon to make
|
|
|
|
// it more graspable!
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
Flush();
|
|
|
|
|
2011-07-05 06:28:20 +00:00
|
|
|
AutoSaveRestoreClippedOut restoreClippedOut(this);
|
|
|
|
|
|
|
|
if (!IsOperatorBoundByMask(aOperator)) {
|
|
|
|
restoreClippedOut.Save();
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
srView = static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView();
|
2015-11-19 23:04:46 +00:00
|
|
|
if (!srView) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
EnsureViews();
|
|
|
|
|
|
|
|
if (!mTempRTView) {
|
|
|
|
// This view is only needed in this path.
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mDevice->CreateRenderTargetView(mTempTexture, nullptr, getter_AddRefs(mTempRTView));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failure to create RenderTargetView. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 06:28:20 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10RenderTargetView> destRTView = mRTView;
|
|
|
|
RefPtr<ID3D10Texture2D> destTexture;
|
2011-06-24 17:41:16 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> maskTexture;
|
|
|
|
RefPtr<ID3D10ShaderResourceView> maskSRView;
|
2012-09-18 23:04:42 +00:00
|
|
|
IntRect clipBounds;
|
2011-06-24 17:41:16 +00:00
|
|
|
if (mPushedClips.size()) {
|
2012-09-18 23:04:42 +00:00
|
|
|
EnsureClipMaskTexture(&clipBounds);
|
2011-07-13 00:34:43 +00:00
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateShaderResourceView(mCurrentClipMaskTexture, nullptr, getter_AddRefs(maskSRView));
|
2011-07-05 06:28:20 +00:00
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
IntSize srcSurfSize;
|
|
|
|
ID3D10RenderTargetView *rtViews;
|
|
|
|
D3D10_VIEWPORT viewport;
|
|
|
|
|
|
|
|
UINT stride = sizeof(Vertex);
|
|
|
|
UINT offset = 0;
|
|
|
|
ID3D10Buffer *buff = mPrivateData->mVB;
|
|
|
|
|
|
|
|
mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
mDevice->IASetVertexBuffers(0, 1, &buff, &stride, &offset);
|
|
|
|
mDevice->IASetInputLayout(mPrivateData->mInputLayout);
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(-1.0f, 1.0f, 2.0f, -2.0f));
|
|
|
|
mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
// If we create a downsampled source surface we need to correct aOffset for that.
|
|
|
|
Point correctedOffset = aOffset + aDest;
|
|
|
|
|
|
|
|
// The 'practical' scaling factors.
|
|
|
|
Float dsFactorX = 1.0f;
|
|
|
|
Float dsFactorY = 1.0f;
|
|
|
|
|
|
|
|
if (aSigma > 1.7f) {
|
|
|
|
// In this case 9 samples of our original will not cover it. Generate the
|
|
|
|
// mip levels for the original and create a downsampled version from
|
|
|
|
// them. We generate a version downsampled so that a kernel for a sigma
|
|
|
|
// of 1.7 will produce the right results.
|
|
|
|
float blurWeights[9] = { 0.234671f, 0.197389f, 0.197389f, 0.117465f, 0.117465f, 0.049456f, 0.049456f, 0.014732f, 0.014732f };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("BlurWeights")->SetRawValue(blurWeights, 0, sizeof(blurWeights));
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
aSurface->GetSize().width,
|
|
|
|
aSurface->GetSize().height);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> mipTexture;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(mipTexture));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-12-17 22:54:04 +00:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(aSurface->GetSize()))) << "[D2D] 2 CreateTexture2D failure " << aSurface->GetSize() << " Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize dsSize = IntSize(int32_t(aSurface->GetSize().width * (1.7f / aSigma)),
|
|
|
|
int32_t(aSurface->GetSize().height * (1.7f / aSigma)));
|
|
|
|
|
|
|
|
if (dsSize.width < 1) {
|
|
|
|
dsSize.width = 1;
|
|
|
|
}
|
|
|
|
if (dsSize.height < 1) {
|
|
|
|
dsSize.height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsFactorX = dsSize.width / Float(aSurface->GetSize().width);
|
|
|
|
dsFactorY = dsSize.height / Float(aSurface->GetSize().height);
|
|
|
|
correctedOffset.x *= dsFactorX;
|
|
|
|
correctedOffset.y *= dsFactorY;
|
|
|
|
|
|
|
|
desc = CD3D10_TEXTURE2D_DESC(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
dsSize.width,
|
|
|
|
dsSize.height, 1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tmpDSTexture;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(tmpDSTexture));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-12-17 22:54:04 +00:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(dsSize))) << "[D2D] 3 CreateTexture2D failure " << dsSize << " Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_BOX box;
|
|
|
|
box.left = box.top = box.front = 0;
|
|
|
|
box.back = 1;
|
|
|
|
box.right = aSurface->GetSize().width;
|
|
|
|
box.bottom = aSurface->GetSize().height;
|
|
|
|
mDevice->CopySubresourceRegion(mipTexture, 0, 0, 0, 0, static_cast<SourceSurfaceD2DTarget*>(aSurface)->mTexture, 0, &box);
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateShaderResourceView(mipTexture, nullptr, getter_AddRefs(srView));
|
2011-06-24 17:41:16 +00:00
|
|
|
mDevice->GenerateMips(srView);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10RenderTargetView> dsRTView;
|
|
|
|
RefPtr<ID3D10ShaderResourceView> dsSRView;
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateRenderTargetView(tmpDSTexture, nullptr, getter_AddRefs(dsRTView));
|
|
|
|
mDevice->CreateShaderResourceView(tmpDSTexture, nullptr, getter_AddRefs(dsSRView));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2011-06-28 00:10:06 +00:00
|
|
|
// We're not guaranteed the texture we created will be empty, we've
|
|
|
|
// seen old content at least on NVidia drivers.
|
|
|
|
float color[4] = { 0, 0, 0, 0 };
|
|
|
|
mDevice->ClearRenderTargetView(dsRTView, color);
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
rtViews = dsRTView;
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetRenderTargets(1, &rtViews, nullptr);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
viewport.MaxDepth = 1;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Height = dsSize.height;
|
|
|
|
viewport.Width = dsSize.width;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(srView);
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTexture")->
|
|
|
|
GetPassByIndex(0)->Apply(0);
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
mDevice->OMSetBlendState(GetBlendStateForOperator(CompositionOp::OP_OVER), nullptr, 0xffffffff);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mDevice->Draw(4, 0);
|
|
|
|
|
|
|
|
srcSurfSize = dsSize;
|
|
|
|
|
|
|
|
srView = dsSRView;
|
|
|
|
} else {
|
|
|
|
// In this case generate a kernel to draw the blur directly to the temp
|
|
|
|
// surf in one direction and to final in the other.
|
|
|
|
float blurWeights[9];
|
|
|
|
|
|
|
|
float normalizeFactor = 1.0f;
|
|
|
|
if (aSigma != 0) {
|
|
|
|
normalizeFactor = 1.0f / Float(sqrt(2 * M_PI * pow(aSigma, 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
blurWeights[0] = normalizeFactor;
|
|
|
|
|
|
|
|
// XXX - We should actually optimize for Sigma = 0 here. We could use a
|
|
|
|
// much simpler shader and save a lot of texture lookups.
|
|
|
|
for (int i = 1; i < 9; i += 2) {
|
|
|
|
if (aSigma != 0) {
|
|
|
|
blurWeights[i] = blurWeights[i + 1] = normalizeFactor *
|
|
|
|
exp(-pow(float((i + 1) / 2), 2) / (2 * pow(aSigma, 2)));
|
|
|
|
} else {
|
|
|
|
blurWeights[i] = blurWeights[i + 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("BlurWeights")->SetRawValue(blurWeights, 0, sizeof(blurWeights));
|
|
|
|
|
|
|
|
viewport.MaxDepth = 1;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Height = aSurface->GetSize().height;
|
|
|
|
viewport.Width = aSurface->GetSize().width;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
|
|
|
|
srcSurfSize = aSurface->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We may need to draw to a different intermediate surface if our temp
|
|
|
|
// texture isn't big enough.
|
|
|
|
bool needBiggerTemp = srcSurfSize.width > mSize.width ||
|
|
|
|
srcSurfSize.height > mSize.height;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10RenderTargetView> tmpRTView;
|
|
|
|
RefPtr<ID3D10ShaderResourceView> tmpSRView;
|
|
|
|
RefPtr<ID3D10Texture2D> tmpTexture;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
IntSize tmpSurfSize = mSize;
|
|
|
|
|
|
|
|
if (!needBiggerTemp) {
|
|
|
|
tmpRTView = mTempRTView;
|
|
|
|
tmpSRView = mSRView;
|
2011-07-05 06:28:17 +00:00
|
|
|
|
|
|
|
// There could still be content here!
|
|
|
|
float color[4] = { 0, 0, 0, 0 };
|
|
|
|
mDevice->ClearRenderTargetView(tmpRTView, color);
|
2011-06-24 17:41:16 +00:00
|
|
|
} else {
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
srcSurfSize.width,
|
|
|
|
srcSurfSize.height,
|
|
|
|
1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(tmpTexture));
|
|
|
|
mDevice->CreateRenderTargetView(tmpTexture, nullptr, getter_AddRefs(tmpRTView));
|
|
|
|
mDevice->CreateShaderResourceView(tmpTexture, nullptr, getter_AddRefs(tmpSRView));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
tmpSurfSize = srcSurfSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtViews = tmpRTView;
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetRenderTargets(1, &rtViews, nullptr);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(srView);
|
|
|
|
|
|
|
|
// Premultiplied!
|
|
|
|
float shadowColor[4] = { aColor.r * aColor.a, aColor.g * aColor.a,
|
|
|
|
aColor.b * aColor.a, aColor.a };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("ShadowColor")->AsVector()->
|
|
|
|
SetFloatVector(shadowColor);
|
|
|
|
|
|
|
|
float pixelOffset = 1.0f / float(srcSurfSize.width);
|
|
|
|
float blurOffsetsH[9] = { 0, pixelOffset, -pixelOffset,
|
|
|
|
2.0f * pixelOffset, -2.0f * pixelOffset,
|
|
|
|
3.0f * pixelOffset, -3.0f * pixelOffset,
|
|
|
|
4.0f * pixelOffset, - 4.0f * pixelOffset };
|
|
|
|
|
|
|
|
pixelOffset = 1.0f / float(tmpSurfSize.height);
|
|
|
|
float blurOffsetsV[9] = { 0, pixelOffset, -pixelOffset,
|
|
|
|
2.0f * pixelOffset, -2.0f * pixelOffset,
|
|
|
|
3.0f * pixelOffset, -3.0f * pixelOffset,
|
|
|
|
4.0f * pixelOffset, - 4.0f * pixelOffset };
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("BlurOffsetsH")->
|
|
|
|
SetRawValue(blurOffsetsH, 0, sizeof(blurOffsetsH));
|
|
|
|
mPrivateData->mEffect->GetVariableByName("BlurOffsetsV")->
|
|
|
|
SetRawValue(blurOffsetsV, 0, sizeof(blurOffsetsV));
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureWithShadow")->
|
|
|
|
GetPassByIndex(0)->Apply(0);
|
|
|
|
|
|
|
|
mDevice->Draw(4, 0);
|
|
|
|
|
|
|
|
viewport.MaxDepth = 1;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Height = mSize.height;
|
|
|
|
viewport.Width = mSize.width;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(tmpSRView);
|
|
|
|
|
|
|
|
rtViews = destRTView;
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetRenderTargets(1, &rtViews, nullptr);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2011-07-13 00:34:43 +00:00
|
|
|
Point shadowDest = aDest + aOffset;
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(-1.0f + ((shadowDest.x / mSize.width) * 2.0f),
|
|
|
|
1.0f - (shadowDest.y / mSize.height * 2.0f),
|
|
|
|
(Float(aSurface->GetSize().width) / mSize.width) * 2.0f,
|
|
|
|
(-Float(aSurface->GetSize().height) / mSize.height) * 2.0f));
|
2011-06-24 17:41:16 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
|
2011-07-13 00:34:43 +00:00
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, Float(srcSurfSize.width) / tmpSurfSize.width,
|
|
|
|
Float(srcSurfSize.height) / tmpSurfSize.height));
|
2011-07-05 06:28:20 +00:00
|
|
|
|
2011-07-05 08:52:48 +00:00
|
|
|
if (mPushedClips.size()) {
|
2011-07-05 06:28:20 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("mask")->AsShaderResource()->SetResource(maskSRView);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("MaskTexCoords")->AsVector()->
|
2012-02-16 03:08:08 +00:00
|
|
|
SetFloatVector(ShaderConstantRectD3D10(shadowDest.x / mSize.width, shadowDest.y / mSize.height,
|
2011-07-13 00:34:43 +00:00
|
|
|
Float(aSurface->GetSize().width) / mSize.width,
|
|
|
|
Float(aSurface->GetSize().height) / mSize.height));
|
2011-07-05 06:28:20 +00:00
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureWithShadow")->
|
|
|
|
GetPassByIndex(2)->Apply(0);
|
2012-09-18 23:04:42 +00:00
|
|
|
SetScissorToRect(&clipBounds);
|
2011-07-05 08:52:48 +00:00
|
|
|
} else {
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureWithShadow")->
|
|
|
|
GetPassByIndex(1)->Apply(0);
|
2011-07-05 06:28:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetBlendState(GetBlendStateForOperator(aOperator), nullptr, 0xffffffff);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mDevice->Draw(4, 0);
|
|
|
|
|
2015-11-19 23:04:46 +00:00
|
|
|
srView = static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView();
|
|
|
|
if (!srView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-13 00:34:43 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(-1.0f + ((aDest.x / mSize.width) * 2.0f),
|
|
|
|
1.0f - (aDest.y / mSize.height * 2.0f),
|
|
|
|
(Float(aSurface->GetSize().width) / mSize.width) * 2.0f,
|
|
|
|
(-Float(aSurface->GetSize().height) / mSize.height) * 2.0f));
|
2011-06-24 17:41:16 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView());
|
|
|
|
mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
|
2011-07-13 00:34:43 +00:00
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
|
2011-07-05 08:52:48 +00:00
|
|
|
if (mPushedClips.size()) {
|
2011-07-13 00:34:43 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("MaskTexCoords")->AsVector()->
|
2012-02-16 03:08:08 +00:00
|
|
|
SetFloatVector(ShaderConstantRectD3D10(aDest.x / mSize.width, aDest.y / mSize.height,
|
2011-07-13 00:34:43 +00:00
|
|
|
Float(aSurface->GetSize().width) / mSize.width,
|
|
|
|
Float(aSurface->GetSize().height) / mSize.height));
|
2011-07-05 08:52:48 +00:00
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleMaskedTexture")->
|
2011-07-05 06:28:20 +00:00
|
|
|
GetPassByIndex(0)->Apply(0);
|
2012-09-18 23:04:42 +00:00
|
|
|
// We've set the scissor rect here for the previous draw call.
|
2011-07-05 06:28:20 +00:00
|
|
|
} else {
|
2011-07-05 08:52:48 +00:00
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTexture")->
|
2011-07-05 06:28:20 +00:00
|
|
|
GetPassByIndex(0)->Apply(0);
|
|
|
|
}
|
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetBlendState(GetBlendStateForOperator(aOperator), nullptr, 0xffffffff);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mDevice->Draw(4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::ClearRect(const Rect &aRect)
|
|
|
|
{
|
2011-10-05 14:08:56 +00:00
|
|
|
MarkChanged();
|
2013-12-11 21:11:07 +00:00
|
|
|
PushClipRect(aRect);
|
2011-10-05 14:08:56 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
PopAllClips();
|
|
|
|
|
|
|
|
AutoSaveRestoreClippedOut restoreClippedOut(this);
|
|
|
|
|
2013-12-11 21:11:37 +00:00
|
|
|
D2D1_RECT_F clipRect;
|
|
|
|
bool isPixelAligned;
|
|
|
|
bool pushedClip = false;
|
|
|
|
if (mTransform.IsRectilinear() &&
|
|
|
|
GetDeviceSpaceClipRect(clipRect, isPixelAligned)) {
|
|
|
|
if (mTransformDirty ||
|
|
|
|
!mTransform.IsIdentity()) {
|
|
|
|
mRT->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRT->PushAxisAlignedClip(clipRect, isPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
|
|
|
pushedClip = true;
|
|
|
|
} else {
|
|
|
|
FlushTransformToRT();
|
|
|
|
restoreClippedOut.Save();
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mRT->Clear(D2D1::ColorF(0, 0.0f));
|
2013-12-11 21:11:37 +00:00
|
|
|
|
|
|
|
if (pushedClip) {
|
|
|
|
mRT->PopAxisAlignedClip();
|
|
|
|
}
|
|
|
|
|
2013-12-11 21:11:07 +00:00
|
|
|
PopClip();
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
|
|
|
const IntPoint &aDestination)
|
|
|
|
{
|
2011-10-05 14:08:56 +00:00
|
|
|
MarkChanged();
|
|
|
|
|
2011-06-29 21:34:58 +00:00
|
|
|
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));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mRT->SetTransform(D2D1::IdentityMatrix());
|
2011-12-09 09:53:14 +00:00
|
|
|
mTransformDirty = true;
|
2011-06-24 17:41:16 +00:00
|
|
|
mRT->PushAxisAlignedClip(D2DRect(dstRect), D2D1_ANTIALIAS_MODE_ALIASED);
|
|
|
|
mRT->Clear(D2D1::ColorF(0, 0.0f));
|
|
|
|
mRT->PopAxisAlignedClip();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap = GetBitmapForSurface(aSurface, srcRect);
|
2011-06-24 17:41:16 +00:00
|
|
|
if (!bitmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aSurface->GetFormat() == SurfaceFormat::A8) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
2013-12-19 18:44:20 +00:00
|
|
|
mRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),
|
2015-10-18 04:40:10 +00:00
|
|
|
D2D1::BrushProperties(), getter_AddRefs(brush));
|
2013-12-19 18:44:20 +00:00
|
|
|
mRT->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
|
|
|
mRT->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
|
|
|
|
} else {
|
|
|
|
mRT->DrawBitmap(bitmap, D2DRect(dstRect), 1.0f,
|
|
|
|
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
|
|
|
D2DRect(srcRect));
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-07-08 18:49:35 +00:00
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush) {
|
|
|
|
rt->FillRectangle(D2DRect(aRect), brush);
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, aRect);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-07-08 18:49:35 +00:00
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush && strokeStyle) {
|
|
|
|
rt->DrawRectangle(D2DRect(aRect), brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, aRect);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-07-08 18:49:35 +00:00
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush && strokeStyle) {
|
|
|
|
rt->DrawLine(D2DPoint(aStart), D2DPoint(aEnd), brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, Rect(0, 0, Float(mSize.width), Float(mSize.height)));
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D) {
|
2011-06-24 17:41:16 +00:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush && strokeStyle) {
|
|
|
|
rt->DrawGeometry(d2dPath->mGeometry, brush, aStrokeOptions.mLineWidth, strokeStyle);
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, Rect(0, 0, Float(mSize.width), Float(mSize.height)));
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D) {
|
2011-06-24 17:41:16 +00:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathD2D *d2dPath = static_cast<const PathD2D*>(aPath);
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
rt->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush) {
|
|
|
|
rt->FillGeometry(d2dPath->mGeometry, brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect bounds;
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOptions.mCompositionOp != CompositionOp::OP_OVER) {
|
2011-06-24 17:41:16 +00:00
|
|
|
D2D1_RECT_F d2dbounds;
|
|
|
|
d2dPath->mGeometry->GetBounds(D2D1::IdentityMatrix(), &d2dbounds);
|
|
|
|
bounds = ToRect(d2dbounds);
|
|
|
|
}
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, bounds);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
2012-03-19 19:20:17 +00:00
|
|
|
const DrawOptions &aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderOptions)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aFont->GetType() != FontType::DWRITE) {
|
2011-06-24 17:41:16 +00:00
|
|
|
gfxDebug() << *this << ": Ignoring drawing call for incompatible font.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScaledFontDWrite *font = static_cast<ScaledFontDWrite*>(aFont);
|
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
IDWriteRenderingParams *params = nullptr;
|
2012-03-19 19:20:17 +00:00
|
|
|
if (aRenderOptions) {
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aRenderOptions->GetType() != FontType::DWRITE) {
|
2012-06-26 00:59:18 +00:00
|
|
|
gfxDebug() << *this << ": Ignoring incompatible GlyphRenderingOptions.";
|
|
|
|
// This should never happen.
|
|
|
|
MOZ_ASSERT(false);
|
2012-03-19 19:20:17 +00:00
|
|
|
} else {
|
|
|
|
params = static_cast<const GlyphRenderingOptionsDWrite*>(aRenderOptions)->mParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 01:53:12 +00:00
|
|
|
AntialiasMode aaMode = font->GetDefaultAAMode();
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOptions.mAntialiasMode != AntialiasMode::DEFAULT) {
|
2012-11-23 01:53:12 +00:00
|
|
|
aaMode = aOptions.mAntialiasMode;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
if (mFormat == SurfaceFormat::B8G8R8A8 && mPermitSubpixelAA &&
|
2014-01-10 19:06:17 +00:00
|
|
|
aOptions.mCompositionOp == CompositionOp::OP_OVER && aPattern.GetType() == PatternType::COLOR &&
|
|
|
|
aaMode == AntialiasMode::SUBPIXEL) {
|
2012-05-15 14:57:51 +00:00
|
|
|
if (FillGlyphsManual(font, aBuffer,
|
|
|
|
static_cast<const ColorPattern*>(&aPattern)->mColor,
|
|
|
|
params, aOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aPattern);
|
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2012-11-23 01:53:12 +00:00
|
|
|
D2D1_TEXT_ANTIALIAS_MODE d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
|
|
|
|
|
|
switch (aaMode) {
|
2014-01-10 19:06:17 +00:00
|
|
|
case AntialiasMode::NONE:
|
2012-11-23 01:53:12 +00:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case AntialiasMode::GRAY:
|
2012-11-23 01:53:12 +00:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case AntialiasMode::SUBPIXEL:
|
2012-11-23 01:53:12 +00:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d2dAAMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE &&
|
2014-01-10 19:06:16 +00:00
|
|
|
mFormat != SurfaceFormat::B8G8R8X8) {
|
2012-11-23 01:53:12 +00:00
|
|
|
d2dAAMode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt->SetTextAntialiasMode(d2dAAMode);
|
|
|
|
|
2012-06-26 00:59:18 +00:00
|
|
|
if (rt != mRT || params != mTextRenderingParams) {
|
|
|
|
rt->SetTextRenderingParams(params);
|
|
|
|
if (rt == mRT) {
|
|
|
|
mTextRenderingParams = params;
|
|
|
|
}
|
|
|
|
}
|
2012-03-19 19:20:17 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
AutoDWriteGlyphRun autoRun;
|
|
|
|
DWriteGlyphRunFromGlyphs(aBuffer, font, &autoRun);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (brush) {
|
2012-05-15 14:57:51 +00:00
|
|
|
rt->DrawGlyphRun(D2D1::Point2F(), &autoRun, brush);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aPattern, Rect(0, 0, (Float)mSize.width, (Float)mSize.height));
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
ID2D1RenderTarget *rt = GetRTForOperation(aOptions.mCompositionOp, aSource);
|
|
|
|
|
|
|
|
PrepareForDrawing(rt);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aSource, aOptions.mAlpha);
|
|
|
|
RefPtr<ID2D1Brush> maskBrush = CreateBrushForPattern(aMask, 1.0f);
|
2011-12-28 05:56:11 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Layer> layer;
|
2012-06-20 21:41:16 +00:00
|
|
|
|
|
|
|
layer = GetCachedLayer();
|
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
rt->PushLayer(D2D1::LayerParameters(D2D1::InfiniteRect(), nullptr,
|
2011-12-28 05:56:11 +00:00
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
|
|
|
D2D1::IdentityMatrix(),
|
|
|
|
1.0f, maskBrush),
|
|
|
|
layer);
|
|
|
|
|
2012-09-28 17:21:40 +00:00
|
|
|
Rect rect(0, 0, (Float)mSize.width, (Float)mSize.height);
|
2011-12-28 05:56:11 +00:00
|
|
|
Matrix mat = mTransform;
|
|
|
|
mat.Invert();
|
|
|
|
|
|
|
|
rt->FillRectangle(D2DRect(mat.TransformBounds(rect)), brush);
|
2012-06-20 21:41:16 +00:00
|
|
|
PopCachedLayer(rt);
|
2011-12-28 05:56:11 +00:00
|
|
|
|
|
|
|
FinalizeRTForOperation(aOptions.mCompositionOp, aSource, Rect(0, 0, (Float)mSize.width, (Float)mSize.height));
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::PushClip(const Path *aPath)
|
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aPath->GetBackendType() != BackendType::DIRECT2D) {
|
2011-06-24 17:41:16 +00:00
|
|
|
gfxDebug() << *this << ": Ignoring clipping call for incompatible path.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
mCurrentClipMaskTexture = nullptr;
|
|
|
|
mCurrentClippedGeometry = nullptr;
|
2012-05-15 14:57:51 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathD2D> pathD2D = static_cast<PathD2D*>(const_cast<Path*>(aPath));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
PushedClip clip;
|
|
|
|
clip.mTransform = D2DMatrix(mTransform);
|
|
|
|
clip.mPath = pathD2D;
|
|
|
|
|
|
|
|
pathD2D->mGeometry->GetBounds(clip.mTransform, &clip.mBounds);
|
2012-06-20 21:41:16 +00:00
|
|
|
|
|
|
|
clip.mLayer = GetCachedLayer();
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
mRT->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
mTransformDirty = true;
|
|
|
|
|
|
|
|
if (mClipsArePushed) {
|
2012-10-08 10:17:17 +00:00
|
|
|
PushD2DLayer(mRT, pathD2D->mGeometry, clip.mLayer, clip.mTransform);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::PushClipRect(const Rect &aRect)
|
|
|
|
{
|
2012-08-14 18:06:12 +00:00
|
|
|
mCurrentClipMaskTexture = nullptr;
|
|
|
|
mCurrentClippedGeometry = nullptr;
|
2011-12-28 05:56:11 +00:00
|
|
|
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
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> pathBuilder = CreatePathBuilder();
|
2011-12-28 05:56:11 +00:00
|
|
|
pathBuilder->MoveTo(aRect.TopLeft());
|
|
|
|
pathBuilder->LineTo(aRect.TopRight());
|
|
|
|
pathBuilder->LineTo(aRect.BottomRight());
|
|
|
|
pathBuilder->LineTo(aRect.BottomLeft());
|
|
|
|
pathBuilder->Close();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> path = pathBuilder->Finish();
|
2011-12-28 05:56:11 +00:00
|
|
|
return PushClip(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
PushedClip clip;
|
2012-09-18 23:04:42 +00:00
|
|
|
Rect rect = mTransform.TransformBounds(aRect);
|
|
|
|
IntRect intRect;
|
|
|
|
clip.mIsPixelAligned = rect.ToIntRect(&intRect);
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
// Do not store the transform, just store the device space rectangle directly.
|
2012-09-18 23:04:42 +00:00
|
|
|
clip.mBounds = D2DRect(rect);
|
2011-12-28 05:56:11 +00:00
|
|
|
|
|
|
|
mPushedClips.push_back(clip);
|
|
|
|
|
|
|
|
mRT->SetTransform(D2D1::IdentityMatrix());
|
2012-03-15 20:26:10 +00:00
|
|
|
mTransformDirty = true;
|
2012-09-18 23:04:42 +00:00
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
if (mClipsArePushed) {
|
2012-09-18 23:04:42 +00:00
|
|
|
mRT->PushAxisAlignedClip(clip.mBounds, clip.mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
2011-12-28 05:56:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::PopClip()
|
|
|
|
{
|
2012-08-14 18:06:12 +00:00
|
|
|
mCurrentClipMaskTexture = nullptr;
|
|
|
|
mCurrentClippedGeometry = nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
if (mClipsArePushed) {
|
2011-12-28 05:56:11 +00:00
|
|
|
if (mPushedClips.back().mLayer) {
|
2012-06-20 21:41:16 +00:00
|
|
|
PopCachedLayer(mRT);
|
2011-12-28 05:56:11 +00:00
|
|
|
} else {
|
|
|
|
mRT->PopAxisAlignedClip();
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
mPushedClips.pop_back();
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurfaceD2D> newSurf = new SourceSurfaceD2D();
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (!newSurf->InitFromData(aData, aSize, aStride, aFormat, mRT)) {
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return newSurf.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::OptimizeSourceSurface(SourceSurface *aSurface) const
|
|
|
|
{
|
2014-04-17 00:45:25 +00:00
|
|
|
if (aSurface->GetType() == SurfaceType::D2D1_BITMAP ||
|
|
|
|
aSurface->GetType() == SurfaceType::D2D1_DRAWTARGET) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
2015-04-30 19:20:30 +00:00
|
|
|
return surface.forget();
|
2014-04-17 00:45:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
|
2014-04-17 00:45:25 +00:00
|
|
|
|
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
if (!data->Map(DataSourceSurface::MapType::READ, &map)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurfaceD2D> newSurf = new SourceSurfaceD2D();
|
2014-04-17 00:45:25 +00:00
|
|
|
bool success = newSurf->InitFromData(map.mData, data->GetSize(), map.mStride, data->GetFormat(), mRT);
|
|
|
|
|
|
|
|
data->Unmap();
|
|
|
|
|
|
|
|
if (!success) {
|
2014-06-13 16:09:23 +00:00
|
|
|
return data.forget();
|
2014-04-17 00:45:25 +00:00
|
|
|
}
|
2014-06-13 16:09:23 +00:00
|
|
|
return newSurf.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
|
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aSurface.mType != NativeSurfaceType::D3D10_TEXTURE) {
|
2011-06-24 17:41:16 +00:00
|
|
|
gfxDebug() << *this << ": Failure to create source surface from non-D3D10 texture native surface.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurfaceD2D> newSurf = new SourceSurfaceD2D();
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (!newSurf->InitFromTexture(static_cast<ID3D10Texture2D*>(aSurface.mSurface),
|
|
|
|
aSurface.mFormat,
|
|
|
|
mRT))
|
|
|
|
{
|
|
|
|
gfxWarning() << *this << ": Failed to create SourceSurface from texture.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return newSurf.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<DrawTarget>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTargetD2D> newTarget =
|
2011-06-24 17:41:16 +00:00
|
|
|
new DrawTargetD2D();
|
|
|
|
|
|
|
|
if (!newTarget->Init(aSize, aFormat)) {
|
|
|
|
gfxDebug() << *this << ": Failed to create optimal draw target. Size: " << aSize;
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return newTarget.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<PathBuilder>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::CreatePathBuilder(FillRule aFillRule) const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1PathGeometry> path;
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = factory()->CreatePathGeometry(getter_AddRefs(path));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to create Direct2D Path Geometry. Code: " << hexa(hr);
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1GeometrySink> sink;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = path->Open(getter_AddRefs(sink));
|
2011-06-24 17:41:16 +00:00
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aFillRule == FillRule::FILL_WINDING) {
|
2011-06-24 17:41:16 +00:00
|
|
|
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:20:30 +00:00
|
|
|
return MakeAndAddRef<PathBuilderD2D>(sink, path, aFillRule, BackendType::DIRECT2D);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<GradientStops>
|
2011-12-28 05:56:11 +00:00
|
|
|
DrawTargetD2D::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2011-12-28 05:09:44 +00:00
|
|
|
D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops];
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
2011-07-08 18:49:35 +00:00
|
|
|
stops[i].position = rawStops[i].offset;
|
|
|
|
stops[i].color = D2DColor(rawStops[i].color);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1GradientStopCollection> stopCollection;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
HRESULT hr =
|
|
|
|
mRT->CreateGradientStopCollection(stops, aNumStops,
|
|
|
|
D2D1_GAMMA_2_2, D2DExtend(aExtendMode),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(stopCollection));
|
2011-12-28 05:56:11 +00:00
|
|
|
delete [] stops;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to create GradientStopCollection. Code: " << hexa(hr);
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 19:20:30 +00:00
|
|
|
return MakeAndAddRef<GradientStopsD2D>(stopCollection, Factory::GetDirect3D11Device());
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<FilterNode>
|
2013-11-27 11:22:56 +00:00
|
|
|
DrawTargetD2D::CreateFilter(FilterType aType)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1DeviceContext> dc;
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mRT->QueryInterface((ID2D1DeviceContext**)getter_AddRefs(dc));
|
2013-11-27 11:25:16 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
2014-09-25 19:18:29 +00:00
|
|
|
return FilterNodeD2D1::Create(dc, aType);
|
2013-11-27 11:25:16 +00:00
|
|
|
}
|
2013-11-27 11:22:56 +00:00
|
|
|
return FilterNodeSoftware::Create(aType);
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
void*
|
|
|
|
DrawTargetD2D::GetNativeSurface(NativeSurfaceType aType)
|
|
|
|
{
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aType != NativeSurfaceType::D3D10_TEXTURE) {
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
DrawTargetD2D::Init(const IntSize &aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
mSize = aSize;
|
|
|
|
mFormat = aFormat;
|
|
|
|
|
|
|
|
if (!Factory::GetDirect3D10Device()) {
|
2014-09-18 22:01:25 +00:00
|
|
|
gfxCriticalError() << "Failed to Init Direct2D DrawTarget (No D3D10 Device set.)";
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mDevice = Factory::GetDirect3D10Device();
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGIFormat(aFormat),
|
2011-06-24 17:41:16 +00:00
|
|
|
mSize.width,
|
|
|
|
mSize.height,
|
|
|
|
1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(mTexture));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-12-17 22:54:04 +00:00
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(aSize))) << "Failed to init Direct2D DrawTarget. Size: " << mSize << " Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
if (!InitD2DRenderTarget()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRT->Clear(D2D1::ColorF(0, 0));
|
|
|
|
return true;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetD2D::Init(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
mTexture = aTexture;
|
|
|
|
mFormat = aFormat;
|
|
|
|
|
|
|
|
if (!mTexture) {
|
2014-11-20 14:48:07 +00:00
|
|
|
gfxCriticalError() << "No valid texture for Direct2D draw target initialization.";
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Device> device;
|
2015-10-18 04:40:10 +00:00
|
|
|
mTexture->GetDevice(getter_AddRefs(device));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = device->QueryInterface((ID3D10Device1**)getter_AddRefs(mDevice));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-07-14 19:22:29 +00:00
|
|
|
gfxCriticalError() << "Failed to get D3D10 device from texture." << " format " << (int)aFormat;
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
mTexture->GetDesc(&desc);
|
|
|
|
mSize.width = desc.Width;
|
|
|
|
mSize.height = desc.Height;
|
|
|
|
|
|
|
|
return InitD2DRenderTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// {0D398B49-AE7B-416F-B26D-EA3C137D1CF7}
|
|
|
|
static const GUID sPrivateDataD2D =
|
|
|
|
{ 0xd398b49, 0xae7b, 0x416f, { 0xb2, 0x6d, 0xea, 0x3c, 0x13, 0x7d, 0x1c, 0xf7 } };
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetD2D::InitD3D10Data()
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
UINT privateDataSize;
|
|
|
|
privateDataSize = sizeof(mPrivateData);
|
|
|
|
hr = mDevice->GetPrivateData(sPrivateDataD2D, &privateDataSize, &mPrivateData);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrivateData = new PrivateD3D10DataD2D;
|
|
|
|
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(D3D10CreateEffectFromMemory)* createD3DEffect;
|
2011-06-24 17:41:16 +00:00
|
|
|
HMODULE d3dModule = LoadLibraryW(L"d3d10_1.dll");
|
2014-02-17 22:32:52 +00:00
|
|
|
createD3DEffect = (decltype(D3D10CreateEffectFromMemory)*)
|
2011-06-24 17:41:16 +00:00
|
|
|
GetProcAddress(d3dModule, "D3D10CreateEffectFromMemory");
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = createD3DEffect((void*)d2deffect, sizeof(d2deffect), 0, mDevice, nullptr, getter_AddRefs(mPrivateData->mEffect));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to initialize Direct2D required effects. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
privateDataSize = sizeof(mPrivateData);
|
|
|
|
mDevice->SetPrivateData(sPrivateDataD2D, privateDataSize, &mPrivateData);
|
|
|
|
|
|
|
|
D3D10_INPUT_ELEMENT_DESC layout[] =
|
|
|
|
{
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
};
|
|
|
|
D3D10_PASS_DESC passDesc;
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTexture")->GetPassByIndex(0)->GetDesc(&passDesc);
|
|
|
|
|
|
|
|
hr = mDevice->CreateInputLayout(layout,
|
|
|
|
sizeof(layout) / sizeof(D3D10_INPUT_ELEMENT_DESC),
|
|
|
|
passDesc.pIAInputSignature,
|
|
|
|
passDesc.IAInputSignatureSize,
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(mPrivateData->mInputLayout));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to initialize Direct2D required InputLayout. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_SUBRESOURCE_DATA data;
|
|
|
|
Vertex vertices[] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}, {1.0, 1.0} };
|
|
|
|
data.pSysMem = vertices;
|
|
|
|
CD3D10_BUFFER_DESC bufferDesc(sizeof(vertices), D3D10_BIND_VERTEX_BUFFER);
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateBuffer(&bufferDesc, &data, getter_AddRefs(mPrivateData->mVB));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << "Failed to initialize Direct2D required VertexBuffer. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private helpers
|
|
|
|
*/
|
2012-06-20 21:41:16 +00:00
|
|
|
uint32_t
|
|
|
|
DrawTargetD2D::GetByteSize() const
|
|
|
|
{
|
|
|
|
return mSize.width * mSize.height * BytesPerPixel(mFormat);
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1Layer>
|
2012-06-20 21:41:16 +00:00
|
|
|
DrawTargetD2D::GetCachedLayer()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Layer> layer;
|
2012-06-20 21:41:16 +00:00
|
|
|
|
|
|
|
if (mCurrentCachedLayer < 5) {
|
|
|
|
if (!mCachedLayers[mCurrentCachedLayer]) {
|
2015-10-18 04:40:10 +00:00
|
|
|
mRT->CreateLayer(getter_AddRefs(mCachedLayers[mCurrentCachedLayer]));
|
2012-06-20 21:41:16 +00:00
|
|
|
mVRAMUsageDT += GetByteSize();
|
|
|
|
}
|
|
|
|
layer = mCachedLayers[mCurrentCachedLayer];
|
|
|
|
} else {
|
2015-10-18 04:40:10 +00:00
|
|
|
mRT->CreateLayer(getter_AddRefs(layer));
|
2012-06-20 21:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentCachedLayer++;
|
2014-06-13 16:09:23 +00:00
|
|
|
return layer.forget();
|
2012-06-20 21:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::PopCachedLayer(ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
aRT->PopLayer();
|
|
|
|
mCurrentCachedLayer--;
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
bool
|
|
|
|
DrawTargetD2D::InitD2DRenderTarget()
|
|
|
|
{
|
|
|
|
if (!factory()) {
|
2014-09-18 22:01:25 +00:00
|
|
|
gfxCriticalError() << "No valid D2D factory available.";
|
2011-06-24 17:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
mRT = CreateRTForTexture(mTexture, mFormat);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (!mRT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRT->BeginDraw();
|
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
if (mFormat == SurfaceFormat::B8G8R8X8) {
|
2011-08-16 02:37:00 +00:00
|
|
|
mRT->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE);
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:41:16 +00:00
|
|
|
mVRAMUsageDT += GetByteSize();
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
return InitD3D10Data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::PrepareForDrawing(ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
if (!mClipsArePushed || aRT == mTempRT) {
|
|
|
|
if (mPushedClips.size()) {
|
|
|
|
// The transform of clips is relative to the world matrix, since we use the total
|
|
|
|
// transform for the clips, make the world matrix identity.
|
2011-12-28 05:56:11 +00:00
|
|
|
aRT->SetTransform(D2D1::IdentityMatrix());
|
|
|
|
if (aRT == mRT) {
|
|
|
|
mTransformDirty = true;
|
|
|
|
mClipsArePushed = true;
|
|
|
|
}
|
2012-05-15 14:57:51 +00:00
|
|
|
PushClipsToRT(aRT);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 09:53:14 +00:00
|
|
|
FlushTransformToRT();
|
2011-06-24 17:41:16 +00:00
|
|
|
MarkChanged();
|
|
|
|
|
|
|
|
if (aRT == mTempRT) {
|
|
|
|
mTempRT->SetTransform(D2DMatrix(mTransform));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::MarkChanged()
|
|
|
|
{
|
2011-12-09 09:51:57 +00:00
|
|
|
if (mSnapshot) {
|
|
|
|
if (mSnapshot->hasOneRef()) {
|
|
|
|
// Just destroy it, since no-one else knows about it.
|
2012-08-14 18:06:12 +00:00
|
|
|
mSnapshot = nullptr;
|
2011-12-09 09:51:57 +00:00
|
|
|
} else {
|
|
|
|
mSnapshot->DrawTargetWillChange();
|
|
|
|
// The snapshot will no longer depend on this target.
|
|
|
|
MOZ_ASSERT(!mSnapshot);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDependentTargets.size()) {
|
2011-11-25 02:12:40 +00:00
|
|
|
// Copy mDependentTargets since the Flush()es below will modify it.
|
2011-12-09 09:51:57 +00:00
|
|
|
TargetSet tmpTargets = mDependentTargets;
|
|
|
|
for (TargetSet::iterator iter = tmpTargets.begin();
|
2011-11-25 02:12:40 +00:00
|
|
|
iter != tmpTargets.end(); iter++) {
|
2011-06-24 17:41:16 +00:00
|
|
|
(*iter)->Flush();
|
|
|
|
}
|
2011-11-25 02:12:40 +00:00
|
|
|
// The Flush() should have broken all dependencies on this target.
|
|
|
|
MOZ_ASSERT(!mDependentTargets.size());
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3D10BlendState*
|
|
|
|
DrawTargetD2D::GetBlendStateForOperator(CompositionOp aOperator)
|
|
|
|
{
|
2014-01-12 06:26:20 +00:00
|
|
|
size_t operatorIndex = static_cast<size_t>(aOperator);
|
|
|
|
if (mPrivateData->mBlendStates[operatorIndex]) {
|
|
|
|
return mPrivateData->mBlendStates[operatorIndex];
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_BLEND_DESC desc;
|
|
|
|
|
|
|
|
memset(&desc, 0, sizeof(D3D10_BLEND_DESC));
|
|
|
|
|
|
|
|
desc.AlphaToCoverageEnable = FALSE;
|
|
|
|
desc.BlendEnable[0] = TRUE;
|
|
|
|
desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
|
|
|
|
desc.BlendOp = desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
|
|
|
|
|
|
|
|
switch (aOperator) {
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_ADD:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_IN:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_OUT:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_ATOP:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_DEST_IN:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_SRC_ALPHA;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_DEST_OUT:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_DEST_ATOP:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_SRC_ALPHA;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_DEST_OVER:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_XOR:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
|
|
|
break;
|
2014-01-10 19:06:17 +00:00
|
|
|
case CompositionOp::OP_SOURCE:
|
2011-06-24 17:41:16 +00:00
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
desc.SrcBlend = desc.SrcBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
desc.DestBlend = desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateBlendState(&desc, getter_AddRefs(mPrivateData->mBlendStates[operatorIndex]));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2014-01-12 06:26:20 +00:00
|
|
|
return mPrivateData->mBlendStates[operatorIndex];
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function prepares the temporary RT for drawing and returns it when a
|
|
|
|
* drawing operation other than OVER is required.
|
|
|
|
*/
|
|
|
|
ID2D1RenderTarget*
|
2011-07-08 18:49:35 +00:00
|
|
|
DrawTargetD2D::GetRTForOperation(CompositionOp aOperator, const Pattern &aPattern)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOperator == CompositionOp::OP_OVER && IsPatternSupportedByD2D(aPattern)) {
|
2011-06-24 17:41:16 +00:00
|
|
|
return mRT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PopAllClips();
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOperator > CompositionOp::OP_XOR) {
|
2012-12-12 20:28:17 +00:00
|
|
|
mRT->Flush();
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
if (mTempRT) {
|
|
|
|
mTempRT->Clear(D2D1::ColorF(0, 0));
|
|
|
|
return mTempRT;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsureViews();
|
|
|
|
|
|
|
|
if (!mRTView || !mSRView) {
|
2014-01-10 19:06:17 +00:00
|
|
|
gfxDebug() << *this << ": Failed to get required views. Defaulting to CompositionOp::OP_OVER.";
|
2011-06-24 17:41:16 +00:00
|
|
|
return mRT;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
mTempRT = CreateRTForTexture(mTempTexture, SurfaceFormat::B8G8R8A8);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (!mTempRT) {
|
|
|
|
return mRT;
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:41:16 +00:00
|
|
|
mVRAMUsageDT += GetByteSize();
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
mTempRT->BeginDraw();
|
|
|
|
|
|
|
|
mTempRT->Clear(D2D1::ColorF(0, 0));
|
|
|
|
|
|
|
|
return mTempRT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function blends back the content of a drawing operation (drawn to an
|
|
|
|
* empty surface with OVER, so the surface now contains the source operation
|
|
|
|
* contents) to the rendertarget using the requested composition operation.
|
|
|
|
* In order to respect clip for operations which are unbound by their mask,
|
|
|
|
* the old content of the surface outside the clipped area may be blended back
|
|
|
|
* to the surface.
|
|
|
|
*/
|
|
|
|
void
|
2011-07-08 18:49:35 +00:00
|
|
|
DrawTargetD2D::FinalizeRTForOperation(CompositionOp aOperator, const Pattern &aPattern, const Rect &aBounds)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOperator == CompositionOp::OP_OVER && IsPatternSupportedByD2D(aPattern)) {
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTempRT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
PopClipsFromRT(mTempRT);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
mRT->Flush();
|
|
|
|
mTempRT->Flush();
|
|
|
|
|
|
|
|
AutoSaveRestoreClippedOut restoreClippedOut(this);
|
|
|
|
|
|
|
|
bool needsWriteBack =
|
|
|
|
!IsOperatorBoundByMask(aOperator) && mPushedClips.size();
|
|
|
|
|
|
|
|
if (needsWriteBack) {
|
|
|
|
restoreClippedOut.Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3D10RenderTargetView *rtViews = mRTView;
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetRenderTargets(1, &rtViews, nullptr);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
UINT stride = sizeof(Vertex);
|
|
|
|
UINT offset = 0;
|
|
|
|
ID3D10Buffer *buff = mPrivateData->mVB;
|
|
|
|
|
|
|
|
mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
mDevice->IASetVertexBuffers(0, 1, &buff, &stride, &offset);
|
|
|
|
mDevice->IASetInputLayout(mPrivateData->mInputLayout);
|
|
|
|
|
|
|
|
D3D10_VIEWPORT viewport;
|
|
|
|
viewport.MaxDepth = 1;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Height = mSize.height;
|
|
|
|
viewport.Width = mSize.width;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tmpTexture;
|
|
|
|
RefPtr<ID3D10ShaderResourceView> mBckSRView;
|
2012-12-12 20:28:17 +00:00
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(-1.0f, 1.0f, 2.0f, -2.0f));
|
|
|
|
|
2012-12-20 06:16:45 +00:00
|
|
|
if (IsPatternSupportedByD2D(aPattern)) {
|
2011-07-08 18:49:35 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(mSRView);
|
2012-12-12 20:28:17 +00:00
|
|
|
|
|
|
|
// Handle the case where we blend with the backdrop
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOperator > CompositionOp::OP_XOR) {
|
2012-12-12 20:28:17 +00:00
|
|
|
IntSize size = mSize;
|
|
|
|
SurfaceFormat format = mFormat;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGIFormat(format), size.width, size.height, 1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(tmpTexture));
|
2012-12-12 20:28:17 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create temporary texture to hold surface data.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice->CopyResource(tmpTexture, mTexture);
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
|
2012-12-12 20:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetD2D::Flush();
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateShaderResourceView(tmpTexture, nullptr, getter_AddRefs(mBckSRView));
|
2012-12-12 20:28:17 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
|
2012-12-12 20:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
unsigned int compop = (unsigned int)aOperator - (unsigned int)CompositionOp::OP_XOR;
|
2012-12-12 20:28:17 +00:00
|
|
|
mPrivateData->mEffect->GetVariableByName("bcktex")->AsShaderResource()->SetResource(mBckSRView);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("blendop")->AsScalar()->SetInt(compop);
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aOperator > CompositionOp::OP_EXCLUSION)
|
2012-12-12 20:28:17 +00:00
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureForNonSeparableBlending")->
|
|
|
|
GetPassByIndex(0)->Apply(0);
|
2014-01-10 19:06:17 +00:00
|
|
|
else if (aOperator > CompositionOp::OP_COLOR_DODGE)
|
2012-12-12 20:28:17 +00:00
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureForSeparableBlending_2")->
|
|
|
|
GetPassByIndex(0)->Apply(0);
|
|
|
|
else
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTextureForSeparableBlending_1")->
|
|
|
|
GetPassByIndex(0)->Apply(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleTexture")->GetPassByIndex(0)->Apply(0);
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
} else if (aPattern.GetType() == PatternType::RADIAL_GRADIENT) {
|
2011-07-08 18:49:35 +00:00
|
|
|
const RadialGradientPattern *pat = static_cast<const RadialGradientPattern*>(&aPattern);
|
|
|
|
|
|
|
|
if (pat->mCenter1 == pat->mCenter2 && pat->mRadius1 == pat->mRadius2) {
|
|
|
|
// Draw nothing!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("mask")->AsShaderResource()->SetResource(mSRView);
|
|
|
|
|
|
|
|
SetupEffectForRadialGradient(pat);
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetBlendState(GetBlendStateForOperator(aOperator), nullptr, 0xffffffff);
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
SetScissorToRect(nullptr);
|
2011-06-24 17:41:16 +00:00
|
|
|
mDevice->Draw(4, 0);
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:18:36 +00: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);
|
2013-12-11 21:11:37 +00:00
|
|
|
|
|
|
|
result.right = max(result.right, result.left);
|
|
|
|
result.bottom = max(result.bottom, result.top);
|
|
|
|
|
2012-08-10 11:18:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-11 21:11:37 +00:00
|
|
|
bool
|
|
|
|
DrawTargetD2D::GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned)
|
|
|
|
{
|
|
|
|
if (!mPushedClips.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DrawTargetD2D::PushedClip>::iterator iter = mPushedClips.begin();
|
|
|
|
if (iter->mPath) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aClipRect = iter->mBounds;
|
|
|
|
aIsPixelAligned = iter->mIsPixelAligned;
|
|
|
|
|
|
|
|
iter++;
|
|
|
|
for (;iter != mPushedClips.end(); iter++) {
|
|
|
|
if (iter->mPath) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aClipRect = IntersectRect(aClipRect, iter->mBounds);
|
|
|
|
if (!iter->mIsPixelAligned) {
|
|
|
|
aIsPixelAligned = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1Geometry>
|
2012-09-18 23:04:42 +00:00
|
|
|
DrawTargetD2D::GetClippedGeometry(IntRect *aClipBounds)
|
2011-07-05 06:28:20 +00:00
|
|
|
{
|
2012-05-15 14:57:51 +00:00
|
|
|
if (mCurrentClippedGeometry) {
|
2012-09-18 23:04:42 +00:00
|
|
|
*aClipBounds = mCurrentClipBounds;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
2015-05-01 13:14:16 +00:00
|
|
|
return clippedGeometry.forget();
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
mCurrentClipBounds = IntRect(IntPoint(0, 0), mSize);
|
|
|
|
|
2012-08-10 11:18:36 +00:00
|
|
|
// if pathGeom is null then pathRect represents the path.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> pathGeom;
|
2012-08-10 11:18:36 +00:00
|
|
|
D2D1_RECT_F pathRect;
|
2012-09-18 23:04:42 +00:00
|
|
|
bool pathRectIsAxisAligned = false;
|
2011-07-05 06:28:20 +00:00
|
|
|
std::vector<DrawTargetD2D::PushedClip>::iterator iter = mPushedClips.begin();
|
2012-09-18 23:04:42 +00:00
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
if (iter->mPath) {
|
2012-09-18 23:04:42 +00:00
|
|
|
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
|
2012-05-15 14:57:51 +00:00
|
|
|
} else {
|
2012-08-10 11:18:36 +00:00
|
|
|
pathRect = iter->mBounds;
|
2012-09-18 23:04:42 +00:00
|
|
|
pathRectIsAxisAligned = iter->mIsPixelAligned;
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
2011-07-05 06:28:20 +00:00
|
|
|
|
|
|
|
iter++;
|
|
|
|
for (;iter != mPushedClips.end(); iter++) {
|
2012-09-18 23:04:42 +00:00
|
|
|
// Do nothing but add it to the current clip bounds.
|
|
|
|
if (!iter->mPath && iter->mIsPixelAligned) {
|
|
|
|
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
|
2012-09-28 17:21:40 +00:00
|
|
|
IntRect(int32_t(iter->mBounds.left), int32_t(iter->mBounds.top),
|
2012-09-18 23:04:42 +00:00
|
|
|
int32_t(iter->mBounds.right - iter->mBounds.left),
|
|
|
|
int32_t(iter->mBounds.bottom - iter->mBounds.top)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-10 11:18:36 +00:00
|
|
|
if (!pathGeom) {
|
2012-09-18 23:04:42 +00:00
|
|
|
if (pathRectIsAxisAligned) {
|
|
|
|
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
|
2012-09-28 17:21:40 +00:00
|
|
|
IntRect(int32_t(pathRect.left), int32_t(pathRect.top),
|
2012-09-18 23:04:42 +00:00
|
|
|
int32_t(pathRect.right - pathRect.left),
|
|
|
|
int32_t(pathRect.bottom - pathRect.top)));
|
|
|
|
}
|
2012-08-10 11:18:36 +00:00
|
|
|
if (iter->mPath) {
|
2012-09-18 23:04:42 +00:00
|
|
|
// See if pathRect needs to go into the path geometry.
|
|
|
|
if (!pathRectIsAxisAligned) {
|
|
|
|
pathGeom = ConvertRectToGeometry(pathRect);
|
|
|
|
} else {
|
|
|
|
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
|
|
|
|
}
|
2012-08-10 11:18:36 +00:00
|
|
|
} else {
|
|
|
|
pathRect = IntersectRect(pathRect, iter->mBounds);
|
2012-09-18 23:04:42 +00:00
|
|
|
pathRectIsAxisAligned = false;
|
2012-08-10 11:18:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1PathGeometry> newGeom;
|
2015-10-18 04:40:10 +00:00
|
|
|
factory()->CreatePathGeometry(getter_AddRefs(newGeom));
|
2011-07-05 06:28:20 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1GeometrySink> currentSink;
|
2015-10-18 04:40:10 +00:00
|
|
|
newGeom->Open(getter_AddRefs(currentSink));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (iter->mPath) {
|
2012-08-10 11:18:36 +00:00
|
|
|
pathGeom->CombineWithGeometry(iter->mPath->GetGeometry(), D2D1_COMBINE_MODE_INTERSECT,
|
|
|
|
iter->mTransform, currentSink);
|
2012-05-15 14:57:51 +00:00
|
|
|
} else {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> rectGeom = ConvertRectToGeometry(iter->mBounds);
|
2012-08-10 11:18:36 +00:00
|
|
|
pathGeom->CombineWithGeometry(rectGeom, D2D1_COMBINE_MODE_INTERSECT,
|
|
|
|
D2D1::IdentityMatrix(), currentSink);
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
2011-07-05 06:28:20 +00:00
|
|
|
|
|
|
|
currentSink->Close();
|
|
|
|
|
2012-08-10 11:18:36 +00:00
|
|
|
pathGeom = newGeom.forget();
|
2011-07-05 06:28:20 +00:00
|
|
|
}
|
|
|
|
|
2013-07-20 08:48:55 +00:00
|
|
|
// 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.
|
2012-08-10 11:18:36 +00:00
|
|
|
if (!pathGeom) {
|
|
|
|
pathGeom = ConvertRectToGeometry(pathRect);
|
|
|
|
}
|
|
|
|
mCurrentClippedGeometry = pathGeom.forget();
|
2012-09-18 23:04:42 +00:00
|
|
|
*aClipBounds = mCurrentClipBounds;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> clippedGeometry(mCurrentClippedGeometry);
|
2015-05-01 13:14:16 +00:00
|
|
|
return clippedGeometry.forget();
|
2011-07-05 06:28:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1RenderTarget>
|
2012-05-15 14:57:51 +00:00
|
|
|
DrawTargetD2D::CreateRTForTexture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDXGISurface> surface;
|
|
|
|
RefPtr<ID2D1RenderTarget> rt;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = aTexture->QueryInterface((IDXGISurface**)getter_AddRefs(surface));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-06-09 20:48:59 +00:00
|
|
|
gfxCriticalError() << "Failed to QI texture to surface. Code: " << hexa(hr);
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
aTexture->GetDesc(&desc);
|
|
|
|
|
2011-08-16 02:37:00 +00:00
|
|
|
D2D1_ALPHA_MODE alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
|
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
if (aFormat == SurfaceFormat::B8G8R8X8 && aTexture == mTexture) {
|
2011-08-16 02:37:00 +00:00
|
|
|
alphaMode = D2D1_ALPHA_MODE_IGNORE;
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
D2D1_RENDER_TARGET_PROPERTIES props =
|
2011-08-16 02:37:00 +00:00
|
|
|
D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat(desc.Format, alphaMode));
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = factory()->CreateDxgiSurfaceRenderTarget(surface, props, getter_AddRefs(rt));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2015-06-09 20:48:59 +00:00
|
|
|
gfxCriticalError() << "Failed to create D2D render target for texture. Code: "
|
|
|
|
<< hexa(hr) << " " << mSize << " Format: " << uint32_t(aFormat);
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return rt.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::EnsureViews()
|
|
|
|
{
|
|
|
|
if (mTempTexture && mSRView && mRTView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
mSize.width,
|
|
|
|
mSize.height,
|
|
|
|
1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(mTempTexture));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << *this << "Failed to create temporary texture for rendertarget. Size: "
|
2014-09-23 15:35:39 +00:00
|
|
|
<< mSize << " Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateShaderResourceView(mTempTexture, nullptr, getter_AddRefs(mSRView));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateRenderTargetView(mTexture, nullptr, getter_AddRefs(mRTView));
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 15:35:39 +00:00
|
|
|
gfxWarning() << *this << "Failed to create rendertarget view for temp texture. Code: " << hexa(hr);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::PopAllClips()
|
|
|
|
{
|
|
|
|
if (mClipsArePushed) {
|
2012-05-15 14:57:51 +00:00
|
|
|
PopClipsFromRT(mRT);
|
|
|
|
|
|
|
|
mClipsArePushed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::PushClipsToRT(ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
for (std::vector<PushedClip>::iterator iter = mPushedClips.begin();
|
|
|
|
iter != mPushedClips.end(); iter++) {
|
|
|
|
if (iter->mLayer) {
|
2012-10-08 10:17:17 +00:00
|
|
|
PushD2DLayer(aRT, iter->mPath->mGeometry, iter->mLayer, iter->mTransform);
|
2012-05-15 14:57:51 +00:00
|
|
|
} else {
|
2012-09-18 23:04:42 +00:00
|
|
|
aRT->PushAxisAlignedClip(iter->mBounds, iter->mIsPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetD2D::PopClipsFromRT(ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
for (int i = mPushedClips.size() - 1; i >= 0; i--) {
|
|
|
|
if (mPushedClips[i].mLayer) {
|
|
|
|
aRT->PopLayer();
|
|
|
|
} else {
|
|
|
|
aRT->PopAxisAlignedClip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-18 23:04:42 +00:00
|
|
|
DrawTargetD2D::EnsureClipMaskTexture(IntRect *aBounds)
|
2012-05-15 14:57:51 +00:00
|
|
|
{
|
2012-05-15 14:57:51 +00:00
|
|
|
if (mCurrentClipMaskTexture || mPushedClips.empty()) {
|
2012-09-18 23:04:42 +00:00
|
|
|
*aBounds = mCurrentClipBounds;
|
2012-05-15 14:57:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> geometry = GetClippedGeometry(aBounds);
|
2012-09-18 23:04:42 +00:00
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_A8_UNORM,
|
|
|
|
mSize.width,
|
|
|
|
mSize.height,
|
|
|
|
1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(mCurrentClipMaskTexture));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create texture for ClipMask!";
|
|
|
|
return;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2012-05-15 14:57:51 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1RenderTarget> rt = CreateRTForTexture(mCurrentClipMaskTexture, SurfaceFormat::A8);
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (!rt) {
|
|
|
|
gfxWarning() << "Failed to create RT for ClipMask!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> brush;
|
2015-10-18 04:40:10 +00:00
|
|
|
rt->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), getter_AddRefs(brush));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
rt->BeginDraw();
|
|
|
|
rt->Clear(D2D1::ColorF(0, 0));
|
|
|
|
rt->FillGeometry(geometry, brush);
|
|
|
|
rt->EndDraw();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
bool
|
|
|
|
DrawTargetD2D::FillGlyphsManual(ScaledFontDWrite *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Color &aColor,
|
|
|
|
IDWriteRenderingParams *aParams,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDWriteRenderingParams> params;
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (aParams) {
|
|
|
|
params = aParams;
|
|
|
|
} else {
|
2015-10-18 04:40:10 +00:00
|
|
|
mRT->GetTextRenderingParams(getter_AddRefs(params));
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWRITE_RENDERING_MODE renderMode = DWRITE_RENDERING_MODE_DEFAULT;
|
|
|
|
if (params) {
|
|
|
|
hr = aFont->mFontFace->GetRecommendedRenderingMode(
|
2012-08-08 20:17:04 +00:00
|
|
|
(FLOAT)aFont->GetSize(),
|
2012-05-15 14:57:51 +00:00
|
|
|
1.0f,
|
|
|
|
DWRITE_MEASURING_MODE_NATURAL,
|
|
|
|
params,
|
|
|
|
&renderMode);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
// this probably never happens, but let's play it safe
|
|
|
|
renderMode = DWRITE_RENDERING_MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with rendering modes CreateGlyphRunAnalysis doesn't accept.
|
|
|
|
switch (renderMode) {
|
|
|
|
case DWRITE_RENDERING_MODE_ALIASED:
|
|
|
|
// ClearType texture creation will fail in this mode, so bail out
|
|
|
|
return false;
|
|
|
|
case DWRITE_RENDERING_MODE_DEFAULT:
|
|
|
|
// As per DWRITE_RENDERING_MODE documentation, pick Natural for font
|
|
|
|
// sizes under 16 ppem
|
2012-08-08 20:17:04 +00:00
|
|
|
if (aFont->GetSize() < 16.0f) {
|
2012-05-15 14:57:51 +00:00
|
|
|
renderMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
|
|
|
|
} else {
|
|
|
|
renderMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DWRITE_RENDERING_MODE_OUTLINE:
|
|
|
|
renderMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWRITE_MEASURING_MODE measureMode =
|
|
|
|
renderMode <= DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC ? DWRITE_MEASURING_MODE_GDI_CLASSIC :
|
|
|
|
renderMode == DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL ? DWRITE_MEASURING_MODE_GDI_NATURAL :
|
|
|
|
DWRITE_MEASURING_MODE_NATURAL;
|
|
|
|
|
|
|
|
DWRITE_MATRIX mat = DWriteMatrixFromMatrix(mTransform);
|
|
|
|
|
|
|
|
AutoDWriteGlyphRun autoRun;
|
|
|
|
DWriteGlyphRunFromGlyphs(aBuffer, aFont, &autoRun);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDWriteGlyphRunAnalysis> analysis;
|
2012-05-15 14:57:51 +00:00
|
|
|
hr = GetDWriteFactory()->CreateGlyphRunAnalysis(&autoRun, 1.0f, &mat,
|
2015-10-18 04:40:10 +00:00
|
|
|
renderMode, measureMode, 0, 0, getter_AddRefs(analysis));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECT bounds;
|
|
|
|
hr = analysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &bounds);
|
2012-06-13 08:42:23 +00:00
|
|
|
|
|
|
|
if (bounds.bottom <= bounds.top || bounds.right <= bounds.left) {
|
|
|
|
// DWrite seems to do this sometimes. I'm not 100% sure why. See bug 758980.
|
|
|
|
gfxDebug() << "Empty alpha texture bounds! Falling back to regular drawing.";
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-15 14:57:51 +00:00
|
|
|
IntRect rectBounds(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
|
|
|
|
IntRect surfBounds(IntPoint(0, 0), mSize);
|
|
|
|
|
|
|
|
rectBounds.IntersectRect(rectBounds, surfBounds);
|
|
|
|
|
|
|
|
if (rectBounds.IsEmpty()) {
|
|
|
|
// Nothing to do.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tex = CreateTextureForAnalysis(analysis, rectBounds);
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (!tex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10ShaderResourceView> srView;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateShaderResourceView(tex, nullptr, getter_AddRefs(srView));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkChanged();
|
|
|
|
|
|
|
|
// Prepare our background texture for drawing.
|
|
|
|
PopAllClips();
|
|
|
|
mRT->Flush();
|
|
|
|
|
|
|
|
SetupStateForRendering();
|
|
|
|
|
|
|
|
ID3D10EffectTechnique *technique = mPrivateData->mEffect->GetTechniqueByName("SampleTextTexture");
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(-1.0f + ((Float(rectBounds.x) / mSize.width) * 2.0f),
|
|
|
|
1.0f - (Float(rectBounds.y) / mSize.height * 2.0f),
|
|
|
|
(Float(rectBounds.width) / mSize.width) * 2.0f,
|
|
|
|
(-Float(rectBounds.height) / mSize.height) * 2.0f));
|
|
|
|
mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
FLOAT color[4] = { aColor.r, aColor.g, aColor.b, aColor.a };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("TextColor")->AsVector()->
|
|
|
|
SetFloatVector(color);
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(srView);
|
|
|
|
|
|
|
|
bool isMasking = false;
|
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
IntRect clipBoundsStorage;
|
|
|
|
IntRect *clipBounds = nullptr;
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
if (!mPushedClips.empty()) {
|
2012-09-18 23:04:42 +00:00
|
|
|
clipBounds = &clipBoundsStorage;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(clipBounds);
|
2012-05-15 14:57:51 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1RectangleGeometry> rectGeom;
|
2012-09-28 17:21:40 +00:00
|
|
|
factory()->CreateRectangleGeometry(D2D1::RectF(Float(rectBounds.x),
|
|
|
|
Float(rectBounds.y),
|
|
|
|
Float(rectBounds.width + rectBounds.x),
|
|
|
|
Float(rectBounds.height + rectBounds.y)),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(rectGeom));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
D2D1_GEOMETRY_RELATION relation;
|
|
|
|
if (FAILED(geom->CompareWithGeometry(rectGeom, D2D1::IdentityMatrix(), &relation)) ||
|
2012-09-18 23:04:42 +00:00
|
|
|
relation != D2D1_GEOMETRY_RELATION_CONTAINS ) {
|
2012-05-15 14:57:51 +00:00
|
|
|
isMasking = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMasking) {
|
2012-09-18 23:04:42 +00:00
|
|
|
clipBounds = &clipBoundsStorage;
|
|
|
|
EnsureClipMaskTexture(clipBounds);
|
2012-05-15 14:57:51 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10ShaderResourceView> srViewMask;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateShaderResourceView(mCurrentClipMaskTexture, nullptr, getter_AddRefs(srViewMask));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("mask")->AsShaderResource()->SetResource(srViewMask);
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("MaskTexCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(Float(rectBounds.x) / mSize.width, Float(rectBounds.y) / mSize.height,
|
|
|
|
Float(rectBounds.width) / mSize.width, Float(rectBounds.height) / mSize.height));
|
|
|
|
|
|
|
|
technique->GetPassByIndex(1)->Apply(0);
|
|
|
|
} else {
|
|
|
|
technique->GetPassByIndex(0)->Apply(0);
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10RenderTargetView> rtView;
|
2012-05-15 14:57:51 +00:00
|
|
|
ID3D10RenderTargetView *rtViews;
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateRenderTargetView(mTexture, nullptr, getter_AddRefs(rtView));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
rtViews = rtView;
|
2012-08-14 18:06:12 +00:00
|
|
|
mDevice->OMSetRenderTargets(1, &rtViews, nullptr);
|
2012-09-18 23:04:42 +00:00
|
|
|
SetScissorToRect(clipBounds);
|
2012-05-15 14:57:51 +00:00
|
|
|
mDevice->Draw(4, 0);
|
2012-05-21 09:03:06 +00:00
|
|
|
return true;
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
2012-05-15 14:57:51 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID2D1Brush>
|
2011-06-24 17:41:16 +00:00
|
|
|
DrawTargetD2D::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
|
|
|
|
{
|
2012-12-20 04:19:45 +00:00
|
|
|
if (!IsPatternSupportedByD2D(aPattern)) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> colBrush;
|
2015-10-18 04:40:10 +00:00
|
|
|
mRT->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), getter_AddRefs(colBrush));
|
2014-06-13 16:09:23 +00:00
|
|
|
return colBrush.forget();
|
2011-07-08 18:49:35 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 19:06:17 +00:00
|
|
|
if (aPattern.GetType() == PatternType::COLOR) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> colBrush;
|
2011-06-24 17:41:16 +00:00
|
|
|
Color color = static_cast<const ColorPattern*>(&aPattern)->mColor;
|
|
|
|
mRT->CreateSolidColorBrush(D2D1::ColorF(color.r, color.g,
|
|
|
|
color.b, color.a),
|
|
|
|
D2D1::BrushProperties(aAlpha),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(colBrush));
|
2014-06-13 16:09:23 +00:00
|
|
|
return colBrush.forget();
|
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::LINEAR_GRADIENT) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1LinearGradientBrush> gradBrush;
|
2011-06-24 17:41:16 +00: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.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 05:56:11 +00:00
|
|
|
if (pat->mBegin == pat->mEnd) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> colBrush;
|
2011-12-28 05:56:11 +00:00
|
|
|
uint32_t stopCount = stops->mStopCollection->GetGradientStopCount();
|
|
|
|
vector<D2D1_GRADIENT_STOP> d2dStops(stopCount);
|
|
|
|
stops->mStopCollection->GetGradientStops(&d2dStops.front(), stopCount);
|
|
|
|
mRT->CreateSolidColorBrush(d2dStops.back().color,
|
|
|
|
D2D1::BrushProperties(aAlpha),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(colBrush));
|
2014-06-13 16:09:23 +00:00
|
|
|
return colBrush.forget();
|
2011-12-28 05:56:11 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
mRT->CreateLinearGradientBrush(D2D1::LinearGradientBrushProperties(D2DPoint(pat->mBegin),
|
|
|
|
D2DPoint(pat->mEnd)),
|
2011-12-28 05:56:11 +00:00
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(pat->mMatrix)),
|
2011-06-24 17:41:16 +00:00
|
|
|
stops->mStopCollection,
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(gradBrush));
|
2014-06-13 16:09:23 +00:00
|
|
|
return gradBrush.forget();
|
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::RADIAL_GRADIENT) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1RadialGradientBrush> gradBrush;
|
2011-06-24 17:41:16 +00: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.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
// This will not be a complex radial gradient brush.
|
|
|
|
mRT->CreateRadialGradientBrush(
|
2013-03-12 19:55:50 +00:00
|
|
|
D2D1::RadialGradientBrushProperties(D2DPoint(pat->mCenter2),
|
|
|
|
D2DPoint(pat->mCenter1 - pat->mCenter2),
|
2011-07-08 18:49:35 +00:00
|
|
|
pat->mRadius2, pat->mRadius2),
|
2011-12-28 05:56:11 +00:00
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(pat->mMatrix)),
|
2011-07-08 18:49:35 +00:00
|
|
|
stops->mStopCollection,
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(gradBrush));
|
2011-07-08 18:49:35 +00:00
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return gradBrush.forget();
|
|
|
|
}
|
|
|
|
if (aPattern.GetType() == PatternType::SURFACE) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1BitmapBrush> bmBrush;
|
2011-06-24 17:41:16 +00:00
|
|
|
const SurfacePattern *pat =
|
|
|
|
static_cast<const SurfacePattern*>(&aPattern);
|
|
|
|
|
|
|
|
if (!pat->mSurface) {
|
|
|
|
gfxDebug() << "No source surface specified for surface pattern";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Bitmap> bitmap;
|
2011-12-28 05:56:11 +00:00
|
|
|
|
|
|
|
Matrix mat = pat->mMatrix;
|
2014-09-12 05:19:23 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface> source = pat->mSurface;
|
2014-09-12 05:19:23 +00:00
|
|
|
|
2014-09-24 17:23:15 +00:00
|
|
|
if (!pat->mSamplingRect.IsEmpty() &&
|
|
|
|
(source->GetType() == SurfaceType::D2D1_BITMAP ||
|
|
|
|
source->GetType() == SurfaceType::D2D1_DRAWTARGET)) {
|
2014-09-12 05:19:23 +00:00
|
|
|
IntRect samplingRect = pat->mSamplingRect;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTargetD2D> dt = new DrawTargetD2D();
|
2014-09-12 05:19:23 +00:00
|
|
|
if (!dt->Init(samplingRect.Size(),
|
|
|
|
source->GetFormat())) {
|
2014-11-19 10:08:14 +00:00
|
|
|
// FIXME: Uncomment assertion, bug 1068195
|
|
|
|
// MOZ_ASSERT(false, "Invalid sampling rect size!");
|
2014-09-12 05:19:23 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
dt->CopySurface(source, samplingRect, IntPoint());
|
|
|
|
source = dt->Snapshot();
|
|
|
|
|
|
|
|
mat.PreTranslate(samplingRect.x, samplingRect.y);
|
|
|
|
}
|
2011-06-24 17:41:16 +00:00
|
|
|
|
2014-09-12 05:19:23 +00:00
|
|
|
switch (source->GetType()) {
|
2014-01-10 18:55:24 +00:00
|
|
|
case SurfaceType::D2D1_BITMAP:
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
2014-09-12 05:19:23 +00:00
|
|
|
SourceSurfaceD2D *surf = static_cast<SourceSurfaceD2D*>(source.get());
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
bitmap = surf->mBitmap;
|
|
|
|
|
|
|
|
if (!bitmap) {
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 18:55:24 +00:00
|
|
|
case SurfaceType::D2D1_DRAWTARGET:
|
2011-06-24 17:41:16 +00:00
|
|
|
{
|
|
|
|
SourceSurfaceD2DTarget *surf =
|
2014-09-12 05:19:23 +00:00
|
|
|
static_cast<SourceSurfaceD2DTarget*>(source.get());
|
2011-06-24 17:41:16 +00:00
|
|
|
bitmap = surf->GetBitmap(mRT);
|
2011-12-09 09:51:57 +00:00
|
|
|
AddDependencyOnSource(surf);
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-08-22 20:56:03 +00:00
|
|
|
default:
|
2012-05-21 15:27:30 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DataSourceSurface> dataSurf = source->GetDataSurface();
|
2012-08-22 20:56:03 +00:00
|
|
|
if (!dataSurf) {
|
|
|
|
gfxWarning() << "Invalid surface type.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-24 17:23:15 +00:00
|
|
|
IntRect sourceRect = pat->mSamplingRect;
|
|
|
|
if (sourceRect.IsEmpty()) {
|
|
|
|
sourceRect = IntRect(0, 0, source->GetSize().width, source->GetSize().height);
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap = CreatePartialBitmapForSurface(dataSurf, mTransform, mSize, pat->mExtendMode, mat, mRT, &sourceRect);
|
2012-05-21 15:27:30 +00:00
|
|
|
if (!bitmap) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1SolidColorBrush> colBrush;
|
2015-10-18 04:40:10 +00:00
|
|
|
mRT->CreateSolidColorBrush(D2D1::ColorF(0, 0), getter_AddRefs(colBrush));
|
2014-11-20 20:48:01 +00:00
|
|
|
return colBrush.forget();
|
2012-05-21 15:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
2015-02-25 22:44:56 +00:00
|
|
|
|
|
|
|
HRESULT hr = mRT->CreateBitmapBrush(bitmap,
|
2011-12-28 05:56:11 +00:00
|
|
|
D2D1::BitmapBrushProperties(D2DExtend(pat->mExtendMode),
|
|
|
|
D2DExtend(pat->mExtendMode),
|
2011-06-24 17:41:16 +00:00
|
|
|
D2DFilter(pat->mFilter)),
|
2011-12-28 05:56:11 +00:00
|
|
|
D2D1::BrushProperties(aAlpha, D2DMatrix(mat)),
|
2015-10-18 04:40:10 +00:00
|
|
|
getter_AddRefs(bmBrush));
|
2015-02-25 22:44:56 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalError() << "[D2D] 1CreateBitmapBrush failure: " << hexa(hr);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-13 16:09:23 +00:00
|
|
|
return bmBrush.forget();
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxWarning() << "Invalid pattern type detected.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID3D10Texture2D>
|
2011-07-08 18:49:35 +00:00
|
|
|
DrawTargetD2D::CreateGradientTexture(const GradientStopsD2D *aStops)
|
|
|
|
{
|
2012-05-21 15:24:05 +00:00
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, 4096, 1, 1, 1);
|
2011-07-08 18:49:35 +00:00
|
|
|
|
|
|
|
std::vector<D2D1_GRADIENT_STOP> rawStops;
|
|
|
|
rawStops.resize(aStops->mStopCollection->GetGradientStopCount());
|
|
|
|
aStops->mStopCollection->GetGradientStops(&rawStops.front(), rawStops.size());
|
|
|
|
|
|
|
|
std::vector<unsigned char> textureData;
|
|
|
|
textureData.resize(4096 * 4);
|
|
|
|
unsigned char *texData = &textureData.front();
|
|
|
|
|
|
|
|
float prevColorPos = 0;
|
|
|
|
float nextColorPos = 1.0f;
|
|
|
|
D2D1_COLOR_F prevColor = rawStops[0].color;
|
|
|
|
D2D1_COLOR_F nextColor = prevColor;
|
|
|
|
|
|
|
|
if (rawStops.size() >= 2) {
|
|
|
|
nextColor = rawStops[1].color;
|
|
|
|
nextColorPos = rawStops[1].position;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t stopPosition = 2;
|
|
|
|
|
|
|
|
// Not the most optimized way but this will do for now.
|
|
|
|
for (int i = 0; i < 4096; i++) {
|
|
|
|
// The 4095 seems a little counter intuitive, but we want the gradient
|
|
|
|
// color at offset 0 at the first pixel, and at offset 1.0f at the last
|
|
|
|
// pixel.
|
|
|
|
float pos = float(i) / 4095;
|
|
|
|
|
2012-06-01 22:00:28 +00:00
|
|
|
while (pos > nextColorPos) {
|
2011-07-08 18:49:35 +00:00
|
|
|
prevColor = nextColor;
|
|
|
|
prevColorPos = nextColorPos;
|
|
|
|
if (rawStops.size() > stopPosition) {
|
|
|
|
nextColor = rawStops[stopPosition].color;
|
|
|
|
nextColorPos = rawStops[stopPosition++].position;
|
|
|
|
} else {
|
|
|
|
nextColorPos = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 22:00:28 +00:00
|
|
|
float interp;
|
|
|
|
|
|
|
|
if (nextColorPos != prevColorPos) {
|
|
|
|
interp = (pos - prevColorPos) / (nextColorPos - prevColorPos);
|
|
|
|
} else {
|
|
|
|
interp = 0;
|
|
|
|
}
|
2011-07-08 18:49:35 +00:00
|
|
|
|
|
|
|
Color newColor(prevColor.r + (nextColor.r - prevColor.r) * interp,
|
|
|
|
prevColor.g + (nextColor.g - prevColor.g) * interp,
|
|
|
|
prevColor.b + (nextColor.b - prevColor.b) * interp,
|
|
|
|
prevColor.a + (nextColor.a - prevColor.a) * interp);
|
|
|
|
|
|
|
|
texData[i * 4] = (char)(255.0f * newColor.b);
|
|
|
|
texData[i * 4 + 1] = (char)(255.0f * newColor.g);
|
|
|
|
texData[i * 4 + 2] = (char)(255.0f * newColor.r);
|
|
|
|
texData[i * 4 + 3] = (char)(255.0f * newColor.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_SUBRESOURCE_DATA data;
|
|
|
|
data.pSysMem = &textureData.front();
|
2012-05-21 15:24:05 +00:00
|
|
|
data.SysMemPitch = 4096 * 4;
|
2011-07-08 18:49:35 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tex;
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateTexture2D(&desc, &data, getter_AddRefs(tex));
|
2011-07-08 18:49:35 +00:00
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return tex.forget();
|
2011-07-08 18:49:35 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<ID3D10Texture2D>
|
2012-05-15 14:57:51 +00:00
|
|
|
DrawTargetD2D::CreateTextureForAnalysis(IDWriteGlyphRunAnalysis *aAnalysis, const IntRect &aBounds)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
uint32_t bufferSize = aBounds.width * aBounds.height * 3;
|
|
|
|
|
|
|
|
RECT bounds;
|
|
|
|
bounds.left = aBounds.x;
|
|
|
|
bounds.top = aBounds.y;
|
|
|
|
bounds.right = aBounds.x + aBounds.width;
|
|
|
|
bounds.bottom = aBounds.y + aBounds.height;
|
|
|
|
|
|
|
|
// Add one byte so we can safely read a 32-bit int when copying the last
|
|
|
|
// 3 bytes.
|
|
|
|
BYTE *texture = new BYTE[bufferSize + 1];
|
|
|
|
hr = aAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1, &bounds, texture, bufferSize);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
delete [] texture;
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int alignedBufferSize = aBounds.width * aBounds.height * 4;
|
|
|
|
|
|
|
|
// Create a one-off immutable texture from system memory.
|
|
|
|
BYTE *alignedTextureData = new BYTE[alignedBufferSize];
|
|
|
|
for (int y = 0; y < aBounds.height; y++) {
|
|
|
|
for (int x = 0; x < aBounds.width; x++) {
|
|
|
|
// Copy 3 Bpp source to 4 Bpp destination memory used for
|
|
|
|
// texture creation. D3D10 has no 3 Bpp texture format we can
|
|
|
|
// use.
|
|
|
|
//
|
|
|
|
// Since we don't care what ends up in the alpha pixel of the
|
|
|
|
// destination, therefor we can simply copy a normal 32 bit
|
|
|
|
// integer each time, filling the alpha pixel of the destination
|
|
|
|
// with the first subpixel of the next pixel from the source.
|
|
|
|
*((int*)(alignedTextureData + (y * aBounds.width + x) * 4)) =
|
|
|
|
*((int*)(texture + (y * aBounds.width + x) * 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_SUBRESOURCE_DATA data;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
aBounds.width, aBounds.height,
|
|
|
|
1, 1);
|
|
|
|
desc.Usage = D3D10_USAGE_IMMUTABLE;
|
|
|
|
|
|
|
|
data.SysMemPitch = aBounds.width * 4;
|
|
|
|
data.pSysMem = alignedTextureData;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tex;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mDevice->CreateTexture2D(&desc, &data, getter_AddRefs(tex));
|
2012-05-15 14:57:51 +00:00
|
|
|
|
|
|
|
delete [] alignedTextureData;
|
|
|
|
delete [] texture;
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 16:09:23 +00:00
|
|
|
return tex.forget();
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
2012-07-04 18:23:16 +00:00
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::SetupEffectForRadialGradient(const RadialGradientPattern *aPattern)
|
|
|
|
{
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleRadialGradient")->GetPassByIndex(0)->Apply(0);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("MaskTexCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
float dimensions[] = { float(mSize.width), float(mSize.height), 0, 0 };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("dimensions")->AsVector()->
|
|
|
|
SetFloatVector(dimensions);
|
|
|
|
|
|
|
|
const GradientStopsD2D *stops =
|
|
|
|
static_cast<const GradientStopsD2D*>(aPattern->mStops.get());
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10Texture2D> tex = CreateGradientTexture(stops);
|
2011-07-08 18:49:35 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D10ShaderResourceView> srView;
|
2015-10-18 04:40:10 +00:00
|
|
|
mDevice->CreateShaderResourceView(tex, nullptr, getter_AddRefs(srView));
|
2011-07-08 18:49:35 +00:00
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(srView);
|
|
|
|
|
|
|
|
Point dc = aPattern->mCenter2 - aPattern->mCenter1;
|
|
|
|
float dr = aPattern->mRadius2 - aPattern->mRadius1;
|
|
|
|
|
|
|
|
float diffv[] = { dc.x, dc.y, dr, 0 };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("diff")->AsVector()->
|
|
|
|
SetFloatVector(diffv);
|
|
|
|
|
|
|
|
float center1[] = { aPattern->mCenter1.x, aPattern->mCenter1.y, dr, 0 };
|
|
|
|
mPrivateData->mEffect->GetVariableByName("center1")->AsVector()->
|
|
|
|
SetFloatVector(center1);
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("radius1")->AsScalar()->
|
|
|
|
SetFloat(aPattern->mRadius1);
|
|
|
|
mPrivateData->mEffect->GetVariableByName("sq_radius1")->AsScalar()->
|
|
|
|
SetFloat(pow(aPattern->mRadius1, 2));
|
|
|
|
|
|
|
|
Matrix invTransform = mTransform;
|
|
|
|
|
|
|
|
if (!invTransform.Invert()) {
|
|
|
|
// Bail if the matrix is singular.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float matrix[] = { invTransform._11, invTransform._12, 0, 0,
|
|
|
|
invTransform._21, invTransform._22, 0, 0,
|
|
|
|
invTransform._31, invTransform._32, 1.0f, 0,
|
|
|
|
0, 0, 0, 1.0f };
|
|
|
|
|
|
|
|
mPrivateData->mEffect->GetVariableByName("DeviceSpaceToUserSpace")->
|
|
|
|
AsMatrix()->SetMatrix(matrix);
|
|
|
|
|
2014-08-28 16:45:48 +00:00
|
|
|
float A = dc.x * dc.x + dc.y * dc.y - dr * dr;
|
2011-12-28 05:56:11 +00:00
|
|
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
switch (stops->mStopCollection->GetExtendMode()) {
|
|
|
|
case D2D1_EXTEND_MODE_WRAP:
|
|
|
|
offset = 1;
|
|
|
|
break;
|
|
|
|
case D2D1_EXTEND_MODE_MIRROR:
|
|
|
|
offset = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gfxWarning() << "This shouldn't happen! Invalid extend mode for gradient stops.";
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:49:35 +00:00
|
|
|
if (A == 0) {
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleRadialGradient")->
|
2011-12-28 05:56:11 +00:00
|
|
|
GetPassByIndex(offset * 2 + 1)->Apply(0);
|
2011-07-08 18:49:35 +00:00
|
|
|
} else {
|
|
|
|
mPrivateData->mEffect->GetVariableByName("A")->AsScalar()->SetFloat(A);
|
|
|
|
mPrivateData->mEffect->GetTechniqueByName("SampleRadialGradient")->
|
2011-12-28 05:56:11 +00:00
|
|
|
GetPassByIndex(offset * 2)->Apply(0);
|
2011-07-08 18:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::SetupStateForRendering()
|
|
|
|
{
|
|
|
|
UINT stride = sizeof(Vertex);
|
|
|
|
UINT offset = 0;
|
|
|
|
ID3D10Buffer *buff = mPrivateData->mVB;
|
|
|
|
|
|
|
|
mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
mDevice->IASetVertexBuffers(0, 1, &buff, &stride, &offset);
|
|
|
|
mDevice->IASetInputLayout(mPrivateData->mInputLayout);
|
|
|
|
|
|
|
|
D3D10_VIEWPORT viewport;
|
|
|
|
viewport.MaxDepth = 1;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Height = mSize.height;
|
|
|
|
viewport.Width = mSize.width;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
ID2D1Factory*
|
|
|
|
DrawTargetD2D::factory()
|
|
|
|
{
|
|
|
|
if (mFactory) {
|
|
|
|
return mFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1CreateFactoryFunc createD2DFactory;
|
|
|
|
HMODULE d2dModule = LoadLibraryW(L"d2d1.dll");
|
|
|
|
createD2DFactory = (D2D1CreateFactoryFunc)
|
|
|
|
GetProcAddress(d2dModule, "D2D1CreateFactory");
|
|
|
|
|
|
|
|
if (!createD2DFactory) {
|
|
|
|
gfxWarning() << "Failed to locate D2D1CreateFactory function.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_FACTORY_OPTIONS options;
|
|
|
|
#ifdef _DEBUG
|
2011-12-28 05:56:11 +00:00
|
|
|
options.debugLevel = D2D1_DEBUG_LEVEL_WARNING;
|
2011-06-24 17:41:16 +00:00
|
|
|
#else
|
|
|
|
options.debugLevel = D2D1_DEBUG_LEVEL_NONE;
|
|
|
|
#endif
|
2014-09-14 21:51:34 +00:00
|
|
|
//options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
|
2011-06-24 17:41:16 +00:00
|
|
|
|
|
|
|
HRESULT hr = createD2DFactory(D2D1_FACTORY_TYPE_MULTI_THREADED,
|
|
|
|
__uuidof(ID2D1Factory),
|
|
|
|
&options,
|
|
|
|
(void**)&mFactory);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create Direct2D factory.";
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Factory1> factoryD2D1;
|
2015-10-18 04:40:10 +00:00
|
|
|
hr = mFactory->QueryInterface((ID2D1Factory1**)getter_AddRefs(factoryD2D1));
|
2015-02-09 19:04:11 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
ExtendInputEffectD2D1::Register(factoryD2D1);
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
return mFactory;
|
|
|
|
}
|
|
|
|
|
2012-11-25 19:00:31 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::CleanupD2D()
|
|
|
|
{
|
|
|
|
if (mFactory) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1Factory1> factoryD2D1;
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = mFactory->QueryInterface((ID2D1Factory1**)getter_AddRefs(factoryD2D1));
|
2015-02-09 19:04:11 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
ExtendInputEffectD2D1::Unregister(factoryD2D1);
|
|
|
|
}
|
|
|
|
|
2012-11-25 19:00:31 +00:00
|
|
|
mFactory->Release();
|
|
|
|
mFactory = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:57:51 +00:00
|
|
|
IDWriteFactory*
|
|
|
|
DrawTargetD2D::GetDWriteFactory()
|
|
|
|
{
|
|
|
|
if (mDWriteFactory) {
|
|
|
|
return mDWriteFactory;
|
|
|
|
}
|
|
|
|
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(DWriteCreateFactory)* createDWriteFactory;
|
2012-05-15 14:57:51 +00:00
|
|
|
HMODULE dwriteModule = LoadLibraryW(L"dwrite.dll");
|
2014-02-17 22:32:52 +00:00
|
|
|
createDWriteFactory = (decltype(DWriteCreateFactory)*)
|
2012-05-15 14:57:51 +00:00
|
|
|
GetProcAddress(dwriteModule, "DWriteCreateFactory");
|
|
|
|
|
|
|
|
if (!createDWriteFactory) {
|
|
|
|
gfxWarning() << "Failed to locate DWriteCreateFactory function.";
|
2012-08-14 18:06:12 +00:00
|
|
|
return nullptr;
|
2012-05-15 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = createDWriteFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
|
|
|
|
reinterpret_cast<IUnknown**>(&mDWriteFactory));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create DWrite Factory.";
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDWriteFactory;
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:04:42 +00:00
|
|
|
void
|
|
|
|
DrawTargetD2D::SetScissorToRect(IntRect *aRect)
|
|
|
|
{
|
|
|
|
D3D10_RECT rect;
|
|
|
|
if (aRect) {
|
|
|
|
rect.left = aRect->x;
|
|
|
|
rect.right = aRect->XMost();
|
|
|
|
rect.top = aRect->y;
|
|
|
|
rect.bottom = aRect->YMost();
|
|
|
|
} else {
|
2012-10-03 11:30:56 +00:00
|
|
|
rect.left = rect.top = INT32_MIN;
|
|
|
|
rect.right = rect.bottom = INT32_MAX;
|
2012-09-18 23:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mDevice->RSSetScissorRects(1, &rect);
|
|
|
|
}
|
|
|
|
|
2012-10-06 23:43:16 +00:00
|
|
|
void
|
2012-10-08 10:17:17 +00:00
|
|
|
DrawTargetD2D::PushD2DLayer(ID2D1RenderTarget *aRT, ID2D1Geometry *aGeometry, ID2D1Layer *aLayer, const D2D1_MATRIX_3X2_F &aTransform)
|
2012-10-06 23:43:16 +00:00
|
|
|
{
|
|
|
|
D2D1_LAYER_OPTIONS options = D2D1_LAYER_OPTIONS_NONE;
|
|
|
|
D2D1_LAYER_OPTIONS1 options1 = D2D1_LAYER_OPTIONS1_NONE;
|
|
|
|
|
2013-01-15 01:20:10 +00:00
|
|
|
if (aRT->GetPixelFormat().alphaMode == D2D1_ALPHA_MODE_IGNORE) {
|
2012-10-06 23:43:16 +00:00
|
|
|
options = D2D1_LAYER_OPTIONS_INITIALIZE_FOR_CLEARTYPE;
|
|
|
|
options1 = D2D1_LAYER_OPTIONS1_IGNORE_ALPHA | D2D1_LAYER_OPTIONS1_INITIALIZE_FROM_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID2D1DeviceContext> dc;
|
2015-10-18 04:40:10 +00:00
|
|
|
HRESULT hr = aRT->QueryInterface(IID_ID2D1DeviceContext, (void**)((ID2D1DeviceContext**)getter_AddRefs(dc)));
|
2012-10-06 23:43:16 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2012-10-08 10:17:17 +00:00
|
|
|
aRT->PushLayer(D2D1::LayerParameters(D2D1::InfiniteRect(), aGeometry,
|
2012-10-06 23:43:16 +00:00
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, aTransform,
|
|
|
|
1.0, nullptr, options),
|
|
|
|
aLayer);
|
|
|
|
} else {
|
|
|
|
dc->PushLayer(D2D1::LayerParameters1(D2D1::InfiniteRect(), aGeometry,
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, aTransform,
|
|
|
|
1.0, nullptr, options1),
|
|
|
|
aLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|