~mc-return/compiz/compiz.merge-src-screen.cpp-improvements

« back to all changes in this revision

Viewing changes to plugins/imgsvg.h

  • Committer: Dennis kasprzyk
  • Author(s): Dennis Kasprzyk
  • Date: 2009-03-15 05:09:18 UTC
  • Revision ID: git-v1:163f6b6f3c3b7764987cbdf8e03cc355edeaa499
New generalized build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2006 Novell, Inc.
3
 
 *
4
 
 * Permission to use, copy, modify, distribute, and sell this software
5
 
 * and its documentation for any purpose is hereby granted without
6
 
 * fee, provided that the above copyright notice appear in all copies
7
 
 * and that both that copyright notice and this permission notice
8
 
 * appear in supporting documentation, and that the name of
9
 
 * Novell, Inc. not be used in advertising or publicity pertaining to
10
 
 * distribution of the software without specific, written prior permission.
11
 
 * Novell, Inc. makes no representations about the suitability of this
12
 
 * software for any purpose. It is provided "as is" without express or
13
 
 * implied warranty.
14
 
 *
15
 
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
 
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 
 *
23
 
 * Author: David Reveman <davidr@novell.com>
24
 
 */
25
 
 
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
 
29
 
#include <cairo/cairo-xlib.h>
30
 
#include <librsvg/rsvg.h>
31
 
#include <librsvg/rsvg-cairo.h>
32
 
 
33
 
#include <X11/Xatom.h>
34
 
#include <X11/extensions/shape.h>
35
 
 
36
 
#include <core/core.h>
37
 
#include <core/privatehandler.h>
38
 
#include <composite/composite.h>
39
 
#include <opengl/opengl.h>
40
 
#include <decoration.h>
41
 
 
42
 
#include <iostream>
43
 
#include <fstream>
44
 
 
45
 
#define SVG_OPTION_SET 0
46
 
#define SVG_OPTION_NUM 1
47
 
 
48
 
#define SVG_SCREEN(s) SvgScreen *ss = SvgScreen::get (s)
49
 
#define SVG_WINDOW(w) SvgWindow *sw = SvgWindow::get (w)
50
 
 
51
 
class SvgScreen :
52
 
    public ScreenInterface,
53
 
    public PrivateHandler<SvgScreen, CompScreen>
54
 
{
55
 
    public:
56
 
        SvgScreen (CompScreen *screen);
57
 
        ~SvgScreen ();
58
 
 
59
 
        CompOption::Vector & getOptions ();
60
 
        bool setOption (const char *name, CompOption::Value &value);
61
 
 
62
 
        bool fileToImage (CompString &path, CompSize &size,
63
 
                          int &stride, void *&data);
64
 
        void handleCompizEvent (const char *plugin, const char *event,
65
 
                                CompOption::Vector &options);
66
 
 
67
 
        CompRect zoom;
68
 
 
69
 
    private:
70
 
        CompOption::Vector opt;
71
 
 
72
 
        bool readSvgToImage (const char *file, CompSize &size, void *& data);
73
 
};
74
 
 
75
 
class SvgWindow :
76
 
    public WindowInterface,
77
 
    public GLWindowInterface,
78
 
    public PrivateHandler<SvgWindow, CompWindow>
79
 
{
80
 
    public:
81
 
        SvgWindow (CompWindow *window);
82
 
        ~SvgWindow ();
83
 
 
84
 
        bool glDraw (const GLMatrix &transform, GLFragment::Attrib &fragment,
85
 
                     const CompRegion &region, unsigned int mask);
86
 
        void moveNotify (int dx, int dy, bool immediate);
87
 
        void resizeNotify (int dx, int dy, int dwidth, int dheight);
88
 
 
89
 
        void setSvg (CompString &data, decor_point_t p[2]);
90
 
 
91
 
    private:
92
 
        typedef struct {
93
 
            decor_point_t p1;
94
 
            decor_point_t p2;
95
 
 
96
 
            RsvgHandle        *svg;
97
 
            RsvgDimensionData dimension;
98
 
        } SvgSource;
99
 
 
100
 
        typedef struct {
101
 
            GLTexture::List       textures;
102
 
            GLTexture::MatrixList matrices;
103
 
            cairo_t           *cr;
104
 
            Pixmap            pixmap;
105
 
            CompSize          size;
106
 
        } SvgTexture;
107
 
 
108
 
        typedef struct {
109
 
            SvgSource  *source;
110
 
            CompRegion box;
111
 
            SvgTexture texture[2];
112
 
            CompRect   rect;
113
 
            CompSize   size;
114
 
        } SvgContext;
115
 
 
116
 
        SvgSource  *source;
117
 
        SvgContext *context;
118
 
 
119
 
        SvgScreen  *sScreen;
120
 
        GLScreen   *gScreen;
121
 
 
122
 
        CompWindow *window;
123
 
        GLWindow   *gWindow;
124
 
 
125
 
        void updateSvgMatrix ();
126
 
        void updateSvgContext ();
127
 
 
128
 
        void renderSvg (SvgSource *source, SvgTexture &texture, CompSize size,
129
 
                        float x1, float y1, float x2, float y2);
130
 
        bool initTexture (SvgSource *source, SvgTexture &texture, CompSize size);
131
 
        void finiTexture (SvgTexture &texture);
132
 
};
133
 
 
134
 
class SvgPluginVTable :
135
 
    public CompPlugin::VTableForScreenAndWindow<SvgScreen, SvgWindow>
136
 
{
137
 
    public:
138
 
 
139
 
        bool init ();
140
 
        void fini ();
141
 
 
142
 
        PLUGIN_OPTION_HELPER (SvgScreen);
143
 
};