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 "nsAutoPtr.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxMatrix.h"
|
2013-10-02 01:01:19 +04:00
|
|
|
#include "GraphicsFilter.h"
|
2013-11-13 08:31:12 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
class gfxASurface;
|
|
|
|
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:
|
|
|
|
gfxDrawable(const gfxIntSize aSize)
|
|
|
|
: 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 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepeat,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
2010-08-13 17:30:14 +04:00
|
|
|
virtual gfxIntSize Size() { return mSize; }
|
|
|
|
|
|
|
|
protected:
|
2014-04-04 20:27:02 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~gfxDrawable() {}
|
|
|
|
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxIntSize mSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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:
|
2013-11-27 05:05:03 +04:00
|
|
|
gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface, const gfxIntSize aSize,
|
|
|
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepeat,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2013-09-19 09:23:31 +04:00
|
|
|
|
2010-08-13 17:30:14 +04:00
|
|
|
protected:
|
2013-11-27 05:05:03 +04:00
|
|
|
mozilla::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
|
|
|
/**
|
|
|
|
* 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 10:19:26 +04:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix()) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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:
|
|
|
|
gfxCallbackDrawable(gfxDrawingCallback* aCallback, const gfxIntSize aSize);
|
|
|
|
virtual ~gfxCallbackDrawable() {}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool Draw(gfxContext* aContext,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepeat,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
protected:
|
2013-10-02 01:01:19 +04:00
|
|
|
already_AddRefed<gfxSurfaceDrawable> MakeSurfaceDrawable(const GraphicsFilter aFilter = GraphicsFilter::FILTER_FAST);
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
nsRefPtr<gfxDrawingCallback> mCallback;
|
|
|
|
nsRefPtr<gfxSurfaceDrawable> mSurfaceDrawable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
const gfxIntSize 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,
|
2010-08-13 17:30:14 +04:00
|
|
|
const gfxRect& aFillRect,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepeat,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2014-08-07 02:43:25 +04:00
|
|
|
const gfxMatrix& aTransform = gfxMatrix());
|
2010-08-13 17:30:14 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
already_AddRefed<gfxCallbackDrawable> MakeCallbackDrawable();
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> mPattern;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_DRAWABLE_H */
|