|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
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 GFXXLIBNATIVERENDER_H_ |
|
7 #define GFXXLIBNATIVERENDER_H_ |
|
8 |
|
9 #include "nsPoint.h" |
|
10 #include "nsRect.h" |
|
11 #include <X11/Xlib.h> |
|
12 |
|
13 namespace mozilla { |
|
14 namespace gfx { |
|
15 class DrawTarget; |
|
16 } |
|
17 } |
|
18 |
|
19 class gfxASurface; |
|
20 class gfxContext; |
|
21 struct nsIntRect; |
|
22 struct nsIntPoint; |
|
23 struct nsIntSize; |
|
24 typedef struct _cairo cairo_t; |
|
25 typedef struct _cairo_surface cairo_surface_t; |
|
26 |
|
27 /** |
|
28 * This class lets us take code that draws into an X drawable and lets us |
|
29 * use it to draw into any Thebes context. The user should subclass this class, |
|
30 * override DrawWithXib, and then call Draw(). The drawing will be subjected |
|
31 * to all Thebes transformations, clipping etc. |
|
32 */ |
|
33 class gfxXlibNativeRenderer { |
|
34 public: |
|
35 /** |
|
36 * Perform the native drawing. |
|
37 * @param surface the cairo_surface_t for drawing. Must be a cairo_xlib_surface_t. |
|
38 * The extents of this surface do not necessarily cover the |
|
39 * entire rectangle with size provided to Draw(). |
|
40 * @param offset draw at this offset into the given drawable |
|
41 * @param clipRects an array of rectangles; clip to the union. |
|
42 * Any rectangles provided will be contained by the |
|
43 * rectangle with size provided to Draw and by the |
|
44 * surface extents. |
|
45 * @param numClipRects the number of rects in the array, or zero if |
|
46 * no clipping is required. |
|
47 */ |
|
48 virtual nsresult DrawWithXlib(cairo_surface_t* surface, |
|
49 nsIntPoint offset, |
|
50 nsIntRect* clipRects, uint32_t numClipRects) = 0; |
|
51 |
|
52 enum { |
|
53 // If set, then Draw() is opaque, i.e., every pixel in the intersection |
|
54 // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height) |
|
55 // will be set and there is no dependence on what the existing pixels |
|
56 // in the drawable are set to. |
|
57 DRAW_IS_OPAQUE = 0x01, |
|
58 // If set, then numClipRects can be zero or one |
|
59 DRAW_SUPPORTS_CLIP_RECT = 0x04, |
|
60 // If set, then numClipRects can be any value. If neither this |
|
61 // nor CLIP_RECT are set, then numClipRects will be zero |
|
62 DRAW_SUPPORTS_CLIP_LIST = 0x08, |
|
63 // If set, then the surface in the callback may have any visual; |
|
64 // otherwise the pixels will have the same format as the visual |
|
65 // passed to 'Draw'. |
|
66 DRAW_SUPPORTS_ALTERNATE_VISUAL = 0x10, |
|
67 // If set, then the Screen 'screen' in the callback can be different |
|
68 // from the default Screen of the display passed to 'Draw' and can be |
|
69 // on a different display. |
|
70 DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20 |
|
71 }; |
|
72 |
|
73 /** |
|
74 * @param flags see above |
|
75 * @param size the size of the rectangle being drawn; |
|
76 * the caller guarantees that drawing will not extend beyond the rectangle |
|
77 * (0,0,size.width,size.height). |
|
78 * @param screen a Screen to use for the drawing if ctx doesn't have one. |
|
79 * @param visual a Visual to use for the drawing if ctx doesn't have one. |
|
80 * @param result if non-null, we will try to capture a copy of the |
|
81 * rendered image into a surface similar to the surface of ctx; if |
|
82 * successful, a pointer to the new gfxASurface is stored in *resultSurface, |
|
83 * otherwise *resultSurface is set to nullptr. |
|
84 */ |
|
85 void Draw(gfxContext* ctx, nsIntSize size, |
|
86 uint32_t flags, Screen *screen, Visual *visual); |
|
87 |
|
88 private: |
|
89 bool DrawDirect(gfxContext *ctx, nsIntSize bounds, |
|
90 uint32_t flags, Screen *screen, Visual *visual); |
|
91 |
|
92 bool DrawCairo(cairo_t* cr, nsIntSize size, |
|
93 uint32_t flags, Screen *screen, Visual *visual); |
|
94 |
|
95 void DrawFallback(mozilla::gfx::DrawTarget* dt, gfxContext* ctx, |
|
96 gfxASurface* aSurface, nsIntSize& size, |
|
97 nsIntRect& drawingRect, bool canDrawOverBackground, |
|
98 uint32_t flags, Screen* screen, Visual* visual); |
|
99 |
|
100 bool DrawOntoTempSurface(cairo_surface_t *tempXlibSurface, |
|
101 nsIntPoint offset); |
|
102 |
|
103 }; |
|
104 |
|
105 #endif /*GFXXLIBNATIVERENDER_H_*/ |