1 : /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Vladimir Vukicevic <vladimir@pobox.com>
19 : * Portions created by the Initial Developer are Copyright (C) 2005
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsICanvasRenderingContextInternal_h___
39 : #define nsICanvasRenderingContextInternal_h___
40 :
41 : #include "nsISupports.h"
42 : #include "nsIInputStream.h"
43 : #include "nsIDocShell.h"
44 : #include "gfxPattern.h"
45 : #include "mozilla/RefPtr.h"
46 :
47 : #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
48 : { 0xffb42d3c, 0x8281, 0x44c8, \
49 : { 0xac, 0xba, 0x73, 0x15, 0x31, 0xaa, 0xe5, 0x07 } }
50 :
51 : class nsHTMLCanvasElement;
52 : class gfxContext;
53 : class gfxASurface;
54 : class nsIPropertyBag;
55 : class nsDisplayListBuilder;
56 :
57 : namespace mozilla {
58 : namespace layers {
59 : class CanvasLayer;
60 : class LayerManager;
61 : }
62 : namespace ipc {
63 : class Shmem;
64 : }
65 : namespace gfx {
66 : class SourceSurface;
67 : }
68 : }
69 :
70 0 : class nsICanvasRenderingContextInternal : public nsISupports {
71 : public:
72 : typedef mozilla::layers::CanvasLayer CanvasLayer;
73 : typedef mozilla::layers::LayerManager LayerManager;
74 :
75 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
76 :
77 : // This method should NOT hold a ref to aParentCanvas; it will be called
78 : // with nsnull when the element is going away.
79 : NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas) = 0;
80 :
81 : // Sets the dimensions of the canvas, in pixels. Called
82 : // whenever the size of the element changes.
83 : NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height) = 0;
84 :
85 : NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, PRInt32 width, PRInt32 height) = 0;
86 :
87 : // Render the canvas at the origin of the given gfxContext
88 : NS_IMETHOD Render(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter) = 0;
89 :
90 : // Gives you a stream containing the image represented by this context.
91 : // The format is given in aMimeTime, for example "image/png".
92 : //
93 : // If the image format does not support transparency or aIncludeTransparency
94 : // is false, alpha will be discarded and the result will be the image
95 : // composited on black.
96 : NS_IMETHOD GetInputStream(const char *aMimeType,
97 : const PRUnichar *aEncoderOptions,
98 : nsIInputStream **aStream) = 0;
99 :
100 : // If this canvas context can be represented with a simple Thebes surface,
101 : // return the surface. Otherwise returns an error.
102 : NS_IMETHOD GetThebesSurface(gfxASurface **surface) = 0;
103 :
104 : // This gets an Azure SourceSurface for the canvas, this will be a snapshot
105 : // of the canvas at the time it was called. This will return null for a
106 : // non-azure canvas.
107 : virtual mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot() = 0;
108 :
109 : // If this context is opaque, the backing store of the canvas should
110 : // be created as opaque; all compositing operators should assume the
111 : // dst alpha is always 1.0. If this is never called, the context
112 : // defaults to false (not opaque).
113 : NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
114 :
115 : // Invalidate this context and release any held resources, in preperation
116 : // for possibly reinitializing with SetDimensions/InitializeWithSurface.
117 : NS_IMETHOD Reset() = 0;
118 :
119 : // Return the CanvasLayer for this context, creating
120 : // one for the given layer manager if not available.
121 : virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
122 : CanvasLayer *aOldLayer,
123 : LayerManager *aManager) = 0;
124 :
125 : // Return true if the canvas should be forced to be "inactive" to ensure
126 : // it can be drawn to the screen even if it's too large to be blitted by
127 : // an accelerated CanvasLayer.
128 0 : virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
129 :
130 : virtual void MarkContextClean() = 0;
131 :
132 : // Redraw the dirty rectangle of this canvas.
133 : NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
134 :
135 : // Passes a generic nsIPropertyBag options argument, along with the
136 : // previous one, if any. Optional.
137 0 : NS_IMETHOD SetContextOptions(nsIPropertyBag *aNewOptions) { return NS_OK; }
138 :
139 : //
140 : // shmem support
141 : //
142 :
143 : // If this context can be set to use Mozilla's Shmem segments as its backing
144 : // store, this will set it to that state. Note that if you have drawn
145 : // anything into this canvas before changing the shmem state, it will be
146 : // lost.
147 : NS_IMETHOD SetIsIPC(bool isIPC) = 0;
148 : };
149 :
150 : NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
151 : NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
152 :
153 : #endif /* nsICanvasRenderingContextInternal_h___ */
|