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

Side by Side Diff: ui/compositor/test/test_compositor_host_ozone.cc

Issue 2737513003: Fix compositor_unittests with Ozone X11. (Closed)
Patch Set: Group. Created 3 years, 9 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
« no previous file with comments | « ui/compositor/test/DEPS ('k') | ui/compositor/test/test_suite.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/test/test_compositor_host.h" 5 #include "ui/compositor/test/test_compositor_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "ui/compositor/compositor.h" 15 #include "ui/compositor/compositor.h"
16 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/ozone/public/ozone_platform.h"
19 #include "ui/platform_window/platform_window.h"
20 #include "ui/platform_window/platform_window_delegate.h"
17 21
18 namespace ui { 22 namespace ui {
19 23
24 namespace {
25
26 // Stub implementation of PlatformWindowDelegate that stores the
27 // AcceleratedWidget.
28 class StubPlatformWindowDelegate : public PlatformWindowDelegate {
29 public:
30 StubPlatformWindowDelegate() {}
31 ~StubPlatformWindowDelegate() override {}
32
33 gfx::AcceleratedWidget widget() const { return widget_; }
34
35 // PlatformWindowDelegate:
36 void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
37 void OnDamageRect(const gfx::Rect& damaged_region) override {}
38 void DispatchEvent(Event* event) override {}
39 void OnCloseRequest() override {}
40 void OnClosed() override {}
41 void OnWindowStateChanged(PlatformWindowState new_state) override {}
42 void OnLostCapture() override {}
43 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
44 float device_pixel_ratio) override {
45 widget_ = widget;
46 }
47 void OnAcceleratedWidgetDestroyed() override {
48 widget_ = gfx::kNullAcceleratedWidget;
49 }
50 void OnActivationChanged(bool active) override {}
51
52 private:
53 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
54
55 DISALLOW_COPY_AND_ASSIGN(StubPlatformWindowDelegate);
56 };
57
20 class TestCompositorHostOzone : public TestCompositorHost { 58 class TestCompositorHostOzone : public TestCompositorHost {
21 public: 59 public:
22 TestCompositorHostOzone(const gfx::Rect& bounds, 60 TestCompositorHostOzone(const gfx::Rect& bounds,
23 ui::ContextFactory* context_factory, 61 ui::ContextFactory* context_factory,
24 ui::ContextFactoryPrivate* context_factory_private); 62 ui::ContextFactoryPrivate* context_factory_private);
25 ~TestCompositorHostOzone() override; 63 ~TestCompositorHostOzone() override;
26 64
27 private: 65 private:
28 // Overridden from TestCompositorHost: 66 // Overridden from TestCompositorHost:
29 void Show() override; 67 void Show() override;
30 ui::Compositor* GetCompositor() override; 68 ui::Compositor* GetCompositor() override;
31 69
32 gfx::Rect bounds_; 70 gfx::Rect bounds_;
33
34 ui::Compositor compositor_; 71 ui::Compositor compositor_;
72 std::unique_ptr<PlatformWindow> window_;
73 StubPlatformWindowDelegate window_delegate_;
35 74
36 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone); 75 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone);
37 }; 76 };
38 77
39 TestCompositorHostOzone::TestCompositorHostOzone( 78 TestCompositorHostOzone::TestCompositorHostOzone(
40 const gfx::Rect& bounds, 79 const gfx::Rect& bounds,
41 ui::ContextFactory* context_factory, 80 ui::ContextFactory* context_factory,
42 ui::ContextFactoryPrivate* context_factory_private) 81 ui::ContextFactoryPrivate* context_factory_private)
43 : bounds_(bounds), 82 : bounds_(bounds),
44 compositor_(context_factory_private->AllocateFrameSinkId(), 83 compositor_(context_factory_private->AllocateFrameSinkId(),
45 context_factory, 84 context_factory,
46 context_factory_private, 85 context_factory_private,
47 base::ThreadTaskRunnerHandle::Get()) {} 86 base::ThreadTaskRunnerHandle::Get()) {}
48 87
49 TestCompositorHostOzone::~TestCompositorHostOzone() {} 88 TestCompositorHostOzone::~TestCompositorHostOzone() {}
50 89
51 void TestCompositorHostOzone::Show() { 90 void TestCompositorHostOzone::Show() {
52 // Ozone should rightly have a backing native framebuffer 91 // Create a PlatformWindow to get the AcceleratedWidget backing it.
53 // An in-memory array draw into by OSMesa is a reasonble 92 window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
54 // fascimile of a dumb framebuffer at present. 93 &window_delegate_, bounds_);
55 // GLSurface will allocate the array so long as it is provided 94 window_->Show();
56 // with a non-0 widget. 95 DCHECK_NE(window_delegate_.widget(), gfx::kNullAcceleratedWidget);
57 // TODO(rjkroege): Use a "real" ozone widget when it is 96
58 // available: http://crbug.com/255128 97 compositor_.SetAcceleratedWidget(window_delegate_.widget());
59 compositor_.SetAcceleratedWidget(1);
60 compositor_.SetScaleAndSize(1.0f, bounds_.size()); 98 compositor_.SetScaleAndSize(1.0f, bounds_.size());
61 compositor_.SetVisible(true); 99 compositor_.SetVisible(true);
62 } 100 }
63 101
64 ui::Compositor* TestCompositorHostOzone::GetCompositor() { 102 ui::Compositor* TestCompositorHostOzone::GetCompositor() {
65 return &compositor_; 103 return &compositor_;
66 } 104 }
67 105
106 } // namespace
107
68 // static 108 // static
69 TestCompositorHost* TestCompositorHost::Create( 109 TestCompositorHost* TestCompositorHost::Create(
70 const gfx::Rect& bounds, 110 const gfx::Rect& bounds,
71 ui::ContextFactory* context_factory, 111 ui::ContextFactory* context_factory,
72 ui::ContextFactoryPrivate* context_factory_private) { 112 ui::ContextFactoryPrivate* context_factory_private) {
73 return new TestCompositorHostOzone(bounds, context_factory, 113 return new TestCompositorHostOzone(bounds, context_factory,
74 context_factory_private); 114 context_factory_private);
75 } 115 }
76 116
77 } // namespace ui 117 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/test/DEPS ('k') | ui/compositor/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698