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:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsCairo, override)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
GradientStopsCairo(GradientStop* aStops, uint32_t aNumStops,
|
2012-10-10 14:32:36 +04:00
|
|
|
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]);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~GradientStopsCairo() = default;
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const std::vector<GradientStop>& GetStops() const { return mStops; }
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2012-10-10 14:32:36 +04:00
|
|
|
ExtendMode GetExtendMode() const { return mExtendMode; }
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual BackendType GetBackendType() const override {
|
|
|
|
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;
|
2018-01-23 20:10:11 +03:00
|
|
|
virtual IntSize GetSize() const 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
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual bool LockBits(uint8_t** aData, IntSize* aSize, int32_t* aStride,
|
|
|
|
SurfaceFormat* aFormat,
|
|
|
|
IntPoint* aOrigin = nullptr) override;
|
|
|
|
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(
|
2019-05-01 11:47:10 +03:00
|
|
|
SourceSurface* aSurface, const Rect& aDest, const Rect& aSource,
|
|
|
|
const DrawSurfaceOptions& aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void DrawFilter(FilterNode* aNode, const Rect& aSourceRect,
|
|
|
|
const Point& aDestPoint,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface* aSurface,
|
|
|
|
const Point& aDest, const Color& aColor,
|
|
|
|
const Point& aOffset, Float aSigma,
|
2015-03-21 19:28:04 +03:00
|
|
|
CompositionOp aOperator) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void ClearRect(const Rect& aRect) override;
|
|
|
|
|
|
|
|
virtual void CopySurface(SourceSurface* aSurface, const IntRect& aSourceRect,
|
|
|
|
const IntPoint& aDestination) override;
|
|
|
|
virtual void CopyRect(const IntRect& aSourceRect,
|
|
|
|
const IntPoint& aDestination) override;
|
|
|
|
|
|
|
|
virtual void FillRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void StrokeRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void StrokeLine(const Point& aStart, const Point& aEnd,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
|
|
|
virtual void Stroke(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
|
|
|
virtual void Fill(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
|
|
|
virtual void FillGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions) override;
|
|
|
|
virtual void Mask(const Pattern& aSource, const Pattern& aMask,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2013-06-28 00:20:30 +04:00
|
|
|
virtual void MaskSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
const Pattern& aSource, SourceSurface* aMask, Point aOffset,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual bool Draw3DTransformedSurface(SourceSurface* aSurface,
|
|
|
|
const Matrix4x4& aMatrix) override;
|
2016-03-23 08:03:10 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void PushClip(const Path* aPath) override;
|
|
|
|
virtual void PushClipRect(const Rect& aRect) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PopClip() override;
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
2016-01-06 02:04:38 +03:00
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(
|
2019-05-01 11:47:10 +03:00
|
|
|
unsigned char* aData, 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(
|
2019-05-01 11:47:10 +03:00
|
|
|
SourceSurface* aSurface) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromNativeSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
const NativeSurface& aSurface) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateSimilarDrawTarget(
|
2019-05-01 11:47:10 +03:00
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateShadowDrawTarget(
|
2019-05-01 11:47:10 +03:00
|
|
|
const IntSize& aSize, SurfaceFormat aFormat, float aSigma) const override;
|
2019-06-21 12:51:00 +03:00
|
|
|
virtual RefPtr<DrawTarget> CreateClippedDrawTarget(
|
|
|
|
const Rect& aBounds, SurfaceFormat aFormat) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<GradientStops> CreateGradientStops(
|
2019-05-01 11:47:10 +03:00
|
|
|
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(
|
2019-05-01 11:47:10 +03:00
|
|
|
ScaledFont* aScaledFont, const uint16_t* aGlyphIndices,
|
|
|
|
uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) override;
|
2016-08-10 02:49:00 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void* GetNativeSurface(NativeSurfaceType aType) override;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool Init(cairo_surface_t* aSurface, const IntSize& aSize,
|
|
|
|
SurfaceFormat* aFormat = nullptr);
|
|
|
|
bool Init(const IntSize& aSize, SurfaceFormat aFormat);
|
|
|
|
bool Init(unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
2013-11-04 03:57:36 +04:00
|
|
|
SurfaceFormat aFormat);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2019-05-01 11:47:10 +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).
|
2019-05-01 11:47:10 +03:00
|
|
|
void PrepareForDrawing(cairo_t* aContext, const Path* aPath = nullptr);
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static cairo_surface_t* GetDummySurface();
|
2013-09-28 18:20:24 +04:00
|
|
|
|
2015-02-25 00:39:01 +03:00
|
|
|
// Cairo hardcodes this as its maximum surface size.
|
2019-05-10 06:00:34 +03:00
|
|
|
static size_t GetMaxSurfaceSize() { return 32766; }
|
2015-02-25 00:39:01 +03:00
|
|
|
|
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.
|
2019-05-01 11:47:10 +03: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 };
|
2019-05-01 11:47:10 +03:00
|
|
|
void DrawPattern(const Pattern& aPattern, const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions, DrawPatternType aDrawType,
|
2013-10-18 03:08:20 +04:00
|
|
|
bool aPathBoundsClip = false);
|
2012-01-10 01:50:01 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void CopySurfaceInternal(cairo_surface_t* aSurface, const IntRect& aSource,
|
|
|
|
const IntPoint& aDest);
|
2013-10-15 05:55:16 +04:00
|
|
|
|
2019-06-21 12:51:00 +03:00
|
|
|
Rect GetUserSpaceClip() const;
|
2013-10-22 14:11:30 +04:00
|
|
|
|
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.
|
2019-05-01 11:47:10 +03: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.
|
2019-05-01 11:47:10 +03:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
cairo_t* mContext;
|
|
|
|
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
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
uint8_t* mLockedBits;
|
2013-10-12 00:47:47 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
cairo_font_options_t* mFontOptions;
|
2016-08-26 22:28:28 +03:00
|
|
|
|
2016-01-06 02:04:38 +03:00
|
|
|
struct PushedLayer {
|
|
|
|
PushedLayer(Float aOpacity, bool aWasPermittingSubpixelAA)
|
|
|
|
: mOpacity(aOpacity),
|
|
|
|
mMaskPattern(nullptr),
|
|
|
|
mWasPermittingSubpixelAA(aWasPermittingSubpixelAA) {}
|
|
|
|
Float mOpacity;
|
2019-05-01 11:47:10 +03:00
|
|
|
cairo_pattern_t* mMaskPattern;
|
2016-01-06 02:04:38 +03:00
|
|
|
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;
|
2019-05-01 11:47:10 +03: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_
|