michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFXXLIBNATIVERENDER_H_ michael@0: #define GFXXLIBNATIVERENDER_H_ michael@0: michael@0: #include "nsPoint.h" michael@0: #include "nsRect.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class DrawTarget; michael@0: } michael@0: } michael@0: michael@0: class gfxASurface; michael@0: class gfxContext; michael@0: struct nsIntRect; michael@0: struct nsIntPoint; michael@0: struct nsIntSize; michael@0: typedef struct _cairo cairo_t; michael@0: typedef struct _cairo_surface cairo_surface_t; michael@0: michael@0: /** michael@0: * This class lets us take code that draws into an X drawable and lets us michael@0: * use it to draw into any Thebes context. The user should subclass this class, michael@0: * override DrawWithXib, and then call Draw(). The drawing will be subjected michael@0: * to all Thebes transformations, clipping etc. michael@0: */ michael@0: class gfxXlibNativeRenderer { michael@0: public: michael@0: /** michael@0: * Perform the native drawing. michael@0: * @param surface the cairo_surface_t for drawing. Must be a cairo_xlib_surface_t. michael@0: * The extents of this surface do not necessarily cover the michael@0: * entire rectangle with size provided to Draw(). michael@0: * @param offset draw at this offset into the given drawable michael@0: * @param clipRects an array of rectangles; clip to the union. michael@0: * Any rectangles provided will be contained by the michael@0: * rectangle with size provided to Draw and by the michael@0: * surface extents. michael@0: * @param numClipRects the number of rects in the array, or zero if michael@0: * no clipping is required. michael@0: */ michael@0: virtual nsresult DrawWithXlib(cairo_surface_t* surface, michael@0: nsIntPoint offset, michael@0: nsIntRect* clipRects, uint32_t numClipRects) = 0; michael@0: michael@0: enum { michael@0: // If set, then Draw() is opaque, i.e., every pixel in the intersection michael@0: // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height) michael@0: // will be set and there is no dependence on what the existing pixels michael@0: // in the drawable are set to. michael@0: DRAW_IS_OPAQUE = 0x01, michael@0: // If set, then numClipRects can be zero or one michael@0: DRAW_SUPPORTS_CLIP_RECT = 0x04, michael@0: // If set, then numClipRects can be any value. If neither this michael@0: // nor CLIP_RECT are set, then numClipRects will be zero michael@0: DRAW_SUPPORTS_CLIP_LIST = 0x08, michael@0: // If set, then the surface in the callback may have any visual; michael@0: // otherwise the pixels will have the same format as the visual michael@0: // passed to 'Draw'. michael@0: DRAW_SUPPORTS_ALTERNATE_VISUAL = 0x10, michael@0: // If set, then the Screen 'screen' in the callback can be different michael@0: // from the default Screen of the display passed to 'Draw' and can be michael@0: // on a different display. michael@0: DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20 michael@0: }; michael@0: michael@0: /** michael@0: * @param flags see above michael@0: * @param size the size of the rectangle being drawn; michael@0: * the caller guarantees that drawing will not extend beyond the rectangle michael@0: * (0,0,size.width,size.height). michael@0: * @param screen a Screen to use for the drawing if ctx doesn't have one. michael@0: * @param visual a Visual to use for the drawing if ctx doesn't have one. michael@0: * @param result if non-null, we will try to capture a copy of the michael@0: * rendered image into a surface similar to the surface of ctx; if michael@0: * successful, a pointer to the new gfxASurface is stored in *resultSurface, michael@0: * otherwise *resultSurface is set to nullptr. michael@0: */ michael@0: void Draw(gfxContext* ctx, nsIntSize size, michael@0: uint32_t flags, Screen *screen, Visual *visual); michael@0: michael@0: private: michael@0: bool DrawDirect(gfxContext *ctx, nsIntSize bounds, michael@0: uint32_t flags, Screen *screen, Visual *visual); michael@0: michael@0: bool DrawCairo(cairo_t* cr, nsIntSize size, michael@0: uint32_t flags, Screen *screen, Visual *visual); michael@0: michael@0: void DrawFallback(mozilla::gfx::DrawTarget* dt, gfxContext* ctx, michael@0: gfxASurface* aSurface, nsIntSize& size, michael@0: nsIntRect& drawingRect, bool canDrawOverBackground, michael@0: uint32_t flags, Screen* screen, Visual* visual); michael@0: michael@0: bool DrawOntoTempSurface(cairo_surface_t *tempXlibSurface, michael@0: nsIntPoint offset); michael@0: michael@0: }; michael@0: michael@0: #endif /*GFXXLIBNATIVERENDER_H_*/