Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / compositor / software_output_device_x11.cc
blob016b4915f834f8d85daa4111d1d8ca99ed0dac24
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
3 // found in the LICENSE file.
5 #include "content/browser/compositor/software_output_device_x11.h"
7 #include <X11/Xlib.h>
8 #include <X11/Xutil.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"
14 #include "ui/gfx/x/x11_types.h"
16 namespace content {
18 SoftwareOutputDeviceX11::SoftwareOutputDeviceX11(ui::Compositor* compositor)
19 : compositor_(compositor), display_(gfx::GetXDisplay()), gc_(NULL) {
20 // TODO(skaslev) Remove this when crbug.com/180702 is fixed.
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
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;
31 SoftwareOutputDeviceX11::~SoftwareOutputDeviceX11() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 XFreeGC(display_, gc_);
37 void SoftwareOutputDeviceX11::EndPaint(cc::SoftwareFrameData* frame_data) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 DCHECK(canvas_);
40 DCHECK(frame_data);
42 if (!canvas_)
43 return;
45 SoftwareOutputDevice::EndPaint(frame_data);
47 gfx::Rect rect = damage_rect_;
48 rect.Intersect(gfx::Rect(viewport_size_));
49 if (rect.IsEmpty())
50 return;
52 // TODO(jbauman): Switch to XShmPutImage since it's async.
53 SkImageInfo info;
54 size_t rowBytes;
55 const void* addr = canvas_->peekPixels(&info, &rowBytes);
56 gfx::PutARGBImage(display_,
57 attributes_.visual,
58 attributes_.depth,
59 compositor_->widget(),
60 gc_,
61 static_cast<const uint8*>(addr),
62 viewport_size_.width(),
63 viewport_size_.height(),
64 rect.x(),
65 rect.y(),
66 rect.x(),
67 rect.y(),
68 rect.width(),
69 rect.height());
72 } // namespace content