[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 5 | #include "base/at_exit.h" |
| 6 | #include "base/command_line.h" |
| 7 | #include "base/i18n/icu_util.h" |
avi | 4ca29411 | 2015-12-24 08:04:09 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 10 | #include "base/message_loop/message_loop.h" |
ckocagil | 8a06497 | 2015-02-09 17:05:43 | [diff] [blame] | 11 | #include "base/power_monitor/power_monitor.h" |
| 12 | #include "base/power_monitor/power_monitor_device_source.h" |
avi | 4ca29411 | 2015-12-24 08:04:09 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 14 | #include "third_party/skia/include/core/SkXfermode.h" |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 15 | #include "ui/aura/client/default_capture_client.h" |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 16 | #include "ui/aura/client/window_tree_client.h" |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 17 | #include "ui/aura/env.h" |
[email protected] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 18 | #include "ui/aura/test/test_focus_client.h" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame] | 19 | #include "ui/aura/test/test_screen.h" |
[email protected] | dbf3d40 | 2011-09-14 21:32:16 | [diff] [blame] | 20 | #include "ui/aura/window.h" |
| 21 | #include "ui/aura/window_delegate.h" |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 22 | #include "ui/aura/window_tree_host.h" |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 23 | #include "ui/base/hit_test.h" |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 24 | #include "ui/compositor/paint_recorder.h" |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 25 | #include "ui/compositor/test/in_process_context_factory.h" |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 26 | #include "ui/events/event.h" |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 27 | #include "ui/gfx/canvas.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 28 | #include "ui/gfx/geometry/rect.h" |
danakj | c963112 | 2015-03-02 23:50:32 | [diff] [blame] | 29 | #include "ui/gfx/skia_util.h" |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 30 | #include "ui/gl/gl_surface.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 31 | |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 32 | #if defined(USE_X11) |
kylechar | 4abed71f | 2016-04-06 14:46:42 | [diff] [blame^] | 33 | #include "ui/gfx/x/x11_connection.h" // nogncheck |
[email protected] | 4a6bef3 | 2011-09-07 02:06:01 | [diff] [blame] | 34 | #endif |
| 35 | |
[email protected] | 804f479 | 2014-04-22 22:54:37 | [diff] [blame] | 36 | #if defined(OS_WIN) |
| 37 | #include "ui/gfx/win/dpi.h" |
| 38 | #endif |
| 39 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 40 | namespace { |
| 41 | |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 42 | // Trivial WindowDelegate implementation that draws a colored background. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 43 | class DemoWindowDelegate : public aura::WindowDelegate { |
| 44 | public: |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 45 | explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 46 | |
[email protected] | 8dd791d | 2011-09-16 16:37:30 | [diff] [blame] | 47 | // Overridden from WindowDelegate: |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 48 | gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
[email protected] | fa574b6 | 2012-11-26 04:11:38 | [diff] [blame] | 49 | |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 50 | gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
[email protected] | fa574b6 | 2012-11-26 04:11:38 | [diff] [blame] | 51 | |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 52 | void OnBoundsChanged(const gfx::Rect& old_bounds, |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 53 | const gfx::Rect& new_bounds) override { |
| 54 | window_bounds_ = new_bounds; |
| 55 | } |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 56 | gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
[email protected] | 62c9f10 | 2014-03-27 06:07:04 | [diff] [blame] | 57 | return gfx::kNullCursor; |
| 58 | } |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 59 | int GetNonClientComponent(const gfx::Point& point) const override { |
[email protected] | eaf6dd5 | 2011-09-02 00:39:26 | [diff] [blame] | 60 | return HTCAPTION; |
| 61 | } |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 62 | bool ShouldDescendIntoChildForEventHandling( |
[email protected] | 334b8189 | 2012-06-16 16:38:14 | [diff] [blame] | 63 | aura::Window* child, |
mostynb | 3b3d52b | 2014-10-09 10:54:27 | [diff] [blame] | 64 | const gfx::Point& location) override { |
[email protected] | 334b8189 | 2012-06-16 16:38:14 | [diff] [blame] | 65 | return true; |
| 66 | } |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 67 | bool CanFocus() override { return true; } |
| 68 | void OnCaptureLost() override {} |
danakj | 85d970e | 2015-04-04 00:15:24 | [diff] [blame] | 69 | void OnPaint(const ui::PaintContext& context) override { |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 70 | ui::PaintRecorder recorder(context, window_bounds_.size()); |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 71 | recorder.canvas()->DrawColor(color_, SkXfermode::kSrc_Mode); |
danakj | c963112 | 2015-03-02 23:50:32 | [diff] [blame] | 72 | gfx::Rect r; |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 73 | recorder.canvas()->GetClipBounds(&r); |
danakj | c963112 | 2015-03-02 23:50:32 | [diff] [blame] | 74 | // Fill with a non-solid color so that the compositor will exercise its |
| 75 | // texture upload path. |
| 76 | while (!r.IsEmpty()) { |
| 77 | r.Inset(2, 2); |
danakj | 533d734 | 2015-04-07 22:32:29 | [diff] [blame] | 78 | recorder.canvas()->FillRect(r, color_, SkXfermode::kXor_Mode); |
danakj | c963112 | 2015-03-02 23:50:32 | [diff] [blame] | 79 | } |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 80 | } |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 81 | void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
| 82 | void OnWindowDestroying(aura::Window* window) override {} |
| 83 | void OnWindowDestroyed(aura::Window* window) override {} |
| 84 | void OnWindowTargetVisibilityChanged(bool visible) override {} |
| 85 | bool HasHitTestMask() const override { return false; } |
| 86 | void GetHitTestMask(gfx::Path* mask) const override {} |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 87 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 88 | private: |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 89 | SkColor color_; |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 90 | gfx::Rect window_bounds_; |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 91 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
| 93 | }; |
| 94 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 95 | class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 96 | public: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 97 | explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
| 98 | aura::client::SetWindowTreeClient(window_, this); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 99 | } |
| 100 | |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 101 | ~DemoWindowTreeClient() override { |
yukishiino | 907eabf | 2015-01-28 04:31:12 | [diff] [blame] | 102 | aura::client::SetWindowTreeClient(window_, nullptr); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 105 | // Overridden from aura::client::WindowTreeClient: |
dcheng | 5bdeb6b | 2014-10-27 20:58:05 | [diff] [blame] | 106 | aura::Window* GetDefaultParent(aura::Window* context, |
| 107 | aura::Window* window, |
| 108 | const gfx::Rect& bounds) override { |
[email protected] | 363e754 | 2013-04-23 22:33:14 | [diff] [blame] | 109 | if (!capture_client_) { |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 110 | capture_client_.reset( |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 111 | new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 112 | } |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 113 | return window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | private: |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 117 | aura::Window* window_; |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 118 | |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 119 | scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
[email protected] | be2a0ac | 2012-07-24 11:23:22 | [diff] [blame] | 120 | |
[email protected] | e3225e0 | 2013-10-23 20:44:37 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
[email protected] | b370f4f | 2012-03-12 20:16:23 | [diff] [blame] | 122 | }; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 123 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 124 | int DemoMain() { |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 125 | #if defined(USE_X11) |
| 126 | // This demo uses InProcessContextFactory which uses X on a separate Gpu |
| 127 | // thread. |
[email protected] | 82f884d6ffb | 2014-04-15 03:34:54 | [diff] [blame] | 128 | gfx::InitializeThreadedX11(); |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 129 | #endif |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 130 | |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 131 | gfx::GLSurface::InitializeOneOff(); |
| 132 | |
[email protected] | 804f479 | 2014-04-22 22:54:37 | [diff] [blame] | 133 | #if defined(OS_WIN) |
pkasting | 91475b0 | 2015-12-17 08:35:24 | [diff] [blame] | 134 | gfx::SetDefaultDeviceScaleFactor(1.0f); |
[email protected] | 804f479 | 2014-04-22 22:54:37 | [diff] [blame] | 135 | #endif |
| 136 | |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 137 | // The ContextFactory must exist before any Compositors are created. |
weiliangc | 5efa0a1 | 2015-01-29 19:56:46 | [diff] [blame] | 138 | bool context_factory_for_test = false; |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 139 | scoped_ptr<ui::InProcessContextFactory> context_factory( |
jbauman | f400ce53 | 2015-02-03 04:54:59 | [diff] [blame] | 140 | new ui::InProcessContextFactory(context_factory_for_test, nullptr)); |
sky | bd253e8 | 2014-11-11 01:49:07 | [diff] [blame] | 141 | context_factory->set_use_test_surface(false); |
[email protected] | 27a80e75 | 2014-03-13 20:36:41 | [diff] [blame] | 142 | |
| 143 | // Create the message-loop here before creating the root window. |
| 144 | base::MessageLoopForUI message_loop; |
[email protected] | f321f80b | 2013-09-11 22:59:14 | [diff] [blame] | 145 | |
ckocagil | 8a06497 | 2015-02-09 17:05:43 | [diff] [blame] | 146 | base::PowerMonitor power_monitor(make_scoped_ptr( |
| 147 | new base::PowerMonitorDeviceSource)); |
| 148 | |
fsamuel | 58ea5a7 | 2015-08-18 22:46:11 | [diff] [blame] | 149 | aura::Env::CreateInstance(true); |
| 150 | aura::Env::GetInstance()->set_context_factory(context_factory.get()); |
[email protected] | ad3a62c | 2014-06-20 13:18:34 | [diff] [blame] | 151 | scoped_ptr<aura::TestScreen> test_screen( |
| 152 | aura::TestScreen::Create(gfx::Size())); |
scottmg | fb33c34 | 2016-01-27 01:30:36 | [diff] [blame] | 153 | gfx::Screen::SetScreenInstance(test_screen.get()); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 154 | scoped_ptr<aura::WindowTreeHost> host( |
| 155 | test_screen->CreateHostForPrimaryDisplay()); |
| 156 | scoped_ptr<DemoWindowTreeClient> window_tree_client( |
| 157 | new DemoWindowTreeClient(host->window())); |
[email protected] | 98096954 | 2013-10-18 22:07:34 | [diff] [blame] | 158 | aura::test::TestFocusClient focus_client; |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 159 | aura::client::SetFocusClient(host->window(), &focus_client); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 160 | |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 161 | // Create a hierarchy of test windows. |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 162 | gfx::Rect window1_bounds(100, 100, 400, 400); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 163 | DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
| 164 | aura::Window window1(&window_delegate1); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 165 | window1.set_id(1); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 166 | window1.Init(ui::LAYER_TEXTURED); |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 167 | window1.SetBounds(window1_bounds); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 168 | window1.Show(); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 169 | aura::client::ParentWindowWithContext(&window1, host->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 170 | |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 171 | gfx::Rect window2_bounds(200, 200, 350, 350); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 172 | DemoWindowDelegate window_delegate2(SK_ColorRED); |
| 173 | aura::Window window2(&window_delegate2); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 174 | window2.set_id(2); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 175 | window2.Init(ui::LAYER_TEXTURED); |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 176 | window2.SetBounds(window2_bounds); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 177 | window2.Show(); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 178 | aura::client::ParentWindowWithContext(&window2, host->window(), gfx::Rect()); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 179 | |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 180 | gfx::Rect window3_bounds(10, 10, 50, 50); |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 181 | DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
| 182 | aura::Window window3(&window_delegate3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 183 | window3.set_id(3); |
danakj | b161836d | 2015-04-03 05:14:18 | [diff] [blame] | 184 | window3.Init(ui::LAYER_TEXTURED); |
weiliangc | a032f93b | 2015-07-13 22:39:47 | [diff] [blame] | 185 | window3.SetBounds(window3_bounds); |
[email protected] | a3929aba | 2011-09-30 18:30:17 | [diff] [blame] | 186 | window3.Show(); |
[email protected] | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 187 | window2.AddChild(&window3); |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 188 | |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 189 | host->Show(); |
[email protected] | 7060d659 | 2013-04-29 19:01:48 | [diff] [blame] | 190 | base::MessageLoopForUI::current()->Run(); |
[email protected] | 9783633c | 2011-10-27 15:41:52 | [diff] [blame] | 191 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 192 | return 0; |
| 193 | } |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 194 | |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 195 | } // namespace |
| 196 | |
| 197 | int main(int argc, char** argv) { |
avi | 6b10fd0 | 2014-12-23 05:51:23 | [diff] [blame] | 198 | base::CommandLine::Init(argc, argv); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 199 | |
| 200 | // The exit manager is in charge of calling the dtors of singleton objects. |
| 201 | base::AtExitManager exit_manager; |
| 202 | |
[email protected] | d7477f0 | 2013-08-23 00:39:09 | [diff] [blame] | 203 | base::i18n::InitializeICU(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 204 | |
[email protected] | 56deede | 2012-10-01 21:25:12 | [diff] [blame] | 205 | return DemoMain(); |
[email protected] | f7a0b4d2 | 2012-09-18 16:31:01 | [diff] [blame] | 206 | } |