Bug 1703443 - pt 6. Move RunNextCollectorTimer() into CCGCScheduler r=smaug
[gecko.git] / gfx / thebes / gfxXlibNativeRenderer.h
blob3845627c806d430ef7b3a2e2f9d09b993f08f8ae
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
6 #ifndef GFXXLIBNATIVERENDER_H_
7 #define GFXXLIBNATIVERENDER_H_
9 #include "nsPoint.h"
10 #include "nsRect.h"
11 #include "mozilla/gfx/Rect.h"
12 #include "mozilla/gfx/Point.h"
13 #include <X11/Xlib.h>
15 namespace mozilla {
16 namespace gfx {
17 class DrawTarget;
19 } // namespace mozilla
21 class gfxASurface;
22 class gfxContext;
23 typedef struct _cairo cairo_t;
24 typedef struct _cairo_surface cairo_surface_t;
26 /**
27 * This class lets us take code that draws into an X drawable and lets us
28 * use it to draw into any Thebes context. The user should subclass this class,
29 * override DrawWithXib, and then call Draw(). The drawing will be subjected
30 * to all Thebes transformations, clipping etc.
32 class gfxXlibNativeRenderer {
33 public:
34 /**
35 * Perform the native drawing.
36 * @param surface the cairo_surface_t for drawing. Must be a
37 * cairo_xlib_surface_t. The extents of this surface do not necessarily cover
38 * the entire rectangle with size provided to Draw().
39 * @param offset draw at this offset into the given drawable
40 * @param clipRects an array of rectangles; clip to the union.
41 * Any rectangles provided will be contained by the
42 * rectangle with size provided to Draw and by the
43 * surface extents.
44 * @param numClipRects the number of rects in the array, or zero if
45 * no clipping is required.
47 virtual nsresult DrawWithXlib(cairo_surface_t* surface,
48 mozilla::gfx::IntPoint offset,
49 mozilla::gfx::IntRect* clipRects,
50 uint32_t numClipRects) = 0;
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
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.
85 void Draw(gfxContext* ctx, mozilla::gfx::IntSize size, uint32_t flags,
86 Screen* screen, Visual* visual);
88 private:
89 bool DrawDirect(mozilla::gfx::DrawTarget* aDT, mozilla::gfx::IntSize bounds,
90 uint32_t flags, Screen* screen, Visual* visual);
92 bool DrawCairo(cairo_t* cr, mozilla::gfx::IntSize size, uint32_t flags,
93 Screen* screen, Visual* visual);
95 void DrawFallback(mozilla::gfx::DrawTarget* dt, gfxContext* ctx,
96 gfxASurface* aSurface, mozilla::gfx::IntSize& size,
97 mozilla::gfx::IntRect& drawingRect,
98 bool canDrawOverBackground, uint32_t flags, Screen* screen,
99 Visual* visual);
101 bool DrawOntoTempSurface(cairo_surface_t* tempXlibSurface,
102 mozilla::gfx::IntPoint offset);
105 #endif /*GFXXLIBNATIVERENDER_H_*/