OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/software_output_device.h" | |
6 | |
7 #include <X11/Xlib.h> | |
8 #include <X11/Xutil.h> | |
9 | |
10 #include "base/command_line.h" | |
11 #include "third_party/skia/include/core/SkBitmap.h" | |
12 #include "third_party/skia/include/core/SkDevice.h" | |
13 #include "ui/compositor/compositor.h" | |
14 #include "ui/compositor/compositor_switches.h" | |
15 | |
16 namespace content { | |
17 | |
18 SoftwareOutputDevice::SoftwareOutputDevice(ui::Compositor* compositor) | |
19 : compositor_(compositor), | |
20 display_(ui::GetXDisplay()), | |
21 gc_(NULL), | |
22 image_(NULL) { | |
23 // TODO Remove this when crbug.com/180702 is fixed | |
piman
2013/03/07 00:25:51
nit: syntax is // TODO(skaslev): Remove this when
slavi
2013/03/07 01:48:30
Done.
| |
24 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | |
25 switches::kUIEnableThreadedCompositing)); | |
piman
2013/03/07 00:25:51
How about moving this check to image_transport_fac
slavi
2013/03/07 01:48:30
Changed that to an explicit DCHECK we're called on
| |
26 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL); | |
27 } | |
28 | |
29 SoftwareOutputDevice::~SoftwareOutputDevice() { | |
30 XFreeGC(display_, gc_); | |
31 ClearImage(); | |
32 } | |
33 | |
34 void SoftwareOutputDevice::ClearImage() { | |
35 if (image_) { | |
36 // XDestroyImage deletes the data referenced by the image which | |
37 // is actually owned by the device_. So we have to reset data here. | |
38 image_->data = NULL; | |
39 XDestroyImage(image_); | |
40 image_ = NULL; | |
41 } | |
42 } | |
43 | |
44 void SoftwareOutputDevice::Resize(const gfx::Size& viewport_size) { | |
45 cc::SoftwareOutputDevice::Resize(viewport_size); | |
46 | |
47 ClearImage(); | |
48 if (!device_) | |
49 return; | |
50 | |
51 const SkBitmap& bitmap = device_->accessBitmap(false); | |
52 image_ = XCreateImage(display_, CopyFromParent, | |
53 DefaultDepth(display_, DefaultScreen(display_)), | |
54 ZPixmap, 0, | |
55 static_cast<char*>(bitmap.getPixels()), | |
56 viewport_size_.width(), viewport_size_.height(), | |
57 32, 4 * viewport_size_.width()); | |
58 } | |
59 | |
60 void SoftwareOutputDevice::EndPaint(cc::SoftwareFrameData* frame_data) { | |
61 DCHECK(device_); | |
62 DCHECK(frame_data == NULL); | |
63 | |
64 if (!device_) | |
65 return; | |
66 | |
67 gfx::Rect rect = damage_rect_; | |
68 rect.Intersect(gfx::Rect(viewport_size_)); | |
69 if (rect.IsEmpty()) | |
70 return; | |
71 | |
72 // TODO(skaslev): Maybe switch XShmPutImage since it's async. | |
73 XPutImage(display_, compositor_->widget(), gc_, image_, | |
74 rect.x(), rect.y(), | |
75 rect.x(), rect.y(), | |
76 rect.width(), rect.height()); | |
77 } | |
78 | |
79 } // namespace content | |
OLD | NEW |