2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_DRAWTARGETDUAL_H_
|
|
|
|
#define MOZILLA_GFX_DRAWTARGETDUAL_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "SourceSurfaceDual.h"
|
|
|
|
|
|
|
|
#include "2D.h"
|
2013-11-27 15:22:56 +04:00
|
|
|
#include "Filters.h"
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
#define FORWARD_FUNCTION(funcName) \
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void funcName() override { mA->funcName(); mB->funcName(); }
|
2012-04-04 00:25:52 +04:00
|
|
|
#define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void funcName(var1Type var1Name) override { mA->funcName(var1Name); mB->funcName(var1Name); }
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
/* This is a special type of DrawTarget. It duplicates all drawing calls
|
|
|
|
* accross two drawtargets. An exception to this is when a snapshot of another
|
|
|
|
* dual DrawTarget is used as the source for any surface data. In this case
|
|
|
|
* the snapshot of the first source DrawTarget is used as a source for the call
|
|
|
|
* to the first destination DrawTarget (mA) and the snapshot of the second
|
|
|
|
* source DrawTarget is used at the source for the second destination
|
|
|
|
* DrawTarget (mB). This class facilitates black-background/white-background
|
|
|
|
* drawing for per-component alpha extraction for backends which do not support
|
|
|
|
* native component alpha.
|
|
|
|
*/
|
|
|
|
class DrawTargetDual : public DrawTarget
|
|
|
|
{
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetDual, override)
|
2012-04-04 00:25:52 +04:00
|
|
|
DrawTargetDual(DrawTarget *aA, DrawTarget *aB)
|
|
|
|
: mA(aA)
|
|
|
|
, mB(aB)
|
|
|
|
{
|
|
|
|
mFormat = aA->GetFormat();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual DrawTargetType GetType() const override { return mA->GetType(); }
|
|
|
|
virtual BackendType GetBackendType() const override { return mA->GetBackendType(); }
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> Snapshot() override {
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<SourceSurfaceDual>(mA, mB);
|
|
|
|
}
|
2018-01-23 20:10:11 +03:00
|
|
|
virtual IntSize GetSize() const override { return mA->GetSize(); }
|
2016-07-01 11:58:13 +03:00
|
|
|
|
|
|
|
virtual void DetachAllSnapshots() override;
|
|
|
|
|
2012-04-04 00:25:52 +04:00
|
|
|
FORWARD_FUNCTION(Flush)
|
|
|
|
FORWARD_FUNCTION1(PushClip, const Path *, aPath)
|
|
|
|
FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect)
|
|
|
|
FORWARD_FUNCTION(PopClip)
|
2016-01-06 02:23:33 +03:00
|
|
|
FORWARD_FUNCTION(PopLayer)
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetTransform(const Matrix &aTransform) override {
|
2012-04-04 00:25:52 +04:00
|
|
|
mTransform = aTransform;
|
|
|
|
mA->SetTransform(aTransform);
|
|
|
|
mB->SetTransform(aTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions) override;
|
2013-06-13 07:57:51 +04:00
|
|
|
|
2013-11-27 15:22:56 +04:00
|
|
|
virtual void DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override
|
2013-11-27 15:22:56 +04:00
|
|
|
{
|
|
|
|
mA->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions);
|
|
|
|
mB->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions);
|
|
|
|
}
|
|
|
|
|
2013-06-13 07:57:51 +04:00
|
|
|
virtual void MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2013-06-13 07:57:51 +04:00
|
|
|
|
2012-04-04 00:25:52 +04:00
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
|
|
|
|
const Color &aColor, const Point &aOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
Float aSigma, CompositionOp aOp) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2018-08-01 20:45:35 +03:00
|
|
|
virtual void ClearRect(const Rect &aRect) override;
|
|
|
|
|
2012-04-04 00:25:52 +04:00
|
|
|
virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
const IntPoint &aDestination) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
virtual void Stroke(const Path *aPath, const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer,
|
2017-11-03 04:42:56 +03:00
|
|
|
const Pattern &aPattern, const DrawOptions &aOptions) override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions) override;
|
2016-01-06 02:23:33 +03:00
|
|
|
|
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity,
|
|
|
|
SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
|
|
|
bool aCopyBackground = false) override;
|
|
|
|
|
2018-08-01 20:50:32 +03:00
|
|
|
virtual bool Unrotate(IntPoint aRotation) override
|
|
|
|
{
|
|
|
|
return mA->Unrotate(aRotation) &&
|
|
|
|
mB->Unrotate(aRotation);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface>
|
2012-04-04 00:25:52 +04:00
|
|
|
CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
2015-03-21 19:28:04 +03:00
|
|
|
SurfaceFormat aFormat) const override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
|
|
|
return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
|
|
|
return mA->OptimizeSourceSurface(aSurface);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface>
|
2015-03-21 19:28:04 +03:00
|
|
|
CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
|
|
|
return mA->CreateSourceSurfaceFromNativeSurface(aSurface);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget>
|
2015-03-21 19:28:04 +03:00
|
|
|
CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override;
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
|
|
|
return mA->CreatePathBuilder(aFillRule);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<GradientStops>
|
2012-04-04 00:25:52 +04:00
|
|
|
CreateGradientStops(GradientStop *aStops,
|
|
|
|
uint32_t aNumStops,
|
2015-03-21 19:28:04 +03:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
|
|
|
return mA->CreateGradientStops(aStops, aNumStops, aExtendMode);
|
|
|
|
}
|
2013-11-27 15:22:56 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override
|
2013-11-27 15:22:56 +04:00
|
|
|
{
|
|
|
|
return mA->CreateFilter(aType);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void *GetNativeSurface(NativeSurfaceType aType) override
|
2012-04-04 00:25:52 +04:00
|
|
|
{
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2012-04-04 00:25:52 +04:00
|
|
|
}
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsDualDrawTarget() const override
|
2013-07-13 01:19:29 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-06 02:23:33 +03:00
|
|
|
|
|
|
|
virtual bool IsCurrentGroupOpaque() override { return mA->IsCurrentGroupOpaque(); }
|
2012-04-04 00:25:52 +04:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> mA;
|
|
|
|
RefPtr<DrawTarget> mB;
|
2012-04-04 00:25:52 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-04-04 00:25:52 +04:00
|
|
|
|
2012-08-14 22:06:12 +04:00
|
|
|
#endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */
|