Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / nsICanvasRenderingContextInternal.h
blobdbf2d14af248079b5753d5c5e6284d3e8b3cc97b
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsICanvasRenderingContextInternal_h___
7 #define nsICanvasRenderingContextInternal_h___
9 #include "mozilla/gfx/2D.h"
10 #include "nsISupports.h"
11 #include "nsIInputStream.h"
12 #include "nsIDocShell.h"
13 #include "mozilla/dom/HTMLCanvasElement.h"
14 #include "GraphicsFilter.h"
15 #include "mozilla/RefPtr.h"
17 #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
18 { 0x3cc9e801, 0x1806, 0x4ff6, \
19 { 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } }
21 class gfxContext;
22 class gfxASurface;
23 class nsDisplayListBuilder;
25 namespace mozilla {
26 namespace layers {
27 class CanvasLayer;
28 class LayerManager;
30 namespace ipc {
31 class Shmem;
33 namespace gfx {
34 class SourceSurface;
38 class nsICanvasRenderingContextInternal : public nsISupports {
39 public:
40 typedef mozilla::layers::CanvasLayer CanvasLayer;
41 typedef mozilla::layers::LayerManager LayerManager;
43 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
45 void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas)
47 mCanvasElement = aParentCanvas;
49 mozilla::dom::HTMLCanvasElement* GetParentObject() const
51 return mCanvasElement;
54 #ifdef DEBUG
55 // Useful for testing
56 virtual int32_t GetWidth() const = 0;
57 virtual int32_t GetHeight() const = 0;
58 #endif
60 // Sets the dimensions of the canvas, in pixels. Called
61 // whenever the size of the element changes.
62 NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
64 NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
66 // Creates an image buffer. Returns null on failure.
67 virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0;
69 // Gives you a stream containing the image represented by this context.
70 // The format is given in aMimeTime, for example "image/png".
72 // If the image format does not support transparency or aIncludeTransparency
73 // is false, alpha will be discarded and the result will be the image
74 // composited on black.
75 NS_IMETHOD GetInputStream(const char *aMimeType,
76 const char16_t *aEncoderOptions,
77 nsIInputStream **aStream) = 0;
79 // This gets an Azure SourceSurface for the canvas, this will be a snapshot
80 // of the canvas at the time it was called.
81 // If aPremultAlpha is provided, then it assumed the callee can handle
82 // un-premultiplied surfaces, and *aPremultAlpha will be set to false
83 // if one is returned.
84 virtual mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0;
86 // If this context is opaque, the backing store of the canvas should
87 // be created as opaque; all compositing operators should assume the
88 // dst alpha is always 1.0. If this is never called, the context
89 // defaults to false (not opaque).
90 NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
91 virtual bool GetIsOpaque() = 0;
93 // Invalidate this context and release any held resources, in preperation
94 // for possibly reinitializing with SetDimensions/InitializeWithSurface.
95 NS_IMETHOD Reset() = 0;
97 // Return the CanvasLayer for this context, creating
98 // one for the given layer manager if not available.
99 virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
100 CanvasLayer *aOldLayer,
101 LayerManager *aManager) = 0;
103 // Return true if the canvas should be forced to be "inactive" to ensure
104 // it can be drawn to the screen even if it's too large to be blitted by
105 // an accelerated CanvasLayer.
106 virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
108 virtual void MarkContextClean() = 0;
110 // Redraw the dirty rectangle of this canvas.
111 NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
113 NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; }
115 // return true and fills in the bounding rect if elementis a child and has a hit region.
116 virtual bool GetHitRegionRect(mozilla::dom::Element* aElement, nsRect& aRect) { return false; }
118 // Given a point, return hit region ID if it exists or an empty string if it doesn't
119 virtual nsString GetHitRegion(const mozilla::gfx::Point& aPoint) { return nsString(); }
122 // shmem support
125 // If this context can be set to use Mozilla's Shmem segments as its backing
126 // store, this will set it to that state. Note that if you have drawn
127 // anything into this canvas before changing the shmem state, it will be
128 // lost.
129 NS_IMETHOD SetIsIPC(bool isIPC) = 0;
131 protected:
132 nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
135 namespace mozilla {
136 namespace dom {
141 NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
142 NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
144 #endif /* nsICanvasRenderingContextInternal_h___ */