2011-06-24 21:41:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 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
|
|
|
};
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
class DrawTargetCairo : public DrawTarget
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetCairo)
|
2013-09-20 06:00:35 +04:00
|
|
|
friend class BorrowedCairoContext;
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
DrawTargetCairo();
|
|
|
|
virtual ~DrawTargetCairo();
|
|
|
|
|
2014-06-27 13:17:49 +04:00
|
|
|
virtual DrawTargetType GetType() const MOZ_OVERRIDE;
|
2014-06-20 00:35:33 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual TemporaryRef<SourceSurface> Snapshot();
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual IntSize GetSize();
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2013-11-05 08:50:56 +04:00
|
|
|
virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA);
|
|
|
|
|
2013-10-12 00:47:47 +04:00
|
|
|
virtual bool LockBits(uint8_t** aData, IntSize* aSize,
|
|
|
|
int32_t* aStride, SurfaceFormat* aFormat);
|
|
|
|
virtual void ReleaseBits(uint8_t* aData);
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void Flush();
|
|
|
|
virtual void DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2013-11-27 15:22:56 +04:00
|
|
|
virtual void DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
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,
|
2012-01-10 01:50:01 +04:00
|
|
|
CompositionOp aOperator);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual void ClearRect(const Rect &aRect);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
2012-01-10 01:50:01 +04:00
|
|
|
const IntPoint &aDestination);
|
2013-10-15 05:55:16 +04:00
|
|
|
virtual void CopyRect(const IntRect &aSourceRect,
|
|
|
|
const IntPoint &aDestination);
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
|
|
|
virtual void StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2012-01-10 01:50:01 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-06-24 21:41:16 +04:00
|
|
|
virtual void StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2012-01-10 01:50:01 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2012-01-10 01:50:01 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
2012-01-10 01:50:01 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual void FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
2012-03-19 23:20:17 +04:00
|
|
|
const DrawOptions &aOptions,
|
2012-08-14 22:06:12 +04:00
|
|
|
const GlyphRenderingOptions *aRenderingOptions = nullptr);
|
2011-12-28 09:56:11 +04:00
|
|
|
virtual void Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
2012-01-10 02:15:10 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2013-06-28 00:20:30 +04:00
|
|
|
virtual void MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
2013-07-11 18:43:34 +04:00
|
|
|
const DrawOptions &aOptions = DrawOptions());
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual void PushClip(const Path *aPath);
|
2012-01-10 02:15:10 +04:00
|
|
|
virtual void PushClipRect(const Rect &aRect);
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual void PopClip();
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-01-10 23:06:17 +04:00
|
|
|
virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const;
|
|
|
|
virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
|
|
|
|
virtual TemporaryRef<SourceSurface>
|
|
|
|
CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
|
|
|
|
virtual TemporaryRef<DrawTarget>
|
2012-01-10 01:50:01 +04:00
|
|
|
CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
|
2012-09-03 03:07:06 +04:00
|
|
|
virtual TemporaryRef<DrawTarget>
|
2012-09-03 03:07:06 +04:00
|
|
|
CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat,
|
|
|
|
float aSigma) const;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual TemporaryRef<GradientStops>
|
|
|
|
CreateGradientStops(GradientStop *aStops,
|
|
|
|
uint32_t aNumStops,
|
2014-01-10 23:06:17 +04:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2013-11-27 15:22:56 +04:00
|
|
|
virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
|
|
|
|
|
2012-01-10 01:50:01 +04:00
|
|
|
virtual void *GetNativeSurface(NativeSurfaceType aType);
|
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
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
virtual void SetTransform(const Matrix& aTransform);
|
2012-01-10 01:50:01 +04:00
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
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;
|
2012-09-06 08:07:53 +04:00
|
|
|
|
2013-10-12 00:47:47 +04:00
|
|
|
uint8_t* mLockedBits;
|
|
|
|
|
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.
|
|
|
|
RefPtr<SourceSurfaceCairo> mSnapshot;
|
2013-09-28 18:20:24 +04:00
|
|
|
static cairo_surface_t *mDummySurface;
|
2011-06-24 21:41:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _MOZILLA_GFX_DRAWTARGET_CAIRO_H_
|