~serge-hallyn/ubuntu/raring/spice/spice-fixed2

« back to all changes in this revision

Viewing changes to client/display_channel.h

  • Committer: Package Import Robot
  • Author(s): Liang Guo
  • Date: 2011-07-23 12:21:04 UTC
  • Revision ID: package-import@ubuntu.com-20110723122104-gvv70gd6ui6213qd
Tags: upstream-0.8.2
ImportĀ upstreamĀ versionĀ 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
/*
 
3
   Copyright (C) 2009 Red Hat, Inc.
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Lesser General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2.1 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Lesser General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Lesser General Public
 
16
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#ifndef _H_DISPLAY_CHANNEL
 
20
#define _H_DISPLAY_CHANNEL
 
21
 
 
22
#include "common.h"
 
23
#include "canvas.h"
 
24
#include "region.h"
 
25
#include "red_channel.h"
 
26
#include "cache.hpp"
 
27
#include "screen_layer.h"
 
28
#include "process_loop.h"
 
29
#ifdef USE_OGL
 
30
#include "red_pixmap_gl.h"
 
31
#endif
 
32
#include "glz_decoder_window.h"
 
33
 
 
34
class RedScreen;
 
35
class ChannelFactory;
 
36
class VideoStream;
 
37
class DisplayChannel;
 
38
class CursorData;
 
39
class InputsChannel;
 
40
 
 
41
class StreamsTrigger: public EventSources::Trigger {
 
42
public:
 
43
    StreamsTrigger(DisplayChannel& channel);
 
44
 
 
45
    virtual void on_event();
 
46
 
 
47
private:
 
48
    DisplayChannel& _channel;
 
49
};
 
50
 
 
51
#ifdef USE_OGL
 
52
class GLInterruptRecreate: public EventSources::Trigger {
 
53
public:
 
54
    GLInterruptRecreate(DisplayChannel& channel);
 
55
    virtual void trigger();
 
56
    virtual void on_event();
 
57
 
 
58
private:
 
59
    DisplayChannel& _channel;
 
60
    Mutex _lock;
 
61
    Condition _cond;
 
62
};
 
63
#endif
 
64
 
 
65
class InterruptUpdate: public EventSources::Trigger {
 
66
public:
 
67
    InterruptUpdate(DisplayChannel& channel);
 
68
 
 
69
    virtual void on_event();
 
70
 
 
71
private:
 
72
    DisplayChannel& _channel;
 
73
};
 
74
 
 
75
class StreamsTimer: public Timer {
 
76
public:
 
77
    StreamsTimer(DisplayChannel& channel);
 
78
    virtual void response(AbstractProcessLoop& events_loop);
 
79
private:
 
80
    DisplayChannel& _channel;
 
81
};
 
82
 
 
83
class DisplaySurfacesManger {
 
84
public:
 
85
    void add_surface(int surface_id, SpiceCanvas *surface);
 
86
    void del_surface(int surface_id);
 
87
    void add_canvas(int surface_id, Canvas *canvas);
 
88
    void del_canvas(int surface_id);
 
89
 
 
90
    CSurfaces& get_surfaces();
 
91
    bool is_present_canvas(int surface_id);
 
92
    Canvas* get_canvas(int surface_id);
 
93
private:
 
94
    CSurfaces surfaces;
 
95
    CCanvases canvases;
 
96
};
 
97
 
 
98
class DisplayChannel: public RedChannel, public ScreenLayer {
 
99
public:
 
100
    DisplayChannel(RedClient& client, uint32_t id,
 
101
                   PixmapCache& pixmap_cache, GlzDecoderWindow& glz_window);
 
102
    virtual ~DisplayChannel();
 
103
 
 
104
    virtual void copy_pixels(const QRegion& dest_region, RedDrawable& dest_dc);
 
105
    virtual void copy_pixels(const QRegion& dest_region, const PixmapHeader &dest);
 
106
#ifdef USE_OGL
 
107
    virtual void recreate_ogl_context();
 
108
    virtual void recreate_ogl_context_interrupt();
 
109
    virtual void pre_migrate();
 
110
    virtual void post_migrate();
 
111
#endif
 
112
    virtual void update_interrupt();
 
113
    void set_cursor(CursorData* cursor);
 
114
    void hide_cursor();
 
115
    void set_capture_mode(bool on);
 
116
 
 
117
    virtual bool pointer_test(int x, int y);
 
118
    virtual void on_pointer_enter(int x, int y, unsigned int buttons_state);
 
119
    virtual void on_pointer_motion(int x, int y, unsigned int buttons_state);
 
120
    virtual void on_pointer_leave();
 
121
    virtual void on_mouse_button_press(int button, int buttons_state);
 
122
    virtual void on_mouse_button_release(int button, int buttons_state);
 
123
 
 
124
    void attach_inputs(InputsChannel* inputs_channel);
 
125
    void detach_inputs();
 
126
 
 
127
    static ChannelFactory& Factory();
 
128
 
 
129
protected:
 
130
    virtual void on_connect();
 
131
    virtual void on_disconnect();
 
132
 
 
133
private:
 
134
    void set_draw_handlers();
 
135
    void clear_draw_handlers();
 
136
    bool create_sw_canvas(int surface_id, int width, int height, uint32_t format);
 
137
#ifdef USE_OGL
 
138
    bool create_ogl_canvas(int surface_id, int width, int height, uint32_t format, bool recreate,
 
139
                           RenderType rendertype);
 
140
#endif
 
141
#ifdef WIN32
 
142
    bool create_gdi_canvas(int surface_id, int width, int height, uint32_t format);
 
143
#endif
 
144
    void destroy_canvas(int surface_id);
 
145
    void create_canvas(int surface_id, const std::vector<int>& canvas_type, int width, int height,
 
146
                       uint32_t format);
 
147
    void destroy_strams();
 
148
    void update_cursor();
 
149
 
 
150
    void create_primary_surface(int width, int height, uint32_t format);
 
151
    void create_surface(int surface_id, int width, int height, uint32_t format);
 
152
    void destroy_primary_surface();
 
153
    void destroy_surface(int surface_id);
 
154
 
 
155
    void handle_mode(RedPeer::InMessage* message);
 
156
    void handle_mark(RedPeer::InMessage* message);
 
157
    void handle_reset(RedPeer::InMessage* message);
 
158
 
 
159
    void handle_inval_list(RedPeer::InMessage* message);
 
160
    void handle_inval_all_pixmaps(RedPeer::InMessage* message);
 
161
    void handle_inval_palette(RedPeer::InMessage* message);
 
162
    void handle_inval_all_palettes(RedPeer::InMessage* message);
 
163
    void handle_copy_bits(RedPeer::InMessage* message);
 
164
    void handle_stream_create(RedPeer::InMessage* message);
 
165
    void handle_stream_data(RedPeer::InMessage* message);
 
166
    void handle_stream_clip(RedPeer::InMessage* message);
 
167
    void handle_stream_destroy(RedPeer::InMessage* message);
 
168
    void handle_stream_destroy_all(RedPeer::InMessage* message);
 
169
 
 
170
    void handle_surface_create(RedPeer::InMessage* message);
 
171
    void handle_surface_destroy(RedPeer::InMessage* message);
 
172
 
 
173
    void handle_draw_fill(RedPeer::InMessage* message);
 
174
    void handle_draw_opaque(RedPeer::InMessage* message);
 
175
    void handle_draw_copy(RedPeer::InMessage* message);
 
176
    void handle_draw_blend(RedPeer::InMessage* message);
 
177
    void handle_draw_blackness(RedPeer::InMessage* message);
 
178
    void handle_draw_whiteness(RedPeer::InMessage* message);
 
179
    void handle_draw_invers(RedPeer::InMessage* message);
 
180
    void handle_draw_rop3(RedPeer::InMessage* message);
 
181
    void handle_draw_stroke(RedPeer::InMessage* message);
 
182
    void handle_draw_text(RedPeer::InMessage* message);
 
183
    void handle_draw_transparent(RedPeer::InMessage* message);
 
184
    void handle_draw_alpha_blend(RedPeer::InMessage* message);
 
185
 
 
186
    void on_streams_trigger();
 
187
    virtual void on_update_completion(uint64_t mark);
 
188
    void streams_time();
 
189
    void activate_streams_timer();
 
190
    void stream_update_request(uint32_t update_time);
 
191
    void reset_screen();
 
192
 
 
193
    static void set_clip_rects(const SpiceClip& clip, uint32_t& num_clip_rects, SpiceRect*& clip_rects);
 
194
private:
 
195
    DisplaySurfacesManger surfaces_mngr;
 
196
    PixmapCache& _pixmap_cache;
 
197
    PaletteCache _palette_cache;
 
198
    GlzDecoderWindow& _glz_window;
 
199
    bool _mark;
 
200
    int _x_res;
 
201
    int _y_res;
 
202
    uint32_t _format;
 
203
#ifdef USE_OGL
 
204
    RenderType _rendertype;
 
205
#endif
 
206
 
 
207
#ifndef RED64
 
208
    Mutex _mark_lock;
 
209
#endif
 
210
    uint64_t _update_mark;
 
211
    Mutex _streams_lock;
 
212
 
 
213
    Mutex _timer_lock;
 
214
    AutoRef<StreamsTimer> _streams_timer;
 
215
    uint32_t _next_timer_time;
 
216
 
 
217
    AutoRef<CursorData> _cursor;
 
218
    bool _cursor_visibal;
 
219
    bool _active_pointer;
 
220
    bool _capture_mouse_mode;
 
221
    InputsChannel* _inputs_channel;
 
222
 
 
223
    SpicePoint _pointer_pos;
 
224
    int _buttons_state;
 
225
 
 
226
    std::vector<VideoStream*> _streams;
 
227
    VideoStream* _active_streams;
 
228
    StreamsTrigger _streams_trigger;
 
229
#ifdef USE_OGL
 
230
    GLInterruptRecreate _gl_interrupt_recreate;
 
231
#endif
 
232
    InterruptUpdate _interrupt_update;
 
233
 
 
234
    friend class SetModeEvent;
 
235
    friend class CreatePrimarySurfaceEvent;
 
236
    friend class DestroyPrimarySurfaceEvent;
 
237
    friend class CreateSurfaceEvent;
 
238
    friend class DestroySurfaceEvent;
 
239
    friend class ActivateTimerEvent;
 
240
    friend class VideoStream;
 
241
    friend class StreamsTrigger;
 
242
    friend class GLInterupt;
 
243
    friend class StreamsTimer;
 
244
    friend class AttachChannelsEvent;
 
245
    friend class DetachChannelsEvent;
 
246
};
 
247
 
 
248
#endif
 
249