summaryrefslogtreecommitdiffstats
path: root/client/red_gdi_canvas.cpp
blob: 809468fc90cbbfa75d0fd46741ae0fe9fcfdc031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
   Copyright (C) 2009 Red Hat, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include <stdint.h>
#include "red_gdi_canvas.h"
#include "utils.h"
#include "debug.h"
#include "region.h"
#include "red_pixmap_gdi.h"

GDICanvas::GDICanvas(PixmapCache& pixmap_cache, PaletteCache& palette_cache,
                     GlzDecoderWindow &glz_decoder_window)
    : Canvas (pixmap_cache, palette_cache, glz_decoder_window)
    , _canvas (NULL)
    , _pixmap (0)
{
}

GDICanvas::~GDICanvas()
{
    destroy();
}

void GDICanvas::destroy()
{
    if (_canvas) {
        _canvas = NULL;
    }
    destroy_pixmap();
}

void GDICanvas::clear()
{
    if (_canvas) {
        gdi_canvas_clear(_canvas);
    }
}

void GDICanvas::destroy_pixmap()
{
    delete _pixmap;
    _pixmap = NULL;
}

void GDICanvas::create_pixmap(int width, int height)
{
    _pixmap = new RedPixmapGdi(width, height, RedPixmap::RGB32, true, NULL);
}

void GDICanvas::copy_pixels(const QRegion& region, RedDrawable& dest_dc)
{
    for (int i = 0; i < (int)region.num_rects; i++) {
        Rect* r = &region.rects[i];
        dest_dc.copy_pixels(*_pixmap, r->left, r->top, *r);
    }
}

void GDICanvas::copy_pixels(const QRegion& region, RedDrawable* dest_dc, const PixmapHeader* pixmap)
{
    copy_pixels(region, *dest_dc);
}

void GDICanvas::set_mode(int width, int height, int depth)
{
    destroy();
    create_pixmap(width, height);
    if (!(_canvas = gdi_canvas_create(_pixmap->get_dc(),
                                      &_pixmap->get_mutex(),
                                      depth, &pixmap_cache(), bits_cache_put,
                                      bits_cache_get, &palette_cache(),
                                      palette_cache_put, palette_cache_get,
                                      palette_cache_release,
                                      &glz_decoder(),
                                      glz_decode))) {
        THROW("create canvas failed");
    }
}

void GDICanvas::set_access_params(ADDRESS delta, unsigned long base, unsigned long max)
{
    gdi_canvas_set_access_params(_canvas, delta, base, max);
}

void GDICanvas::draw_fill(Rect *bbox, Clip *clip, Fill *fill)
{
    gdi_canvas_draw_fill(_canvas, bbox, clip, fill);
}

void GDICanvas::draw_text(Rect *bbox, Clip *clip, Text *text)
{
    gdi_canvas_draw_text(_canvas, bbox, clip, text);
}

void GDICanvas::draw_opaque(Rect *bbox, Clip *clip, Opaque *opaque)
{
    gdi_canvas_draw_opaque(_canvas, bbox, clip, opaque);
}

void GDICanvas::draw_copy(Rect *bbox, Clip *clip, Copy *copy)
{
    gdi_canvas_draw_copy(_canvas, bbox, clip, copy);
}

void GDICanvas::draw_transparent(Rect *bbox, Clip *clip, Transparent* transparent)
{
    gdi_canvas_draw_transparent(_canvas, bbox, clip, transparent);
}

void GDICanvas::draw_alpha_blend(Rect *bbox, Clip *clip, AlphaBlnd* alpha_blend)
{
    gdi_canvas_draw_alpha_blend(_canvas, bbox, clip, alpha_blend);
}

void GDICanvas::copy_bits(Rect *bbox, Clip *clip, Point *src_pos)
{
    gdi_canvas_copy_bits(_canvas, bbox, clip, src_pos);
}

void GDICanvas::draw_blend(Rect *bbox, Clip *clip, Blend *blend)
{
    gdi_canvas_draw_blend(_canvas, bbox, clip, blend);
}

void GDICanvas::draw_blackness(Rect *bbox, Clip *clip, Blackness *blackness)
{
    gdi_canvas_draw_blackness(_canvas, bbox, clip, blackness);
}

void GDICanvas::draw_whiteness(Rect *bbox, Clip *clip, Whiteness *whiteness)
{
    gdi_canvas_draw_whiteness(_canvas, bbox, clip, whiteness);
}

void GDICanvas::draw_invers(Rect *bbox, Clip *clip, Invers *invers)
{
    gdi_canvas_draw_invers(_canvas, bbox, clip, invers);
}

void GDICanvas::draw_rop3(Rect *bbox, Clip *clip, Rop3 *rop3)
{
    gdi_canvas_draw_rop3(_canvas, bbox, clip, rop3);
}

void GDICanvas::draw_stroke(Rect *bbox, Clip *clip, Stroke *stroke)
{
    gdi_canvas_draw_stroke(_canvas, bbox, clip, stroke);
}

void GDICanvas::put_image(HDC dc, const PixmapHeader& image, const Rect& dest, const QRegion* clip)
{
    gdi_canvas_put_image(_canvas, dc, &dest, image.data, image.width, image.height, image.stride,
                         clip);
}

CanvasType GDICanvas::get_pixmap_type()
{
    return CANVAS_TYPE_GDI;
}