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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/platform/ozonex/DEPS ('k') | ui/ozone/platform/ozonex/ozonex.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/bind.h"
6 #include "base/file_util.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h"
9 #include "base/threading/worker_pool.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkSurface.h"
12 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
13 #include "ui/display/types/chromeos/native_display_delegate.h"
14 #include "ui/events/ozone/event_factory_ozone.cc"
15 #include "ui/events/platform/x11/x11_event_source.h"
16 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/ozone/surface_factory_ozone.h"
18 #include "ui/gfx/ozone/surface_ozone_canvas.h"
19 #include "ui/gfx/vsync_provider.h"
20 #include "ui/gfx/x/x11_types.h"
21 #include "ui/ozone/ozone_export.h"
22 #include "ui/ozone/ozone_platform.h"
23 #include "ui/platform_window/platform_window.h"
24 #include "ui/platform_window/platform_window_delegate.h"
25
26 namespace ui {
27
28 extern scoped_ptr<PlatformEventSource> CreateX11LibeventSource();
29
30 namespace {
31
32 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) {
33 std::vector<unsigned char> png_data;
34 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
35 base::WriteFile(location,
36 reinterpret_cast<const char*>(vector_as_array(&png_data)),
37 png_data.size());
38 }
39
40 class FileSurface : public gfx::SurfaceOzoneCanvas {
41 public:
42 FileSurface(const base::FilePath& location) : location_(location) {}
43 virtual ~FileSurface() {}
44
45 // SurfaceOzoneCanvas overrides:
46 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE {
47 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
48 viewport_size.width(), viewport_size.height())));
49 }
50 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE {
51 return skia::SharePtr(surface_->getCanvas());
52 }
53 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {
54 SkBitmap bitmap;
55 bitmap.setConfig(surface_->getCanvas()->imageInfo());
56
57 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy.
58 // See crbug.com/361605 for details.
59 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) {
60 base::WorkerPool::PostTask(
61 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
62 }
63 }
64 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
65 return scoped_ptr<gfx::VSyncProvider>();
66 }
67
68 private:
69 base::FilePath location_;
70 skia::RefPtr<SkSurface> surface_;
71 };
72
73 class StubPlatformWindowDelegate : public ui::PlatformWindowDelegate {
74 public:
75 virtual ~StubPlatformWindowDelegate() {}
76
77 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE {}
78
79 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {}
80
81 virtual void DispatchEvent(ui::Event* event) OVERRIDE {
82 }
83
84 virtual void OnCloseRequest() OVERRIDE {}
85 virtual void OnClosed() OVERRIDE {}
86
87 virtual void OnWindowStateChanged(
88 ui::PlatformWindowState new_state) OVERRIDE {}
89
90 virtual void OnLostCapture() OVERRIDE {}
91 };
92
93 class XSurfaceFactory : public gfx::SurfaceFactoryOzone {
94 public:
95 virtual HardwareState InitializeHardware() OVERRIDE { return INITIALIZED; }
96
97 virtual void ShutdownHardware() OVERRIDE {}
98
99 virtual intptr_t CreatePlatformWindow(
100 ui::PlatformWindowDelegate* delegate) OVERRIDE {
101 scoped_ptr<ui::PlatformWindow> platform_window(
102 ui::CreatePlatformWindow(delegate));
103 platform_window->SetBounds(gfx::Rect(100, 200, 600, 800));
104 platform_window->Show();
105 return reinterpret_cast<intptr_t>(platform_window.release());
106 }
107
108 virtual scoped_ptr<gfx::SurfaceOzoneCanvas> CreateCanvasForWidget(
109 intptr_t widget) OVERRIDE {
110 return make_scoped_ptr<gfx::SurfaceOzoneCanvas>(
111 new FileSurface(base::FilePath("/tmp/qqq.png")));
112 }
113
114 virtual bool LoadEGLGLES2Bindings(
115 AddGLLibraryCallback add_gl_library,
116 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE {
117 return false;
118 }
119 };
120
121 class OzonePlatformOzoneX : public OzonePlatform {
122 public:
123 OzonePlatformOzoneX();
124 virtual ~OzonePlatformOzoneX();
125
126 virtual gfx::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE;
127 virtual ui::EventFactoryOzone* GetEventFactoryOzone() OVERRIDE;
128 virtual ui::CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE;
129 #if defined(OS_CHROMEOS)
130 virtual scoped_ptr<ui::NativeDisplayDelegate> CreateNativeDisplayDelegate()
131 OVERRIDE;
132 #endif
133
134 private:
135 virtual void InitializeUI() OVERRIDE;
136 virtual void InitializeGPU() OVERRIDE;
137
138 scoped_ptr<PlatformEventSource> platform_event_source_;
139 scoped_ptr<EventFactoryOzone> event_factory_;
140 scoped_ptr<XSurfaceFactory> surface_factory_;
141
142 DISALLOW_COPY_AND_ASSIGN(OzonePlatformOzoneX);
143 };
144
145 OzonePlatformOzoneX::OzonePlatformOzoneX() {
146 }
147
148 OzonePlatformOzoneX::~OzonePlatformOzoneX() {
149 }
150
151 gfx::SurfaceFactoryOzone* OzonePlatformOzoneX::GetSurfaceFactoryOzone() {
152 return surface_factory_.get();
153 }
154
155 ui::EventFactoryOzone* OzonePlatformOzoneX::GetEventFactoryOzone() {
156 return event_factory_.get();
157 }
158
159 ui::CursorFactoryOzone* OzonePlatformOzoneX::GetCursorFactoryOzone() {
160 return NULL;
161 }
162
163 void OzonePlatformOzoneX::InitializeUI() {
164 platform_event_source_ = ui::CreateX11LibeventSource();
165 event_factory_.reset(new EventFactoryOzone());
166 surface_factory_.reset(new XSurfaceFactory());
167 }
168
169 void OzonePlatformOzoneX::InitializeGPU() {
170 }
171
172 #if defined(OS_CHROMEOS)
173 scoped_ptr<ui::NativeDisplayDelegate>
174 OzonePlatformOzoneX::CreateNativeDisplayDelegate() {
175 return scoped_ptr<ui::NativeDisplayDelegate>();
176 }
177 #endif
178
179 } // namespace
180
181 } // namespace ui
182
183 extern "C" {
184 ui::OzonePlatform* __attribute__((visibility("default")))
185 CreateOzonePlatform() {
186 return new ui::OzonePlatformOzoneX();
187 }
188 }
OLDNEW
« 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