Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / compositor / test / test_compositor_host_x11.cc
blob12184aa4ef536f6587b5baa8694dc006a0e2f326
1 // Copyright 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.
5 #include "ui/compositor/test/test_compositor_host.h"
7 #include <X11/Xlib.h>
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/thread_task_runner_handle.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/x/x11_types.h"
20 namespace ui {
22 class TestCompositorHostX11 : public TestCompositorHost {
23 public:
24 TestCompositorHostX11(const gfx::Rect& bounds,
25 ui::ContextFactory* context_factory);
26 ~TestCompositorHostX11() override;
28 private:
29 // Overridden from TestCompositorHost:
30 void Show() override;
31 ui::Compositor* GetCompositor() override;
33 gfx::Rect bounds_;
35 ui::ContextFactory* context_factory_;
37 scoped_ptr<ui::Compositor> compositor_;
39 XID window_;
41 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11);
44 TestCompositorHostX11::TestCompositorHostX11(
45 const gfx::Rect& bounds,
46 ui::ContextFactory* context_factory)
47 : bounds_(bounds),
48 context_factory_(context_factory) {
51 TestCompositorHostX11::~TestCompositorHostX11() {
54 void TestCompositorHostX11::Show() {
55 XDisplay* display = gfx::GetXDisplay();
56 XSetWindowAttributes swa;
57 swa.event_mask = StructureNotifyMask | ExposureMask;
58 swa.override_redirect = True;
59 window_ = XCreateWindow(
60 display,
61 RootWindow(display, DefaultScreen(display)), // parent
62 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
63 0, // border width
64 CopyFromParent, // depth
65 InputOutput,
66 CopyFromParent, // visual
67 CWEventMask | CWOverrideRedirect, &swa);
68 XMapWindow(display, window_);
70 while (1) {
71 XEvent event;
72 XNextEvent(display, &event);
73 if (event.type == MapNotify && event.xmap.window == window_)
74 break;
76 compositor_.reset(new ui::Compositor(window_,
77 context_factory_,
78 base::ThreadTaskRunnerHandle::Get()));
79 compositor_->SetScaleAndSize(1.0f, bounds_.size());
82 ui::Compositor* TestCompositorHostX11::GetCompositor() {
83 return compositor_.get();
86 // static
87 TestCompositorHost* TestCompositorHost::Create(
88 const gfx::Rect& bounds,
89 ui::ContextFactory* context_factory) {
90 return new TestCompositorHostX11(bounds, context_factory);
93 } // namespace ui