2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsICanvasRenderingContextInternal_h___
|
|
|
|
#define nsICanvasRenderingContextInternal_h___
|
|
|
|
|
2014-04-17 03:13:34 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIInputStream.h"
|
2009-08-09 13:29:56 -07:00
|
|
|
#include "nsIDocShell.h"
|
2013-01-03 21:16:14 -08:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-10-01 14:01:19 -07:00
|
|
|
#include "GraphicsFilter.h"
|
2011-06-24 10:41:18 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
|
2014-04-17 03:13:34 -07:00
|
|
|
{ 0x3cc9e801, 0x1806, 0x4ff6, \
|
|
|
|
{ 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-25 13:46:08 -07:00
|
|
|
class gfxContext;
|
2008-04-30 10:04:46 -07:00
|
|
|
class gfxASurface;
|
2011-03-27 16:59:47 -07:00
|
|
|
class nsDisplayListBuilder;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-24 03:47:18 -07:00
|
|
|
namespace mozilla {
|
2010-05-17 21:04:22 -07:00
|
|
|
namespace layers {
|
|
|
|
class CanvasLayer;
|
|
|
|
class LayerManager;
|
|
|
|
}
|
2010-03-24 03:47:18 -07:00
|
|
|
namespace ipc {
|
|
|
|
class Shmem;
|
|
|
|
}
|
2011-06-24 10:41:18 -07:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
|
|
|
}
|
2010-03-24 03:47:18 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsICanvasRenderingContextInternal : public nsISupports {
|
|
|
|
public:
|
2010-05-17 21:04:22 -07:00
|
|
|
typedef mozilla::layers::CanvasLayer CanvasLayer;
|
|
|
|
typedef mozilla::layers::LayerManager LayerManager;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
|
|
|
|
2013-01-03 21:16:14 -08:00
|
|
|
void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas)
|
2012-06-06 00:42:47 -07:00
|
|
|
{
|
|
|
|
mCanvasElement = aParentCanvas;
|
|
|
|
}
|
2013-01-03 21:16:14 -08:00
|
|
|
mozilla::dom::HTMLCanvasElement* GetParentObject() const
|
2012-06-04 12:41:51 -07:00
|
|
|
{
|
|
|
|
return mCanvasElement;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-30 14:02:40 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Useful for testing
|
|
|
|
virtual int32_t GetWidth() const = 0;
|
|
|
|
virtual int32_t GetHeight() const = 0;
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Sets the dimensions of the canvas, in pixels. Called
|
|
|
|
// whenever the size of the element changes.
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
|
2009-08-04 14:36:02 -07:00
|
|
|
|
2013-10-16 19:55:08 -07:00
|
|
|
// Creates an image buffer. Returns null on failure.
|
|
|
|
virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0;
|
|
|
|
|
2007-03-22 10:30:00 -07: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 13:46:08 -07:00
|
|
|
NS_IMETHOD GetInputStream(const char *aMimeType,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aEncoderOptions,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIInputStream **aStream) = 0;
|
2011-06-24 10:41:18 -07:00
|
|
|
|
|
|
|
// This gets an Azure SourceSurface for the canvas, this will be a snapshot
|
2012-10-16 19:57:30 -07:00
|
|
|
// of the canvas at the time it was called.
|
2014-04-16 22:28:17 -07: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-03 17:00:32 -07: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-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
|
2014-03-16 12:34:14 -07:00
|
|
|
virtual bool GetIsOpaque() = 0;
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2010-08-19 08:22:46 -07:00
|
|
|
// Invalidate this context and release any held resources, in preperation
|
|
|
|
// for possibly reinitializing with SetDimensions/InitializeWithSurface.
|
|
|
|
NS_IMETHOD Reset() = 0;
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
// Return the CanvasLayer for this context, creating
|
|
|
|
// one for the given layer manager if not available.
|
2011-03-27 16:59:47 -07:00
|
|
|
virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
CanvasLayer *aOldLayer,
|
2010-07-15 14:07:46 -07:00
|
|
|
LayerManager *aManager) = 0;
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2011-07-08 03:42:21 -07: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-28 23:19:26 -07:00
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
|
2011-07-08 03:42:21 -07:00
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
virtual void MarkContextClean() = 0;
|
2010-05-24 07:45:59 -07:00
|
|
|
|
2009-10-29 10:58:31 -07:00
|
|
|
// Redraw the dirty rectangle of this canvas.
|
|
|
|
NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
|
2010-03-24 03:47:18 -07:00
|
|
|
|
2013-06-07 11:42:12 -07:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; }
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2014-05-18 16:43:00 -07: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-19 21:54:00 -07: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-16 20:33:03 -08:00
|
|
|
//
|
|
|
|
// shmem support
|
|
|
|
//
|
|
|
|
|
2010-03-24 03:47:18 -07: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-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SetIsIPC(bool isIPC) = 0;
|
2012-06-06 00:42:47 -07:00
|
|
|
|
|
|
|
protected:
|
2013-01-03 21:16:14 -08:00
|
|
|
nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-05-21 14:30:07 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
|
|
|
|
NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
|
|
|
|
|
|
|
#endif /* nsICanvasRenderingContextInternal_h___ */
|