xref: /AOO41X/main/canvas/source/cairo/cairo_xlib_cairo.hxx (revision 91c99ff47293b0d0832bde809a8978c8bfc37548)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CAIROCANVAS_XLIB_CAIRO_HXX
25 #define _CAIROCANVAS_XLIB_CAIRO_HXX
26 
27 #include "cairo_cairo.hxx"
28 
29 struct SystemEnvData;
30 struct SystemGraphicsData;
31 
32 namespace cairo {
33 
34     /// Holds all X11-output relevant data
35     struct X11SysData
36     {
37         X11SysData();
38         explicit X11SysData( const SystemGraphicsData& );
39         explicit X11SysData( const SystemEnvData& );
40 
41         void*   pDisplay;       // the relevant display connection
42         long    hDrawable;      // a drawable
43         void*   pVisual;        // the visual in use
44         int nScreen;        // the current screen of the drawable
45         int     nDepth;         // depth of said visual
46         long    aColormap;      // the colormap being used
47         void*   pRenderFormat;  // render format for drawable
48     };
49 
50     /// RAII wrapper for a pixmap
51     struct X11Pixmap
52     {
53         void* mpDisplay;  // the relevant display connection
54         long  mhDrawable; // a drawable
55 
X11Pixmapcairo::X11Pixmap56         X11Pixmap( long hDrawable, void* pDisplay ) :
57             mpDisplay(pDisplay),
58             mhDrawable(hDrawable)
59         {}
60 
61         ~X11Pixmap();
62 
clearcairo::X11Pixmap63         void clear() { mpDisplay=NULL; mhDrawable=0; }
64     };
65 
66     typedef boost::shared_ptr<X11Pixmap>       X11PixmapSharedPtr;
67 
68     class X11Surface : public Surface
69     {
70         const X11SysData      maSysData;
71         X11PixmapSharedPtr    mpPixmap;
72         CairoSurfaceSharedPtr mpSurface;
73 
74         X11Surface( const X11SysData& rSysData, const X11PixmapSharedPtr& rPixmap, const CairoSurfaceSharedPtr& pSurface );
75 
76     public:
77         /// takes over ownership of passed cairo_surface
78         explicit X11Surface( const CairoSurfaceSharedPtr& pSurface );
79         /// create surface on subarea of given drawable
80         X11Surface( const X11SysData& rSysData, int x, int y, int width, int height );
81         /// create surface for given bitmap data
82         X11Surface( const X11SysData& rSysData, const BitmapSystemData& rBmpData );
83 
84         // Surface interface
85         virtual CairoSharedPtr getCairo() const;
getCairoSurface() const86         virtual CairoSurfaceSharedPtr getCairoSurface() const { return mpSurface; }
87         virtual SurfaceSharedPtr getSimilar( Content aContent, int width, int height ) const;
88 
89         virtual boost::shared_ptr<VirtualDevice> createVirtualDevice() const;
90 
91         virtual void Resize( int width, int height );
92 
93         virtual void flush() const;
94 
95         int getDepth() const;
getPixmap() const96         X11PixmapSharedPtr getPixmap() const { return mpPixmap; }
getRenderFormat() const97         void* getRenderFormat() const { return maSysData.pRenderFormat; }
getDrawable() const98         long getDrawable() const { return mpPixmap ? mpPixmap->mhDrawable : maSysData.hDrawable; }
99     };
100 }
101 
102 #endif
103