2005-04-18 06:33:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 40; 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/. */
|
2005-04-18 06:33:23 +00:00
|
|
|
|
|
|
|
#ifndef nsICanvasRenderingContextInternal_h___
|
|
|
|
#define nsICanvasRenderingContextInternal_h___
|
|
|
|
|
2014-04-17 10:13:34 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2005-04-18 06:33:23 +00:00
|
|
|
#include "nsISupports.h"
|
2005-08-31 22:16:51 +00:00
|
|
|
#include "nsIInputStream.h"
|
2009-08-09 20:29:56 +00:00
|
|
|
#include "nsIDocShell.h"
|
2014-09-10 01:40:51 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-01-04 05:16:14 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-10-01 21:01:19 +00:00
|
|
|
#include "GraphicsFilter.h"
|
2011-06-24 17:41:18 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2005-04-18 06:33:23 +00:00
|
|
|
|
|
|
|
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
|
2014-04-17 10:13:34 +00:00
|
|
|
{ 0x3cc9e801, 0x1806, 0x4ff6, \
|
|
|
|
{ 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } }
|
2006-04-18 21:23:15 +00:00
|
|
|
|
2008-04-30 17:04:46 +00:00
|
|
|
class gfxASurface;
|
2011-03-27 23:59:47 +00:00
|
|
|
class nsDisplayListBuilder;
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2010-03-24 10:47:18 +00:00
|
|
|
namespace mozilla {
|
2010-05-18 04:04:22 +00:00
|
|
|
namespace layers {
|
|
|
|
class CanvasLayer;
|
|
|
|
class LayerManager;
|
|
|
|
}
|
2011-06-24 17:41:18 +00:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
|
|
|
}
|
2010-03-24 10:47:18 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 01:40:51 +00:00
|
|
|
class nsICanvasRenderingContextInternal :
|
|
|
|
public nsISupports,
|
|
|
|
public nsAPostRefreshObserver
|
|
|
|
{
|
2005-04-18 06:33:23 +00:00
|
|
|
public:
|
2010-05-18 04:04:22 +00:00
|
|
|
typedef mozilla::layers::CanvasLayer CanvasLayer;
|
|
|
|
typedef mozilla::layers::LayerManager LayerManager;
|
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2013-01-04 05:16:14 +00:00
|
|
|
void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas)
|
2012-06-06 07:42:47 +00:00
|
|
|
{
|
2014-09-10 01:40:51 +00:00
|
|
|
RemovePostRefreshObserver();
|
2012-06-06 07:42:47 +00:00
|
|
|
mCanvasElement = aParentCanvas;
|
2014-09-10 01:40:51 +00:00
|
|
|
AddPostRefreshObserverIfNecessary();
|
2012-06-06 07:42:47 +00:00
|
|
|
}
|
2014-09-10 01:40:51 +00:00
|
|
|
|
|
|
|
virtual nsIPresShell *GetPresShell() {
|
|
|
|
if (mCanvasElement) {
|
|
|
|
return mCanvasElement->OwnerDoc()->GetShell();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemovePostRefreshObserver()
|
|
|
|
{
|
|
|
|
if (mRefreshDriver) {
|
|
|
|
mRefreshDriver->RemovePostRefreshObserver(this);
|
|
|
|
mRefreshDriver = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddPostRefreshObserverIfNecessary()
|
|
|
|
{
|
|
|
|
if (!GetPresShell() ||
|
|
|
|
!GetPresShell()->GetPresContext() ||
|
|
|
|
!GetPresShell()->GetPresContext()->RefreshDriver()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRefreshDriver = GetPresShell()->GetPresContext()->RefreshDriver();
|
|
|
|
mRefreshDriver->AddPostRefreshObserver(this);
|
|
|
|
}
|
|
|
|
|
2013-01-04 05:16:14 +00:00
|
|
|
mozilla::dom::HTMLCanvasElement* GetParentObject() const
|
2012-06-04 19:41:51 +00:00
|
|
|
{
|
|
|
|
return mCanvasElement;
|
|
|
|
}
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2013-09-30 21:02:40 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Useful for testing
|
|
|
|
virtual int32_t GetWidth() const = 0;
|
|
|
|
virtual int32_t GetHeight() const = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-04-18 21:23:15 +00:00
|
|
|
// Sets the dimensions of the canvas, in pixels. Called
|
|
|
|
// whenever the size of the element changes.
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
|
2006-04-18 21:23:15 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
|
2009-08-04 21:36:02 +00:00
|
|
|
|
2013-10-17 02:55:08 +00:00
|
|
|
// Creates an image buffer. Returns null on failure.
|
|
|
|
virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0;
|
|
|
|
|
2005-08-31 22:16:51 +00:00
|
|
|
// Gives you a stream containing the image represented by this context.
|
|
|
|
// The format is given in aMimeTime, for example "image/png".
|
|
|
|
//
|
|
|
|
// If the image format does not support transparency or aIncludeTransparency
|
|
|
|
// is false, alpha will be discarded and the result will be the image
|
|
|
|
// composited on black.
|
2007-09-25 20:46:08 +00:00
|
|
|
NS_IMETHOD GetInputStream(const char *aMimeType,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *aEncoderOptions,
|
2005-08-31 22:16:51 +00:00
|
|
|
nsIInputStream **aStream) = 0;
|
2011-06-24 17:41:18 +00:00
|
|
|
|
|
|
|
// This gets an Azure SourceSurface for the canvas, this will be a snapshot
|
2012-10-17 02:57:30 +00:00
|
|
|
// of the canvas at the time it was called.
|
2014-04-17 05:28:17 +00:00
|
|
|
// If aPremultAlpha is provided, then it assumed the callee can handle
|
|
|
|
// un-premultiplied surfaces, and *aPremultAlpha will be set to false
|
|
|
|
// if one is returned.
|
|
|
|
virtual mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0;
|
2008-06-04 00:00:32 +00:00
|
|
|
|
|
|
|
// If this context is opaque, the backing store of the canvas should
|
|
|
|
// be created as opaque; all compositing operators should assume the
|
|
|
|
// dst alpha is always 1.0. If this is never called, the context
|
|
|
|
// defaults to false (not opaque).
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
|
2014-03-16 19:34:14 +00:00
|
|
|
virtual bool GetIsOpaque() = 0;
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2010-08-19 15:22:46 +00:00
|
|
|
// Invalidate this context and release any held resources, in preperation
|
|
|
|
// for possibly reinitializing with SetDimensions/InitializeWithSurface.
|
|
|
|
NS_IMETHOD Reset() = 0;
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
// Return the CanvasLayer for this context, creating
|
|
|
|
// one for the given layer manager if not available.
|
2011-03-27 23:59:47 +00:00
|
|
|
virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
CanvasLayer *aOldLayer,
|
2010-07-15 21:07:46 +00:00
|
|
|
LayerManager *aManager) = 0;
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2011-07-08 10:42:21 +00:00
|
|
|
// Return true if the canvas should be forced to be "inactive" to ensure
|
|
|
|
// it can be drawn to the screen even if it's too large to be blitted by
|
|
|
|
// an accelerated CanvasLayer.
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
|
2011-07-08 10:42:21 +00:00
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
virtual void MarkContextClean() = 0;
|
2010-05-24 14:45:59 +00:00
|
|
|
|
2009-10-29 17:58:31 +00:00
|
|
|
// Redraw the dirty rectangle of this canvas.
|
|
|
|
NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
|
2010-03-24 10:47:18 +00:00
|
|
|
|
2013-06-07 18:42:12 +00:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; }
|
2010-11-17 04:33:03 +00:00
|
|
|
|
2014-05-18 23:43:00 +00:00
|
|
|
// return true and fills in the bounding rect if elementis a child and has a hit region.
|
|
|
|
virtual bool GetHitRegionRect(mozilla::dom::Element* aElement, nsRect& aRect) { return false; }
|
|
|
|
|
2014-05-20 04:54:00 +00:00
|
|
|
// Given a point, return hit region ID if it exists or an empty string if it doesn't
|
|
|
|
virtual nsString GetHitRegion(const mozilla::gfx::Point& aPoint) { return nsString(); }
|
|
|
|
|
2010-11-17 04:33:03 +00:00
|
|
|
//
|
|
|
|
// shmem support
|
|
|
|
//
|
|
|
|
|
2010-03-24 10:47:18 +00:00
|
|
|
// If this context can be set to use Mozilla's Shmem segments as its backing
|
|
|
|
// store, this will set it to that state. Note that if you have drawn
|
|
|
|
// anything into this canvas before changing the shmem state, it will be
|
|
|
|
// lost.
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD SetIsIPC(bool isIPC) = 0;
|
2012-06-06 07:42:47 +00:00
|
|
|
|
|
|
|
protected:
|
2013-01-04 05:16:14 +00:00
|
|
|
nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
|
2014-09-10 01:40:51 +00:00
|
|
|
nsRefPtr<nsRefreshDriver> mRefreshDriver;
|
2005-04-18 06:33:23 +00:00
|
|
|
};
|
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
|
|
|
|
NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
|
|
|
|
2005-04-18 06:33:23 +00:00
|
|
|
#endif /* nsICanvasRenderingContextInternal_h___ */
|