michael@0: /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsICanvasRenderingContextInternal_h___ michael@0: #define nsICanvasRenderingContextInternal_h___ michael@0: michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "nsISupports.h" michael@0: #include "nsIInputStream.h" michael@0: #include "nsIDocShell.h" michael@0: #include "mozilla/dom/HTMLCanvasElement.h" michael@0: #include "GraphicsFilter.h" michael@0: #include "mozilla/RefPtr.h" michael@0: michael@0: #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \ michael@0: { 0x3cc9e801, 0x1806, 0x4ff6, \ michael@0: { 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } } michael@0: michael@0: class gfxContext; michael@0: class gfxASurface; michael@0: class nsDisplayListBuilder; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class CanvasLayer; michael@0: class LayerManager; michael@0: } michael@0: namespace ipc { michael@0: class Shmem; michael@0: } michael@0: namespace gfx { michael@0: class SourceSurface; michael@0: } michael@0: } michael@0: michael@0: class nsICanvasRenderingContextInternal : public nsISupports { michael@0: public: michael@0: typedef mozilla::layers::CanvasLayer CanvasLayer; michael@0: typedef mozilla::layers::LayerManager LayerManager; michael@0: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) michael@0: michael@0: void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas) michael@0: { michael@0: mCanvasElement = aParentCanvas; michael@0: } michael@0: mozilla::dom::HTMLCanvasElement* GetParentObject() const michael@0: { michael@0: return mCanvasElement; michael@0: } michael@0: michael@0: #ifdef DEBUG michael@0: // Useful for testing michael@0: virtual int32_t GetWidth() const = 0; michael@0: virtual int32_t GetHeight() const = 0; michael@0: #endif michael@0: michael@0: // Sets the dimensions of the canvas, in pixels. Called michael@0: // whenever the size of the element changes. michael@0: NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0; michael@0: michael@0: NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0; michael@0: michael@0: // Creates an image buffer. Returns null on failure. michael@0: virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0; michael@0: michael@0: // Gives you a stream containing the image represented by this context. michael@0: // The format is given in aMimeTime, for example "image/png". michael@0: // michael@0: // If the image format does not support transparency or aIncludeTransparency michael@0: // is false, alpha will be discarded and the result will be the image michael@0: // composited on black. michael@0: NS_IMETHOD GetInputStream(const char *aMimeType, michael@0: const char16_t *aEncoderOptions, michael@0: nsIInputStream **aStream) = 0; michael@0: michael@0: // This gets an Azure SourceSurface for the canvas, this will be a snapshot michael@0: // of the canvas at the time it was called. michael@0: // If aPremultAlpha is provided, then it assumed the callee can handle michael@0: // un-premultiplied surfaces, and *aPremultAlpha will be set to false michael@0: // if one is returned. michael@0: virtual mozilla::TemporaryRef GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0; michael@0: michael@0: // If this context is opaque, the backing store of the canvas should michael@0: // be created as opaque; all compositing operators should assume the michael@0: // dst alpha is always 1.0. If this is never called, the context michael@0: // defaults to false (not opaque). michael@0: NS_IMETHOD SetIsOpaque(bool isOpaque) = 0; michael@0: virtual bool GetIsOpaque() = 0; michael@0: michael@0: // Invalidate this context and release any held resources, in preperation michael@0: // for possibly reinitializing with SetDimensions/InitializeWithSurface. michael@0: NS_IMETHOD Reset() = 0; michael@0: michael@0: // Return the CanvasLayer for this context, creating michael@0: // one for the given layer manager if not available. michael@0: virtual already_AddRefed GetCanvasLayer(nsDisplayListBuilder* aBuilder, michael@0: CanvasLayer *aOldLayer, michael@0: LayerManager *aManager) = 0; michael@0: michael@0: // Return true if the canvas should be forced to be "inactive" to ensure michael@0: // it can be drawn to the screen even if it's too large to be blitted by michael@0: // an accelerated CanvasLayer. michael@0: virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; } michael@0: michael@0: virtual void MarkContextClean() = 0; michael@0: michael@0: // Redraw the dirty rectangle of this canvas. michael@0: NS_IMETHOD Redraw(const gfxRect &dirty) = 0; michael@0: michael@0: NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle aOptions) { return NS_OK; } michael@0: michael@0: // michael@0: // shmem support michael@0: // michael@0: michael@0: // If this context can be set to use Mozilla's Shmem segments as its backing michael@0: // store, this will set it to that state. Note that if you have drawn michael@0: // anything into this canvas before changing the shmem state, it will be michael@0: // lost. michael@0: NS_IMETHOD SetIsIPC(bool isIPC) = 0; michael@0: michael@0: protected: michael@0: nsRefPtr mCanvasElement; michael@0: }; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: } michael@0: } michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal, michael@0: NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) michael@0: michael@0: #endif /* nsICanvasRenderingContextInternal_h___ */