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 Novell code.
17 * The Initial Developer of the Original Code is Novell.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
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 #include "gfxQtNativeRenderer.h"
39 #include "gfxContext.h"
41 #include "gfxQtPlatform.h"
47 gfxQtNativeRenderer
* mRenderer
;
49 } NativeRenderingClosure
;
53 NativeRendering(void *closure
,
55 short offset_x
, short offset_y
,
56 QRect
* rectangles
, unsigned int num_rects
)
58 NativeRenderingClosure
* cl
= (NativeRenderingClosure
*)closure
;
59 nsresult rv
= cl
->mRenderer
->
60 NativeDraw(drawable
, offset_x
, offset_y
,
61 rectangles
, num_rects
);
63 return NS_SUCCEEDED(rv
);
68 gfxQtNativeRenderer::Draw(gfxContext
* ctx
, int width
, int height
,
69 PRUint32 flags
, DrawOutput
* output
)
71 NativeRenderingClosure closure
= { this, NS_OK
};
74 output
->mSurface
= NULL
;
75 output
->mUniformAlpha
= PR_FALSE
;
76 output
->mUniformColor
= PR_FALSE
;
81 cairo_gdk_drawing_result_t result
;
82 // Make sure result.surface is null to start with; we rely on it
83 // being non-null meaning that a surface actually got allocated.
84 result
.surface
= NULL
;
87 if (flags
& DRAW_SUPPORTS_OFFSET
) {
88 cairoFlags
|= CAIRO_GDK_DRAWING_SUPPORTS_OFFSET
;
90 if (flags
& DRAW_SUPPORTS_CLIP_RECT
) {
91 cairoFlags
|= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT
;
93 if (flags
& DRAW_SUPPORTS_CLIP_LIST
) {
94 cairoFlags
|= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST
;
96 if (flags
& DRAW_SUPPORTS_ALTERNATE_SCREEN
) {
97 cairoFlags
|= CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN
;
99 if (flags
& DRAW_SUPPORTS_NONDEFAULT_VISUAL
) {
100 cairoFlags
|= CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL
;
103 cairo_draw_with_gdk(ctx
->GetCairo(),
104 gfxPlatformGtk::GetPlatform()->GetGdkDrawable(ctx
->OriginalSurface()),
106 &closure
, width
, height
,
107 (flags
& DRAW_IS_OPAQUE
) ? CAIRO_GDK_DRAWING_OPAQUE
: CAIRO_GDK_DRAWING_TRANSPARENT
,
108 (cairo_gdk_drawing_support_t
)cairoFlags
,
109 output
? &result
: NULL
);
111 if (NS_FAILED(closure
.mRV
)) {
112 if (result
.surface
) {
113 NS_ASSERTION(output
, "How did that happen?");
114 cairo_surface_destroy (result
.surface
);
120 if (result
.surface
) {
121 output
->mSurface
= gfxASurface::Wrap(result
.surface
);
122 if (!output
->mSurface
) {
123 cairo_surface_destroy (result
.surface
);
124 return NS_ERROR_OUT_OF_MEMORY
;
128 output
->mUniformAlpha
= result
.uniform_alpha
;
129 output
->mUniformColor
= result
.uniform_color
;
130 output
->mColor
= gfxRGBA(result
.r
, result
.g
, result
.b
, result
.alpha
);