1 // Copyright (c) 2012 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.h"
16 #include "ui/base/x/x11_util.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/gfx/rect.h"
22 class TestCompositorHostLinux
: public TestCompositorHost
,
23 public CompositorDelegate
{
25 TestCompositorHostLinux(const gfx::Rect
& bounds
);
26 virtual ~TestCompositorHostLinux();
29 // Overridden from TestCompositorHost:
30 virtual void Show() OVERRIDE
;
31 virtual ui::Compositor
* GetCompositor() OVERRIDE
;
33 // Overridden from CompositorDelegate:
34 virtual void ScheduleDraw() OVERRIDE
;
40 scoped_ptr
<ui::Compositor
> compositor_
;
44 base::WeakPtrFactory
<TestCompositorHostLinux
> method_factory_
;
46 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux
);
49 TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect
& bounds
)
51 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
54 TestCompositorHostLinux::~TestCompositorHostLinux() {
57 void TestCompositorHostLinux::Show() {
58 Display
* display
= GetXDisplay();
59 XSetWindowAttributes swa
;
60 swa
.event_mask
= StructureNotifyMask
| ExposureMask
;
61 swa
.override_redirect
= True
;
62 window_
= XCreateWindow(
64 RootWindow(display
, DefaultScreen(display
)), // parent
65 bounds_
.x(), bounds_
.y(), bounds_
.width(), bounds_
.height(),
67 CopyFromParent
, // depth
69 CopyFromParent
, // visual
70 CWEventMask
| CWOverrideRedirect
, &swa
);
71 XMapWindow(display
, window_
);
75 XNextEvent(display
, &event
);
76 if (event
.type
== MapNotify
&& event
.xmap
.window
== window_
)
79 compositor_
.reset(new ui::Compositor(this, window_
));
80 compositor_
->SetScaleAndSize(1.0f
, bounds_
.size());
83 ui::Compositor
* TestCompositorHostLinux::GetCompositor() {
84 return compositor_
.get();
87 void TestCompositorHostLinux::ScheduleDraw() {
88 DCHECK(!ui::Compositor::WasInitializedWithThread());
89 if (!method_factory_
.HasWeakPtrs()) {
90 MessageLoopForUI::current()->PostTask(
92 base::Bind(&TestCompositorHostLinux::Draw
,
93 method_factory_
.GetWeakPtr()));
97 void TestCompositorHostLinux::Draw() {
98 if (compositor_
.get())
103 TestCompositorHost
* TestCompositorHost::Create(const gfx::Rect
& bounds
) {
104 return new TestCompositorHostLinux(bounds
);