1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
15 * The Original Code is Oracle Corporation code.
17 * The Initial Developer of the Original Code is Oracle Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
22 * Stuart Parmenter <pavlov@pavlov.net>
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef GFX_ASURFACE_H
39 #define GFX_ASURFACE_H
44 typedef struct _cairo_surface cairo_surface_t
;
45 typedef struct _cairo_user_data_key cairo_user_data_key_t
;
47 typedef void (*thebes_destroy_func_t
) (void *data
);
50 * A surface is something you can draw on. Instantiate a subclass of this
51 * abstract class, and use gfxContext to draw on this surface.
53 class THEBES_API gfxASurface
{
55 nsrefcnt
AddRef(void);
56 nsrefcnt
Release(void);
60 * The format for an image surface. For all formats with alpha data, 0
61 * means transparent, 1 or 255 means fully opaque.
64 ImageFormatARGB32
, ///< ARGB data in native endianness, using premultiplied alpha
65 ImageFormatRGB24
, ///< xRGB data in native endianness
66 ImageFormatA8
, ///< Only an alpha channel
67 ImageFormatA1
, ///< Packed transparency information (one byte refers to 8 pixels)
84 SurfaceTypeWin32Printing
,
85 SurfaceTypeQuartzImage
,
90 CONTENT_COLOR
= 0x1000,
91 CONTENT_ALPHA
= 0x2000,
92 CONTENT_COLOR_ALPHA
= 0x3000
95 /* Wrap the given cairo surface and return a gfxASurface for it */
96 static already_AddRefed
<gfxASurface
> Wrap(cairo_surface_t
*csurf
);
98 /*** this DOES NOT addref the surface */
99 cairo_surface_t
*CairoSurface() {
100 NS_ASSERTION(mSurface
!= nsnull
, "gfxASurface::CairoSurface called with mSurface == nsnull!");
104 gfxSurfaceType
GetType() const;
106 gfxContentType
GetContentType() const;
108 void SetDeviceOffset(const gfxPoint
& offset
);
109 gfxPoint
GetDeviceOffset() const;
113 void MarkDirty(const gfxRect
& r
);
115 /* Printing backend functions */
116 virtual nsresult
BeginPrinting(const nsAString
& aTitle
, const nsAString
& aPrintToFileName
);
117 virtual nsresult
EndPrinting();
118 virtual nsresult
AbortPrinting();
119 virtual nsresult
BeginPage();
120 virtual nsresult
EndPage();
122 void SetData(const cairo_user_data_key_t
*key
,
124 thebes_destroy_func_t destroy
);
125 void *GetData(const cairo_user_data_key_t
*key
);
127 virtual void Finish();
131 /* Make sure that the given dimensions don't overflow a 32-bit signed int
132 * using 4 bytes per pixel; optionally, make sure that either dimension
133 * doesn't exceed the given limit.
135 static PRBool
CheckSurfaceSize(const gfxIntSize
& sz
, PRInt32 limit
= 0);
137 /* Return the default set of context flags for this surface; these are
138 * hints to the context about any special rendering considerations. See
139 * gfxContext::SetFlag for documentation.
141 virtual PRInt32
GetDefaultContextFlags() const { return 0; }
143 static gfxContentType
ContentFromFormat(gfxImageFormat format
);
146 gfxASurface() : mSurface(nsnull
), mFloatingRefs(0), mSurfaceValid(PR_FALSE
) { }
148 static gfxASurface
* GetSurfaceWrapper(cairo_surface_t
*csurf
);
149 static void SetSurfaceWrapper(cairo_surface_t
*csurf
, gfxASurface
*asurf
);
151 void Init(cairo_surface_t
*surface
, PRBool existingSurface
= PR_FALSE
);
153 virtual ~gfxASurface() {
156 static void SurfaceDestroyFunc(void *data
);
158 cairo_surface_t
*mSurface
;
159 PRInt32 mFloatingRefs
;
162 PRPackedBool mSurfaceValid
;
166 * An Unknown surface; used to wrap unknown cairo_surface_t returns from cairo
168 class THEBES_API gfxUnknownSurface
: public gfxASurface
{
170 gfxUnknownSurface(cairo_surface_t
*surf
) {
174 virtual ~gfxUnknownSurface() { }
177 #endif /* GFX_ASURFACE_H */