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 "third_party/skia/include/core/SkBitmap.h" | |
11 #include "third_party/skia/include/core/SkDevice.h" | |
12 #include "ui/compositor/compositor.h" | |
13 | |
14 namespace content { | |
15 | |
16 SoftwareOutputDevice::SoftwareOutputDevice(ui::Compositor* compositor) | |
17 : compositor_(compositor), | |
18 display_(ui::GetXDisplay()), | |
19 gc_(NULL), | |
20 image_(NULL) { | |
21 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL); | |
22 } | |
23 | |
24 SoftwareOutputDevice::~SoftwareOutputDevice() { | |
25 XFreeGC(display_, gc_); | |
piman
2013/03/06 19:22:30
When threaded compositing is on, this, and multipl
| |
26 ClearImage(); | |
27 } | |
28 | |
29 void SoftwareOutputDevice::ClearImage() { | |
30 if (image_) { | |
31 // XDestroyImage deletes the data referenced by the image which | |
32 // is actually owned by the device_. So we have to reset data here. | |
33 image_->data = NULL; | |
34 XDestroyImage(image_); | |
35 image_ = NULL; | |
36 } | |
37 } | |
38 | |
39 void SoftwareOutputDevice::Resize(const gfx::Size& viewport_size) { | |
40 cc::SoftwareOutputDevice::Resize(viewport_size); | |
41 | |
42 ClearImage(); | |
43 if (!device_) | |
44 return; | |
45 | |
46 const SkBitmap& bitmap = device_->accessBitmap(false); | |
47 image_ = XCreateImage(display_, CopyFromParent, | |
48 DefaultDepth(display_, DefaultScreen(display_)), | |
49 ZPixmap, 0, | |
50 static_cast<char*>(bitmap.getPixels()), | |
51 viewport_size_.width(), viewport_size_.height(), | |
52 32, 4 * viewport_size_.width()); | |
53 } | |
54 | |
55 void SoftwareOutputDevice::EndPaint(cc::SoftwareFrameData* frame_data) { | |
56 DCHECK(device_); | |
57 DCHECK(frame_data == NULL); | |
58 | |
59 if (!device_) | |
60 return; | |
61 | |
62 gfx::Rect rect = damage_rect_; | |
63 rect.Intersect(gfx::Rect(viewport_size_)); | |
64 if (rect.IsEmpty()) | |
65 return; | |
66 | |
67 // TODO(skaslev): Maybe switch XShmPutImage since it's async. | |
68 XPutImage(display_, compositor_->widget(), gc_, image_, | |
69 rect.x(), rect.y(), | |
70 rect.x(), rect.y(), | |
71 rect.width(), rect.height()); | |
72 } | |
73 | |
74 } // namespace content | |
OLD | NEW |