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

Unified Diff: ui/ozone/platform/ozonex/ozone_platform_ozonex.cc

Issue 275263002: [wip] ozonex: X11 backend for ozone. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 7 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
« no previous file with comments | « ui/ozone/platform/ozonex/DEPS ('k') | ui/ozone/platform/ozonex/ozonex.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/ozonex/ozone_platform_ozonex.cc
diff --git a/ui/ozone/platform/ozonex/ozone_platform_ozonex.cc b/ui/ozone/platform/ozonex/ozone_platform_ozonex.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d7d31ec15c87e0b105cbf4727532c01138a0400e
--- /dev/null
+++ b/ui/ozone/platform/ozonex/ozone_platform_ozonex.cc
@@ -0,0 +1,188 @@
+// Copyright 2014 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 "base/bind.h"
+#include "base/file_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/stl_util.h"
+#include "base/threading/worker_pool.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSurface.h"
+#include "ui/base/cursor/ozone/cursor_factory_ozone.h"
+#include "ui/display/types/chromeos/native_display_delegate.h"
+#include "ui/events/ozone/event_factory_ozone.cc"
+#include "ui/events/platform/x11/x11_event_source.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/ozone/surface_factory_ozone.h"
+#include "ui/gfx/ozone/surface_ozone_canvas.h"
+#include "ui/gfx/vsync_provider.h"
+#include "ui/gfx/x/x11_types.h"
+#include "ui/ozone/ozone_export.h"
+#include "ui/ozone/ozone_platform.h"
+#include "ui/platform_window/platform_window.h"
+#include "ui/platform_window/platform_window_delegate.h"
+
+namespace ui {
+
+extern scoped_ptr<PlatformEventSource> CreateX11LibeventSource();
+
+namespace {
+
+void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) {
+ std::vector<unsigned char> png_data;
+ gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
+ base::WriteFile(location,
+ reinterpret_cast<const char*>(vector_as_array(&png_data)),
+ png_data.size());
+}
+
+class FileSurface : public gfx::SurfaceOzoneCanvas {
+ public:
+ FileSurface(const base::FilePath& location) : location_(location) {}
+ virtual ~FileSurface() {}
+
+ // SurfaceOzoneCanvas overrides:
+ virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE {
+ surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
+ viewport_size.width(), viewport_size.height())));
+ }
+ virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE {
+ return skia::SharePtr(surface_->getCanvas());
+ }
+ virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {
+ SkBitmap bitmap;
+ bitmap.setConfig(surface_->getCanvas()->imageInfo());
+
+ // TODO(dnicoara) Use SkImage instead to potentially avoid a copy.
+ // See crbug.com/361605 for details.
+ if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) {
+ base::WorkerPool::PostTask(
+ FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
+ }
+ }
+ virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
+ return scoped_ptr<gfx::VSyncProvider>();
+ }
+
+ private:
+ base::FilePath location_;
+ skia::RefPtr<SkSurface> surface_;
+};
+
+class StubPlatformWindowDelegate : public ui::PlatformWindowDelegate {
+ public:
+ virtual ~StubPlatformWindowDelegate() {}
+
+ virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE {}
+
+ virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {}
+
+ virtual void DispatchEvent(ui::Event* event) OVERRIDE {
+ }
+
+ virtual void OnCloseRequest() OVERRIDE {}
+ virtual void OnClosed() OVERRIDE {}
+
+ virtual void OnWindowStateChanged(
+ ui::PlatformWindowState new_state) OVERRIDE {}
+
+ virtual void OnLostCapture() OVERRIDE {}
+};
+
+class XSurfaceFactory : public gfx::SurfaceFactoryOzone {
+ public:
+ virtual HardwareState InitializeHardware() OVERRIDE { return INITIALIZED; }
+
+ virtual void ShutdownHardware() OVERRIDE {}
+
+ virtual intptr_t CreatePlatformWindow(
+ ui::PlatformWindowDelegate* delegate) OVERRIDE {
+ scoped_ptr<ui::PlatformWindow> platform_window(
+ ui::CreatePlatformWindow(delegate));
+ platform_window->SetBounds(gfx::Rect(100, 200, 600, 800));
+ platform_window->Show();
+ return reinterpret_cast<intptr_t>(platform_window.release());
+ }
+
+ virtual scoped_ptr<gfx::SurfaceOzoneCanvas> CreateCanvasForWidget(
+ intptr_t widget) OVERRIDE {
+ return make_scoped_ptr<gfx::SurfaceOzoneCanvas>(
+ new FileSurface(base::FilePath("/tmp/qqq.png")));
+ }
+
+ virtual bool LoadEGLGLES2Bindings(
+ AddGLLibraryCallback add_gl_library,
+ SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE {
+ return false;
+ }
+};
+
+class OzonePlatformOzoneX : public OzonePlatform {
+ public:
+ OzonePlatformOzoneX();
+ virtual ~OzonePlatformOzoneX();
+
+ virtual gfx::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE;
+ virtual ui::EventFactoryOzone* GetEventFactoryOzone() OVERRIDE;
+ virtual ui::CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE;
+#if defined(OS_CHROMEOS)
+ virtual scoped_ptr<ui::NativeDisplayDelegate> CreateNativeDisplayDelegate()
+ OVERRIDE;
+#endif
+
+ private:
+ virtual void InitializeUI() OVERRIDE;
+ virtual void InitializeGPU() OVERRIDE;
+
+ scoped_ptr<PlatformEventSource> platform_event_source_;
+ scoped_ptr<EventFactoryOzone> event_factory_;
+ scoped_ptr<XSurfaceFactory> surface_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(OzonePlatformOzoneX);
+};
+
+OzonePlatformOzoneX::OzonePlatformOzoneX() {
+}
+
+OzonePlatformOzoneX::~OzonePlatformOzoneX() {
+}
+
+gfx::SurfaceFactoryOzone* OzonePlatformOzoneX::GetSurfaceFactoryOzone() {
+ return surface_factory_.get();
+}
+
+ui::EventFactoryOzone* OzonePlatformOzoneX::GetEventFactoryOzone() {
+ return event_factory_.get();
+}
+
+ui::CursorFactoryOzone* OzonePlatformOzoneX::GetCursorFactoryOzone() {
+ return NULL;
+}
+
+void OzonePlatformOzoneX::InitializeUI() {
+ platform_event_source_ = ui::CreateX11LibeventSource();
+ event_factory_.reset(new EventFactoryOzone());
+ surface_factory_.reset(new XSurfaceFactory());
+}
+
+void OzonePlatformOzoneX::InitializeGPU() {
+}
+
+#if defined(OS_CHROMEOS)
+scoped_ptr<ui::NativeDisplayDelegate>
+OzonePlatformOzoneX::CreateNativeDisplayDelegate() {
+ return scoped_ptr<ui::NativeDisplayDelegate>();
+}
+#endif
+
+} // namespace
+
+} // namespace ui
+
+extern "C" {
+ui::OzonePlatform* __attribute__((visibility("default")))
+CreateOzonePlatform() {
+ return new ui::OzonePlatformOzoneX();
+}
+}
« no previous file with comments | « ui/ozone/platform/ozonex/DEPS ('k') | ui/ozone/platform/ozonex/ozonex.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698