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

Unified 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: Addressing review comments. 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/software_output_device_linux.cc
diff --git a/content/browser/renderer_host/software_output_device_linux.cc b/content/browser/renderer_host/software_output_device_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..46d138f5872e7d9eaffd068b96b9aa127cc15c8e
--- /dev/null
+++ b/content/browser/renderer_host/software_output_device_linux.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/software_output_device.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "base/command_line.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkDevice.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/compositor_switches.h"
+
+namespace content {
+
+SoftwareOutputDevice::SoftwareOutputDevice(ui::Compositor* compositor)
+ : compositor_(compositor),
+ display_(ui::GetXDisplay()),
+ gc_(NULL),
+ image_(NULL) {
+ // TODO Remove this when crbug.com/180702 is fixed
piman 2013/03/07 00:25:51 nit: syntax is // TODO(skaslev): Remove this when
slavi 2013/03/07 01:48:30 Done.
+ CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kUIEnableThreadedCompositing));
piman 2013/03/07 00:25:51 How about moving this check to image_transport_fac
slavi 2013/03/07 01:48:30 Changed that to an explicit DCHECK we're called on
+ gc_ = XCreateGC(display_, compositor_->widget(), 0, NULL);
+}
+
+SoftwareOutputDevice::~SoftwareOutputDevice() {
+ XFreeGC(display_, gc_);
+ ClearImage();
+}
+
+void SoftwareOutputDevice::ClearImage() {
+ if (image_) {
+ // XDestroyImage deletes the data referenced by the image which
+ // is actually owned by the device_. So we have to reset data here.
+ image_->data = NULL;
+ XDestroyImage(image_);
+ image_ = NULL;
+ }
+}
+
+void SoftwareOutputDevice::Resize(const gfx::Size& viewport_size) {
+ cc::SoftwareOutputDevice::Resize(viewport_size);
+
+ ClearImage();
+ if (!device_)
+ return;
+
+ const SkBitmap& bitmap = device_->accessBitmap(false);
+ image_ = XCreateImage(display_, CopyFromParent,
+ DefaultDepth(display_, DefaultScreen(display_)),
+ ZPixmap, 0,
+ static_cast<char*>(bitmap.getPixels()),
+ viewport_size_.width(), viewport_size_.height(),
+ 32, 4 * viewport_size_.width());
+}
+
+void SoftwareOutputDevice::EndPaint(cc::SoftwareFrameData* frame_data) {
+ DCHECK(device_);
+ DCHECK(frame_data == NULL);
+
+ if (!device_)
+ return;
+
+ gfx::Rect rect = damage_rect_;
+ rect.Intersect(gfx::Rect(viewport_size_));
+ if (rect.IsEmpty())
+ return;
+
+ // TODO(skaslev): Maybe switch XShmPutImage since it's async.
+ XPutImage(display_, compositor_->widget(), gc_, image_,
+ rect.x(), rect.y(),
+ rect.x(), rect.y(),
+ rect.width(), rect.height());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698