Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: content/browser/renderer_host/software_output_device_linux.cc

Issue 12542006: Implemented browser side software compositing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed reninterpret_casts Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_linux.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xutil.h>
9
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
15 namespace content {
16
17 SoftwareOutputDeviceLinux::SoftwareOutputDeviceLinux(ui::Compositor* compositor)
18 : compositor_(compositor),
19 display_(ui::GetXDisplay()),
20 gc_(NULL),
21 image_(NULL) {
22 // TODO(skaslev) Remove this when crbug.com/180702 is fixed.
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
24
25 gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL);
26 }
27
28 SoftwareOutputDeviceLinux::~SoftwareOutputDeviceLinux() {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30
31 XFreeGC(display_, gc_);
32 ClearImage();
33 }
34
35 void SoftwareOutputDeviceLinux::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 SoftwareOutputDeviceLinux::Resize(const 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 }
64
65 void SoftwareOutputDeviceLinux::EndPaint(cc::SoftwareFrameData* frame_data) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 DCHECK(device_);
68 DCHECK(frame_data == NULL);
69
70 if (!device_)
71 return;
72
73 gfx::Rect rect = damage_rect_;
74 rect.Intersect(gfx::Rect(viewport_size_));
75 if (rect.IsEmpty())
76 return;
77
78 // TODO(skaslev): Maybe switch XShmPutImage since it's async.
79 XPutImage(display_, compositor_->widget(), gc_, image_,
80 rect.x(), rect.y(),
81 rect.x(), rect.y(),
82 rect.width(), rect.height());
83 }
84
85 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698