2018-11-30 19:52:05 +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/. */
|
2010-08-13 13:30:14 +00:00
|
|
|
|
|
|
|
#ifndef GFX_DRAWABLE_H
|
|
|
|
#define GFX_DRAWABLE_H
|
|
|
|
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxMatrix.h"
|
2017-07-05 15:22:00 +00:00
|
|
|
#include "gfxTypes.h"
|
2013-11-13 04:31:12 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-11-23 16:17:35 +00:00
|
|
|
#include "mozilla/gfx/Types.h"
|
2017-07-05 15:22:00 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2010-08-13 13:30:14 +00:00
|
|
|
|
|
|
|
class gfxContext;
|
2013-10-01 21:01:19 +00:00
|
|
|
class gfxPattern;
|
2010-08-13 13:30:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxDrawable
|
|
|
|
* An Interface representing something that has an intrinsic size and can draw
|
|
|
|
* itself repeatedly.
|
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxDrawable {
|
2010-08-13 13:30:14 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
|
|
|
|
public:
|
2016-01-07 02:26:33 +00:00
|
|
|
typedef mozilla::gfx::AntialiasMode AntialiasMode;
|
|
|
|
typedef mozilla::gfx::CompositionOp CompositionOp;
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-06-01 08:26:19 +00:00
|
|
|
explicit gfxDrawable(const mozilla::gfx::IntSize aSize) : mSize(aSize) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
/**
|
2016-05-25 16:01:18 +00:00
|
|
|
* Draw into aContext filling aFillRect, possibly repeating, using
|
2010-08-13 13:30:14 +00:00
|
|
|
* aSamplingFilter. aTransform is a userspace to "image"space matrix. For
|
|
|
|
* example, if Draw draws using a gfxPattern, this is the matrix that should
|
|
|
|
* be set on the pattern prior to rendering it.
|
|
|
|
* @return whether drawing was successful
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext, const gfxRect& aFillRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2014-08-06 22:43:25 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-01-07 02:26:33 +00:00
|
|
|
virtual bool DrawWithSamplingRect(
|
|
|
|
DrawTarget* aDrawTarget, CompositionOp aOp, AntialiasMode aAntialiasMode,
|
2014-09-12 05:18:21 +00:00
|
|
|
const gfxRect& aFillRect, const gfxRect& aSamplingRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-09-12 05:18:21 +00:00
|
|
|
gfxFloat aOpacity = 1.0) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-06-01 08:26:19 +00:00
|
|
|
virtual mozilla::gfx::IntSize Size() { return mSize; }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
protected:
|
2014-04-04 16:27:02 +00:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~gfxDrawable() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-06-01 08:26:19 +00:00
|
|
|
const mozilla::gfx::IntSize mSize;
|
2010-08-13 13:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxSurfaceDrawable
|
|
|
|
* A convenience implementation of gfxDrawable for surfaces.
|
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxSurfaceDrawable : public gfxDrawable {
|
2010-08-13 13:30:14 +00:00
|
|
|
public:
|
2015-06-01 08:26:19 +00:00
|
|
|
gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface,
|
|
|
|
const mozilla::gfx::IntSize aSize,
|
2013-11-27 01:05:03 +00:00
|
|
|
const gfxMatrix aTransform = gfxMatrix());
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~gfxSurfaceDrawable() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext, const gfxRect& aFillRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2017-11-06 03:37:28 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-01-07 02:26:33 +00:00
|
|
|
virtual bool DrawWithSamplingRect(
|
|
|
|
DrawTarget* aDrawTarget, CompositionOp aOp, AntialiasMode aAntialiasMode,
|
2014-09-12 05:18:21 +00:00
|
|
|
const gfxRect& aFillRect, const gfxRect& aSamplingRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2017-11-06 03:37:28 +00:00
|
|
|
gfxFloat aOpacity = 1.0) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
protected:
|
2016-01-07 02:26:33 +00:00
|
|
|
void DrawInternal(DrawTarget* aDrawTarget, CompositionOp aOp,
|
|
|
|
AntialiasMode aAntialiasMode, const gfxRect& aFillRect,
|
2014-09-12 05:18:21 +00:00
|
|
|
const mozilla::gfx::IntRect& aSamplingRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-09-12 05:18:21 +00:00
|
|
|
gfxFloat aOpacity,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
|
2010-08-13 13:30:14 +00:00
|
|
|
const gfxMatrix mTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxDrawingCallback
|
|
|
|
* A simple drawing functor.
|
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxDrawingCallback {
|
2010-08-13 13:30:14 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
|
2014-04-04 16:27:02 +00:00
|
|
|
protected:
|
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~gfxDrawingCallback() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-04-04 16:27:02 +00:00
|
|
|
public:
|
2010-08-13 13:30:14 +00:00
|
|
|
/**
|
2016-05-25 16:01:18 +00:00
|
|
|
* Draw into aContext filling aFillRect using aSamplingFilter.
|
2010-08-13 13:30:14 +00:00
|
|
|
* aTransform is a userspace to "image"space matrix. For example, if Draw
|
|
|
|
* draws using a gfxPattern, this is the matrix that should be set on the
|
|
|
|
* pattern prior to rendering it.
|
|
|
|
* @return whether drawing was successful
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool operator()(gfxContext* aContext, const gfxRect& aFillRect,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 00:18:10 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
2010-08-13 13:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-04-16 16:53:33 +00:00
|
|
|
* gfxCallbackDrawable
|
2010-08-13 13:30:14 +00:00
|
|
|
* A convenience implementation of gfxDrawable for callbacks.
|
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxCallbackDrawable : public gfxDrawable {
|
2010-08-13 13:30:14 +00:00
|
|
|
public:
|
2015-06-01 08:26:19 +00:00
|
|
|
gfxCallbackDrawable(gfxDrawingCallback* aCallback,
|
|
|
|
const mozilla::gfx::IntSize aSize);
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~gfxCallbackDrawable() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext, const gfxRect& aFillRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 00:18:10 +00:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2017-11-06 03:37:28 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
protected:
|
2016-05-25 16:01:18 +00:00
|
|
|
already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(
|
2017-06-09 22:12:40 +00:00
|
|
|
gfxContext* aContext, mozilla::gfx::SamplingFilter aSamplingFilter =
|
|
|
|
mozilla::gfx::SamplingFilter::LINEAR);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxDrawingCallback> mCallback;
|
|
|
|
RefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
|
2010-08-13 13:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxPatternDrawable
|
|
|
|
* A convenience implementation of gfxDrawable for patterns.
|
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxPatternDrawable : public gfxDrawable {
|
2010-08-13 13:30:14 +00:00
|
|
|
public:
|
|
|
|
gfxPatternDrawable(gfxPattern* aPattern, const mozilla::gfx::IntSize aSize);
|
2013-10-15 22:00:28 +00:00
|
|
|
virtual ~gfxPatternDrawable();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext, const gfxRect& aFillRect,
|
2015-11-23 16:17:35 +00:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 16:01:18 +00:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 00:18:10 +00:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2017-11-06 03:37:28 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
protected:
|
|
|
|
already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxPattern> mPattern;
|
2010-08-13 13:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_DRAWABLE_H */
|