OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/compositor/software_output_device_x11.h" | 5 #include "content/browser/compositor/software_output_device_x11.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
9 | 9 |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkDevice.h" | 12 #include "third_party/skia/include/core/SkDevice.h" |
| 13 #include "ui/base/x/x11_util.h" |
| 14 #include "ui/base/x/x11_util_internal.h" |
13 #include "ui/compositor/compositor.h" | 15 #include "ui/compositor/compositor.h" |
14 #include "ui/gfx/x/x11_types.h" | 16 #include "ui/gfx/x/x11_types.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor) | 20 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor) |
19 : compositor_(compositor), display_(gfx::GetXDisplay()), gc_(NULL) { | 21 : compositor_(compositor), display_(gfx::GetXDisplay()), gc_(NULL) { |
20 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. | 22 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. |
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
22 | 24 |
(...skipping 19 matching lines...) Expand all Loading... |
42 if (!canvas_) | 44 if (!canvas_) |
43 return; | 45 return; |
44 | 46 |
45 SoftwareOutputDevice::EndPaint(frame_data); | 47 SoftwareOutputDevice::EndPaint(frame_data); |
46 | 48 |
47 gfx::Rect rect = damage_rect_; | 49 gfx::Rect rect = damage_rect_; |
48 rect.Intersect(gfx::Rect(viewport_size_)); | 50 rect.Intersect(gfx::Rect(viewport_size_)); |
49 if (rect.IsEmpty()) | 51 if (rect.IsEmpty()) |
50 return; | 52 return; |
51 | 53 |
| 54 int bpp = gfx::BitsPerPixelForPixmapDepth(display_, attributes_.depth); |
| 55 |
| 56 if (bpp != 32 && bpp != 16 && ui::QueryRenderSupport(display_)) { |
| 57 // gfx::PutARGBImage only supports 16 and 32 bpp, but Xrender can do other |
| 58 // conversions. |
| 59 Pixmap pixmap = XCreatePixmap( |
| 60 display_, compositor_->widget(), rect.width(), rect.height(), 32); |
| 61 GC gc = XCreateGC(display_, pixmap, 0, NULL); |
| 62 XImage image; |
| 63 memset(&image, 0, sizeof(image)); |
| 64 |
| 65 SkImageInfo info; |
| 66 size_t rowBytes; |
| 67 const void* addr = canvas_->peekPixels(&info, &rowBytes); |
| 68 image.width = viewport_size_.width(); |
| 69 image.height = viewport_size_.height(); |
| 70 image.depth = 32; |
| 71 image.bits_per_pixel = 32; |
| 72 image.format = ZPixmap; |
| 73 image.byte_order = LSBFirst; |
| 74 image.bitmap_unit = 8; |
| 75 image.bitmap_bit_order = LSBFirst; |
| 76 image.bytes_per_line = rowBytes; |
| 77 image.red_mask = 0xff; |
| 78 image.green_mask = 0xff00; |
| 79 image.blue_mask = 0xff0000; |
| 80 image.data = const_cast<char*>(static_cast<const char*>(addr)); |
| 81 |
| 82 XPutImage(display_, |
| 83 pixmap, |
| 84 gc, |
| 85 &image, |
| 86 rect.x(), |
| 87 rect.y() /* source x, y */, |
| 88 0, |
| 89 0 /* dest x, y */, |
| 90 rect.width(), |
| 91 rect.height()); |
| 92 XFreeGC(display_, gc); |
| 93 Picture picture = XRenderCreatePicture( |
| 94 display_, pixmap, ui::GetRenderARGB32Format(display_), 0, NULL); |
| 95 XRenderPictFormat* pictformat = |
| 96 XRenderFindVisualFormat(display_, attributes_.visual); |
| 97 Picture dest_picture = XRenderCreatePicture( |
| 98 display_, compositor_->widget(), pictformat, 0, NULL); |
| 99 XRenderComposite(display_, |
| 100 PictOpSrc, // op |
| 101 picture, // src |
| 102 0, // mask |
| 103 dest_picture, // dest |
| 104 0, // src_x |
| 105 0, // src_y |
| 106 0, // mask_x |
| 107 0, // mask_y |
| 108 rect.x(), // dest_x |
| 109 rect.y(), // dest_y |
| 110 rect.width(), // width |
| 111 rect.height()); // height |
| 112 XRenderFreePicture(display_, picture); |
| 113 XRenderFreePicture(display_, dest_picture); |
| 114 XFreePixmap(display_, pixmap); |
| 115 return; |
| 116 } |
| 117 |
52 // TODO(jbauman): Switch to XShmPutImage since it's async. | 118 // TODO(jbauman): Switch to XShmPutImage since it's async. |
53 SkImageInfo info; | 119 SkImageInfo info; |
54 size_t rowBytes; | 120 size_t rowBytes; |
55 const void* addr = canvas_->peekPixels(&info, &rowBytes); | 121 const void* addr = canvas_->peekPixels(&info, &rowBytes); |
56 gfx::PutARGBImage(display_, | 122 gfx::PutARGBImage(display_, |
57 attributes_.visual, | 123 attributes_.visual, |
58 attributes_.depth, | 124 attributes_.depth, |
59 compositor_->widget(), | 125 compositor_->widget(), |
60 gc_, | 126 gc_, |
61 static_cast<const uint8*>(addr), | 127 static_cast<const uint8*>(addr), |
62 viewport_size_.width(), | 128 viewport_size_.width(), |
63 viewport_size_.height(), | 129 viewport_size_.height(), |
64 rect.x(), | 130 rect.x(), |
65 rect.y(), | 131 rect.y(), |
66 rect.x(), | 132 rect.x(), |
67 rect.y(), | 133 rect.y(), |
68 rect.width(), | 134 rect.width(), |
69 rect.height()); | 135 rect.height()); |
70 } | 136 } |
71 | 137 |
72 } // namespace content | 138 } // namespace content |
OLD | NEW |