|
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/. */ |
|
5 |
|
6 #ifndef nsICanvasRenderingContextInternal_h___ |
|
7 #define nsICanvasRenderingContextInternal_h___ |
|
8 |
|
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" |
|
16 |
|
17 #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \ |
|
18 { 0x3cc9e801, 0x1806, 0x4ff6, \ |
|
19 { 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } } |
|
20 |
|
21 class gfxContext; |
|
22 class gfxASurface; |
|
23 class nsDisplayListBuilder; |
|
24 |
|
25 namespace mozilla { |
|
26 namespace layers { |
|
27 class CanvasLayer; |
|
28 class LayerManager; |
|
29 } |
|
30 namespace ipc { |
|
31 class Shmem; |
|
32 } |
|
33 namespace gfx { |
|
34 class SourceSurface; |
|
35 } |
|
36 } |
|
37 |
|
38 class nsICanvasRenderingContextInternal : public nsISupports { |
|
39 public: |
|
40 typedef mozilla::layers::CanvasLayer CanvasLayer; |
|
41 typedef mozilla::layers::LayerManager LayerManager; |
|
42 |
|
43 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) |
|
44 |
|
45 void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas) |
|
46 { |
|
47 mCanvasElement = aParentCanvas; |
|
48 } |
|
49 mozilla::dom::HTMLCanvasElement* GetParentObject() const |
|
50 { |
|
51 return mCanvasElement; |
|
52 } |
|
53 |
|
54 #ifdef DEBUG |
|
55 // Useful for testing |
|
56 virtual int32_t GetWidth() const = 0; |
|
57 virtual int32_t GetHeight() const = 0; |
|
58 #endif |
|
59 |
|
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; |
|
63 |
|
64 NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0; |
|
65 |
|
66 // Creates an image buffer. Returns null on failure. |
|
67 virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0; |
|
68 |
|
69 // Gives you a stream containing the image represented by this context. |
|
70 // The format is given in aMimeTime, for example "image/png". |
|
71 // |
|
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; |
|
78 |
|
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; |
|
85 |
|
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; |
|
92 |
|
93 // Invalidate this context and release any held resources, in preperation |
|
94 // for possibly reinitializing with SetDimensions/InitializeWithSurface. |
|
95 NS_IMETHOD Reset() = 0; |
|
96 |
|
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; |
|
102 |
|
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; } |
|
107 |
|
108 virtual void MarkContextClean() = 0; |
|
109 |
|
110 // Redraw the dirty rectangle of this canvas. |
|
111 NS_IMETHOD Redraw(const gfxRect &dirty) = 0; |
|
112 |
|
113 NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; } |
|
114 |
|
115 // |
|
116 // shmem support |
|
117 // |
|
118 |
|
119 // If this context can be set to use Mozilla's Shmem segments as its backing |
|
120 // store, this will set it to that state. Note that if you have drawn |
|
121 // anything into this canvas before changing the shmem state, it will be |
|
122 // lost. |
|
123 NS_IMETHOD SetIsIPC(bool isIPC) = 0; |
|
124 |
|
125 protected: |
|
126 nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement; |
|
127 }; |
|
128 |
|
129 namespace mozilla { |
|
130 namespace dom { |
|
131 |
|
132 } |
|
133 } |
|
134 |
|
135 NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal, |
|
136 NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) |
|
137 |
|
138 #endif /* nsICanvasRenderingContextInternal_h___ */ |