2010-08-13 13:30:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
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 "nsAutoPtr.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxMatrix.h"
|
2013-11-13 04:31:12 +00:00
|
|
|
#include "mozilla/gfx/2D.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:
|
2015-06-01 08:26:19 +00:00
|
|
|
explicit gfxDrawable(const mozilla::gfx::IntSize aSize)
|
2010-08-13 13:30:14 +00:00
|
|
|
: mSize(aSize) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw into aContext filling aFillRect, possibly repeating, using aFilter.
|
|
|
|
* 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,
|
2010-08-13 13:30:14 +00:00
|
|
|
const gfxRect& aFillRect,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aRepeat,
|
2015-10-06 00:18:10 +00:00
|
|
|
const mozilla::gfx::Filter& aFilter,
|
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;
|
2014-09-12 05:18:21 +00:00
|
|
|
virtual bool DrawWithSamplingRect(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const gfxRect& aSamplingRect,
|
|
|
|
bool aRepeat,
|
2015-10-06 00:18:10 +00:00
|
|
|
const mozilla::gfx::Filter& aFilter,
|
2014-09-12 05:18:21 +00:00
|
|
|
gfxFloat aOpacity = 1.0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-01 08:26:19 +00:00
|
|
|
virtual mozilla::gfx::IntSize Size() { return mSize; }
|
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():
|
|
|
|
virtual ~gfxDrawable() {}
|
|
|
|
|
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());
|
2010-08-13 13:30:14 +00:00
|
|
|
virtual ~gfxSurfaceDrawable() {}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2010-08-13 13:30:14 +00:00
|
|
|
const gfxRect& aFillRect,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aRepeat,
|
2015-10-06 00:18:10 +00:00
|
|
|
const mozilla::gfx::Filter& aFilter,
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat aOpacity = 1.0,
|
2014-08-06 22:43:25 +00:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2014-09-12 05:18:21 +00:00
|
|
|
virtual bool DrawWithSamplingRect(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const gfxRect& aSamplingRect,
|
|
|
|
bool aRepeat,
|
2015-10-06 00:18:10 +00:00
|
|
|
const mozilla::gfx::Filter& aFilter,
|
2014-09-12 05:18:21 +00:00
|
|
|
gfxFloat aOpacity = 1.0);
|
2013-09-19 05:23:31 +00:00
|
|
|
|
2010-08-13 13:30:14 +00:00
|
|
|
protected:
|
2014-09-12 05:18:21 +00:00
|
|
|
void DrawInternal(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const mozilla::gfx::IntRect& aSamplingRect,
|
|
|
|
bool aRepeat,
|
2015-10-06 00:18:10 +00:00
|
|
|
const mozilla::gfx::Filter& aFilter,
|
2014-09-12 05:18:21 +00:00
|
|
|
gfxFloat aOpacity,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
|
|
|
|
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():
|
2010-08-13 13:30:14 +00:00
|
|
|
virtual ~gfxDrawingCallback() {}
|
|
|
|
|
2014-04-04 16:27:02 +00:00
|
|
|
public:
|
2010-08-13 13:30:14 +00:00
|
|
|
/**
|
|
|
|
* Draw into aContext filling aFillRect using aFilter.
|
|
|
|
* 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,
|
2015-10-06 00:18:10 +00:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const mozilla::gfx::Filter& aFilter,
|
|
|
|
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);
|
2010-08-13 13:30:14 +00:00
|
|
|
virtual ~gfxCallbackDrawable() {}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2015-10-06 00:18:10 +00:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
bool aRepeat,
|
|
|
|
const mozilla::gfx::Filter& aFilter,
|
|
|
|
gfxFloat aOpacity = 1.0,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 13:30:14 +00:00
|
|
|
|
|
|
|
protected:
|
2015-10-06 00:18:10 +00:00
|
|
|
already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(mozilla::gfx::Filter aFilter = mozilla::gfx::Filter::LINEAR);
|
2010-08-13 13:30:14 +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,
|
2015-06-01 08:26:19 +00:00
|
|
|
const mozilla::gfx::IntSize aSize);
|
2013-10-15 22:00:28 +00:00
|
|
|
virtual ~gfxPatternDrawable();
|
2010-08-13 13:30:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2015-10-06 00:18:10 +00:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
bool aRepeat,
|
|
|
|
const mozilla::gfx::Filter& aFilter,
|
|
|
|
gfxFloat aOpacity = 1.0,
|
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 13:30:14 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxPattern> mPattern;
|
2010-08-13 13:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_DRAWABLE_H */
|