| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/aura/software_output_device_x11.h" | 5 #include "content/browser/aura/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/compositor/compositor.h" | 13 #include "ui/compositor/compositor.h" |
| 14 #include "ui/gfx/x/x11_types.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor) | 18 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor) |
| 18 : compositor_(compositor), | 19 : compositor_(compositor), display_(gfx::GetXDisplay()), gc_(NULL) { |
| 19 display_(gfx::GetXDisplay()), | |
| 20 gc_(NULL), | |
| 21 image_(NULL) { | |
| 22 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. | 20 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. |
| 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 24 | 22 |
| 25 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL); | 23 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL); |
| 24 if (!XGetWindowAttributes(display_, compositor_->widget(), &attributes_)) { |
| 25 LOG(ERROR) << "XGetWindowAttributes failed for window " |
| 26 << compositor_->widget(); |
| 27 return; |
| 28 } |
| 26 } | 29 } |
| 27 | 30 |
| 28 SoftwareOutputDeviceX11::~SoftwareOutputDeviceX11() { | 31 SoftwareOutputDeviceX11::~SoftwareOutputDeviceX11() { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 30 | 33 |
| 31 XFreeGC(display_, gc_); | 34 XFreeGC(display_, gc_); |
| 32 ClearImage(); | |
| 33 } | |
| 34 | |
| 35 void SoftwareOutputDeviceX11::ClearImage() { | |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 37 | |
| 38 if (image_) { | |
| 39 // XDestroyImage deletes the data referenced by the image which | |
| 40 // is actually owned by the device_. So we have to reset data here. | |
| 41 image_->data = NULL; | |
| 42 XDestroyImage(image_); | |
| 43 image_ = NULL; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void SoftwareOutputDeviceX11::Resize(gfx::Size viewport_size) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 | |
| 50 cc::SoftwareOutputDevice::Resize(viewport_size); | |
| 51 | |
| 52 ClearImage(); | |
| 53 if (!device_) | |
| 54 return; | |
| 55 | |
| 56 const SkBitmap& bitmap = device_->accessBitmap(false); | |
| 57 image_ = XCreateImage(display_, CopyFromParent, | |
| 58 DefaultDepth(display_, DefaultScreen(display_)), | |
| 59 ZPixmap, 0, | |
| 60 static_cast<char*>(bitmap.getPixels()), | |
| 61 viewport_size_.width(), viewport_size_.height(), | |
| 62 32, 4 * viewport_size_.width()); | |
| 63 } | 35 } |
| 64 | 36 |
| 65 void SoftwareOutputDeviceX11::EndPaint(cc::SoftwareFrameData* frame_data) { | 37 void SoftwareOutputDeviceX11::EndPaint(cc::SoftwareFrameData* frame_data) { |
| 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 67 DCHECK(device_); | 39 DCHECK(device_); |
| 68 DCHECK(frame_data); | 40 DCHECK(frame_data); |
| 69 | 41 |
| 70 if (!device_) | 42 if (!device_) |
| 71 return; | 43 return; |
| 72 | 44 |
| 73 SoftwareOutputDevice::EndPaint(frame_data); | 45 SoftwareOutputDevice::EndPaint(frame_data); |
| 74 | 46 |
| 75 gfx::Rect rect = damage_rect_; | 47 gfx::Rect rect = damage_rect_; |
| 76 rect.Intersect(gfx::Rect(viewport_size_)); | 48 rect.Intersect(gfx::Rect(viewport_size_)); |
| 77 if (rect.IsEmpty()) | 49 if (rect.IsEmpty()) |
| 78 return; | 50 return; |
| 79 | 51 |
| 80 // TODO(skaslev): Maybe switch XShmPutImage since it's async. | 52 // TODO(jbauman): Switch to XShmPutImage since it's async. |
| 81 XPutImage(display_, compositor_->widget(), gc_, image_, | 53 const SkBitmap& bitmap = device_->accessBitmap(false); |
| 82 rect.x(), rect.y(), | 54 gfx::PutARGBImage(display_, |
| 83 rect.x(), rect.y(), | 55 attributes_.visual, |
| 84 rect.width(), rect.height()); | 56 attributes_.depth, |
| 57 compositor_->widget(), |
| 58 gc_, |
| 59 static_cast<const uint8*>(bitmap.getPixels()), |
| 60 viewport_size_.width(), |
| 61 viewport_size_.height(), |
| 62 rect.x(), |
| 63 rect.y(), |
| 64 rect.x(), |
| 65 rect.y(), |
| 66 rect.width(), |
| 67 rect.height()); |
| 85 } | 68 } |
| 86 | 69 |
| 87 } // namespace content | 70 } // namespace content |
| OLD | NEW |