2005-04-18 10:33:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2005-04-18 10:33:23 +04:00
|
|
|
|
|
|
|
#ifndef nsICanvasRenderingContextInternal_h___
|
|
|
|
#define nsICanvasRenderingContextInternal_h___
|
|
|
|
|
2014-04-17 14:13:34 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
#include "nsISupports.h"
|
2005-09-01 02:16:51 +04:00
|
|
|
#include "nsIInputStream.h"
|
2009-08-10 00:29:56 +04:00
|
|
|
#include "nsIDocShell.h"
|
2014-09-10 05:40:51 +04:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-10-02 01:01:19 +04:00
|
|
|
#include "GraphicsFilter.h"
|
2011-06-24 21:41:18 +04:00
|
|
|
#include "mozilla/RefPtr.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
|
|
|
|
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
|
2014-04-17 14:13:34 +04:00
|
|
|
{ 0x3cc9e801, 0x1806, 0x4ff6, \
|
|
|
|
{ 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } }
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2008-04-30 21:04:46 +04:00
|
|
|
class gfxASurface;
|
2011-03-28 03:59:47 +04:00
|
|
|
class nsDisplayListBuilder;
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2010-03-24 13:47:18 +03:00
|
|
|
namespace mozilla {
|
2010-05-18 08:04:22 +04:00
|
|
|
namespace layers {
|
|
|
|
class CanvasLayer;
|
|
|
|
class LayerManager;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2011-06-24 21:41:18 +04:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2010-03-24 13:47:18 +03:00
|
|
|
|
2014-09-10 05:40:51 +04:00
|
|
|
class nsICanvasRenderingContextInternal :
|
|
|
|
public nsISupports,
|
|
|
|
public nsAPostRefreshObserver
|
|
|
|
{
|
2005-04-18 10:33:23 +04:00
|
|
|
public:
|
2010-05-18 08:04:22 +04:00
|
|
|
typedef mozilla::layers::CanvasLayer CanvasLayer;
|
|
|
|
typedef mozilla::layers::LayerManager LayerManager;
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
void SetCanvasElement(mozilla::dom::HTMLCanvasElement* parentCanvas)
|
2012-06-06 11:42:47 +04:00
|
|
|
{
|
2014-09-10 05:40:51 +04:00
|
|
|
RemovePostRefreshObserver();
|
2015-07-15 03:37:28 +03:00
|
|
|
mCanvasElement = parentCanvas;
|
2014-09-10 05:40:51 +04:00
|
|
|
AddPostRefreshObserverIfNecessary();
|
2012-06-06 11:42:47 +04:00
|
|
|
}
|
2014-09-10 05:40:51 +04: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 09:16:14 +04:00
|
|
|
mozilla::dom::HTMLCanvasElement* GetParentObject() const
|
2012-06-04 23:41:51 +04:00
|
|
|
{
|
|
|
|
return mCanvasElement;
|
|
|
|
}
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2013-10-01 01:02:40 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Useful for testing
|
|
|
|
virtual int32_t GetWidth() const = 0;
|
|
|
|
virtual int32_t GetHeight() const = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-04-19 01:23:15 +04:00
|
|
|
// Sets the dimensions of the canvas, in pixels. Called
|
|
|
|
// whenever the size of the element changes.
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
|
2009-08-05 01:36:02 +04:00
|
|
|
|
2013-10-17 06:55:08 +04:00
|
|
|
// Creates an image buffer. Returns null on failure.
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual void GetImageBuffer(uint8_t** imageBuffer, int32_t* format) = 0;
|
2013-10-17 06:55:08 +04:00
|
|
|
|
2005-09-01 02:16:51 +04:00
|
|
|
// Gives you a stream containing the image represented by this context.
|
2015-07-15 03:37:28 +03:00
|
|
|
// The format is given in mimeTime, for example "image/png".
|
2005-09-01 02:16:51 +04:00
|
|
|
//
|
2015-07-15 03:37:28 +03:00
|
|
|
// If the image format does not support transparency or includeTransparency
|
2005-09-01 02:16:51 +04:00
|
|
|
// is false, alpha will be discarded and the result will be the image
|
|
|
|
// composited on black.
|
2015-07-15 03:37:28 +03:00
|
|
|
NS_IMETHOD GetInputStream(const char *mimeType,
|
|
|
|
const char16_t *encoderOptions,
|
|
|
|
nsIInputStream **stream) = 0;
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
// This gets an Azure SourceSurface for the canvas, this will be a snapshot
|
2012-10-17 06:57:30 +04:00
|
|
|
// of the canvas at the time it was called.
|
2015-07-15 03:37:28 +03:00
|
|
|
// If premultAlpha is provided, then it assumed the callee can handle
|
|
|
|
// un-premultiplied surfaces, and *premultAlpha will be set to false
|
2014-04-17 09:28:17 +04:00
|
|
|
// if one is returned.
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* premultAlpha = nullptr) = 0;
|
2008-06-04 04:00:32 +04: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 10:19:26 +04:00
|
|
|
NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
|
2014-03-16 23:34:14 +04:00
|
|
|
virtual bool GetIsOpaque() = 0;
|
2009-10-29 20:58:31 +03:00
|
|
|
|
2010-08-19 19:22:46 +04:00
|
|
|
// Invalidate this context and release any held resources, in preperation
|
|
|
|
// for possibly reinitializing with SetDimensions/InitializeWithSurface.
|
|
|
|
NS_IMETHOD Reset() = 0;
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// Return the CanvasLayer for this context, creating
|
|
|
|
// one for the given layer manager if not available.
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* builder,
|
|
|
|
CanvasLayer *oldLayer,
|
|
|
|
LayerManager *manager) = 0;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-07-08 14:42:21 +04: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.
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager *manager) { return false; }
|
2011-07-08 14:42:21 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
virtual void MarkContextClean() = 0;
|
2010-05-24 18:45:59 +04:00
|
|
|
|
2009-10-29 20:58:31 +03:00
|
|
|
// Redraw the dirty rectangle of this canvas.
|
|
|
|
NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
|
2010-03-24 13:47:18 +03:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options) { return NS_OK; }
|
2010-11-17 07:33:03 +03:00
|
|
|
|
2014-05-19 03:43:00 +04:00
|
|
|
// return true and fills in the bounding rect if elementis a child and has a hit region.
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual bool GetHitRegionRect(mozilla::dom::Element* element, nsRect& rect) { return false; }
|
2014-05-19 03:43:00 +04:00
|
|
|
|
2014-05-20 08:54:00 +04:00
|
|
|
// Given a point, return hit region ID if it exists or an empty string if it doesn't
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual nsString GetHitRegion(const mozilla::gfx::Point& point) { return nsString(); }
|
2014-05-20 08:54:00 +04:00
|
|
|
|
2010-11-17 07:33:03 +03:00
|
|
|
//
|
|
|
|
// shmem support
|
|
|
|
//
|
|
|
|
|
2010-03-24 13:47:18 +03: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 10:19:26 +04:00
|
|
|
NS_IMETHOD SetIsIPC(bool isIPC) = 0;
|
2012-06-06 11:42:47 +04:00
|
|
|
|
|
|
|
protected:
|
2013-01-04 09:16:14 +04:00
|
|
|
nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
|
2014-09-10 05:40:51 +04:00
|
|
|
nsRefPtr<nsRefreshDriver> mRefreshDriver;
|
2005-04-18 10:33:23 +04:00
|
|
|
};
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
|
|
|
|
NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
|
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
#endif /* nsICanvasRenderingContextInternal_h___ */
|