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"
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/message_loop/message_loop.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/x/x11_types.h"
22 class TestCompositorHostX11
: public TestCompositorHost
{
24 TestCompositorHostX11(const gfx::Rect
& bounds
);
25 virtual ~TestCompositorHostX11();
28 // Overridden from TestCompositorHost:
29 virtual void Show() OVERRIDE
;
30 virtual ui::Compositor
* GetCompositor() OVERRIDE
;
36 scoped_ptr
<ui::Compositor
> compositor_
;
40 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11
);
43 TestCompositorHostX11::TestCompositorHostX11(const gfx::Rect
& bounds
)
47 TestCompositorHostX11::~TestCompositorHostX11() {
50 void TestCompositorHostX11::Show() {
51 XDisplay
* display
= gfx::GetXDisplay();
52 XSetWindowAttributes swa
;
53 swa
.event_mask
= StructureNotifyMask
| ExposureMask
;
54 swa
.override_redirect
= True
;
55 window_
= XCreateWindow(
57 RootWindow(display
, DefaultScreen(display
)), // parent
58 bounds_
.x(), bounds_
.y(), bounds_
.width(), bounds_
.height(),
60 CopyFromParent
, // depth
62 CopyFromParent
, // visual
63 CWEventMask
| CWOverrideRedirect
, &swa
);
64 XMapWindow(display
, window_
);
68 XNextEvent(display
, &event
);
69 if (event
.type
== MapNotify
&& event
.xmap
.window
== window_
)
72 compositor_
.reset(new ui::Compositor(window_
));
73 compositor_
->SetScaleAndSize(1.0f
, bounds_
.size());
76 ui::Compositor
* TestCompositorHostX11::GetCompositor() {
77 return compositor_
.get();
80 void TestCompositorHostX11::Draw() {
81 if (compositor_
.get())
86 TestCompositorHost
* TestCompositorHost::Create(const gfx::Rect
& bounds
) {
87 return new TestCompositorHostX11(bounds
);