2010-08-13 17:30:14 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
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/. */
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
#ifndef GFX_DRAWABLE_H
|
|
|
|
#define GFX_DRAWABLE_H
|
|
|
|
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxMatrix.h"
|
2013-11-13 08:31:12 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-11-23 19:17:35 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
class gfxContext;
|
2013-10-02 01:01:19 +04:00
|
|
|
class gfxPattern;
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxDrawable
|
|
|
|
* An Interface representing something that has an intrinsic size and can draw
|
|
|
|
* itself repeatedly.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxDrawable {
|
2010-08-13 17:30:14 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxDrawable)
|
|
|
|
public:
|
2016-01-07 05:26:33 +03:00
|
|
|
typedef mozilla::gfx::AntialiasMode AntialiasMode;
|
|
|
|
typedef mozilla::gfx::CompositionOp CompositionOp;
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
|
2015-06-01 11:26:19 +03:00
|
|
|
explicit gfxDrawable(const mozilla::gfx::IntSize aSize)
|
2010-08-13 17:30:14 +04:00
|
|
|
: mSize(aSize) {}
|
|
|
|
|
|
|
|
/**
|
2016-05-25 19:01:18 +03:00
|
|
|
* Draw into aContext filling aFillRect, possibly repeating, using aSamplingFilter.
|
2010-08-13 17:30:14 +04: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 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-08-29 18:04:34 +04:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2016-01-07 05:26:33 +03:00
|
|
|
virtual bool DrawWithSamplingRect(DrawTarget* aDrawTarget,
|
|
|
|
CompositionOp aOp,
|
|
|
|
AntialiasMode aAntialiasMode,
|
2014-09-12 09:18:21 +04:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const gfxRect& aSamplingRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-09-12 09:18:21 +04:00
|
|
|
gfxFloat aOpacity = 1.0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-01 11:26:19 +03:00
|
|
|
virtual mozilla::gfx::IntSize Size() { return mSize; }
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
protected:
|
2014-04-04 20:27:02 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~gfxDrawable() {}
|
|
|
|
|
2015-06-01 11:26:19 +03:00
|
|
|
const mozilla::gfx::IntSize mSize;
|
2010-08-13 17:30:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxSurfaceDrawable
|
|
|
|
* A convenience implementation of gfxDrawable for surfaces.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxSurfaceDrawable : public gfxDrawable {
|
2010-08-13 17:30:14 +04:00
|
|
|
public:
|
2015-06-01 11:26:19 +03:00
|
|
|
gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface, const mozilla::gfx::IntSize aSize,
|
2013-11-27 05:05:03 +04:00
|
|
|
const gfxMatrix aTransform = gfxMatrix());
|
2010-08-13 17:30:14 +04:00
|
|
|
virtual ~gfxSurfaceDrawable() {}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-08-29 18:04:34 +04:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2016-01-07 05:26:33 +03:00
|
|
|
virtual bool DrawWithSamplingRect(DrawTarget* aDrawTarget,
|
|
|
|
CompositionOp aOp,
|
|
|
|
AntialiasMode aAntialiasMode,
|
2014-09-12 09:18:21 +04:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const gfxRect& aSamplingRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-09-12 09:18:21 +04:00
|
|
|
gfxFloat aOpacity = 1.0);
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2010-08-13 17:30:14 +04:00
|
|
|
protected:
|
2016-01-07 05:26:33 +03:00
|
|
|
void DrawInternal(DrawTarget* aDrawTarget,
|
|
|
|
CompositionOp aOp,
|
|
|
|
AntialiasMode aAntialiasMode,
|
2014-09-12 09:18:21 +04:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const mozilla::gfx::IntRect& aSamplingRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2014-09-12 09:18:21 +04:00
|
|
|
gfxFloat aOpacity,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxMatrix mTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxDrawingCallback
|
|
|
|
* A simple drawing functor.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxDrawingCallback {
|
2010-08-13 17:30:14 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxDrawingCallback)
|
2014-04-04 20:27:02 +04:00
|
|
|
protected:
|
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2010-08-13 17:30:14 +04:00
|
|
|
virtual ~gfxDrawingCallback() {}
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
public:
|
2010-08-13 17:30:14 +04:00
|
|
|
/**
|
2016-05-25 19:01:18 +03:00
|
|
|
* Draw into aContext filling aFillRect using aSamplingFilter.
|
2010-08-13 17:30:14 +04: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 10:19:26 +04:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxRect& aFillRect,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-04-16 20:53:33 +04:00
|
|
|
* gfxCallbackDrawable
|
2010-08-13 17:30:14 +04:00
|
|
|
* A convenience implementation of gfxDrawable for callbacks.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxCallbackDrawable : public gfxDrawable {
|
2010-08-13 17:30:14 +04:00
|
|
|
public:
|
2015-06-01 11:26:19 +03:00
|
|
|
gfxCallbackDrawable(gfxDrawingCallback* aCallback, const mozilla::gfx::IntSize aSize);
|
2010-08-13 17:30:14 +04:00
|
|
|
virtual ~gfxCallbackDrawable() {}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxRect& aFillRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 03:18:10 +03:00
|
|
|
gfxFloat aOpacity = 1.0,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
protected:
|
2016-05-25 19:01:18 +03:00
|
|
|
already_AddRefed<gfxSurfaceDrawable>
|
|
|
|
MakeSurfaceDrawable(mozilla::gfx::SamplingFilter aSamplingFilter =
|
|
|
|
mozilla::gfx::SamplingFilter::LINEAR);
|
2010-08-13 17:30:14 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawingCallback> mCallback;
|
|
|
|
RefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
|
2010-08-13 17:30:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxPatternDrawable
|
|
|
|
* A convenience implementation of gfxDrawable for patterns.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxPatternDrawable : public gfxDrawable {
|
2010-08-13 17:30:14 +04:00
|
|
|
public:
|
|
|
|
gfxPatternDrawable(gfxPattern* aPattern,
|
2015-06-01 11:26:19 +03:00
|
|
|
const mozilla::gfx::IntSize aSize);
|
2013-10-16 02:00:28 +04:00
|
|
|
virtual ~gfxPatternDrawable();
|
2010-08-13 17:30:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxRect& aFillRect,
|
2015-11-23 19:17:35 +03:00
|
|
|
mozilla::gfx::ExtendMode aExtendMode,
|
2016-05-25 19:01:18 +03:00
|
|
|
const mozilla::gfx::SamplingFilter aSamplingFilter,
|
2015-10-06 03:18:10 +03:00
|
|
|
gfxFloat aOpacity = 1.0,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 17:30:14 +04:00
|
|
|
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2010-08-13 17:30:14 +04:00
|
|
|
protected:
|
|
|
|
already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> mPattern;
|
2010-08-13 17:30:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_DRAWABLE_H */
|