Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / gfx / thebes / src / gfxGdkNativeRenderer.cpp
blob3945cdeb7b3aa59abda9539d6c45254c1f0f8e1d
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
13 * License.
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.
21 * Contributor(s):
22 * rocallahan@novell.com
23 * Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "gfxGdkNativeRenderer.h"
40 #include "gfxContext.h"
42 #include "cairo-gdk-utils.h"
44 #include "gfxPlatformGtk.h"
46 typedef struct {
47 gfxGdkNativeRenderer* mRenderer;
48 nsresult mRV;
49 } NativeRenderingClosure;
52 static cairo_bool_t
53 NativeRendering(void *closure,
54 cairo_surface_t *surface,
55 short offset_x, short offset_y,
56 GdkRectangle * rectangles, unsigned int num_rects)
58 NativeRenderingClosure* cl = (NativeRenderingClosure*)closure;
59 nsRefPtr<gfxASurface> gfxSurface = gfxASurface::Wrap(surface);
60 GdkDrawable *drawable =
61 gfxPlatformGtk::GetPlatform()->GetGdkDrawable(gfxSurface);
62 if (!drawable)
63 return 0;
65 nsresult rv = cl->mRenderer->
66 NativeDraw(drawable, offset_x, offset_y,
67 rectangles, num_rects);
68 cl->mRV = rv;
69 return NS_SUCCEEDED(rv);
73 nsresult
74 gfxGdkNativeRenderer::Draw(gfxContext* ctx, int width, int height,
75 PRUint32 flags, DrawOutput* output)
77 NativeRenderingClosure closure = { this, NS_OK };
78 cairo_gdk_drawing_result_t result;
79 // Make sure result.surface is null to start with; we rely on it
80 // being non-null meaning that a surface actually got allocated.
81 result.surface = NULL;
83 if (output) {
84 output->mSurface = NULL;
85 output->mUniformAlpha = PR_FALSE;
86 output->mUniformColor = PR_FALSE;
89 int cairoFlags = 0;
90 if (flags & DRAW_SUPPORTS_OFFSET) {
91 cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_OFFSET;
93 if (flags & DRAW_SUPPORTS_CLIP_RECT) {
94 cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT;
96 if (flags & DRAW_SUPPORTS_CLIP_LIST) {
97 cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST;
99 if (flags & DRAW_SUPPORTS_ALTERNATE_SCREEN) {
100 cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN;
102 if (flags & DRAW_SUPPORTS_NONDEFAULT_VISUAL) {
103 cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL;
105 cairo_draw_with_gdk(ctx->GetCairo(),
106 NativeRendering,
107 &closure, width, height,
108 (flags & DRAW_IS_OPAQUE) ? CAIRO_GDK_DRAWING_OPAQUE : CAIRO_GDK_DRAWING_TRANSPARENT,
109 (cairo_gdk_drawing_support_t)cairoFlags,
110 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);
116 return closure.mRV;
119 if (output) {
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);
133 return NS_OK;