Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: remoting/client/x11_view.cc

Issue 2861047: Refactor the client code. Move all x11-related code into X11View and create... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/x11_view.h" 5 #include "remoting/client/x11_view.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 #include <X11/Xutil.h> 8 #include <X11/Xutil.h>
9 #include <X11/extensions/Xrender.h> 9 #include <X11/extensions/Xrender.h>
10 #include <X11/extensions/Xcomposite.h> 10 #include <X11/extensions/Xcomposite.h>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "remoting/client/decoder_verbatim.h" 13 #include "remoting/client/decoder_verbatim.h"
14 14
15 namespace remoting { 15 namespace remoting {
16 16
17 X11View::X11View()
18 : display_(NULL),
19 window_(0),
20 width_(0),
21 height_(0),
22 picture_(0) {
23 }
24
17 X11View::X11View(Display* display, XID window, int width, int height) 25 X11View::X11View(Display* display, XID window, int width, int height)
18 : display_(display), 26 : display_(display),
19 window_(window), 27 window_(window),
20 width_(width), 28 width_(width),
21 height_(height), 29 height_(height),
22 picture_(0) { 30 picture_(0) {
23 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, width_, height_, 31 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, width_, height_,
24 base::TimeDelta(), base::TimeDelta(), &frame_); 32 base::TimeDelta(), base::TimeDelta(), &frame_);
25 DCHECK(frame_); 33 DCHECK(frame_);
26 } 34 }
27 35
28 X11View::~X11View() { 36 X11View::~X11View() {
37 DCHECK(!display_);
38 DCHECK(!window_);
39 }
40
41 bool X11View::Initialize() {
42 display_ = XOpenDisplay(NULL);
43 if (!display_) {
44 return false;
45 }
46
47 // Get properties of the screen.
48 int screen = DefaultScreen(display_);
49 int root_window = RootWindow(display_, screen);
50
51 // Creates the window.
52 window_ = XCreateSimpleWindow(display_, root_window, 1, 1, 640, 480, 0,
53 BlackPixel(display_, screen),
54 BlackPixel(display_, screen));
55 DCHECK(window_);
56 XStoreName(display_, window_, "X11 Remoting");
57
58 // Specifies what kind of messages we want to receive.
59 XSelectInput(display_, window_, ExposureMask | ButtonPressMask);
60 XMapWindow(display_, window_);
61 return true;
62 }
63
64 void X11View::TearDown() {
65 if (display_ && window_) {
66 // Shutdown the window system.
67 XDestroyWindow(display_, window_);
68 XCloseDisplay(display_);
69 }
70 display_ = NULL;
71 window_ = 0;
29 } 72 }
30 73
31 void X11View::Paint() { 74 void X11View::Paint() {
75 // Don't bother attempting to paint if the display hasn't been set up.
76 if (!display_ || !window_ || !height_ || !width_) {
77 return;
78 }
79
32 // TODO(hclam): Paint only the updated regions. 80 // TODO(hclam): Paint only the updated regions.
33 all_update_rects_.clear(); 81 all_update_rects_.clear();
34 82
35 // If we have not initialized the render target then do it now. 83 // If we have not initialized the render target then do it now.
36 if (!picture_) 84 if (!picture_)
37 InitPaintTarget(); 85 InitPaintTarget();
38 86
39 // Upload the image to a pixmap. And then create a picture from the pixmap 87 // Upload the image to a pixmap. And then create a picture from the pixmap
40 // and composite the picture over the picture representing the window. 88 // and composite the picture over the picture representing the window.
41 89
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // Composite the picture over the picture representing the window. 121 // Composite the picture over the picture representing the window.
74 XRenderComposite(display_, PictOpSrc, picture, 0, 122 XRenderComposite(display_, PictOpSrc, picture, 0,
75 picture_, 0, 0, 0, 0, 0, 0, 123 picture_, 0, 0, 0, 0, 0, 0,
76 width_, height_); 124 width_, height_);
77 125
78 XRenderFreePicture(display_, picture); 126 XRenderFreePicture(display_, picture);
79 XFreePixmap(display_, pixmap); 127 XFreePixmap(display_, pixmap);
80 } 128 }
81 129
82 void X11View::SetSolidFill(uint32 color) { 130 void X11View::SetSolidFill(uint32 color) {
83 // TODO(ajwong): Implement. 131 // TODO(garykac): Implement.
84 NOTIMPLEMENTED(); 132 // NOTIMPLEMENTED();
85 } 133 }
86 134
87 void X11View::UnsetSolidFill() { 135 void X11View::UnsetSolidFill() {
88 // TODO(ajwong): Implement. 136 // TODO(garykac): Implement.
89 NOTIMPLEMENTED(); 137 // NOTIMPLEMENTED();
90 } 138 }
91 139
92 void X11View::SetViewport(int x, int y, int width, int height) { 140 void X11View::SetViewport(int x, int y, int width, int height) {
93 // TODO(ajwong): Implement. 141 // TODO(garykac): Implement.
94 NOTIMPLEMENTED(); 142 // NOTIMPLEMENTED();
95 } 143 }
96 144
97 void X11View::SetBackingStoreSize(int width, int height) { 145 void X11View::SetHostScreenSize(int width, int height) {
98 // TODO(ajwong): Implement. 146 width_ = width;
99 NOTIMPLEMENTED(); 147 height_ = height;
148 XResizeWindow(display_, window_, width_, height_);
100 } 149 }
101 150
102 void X11View::InitPaintTarget() { 151 void X11View::InitPaintTarget() {
103 // Testing XRender support. 152 // Testing XRender support.
104 int dummy; 153 int dummy;
105 bool xrender_support = XRenderQueryExtension(display_, &dummy, &dummy); 154 bool xrender_support = XRenderQueryExtension(display_, &dummy, &dummy);
106 CHECK(xrender_support) << "XRender is not supported!"; 155 CHECK(xrender_support) << "XRender is not supported!";
107 156
108 XWindowAttributes attr; 157 XWindowAttributes attr;
109 XGetWindowAttributes(display_, window_, &attr); 158 XGetWindowAttributes(display_, window_, &attr);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 XEvent event; 211 XEvent event;
163 event.type = Expose; 212 event.type = Expose;
164 XSendEvent(display_, static_cast<int>(window_), true, ExposureMask, &event); 213 XSendEvent(display_, static_cast<int>(window_), true, ExposureMask, &event);
165 } 214 }
166 215
167 void X11View::OnDecodeDone() { 216 void X11View::OnDecodeDone() {
168 // Since we do synchronous decoding here there's nothing in this method. 217 // Since we do synchronous decoding here there's nothing in this method.
169 } 218 }
170 219
171 } // namespace remoting 220 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698