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
3 // found in the LICENSE file.
5 #include "content/browser/aura/software_output_device_x11.h"
10 #include "content/public/browser/browser_thread.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"
17 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor)
18 : compositor_(compositor),
19 display_(gfx::GetXDisplay()),
22 // TODO(skaslev) Remove this when crbug.com/180702 is fixed.
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL);
28 SoftwareOutputDeviceX11::~SoftwareOutputDeviceX11() {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
31 XFreeGC(display_, gc_);
35 void SoftwareOutputDeviceX11::ClearImage() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 // XDestroyImage deletes the data referenced by the image which
40 // is actually owned by the device_. So we have to reset data here.
42 XDestroyImage(image_);
47 void SoftwareOutputDeviceX11::Resize(gfx::Size viewport_size) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 cc::SoftwareOutputDevice::Resize(viewport_size);
56 const SkBitmap& bitmap = device_->accessBitmap(false);
57 image_ = XCreateImage(display_, CopyFromParent,
58 DefaultDepth(display_, DefaultScreen(display_)),
60 static_cast<char*>(bitmap.getPixels()),
61 viewport_size_.width(), viewport_size_.height(),
62 32, 4 * viewport_size_.width());
65 void SoftwareOutputDeviceX11::EndPaint(cc::SoftwareFrameData* frame_data) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
73 SoftwareOutputDevice::EndPaint(frame_data);
75 gfx::Rect rect = damage_rect_;
76 rect.Intersect(gfx::Rect(viewport_size_));
80 // TODO(skaslev): Maybe switch XShmPutImage since it's async.
81 XPutImage(display_, compositor_->widget(), gc_, image_,
84 rect.width(), rect.height());
87 } // namespace content