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/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#ifndef _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
|
|
|
|
#define _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
2011-06-26 18:10:35 +04:00
|
|
|
#include "cairo.h"
|
2012-01-10 02:15:10 +04:00
|
|
|
#include "PathCairo.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
#include <vector>
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
class SourceSurfaceCairo;
|
|
|
|
|
|
|
|
class GradientStopsCairo : public GradientStops
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsCairo)
|
2012-10-10 14:32:36 +04:00
|
|
|
GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops,
|
|
|
|
ExtendMode aExtendMode)
|
|
|
|
: mExtendMode(aExtendMode)
|
2012-01-10 01:50:01 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aNumStops; ++i) {
|
|
|
|
mStops.push_back(aStops[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GradientStopsCairo() {}
|
|
|
|
|
|
|
|
const std::vector<GradientStop>& GetStops() const
|
|
|
|
{
|
|
|
|
return mStops;
|
|
|
|
}
|
|
|
|
|
2012-10-10 14:32:36 +04:00
|
|
|
ExtendMode GetExtendMode() const
|
|
|
|
{
|
|
|
|
return mExtendMode;
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:06:16 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
2012-01-10 01:50:01 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<GradientStop> mStops;
|
2012-10-10 14:32:36 +04:00
|
|
|
ExtendMode mExtendMode;
|
2012-01-10 01:50:01 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 21:35:18 +03:00
|
|
|
class DrawTargetCairo final : public DrawTarget
|
2011-06-24 21:41:16 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetCairo, override)
|
2013-09-20 06:00:35 +04:00
|
|
|
friend class BorrowedCairoContext;
|
2015-05-01 21:08:04 +03:00
|
|
|
friend class BorrowedXlibDrawable;
|
2013-09-20 06:00:35 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
DrawTargetCairo();
|
|
|
|
virtual ~DrawTargetCairo();
|
|
|
|
|
2015-12-04 21:43:00 +03:00
|
|
|
virtual bool IsValid() const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual DrawTargetType GetType() const override;
|
|
|
|
virtual BackendType GetBackendType() const override { return BackendType::CAIRO; }
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> Snapshot() override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual IntSize GetSize() override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2016-01-06 02:04:38 +03:00
|
|
|
virtual bool IsCurrentGroupOpaque() override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
|
2013-11-05 08:50:56 +04:00
|
|
|
|
2013-10-12 00:47:47 +04:00
|
|
|
virtual bool LockBits(uint8_t** aData, IntSize* aSize,
|
2016-01-13 21:11:07 +03:00
|
|
|
int32_t* aStride, SurfaceFormat* aFormat,
|
|
|
|
IntPoint* aOrigin = nullptr) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ReleaseBits(uint8_t* aData) override;
|
2013-10-12 00:47:47 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Flush() override;
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
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;
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
2011-07-05 10:28:14 +04:00
|
|
|
Float aSigma,
|
2015-03-21 19:28:04 +03:00
|
|
|
CompositionOp aOperator) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ClearRect(const Rect &aRect) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
const IntPoint &aDestination) override;
|
2013-10-15 05:55:16 +04:00
|
|
|
virtual void CopyRect(const IntRect &aSourceRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
const IntPoint &aDestination) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
2017-11-03 04:42:56 +03:00
|
|
|
const DrawOptions &aOptions) override;
|
2011-12-28 09:56:11 +04:00
|
|
|
virtual void Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2013-06-28 00:20:30 +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;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2016-03-23 08:03:10 +03:00
|
|
|
virtual bool Draw3DTransformedSurface(SourceSurface* aSurface,
|
|
|
|
const Matrix4x4& aMatrix) override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PushClip(const Path *aPath) override;
|
|
|
|
virtual void PushClipRect(const Rect &aRect) override;
|
|
|
|
virtual void PopClip() override;
|
2016-01-06 02:04:38 +03:00
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity,
|
|
|
|
SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
|
|
|
bool aCopyBackground = false) override;
|
|
|
|
virtual void PopLayer() override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
|
2011-06-24 21:41:16 +04:00
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
2015-03-21 19:28:04 +03:00
|
|
|
SurfaceFormat aFormat) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override;
|
|
|
|
virtual already_AddRefed<SourceSurface>
|
2015-03-21 19:28:04 +03:00
|
|
|
CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override;
|
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;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget>
|
2012-09-03 03:07:06 +04:00
|
|
|
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
|
2015-03-21 19:28:04 +03:00
|
|
|
float aSigma) const override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<GradientStops>
|
2012-01-10 01:50:01 +04:00
|
|
|
CreateGradientStops(GradientStop *aStops,
|
|
|
|
uint32_t aNumStops,
|
2015-03-21 19:28:04 +03:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const override;
|
2011-06-24 21:41:16 +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
|
|
|
|
2016-08-10 02:49:00 +03:00
|
|
|
virtual void GetGlyphRasterizationMetrics(ScaledFont *aScaledFont, const uint16_t* aGlyphIndices,
|
|
|
|
uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void *GetNativeSurface(NativeSurfaceType aType) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-04-15 07:46:31 +04:00
|
|
|
bool Init(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
|
2013-11-04 03:57:36 +04:00
|
|
|
bool Init(const IntSize& aSize, SurfaceFormat aFormat);
|
|
|
|
bool Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetTransform(const Matrix& aTransform) override;
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2016-07-01 11:58:13 +03:00
|
|
|
virtual void DetachAllSnapshots() override { MarkSnapshotIndependent(); }
|
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
// Call to set up aContext for drawing (with the current transform, etc).
|
|
|
|
// Pass the path you're going to be using if you have one.
|
|
|
|
// Implicitly calls WillChange(aPath).
|
2012-08-14 22:06:12 +04:00
|
|
|
void PrepareForDrawing(cairo_t* aContext, const Path* aPath = nullptr);
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2013-09-28 18:20:24 +04:00
|
|
|
static cairo_surface_t *GetDummySurface();
|
|
|
|
|
2015-02-25 00:39:01 +03:00
|
|
|
// Cairo hardcodes this as its maximum surface size.
|
|
|
|
static size_t GetMaxSurfaceSize() {
|
|
|
|
return 32767;
|
|
|
|
}
|
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
private: // methods
|
2012-08-24 03:50:59 +04:00
|
|
|
// Init cairo surface without doing a cairo_surface_reference() call.
|
2014-04-15 07:46:31 +04:00
|
|
|
bool InitAlreadyReferenced(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr);
|
2012-01-10 01:50:01 +04:00
|
|
|
enum DrawPatternType { DRAW_FILL, DRAW_STROKE };
|
2012-01-10 02:15:10 +04:00
|
|
|
void DrawPattern(const Pattern& aPattern,
|
2012-01-10 01:50:01 +04:00
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions,
|
2013-10-18 03:08:20 +04:00
|
|
|
DrawPatternType aDrawType,
|
|
|
|
bool aPathBoundsClip = false);
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2013-10-15 05:55:16 +04:00
|
|
|
void CopySurfaceInternal(cairo_surface_t* aSurface,
|
|
|
|
const IntRect& aSource,
|
|
|
|
const IntPoint& aDest);
|
|
|
|
|
2013-10-22 14:11:30 +04:00
|
|
|
Rect GetUserSpaceClip();
|
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
// Call before you make any changes to the backing surface with which this
|
2012-01-10 02:15:10 +04:00
|
|
|
// context is associated. Pass the path you're going to be using if you have
|
|
|
|
// one.
|
2012-08-14 22:06:12 +04:00
|
|
|
void WillChange(const Path* aPath = nullptr);
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2012-09-06 08:07:53 +04:00
|
|
|
// Call if there is any reason to disassociate the snapshot from this draw
|
2012-01-10 01:50:01 +04:00
|
|
|
// target; for example, because we're going to be destroyed.
|
2012-09-06 08:07:53 +04:00
|
|
|
void MarkSnapshotIndependent();
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2012-07-24 14:18:38 +04:00
|
|
|
// If the current operator is "source" then clear the destination before we
|
|
|
|
// draw into it, to simulate the effect of an unbounded source operator.
|
|
|
|
void ClearSurfaceForUnboundedSource(const CompositionOp &aOperator);
|
2014-07-01 09:52:51 +04:00
|
|
|
|
2016-08-26 22:28:28 +03:00
|
|
|
// Set the Cairo context font options according to the current draw target
|
|
|
|
// font state.
|
|
|
|
void SetFontOptions();
|
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
private: // data
|
2011-06-24 21:41:16 +04:00
|
|
|
cairo_t* mContext;
|
2012-07-24 14:18:38 +04:00
|
|
|
cairo_surface_t* mSurface;
|
2012-07-24 14:18:38 +04:00
|
|
|
IntSize mSize;
|
2015-11-16 07:35:23 +03:00
|
|
|
bool mTransformSingular;
|
2012-09-06 08:07:53 +04:00
|
|
|
|
2013-10-12 00:47:47 +04:00
|
|
|
uint8_t* mLockedBits;
|
|
|
|
|
2016-08-26 22:28:28 +03:00
|
|
|
cairo_font_options_t* mFontOptions;
|
|
|
|
|
2016-01-06 02:04:38 +03:00
|
|
|
struct PushedLayer
|
|
|
|
{
|
|
|
|
PushedLayer(Float aOpacity, bool aWasPermittingSubpixelAA)
|
|
|
|
: mOpacity(aOpacity)
|
|
|
|
, mMaskPattern(nullptr)
|
|
|
|
, mWasPermittingSubpixelAA(aWasPermittingSubpixelAA)
|
|
|
|
{}
|
|
|
|
Float mOpacity;
|
|
|
|
cairo_pattern_t* mMaskPattern;
|
|
|
|
bool mWasPermittingSubpixelAA;
|
|
|
|
};
|
|
|
|
std::vector<PushedLayer> mPushedLayers;
|
|
|
|
|
2012-09-06 08:07:53 +04:00
|
|
|
// The latest snapshot of this surface. This needs to be told when this
|
|
|
|
// target is modified. We keep it alive as a cache.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurfaceCairo> mSnapshot;
|
2013-09-28 18:20:24 +04:00
|
|
|
static cairo_surface_t *mDummySurface;
|
2011-06-24 21:41:16 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#endif // _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
|