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"
|
2014-09-10 05:40:51 +04:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "mozilla/dom/OffscreenCanvas.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-10-26 21:31:12 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-08-23 11:41:21 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
|
|
|
|
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2015-10-12 06:21:03 +03:00
|
|
|
0xb84f2fed, 0x9d4b, 0x430b, { \
|
|
|
|
0xbd, 0xfb, 0x85, 0x57, 0x8a, 0xc2, 0xb4, 0x4b \
|
|
|
|
} \
|
|
|
|
}
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2011-03-28 03:59:47 +04:00
|
|
|
class nsDisplayListBuilder;
|
2019-12-06 12:24:56 +03:00
|
|
|
class nsIDocShell;
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2010-03-24 13:47:18 +03:00
|
|
|
namespace mozilla {
|
2019-04-13 04:03:13 +03:00
|
|
|
class PresShell;
|
2010-05-18 08:04:22 +04:00
|
|
|
namespace layers {
|
|
|
|
class CanvasLayer;
|
2017-08-03 08:55:14 +03:00
|
|
|
class CanvasRenderer;
|
2015-12-18 09:52:17 +03:00
|
|
|
class Layer;
|
2010-05-18 08:04:22 +04:00
|
|
|
class LayerManager;
|
2017-10-28 13:07:27 +03:00
|
|
|
class WebRenderCanvasData;
|
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
|
2018-11-30 13:46:48 +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;
|
2017-08-03 08:55:14 +03:00
|
|
|
typedef mozilla::layers::CanvasRenderer CanvasRenderer;
|
2015-12-18 09:52:17 +03:00
|
|
|
typedef mozilla::layers::Layer Layer;
|
2010-05-18 08:04:22 +04:00
|
|
|
typedef mozilla::layers::LayerManager LayerManager;
|
2017-10-28 13:07:27 +03:00
|
|
|
typedef mozilla::layers::WebRenderCanvasData WebRenderCanvasData;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
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) {
|
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
|
|
|
|
2019-04-13 04:03:13 +03:00
|
|
|
virtual mozilla::PresShell* GetPresShell() {
|
2014-09-10 05:40:51 +04:00
|
|
|
if (mCanvasElement) {
|
2019-03-29 18:12:47 +03:00
|
|
|
return mCanvasElement->OwnerDoc()->GetPresShell();
|
2014-09-10 05:40:51 +04:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
void SetOffscreenCanvas(mozilla::dom::OffscreenCanvas* aOffscreenCanvas) {
|
|
|
|
mOffscreenCanvas = aOffscreenCanvas;
|
|
|
|
}
|
|
|
|
|
2015-10-02 10:18:26 +03:00
|
|
|
// Dimensions of the canvas, in pixels.
|
2017-12-22 04:14:54 +03:00
|
|
|
virtual int32_t GetWidth() = 0;
|
|
|
|
virtual int32_t GetHeight() = 0;
|
2013-10-01 01:02:40 +04:00
|
|
|
|
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
|
|
|
|
2016-04-21 12:30:38 +03:00
|
|
|
// Initializes with an nsIDocShell and DrawTarget. The size is taken from the
|
|
|
|
// DrawTarget.
|
|
|
|
NS_IMETHOD InitializeWithDrawTarget(
|
|
|
|
nsIDocShell* aDocShell,
|
2016-08-23 11:41:21 +03:00
|
|
|
mozilla::NotNull<mozilla::gfx::DrawTarget*> aTarget) = 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-10-26 21:31:12 +03:00
|
|
|
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(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,
|
2019-04-08 04:51:17 +03:00
|
|
|
const nsAString& encoderOptions,
|
2015-07-15 03:37:28 +03:00
|
|
|
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.
|
2017-04-12 12:55:23 +03:00
|
|
|
virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
|
|
|
gfxAlphaType* out_alphaType = nullptr) = 0;
|
2008-06-04 04:00:32 +04:00
|
|
|
|
2018-05-02 18:23:53 +03:00
|
|
|
// If this is called with true, the backing store of the canvas should
|
2008-06-04 04:00:32 +04:00
|
|
|
// be created as opaque; all compositing operators should assume the
|
2018-05-02 18:23:53 +03:00
|
|
|
// dst alpha is always 1.0. If this is never called, the context's
|
|
|
|
// opaqueness is determined by the context attributes that it's initialized
|
|
|
|
// with.
|
|
|
|
virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) = 0;
|
|
|
|
|
|
|
|
// Returns whether the context is opaque. This value can be based both on
|
|
|
|
// the value of the moz-opaque attribute and on the context's initialization
|
|
|
|
// attributes.
|
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-12-18 09:52:17 +03:00
|
|
|
virtual already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* builder,
|
|
|
|
Layer* oldLayer,
|
2017-09-16 01:06:56 +03:00
|
|
|
LayerManager* manager) = 0;
|
2017-10-28 13:07:27 +03:00
|
|
|
virtual bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-18 10:13:29 +03:00
|
|
|
virtual bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-09-16 01:06:56 +03:00
|
|
|
CanvasRenderer* aRenderer) {
|
|
|
|
return true;
|
|
|
|
}
|
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
|
|
|
|
2015-09-17 06:37:05 +03:00
|
|
|
// Called when a frame is captured.
|
|
|
|
virtual void MarkContextCleanForFrameCapture() = 0;
|
|
|
|
|
|
|
|
// Whether the context is clean or has been invalidated since the last frame
|
|
|
|
// was captured.
|
|
|
|
virtual bool IsContextCleanForFrameCapture() = 0;
|
|
|
|
|
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-10-18 14:14:22 +03:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options,
|
|
|
|
mozilla::ErrorResult& aRvForDictionaryInit) {
|
|
|
|
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
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
virtual void OnVisibilityChange() {}
|
|
|
|
|
|
|
|
virtual void OnMemoryPressure() {}
|
|
|
|
|
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:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
|
|
|
|
RefPtr<mozilla::dom::OffscreenCanvas> mOffscreenCanvas;
|
|
|
|
RefPtr<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___ */
|