OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import <AppKit/NSApplication.h> | 7 #import <AppKit/NSApplication.h> |
8 #import <AppKit/NSOpenGL.h> | 8 #import <AppKit/NSOpenGL.h> |
9 #import <AppKit/NSView.h> | 9 #import <AppKit/NSView.h> |
10 #import <AppKit/NSWindow.h> | 10 #import <AppKit/NSWindow.h> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 private: | 75 private: |
76 DISALLOW_COPY_AND_ASSIGN(AppKitHost); | 76 DISALLOW_COPY_AND_ASSIGN(AppKitHost); |
77 }; | 77 }; |
78 | 78 |
79 // TestCompositorHostMac provides a window surface and a coordinated compositor | 79 // TestCompositorHostMac provides a window surface and a coordinated compositor |
80 // for use in the compositor unit tests. | 80 // for use in the compositor unit tests. |
81 class TestCompositorHostMac : public TestCompositorHost, | 81 class TestCompositorHostMac : public TestCompositorHost, |
82 public AppKitHost { | 82 public AppKitHost { |
83 public: | 83 public: |
84 TestCompositorHostMac(const gfx::Rect& bounds); | 84 TestCompositorHostMac(const gfx::Rect& bounds, |
| 85 ui::ContextFactory* context_factory); |
85 virtual ~TestCompositorHostMac(); | 86 virtual ~TestCompositorHostMac(); |
86 | 87 |
87 private: | 88 private: |
88 // TestCompositorHost: | 89 // TestCompositorHost: |
89 virtual void Show() OVERRIDE; | 90 virtual void Show() OVERRIDE; |
90 virtual ui::Compositor* GetCompositor() OVERRIDE; | 91 virtual ui::Compositor* GetCompositor() OVERRIDE; |
91 | 92 |
92 gfx::Rect bounds_; | 93 gfx::Rect bounds_; |
| 94 |
| 95 ui::ContextFactory* context_factory_; |
| 96 |
93 scoped_ptr<ui::Compositor> compositor_; | 97 scoped_ptr<ui::Compositor> compositor_; |
94 | 98 |
95 // Owned. Released when window is closed. | 99 // Owned. Released when window is closed. |
96 NSWindow* window_; | 100 NSWindow* window_; |
97 | 101 |
98 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac); | 102 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac); |
99 }; | 103 }; |
100 | 104 |
101 TestCompositorHostMac::TestCompositorHostMac(const gfx::Rect& bounds) | 105 TestCompositorHostMac::TestCompositorHostMac( |
102 : bounds_(bounds), window_(nil) { | 106 const gfx::Rect& bounds, |
| 107 ui::ContextFactory* context_factory) |
| 108 : bounds_(bounds), context_factory_(context_factory), window_(nil) { |
103 } | 109 } |
104 | 110 |
105 TestCompositorHostMac::~TestCompositorHostMac() { | 111 TestCompositorHostMac::~TestCompositorHostMac() { |
106 // Release reference to |compositor_|. Important because the |compositor_| | 112 // Release reference to |compositor_|. Important because the |compositor_| |
107 // holds |this| as its delegate, so that reference must be removed here. | 113 // holds |this| as its delegate, so that reference must be removed here. |
108 [[window_ contentView] setCompositor:NULL]; | 114 [[window_ contentView] setCompositor:NULL]; |
109 [window_ setContentView:nil]; | 115 [window_ setContentView:nil]; |
110 | 116 |
111 [window_ orderOut:nil]; | 117 [window_ orderOut:nil]; |
112 [window_ close]; | 118 [window_ close]; |
113 } | 119 } |
114 | 120 |
115 void TestCompositorHostMac::Show() { | 121 void TestCompositorHostMac::Show() { |
116 DCHECK(!window_); | 122 DCHECK(!window_); |
117 window_ = [[NSWindow alloc] | 123 window_ = [[NSWindow alloc] |
118 initWithContentRect:NSMakeRect(bounds_.x(), | 124 initWithContentRect:NSMakeRect(bounds_.x(), |
119 bounds_.y(), | 125 bounds_.y(), |
120 bounds_.width(), | 126 bounds_.width(), |
121 bounds_.height()) | 127 bounds_.height()) |
122 styleMask:NSBorderlessWindowMask | 128 styleMask:NSBorderlessWindowMask |
123 backing:NSBackingStoreBuffered | 129 backing:NSBackingStoreBuffered |
124 defer:NO]; | 130 defer:NO]; |
125 base::scoped_nsobject<AcceleratedTestView> view( | 131 base::scoped_nsobject<AcceleratedTestView> view( |
126 [[AcceleratedTestView alloc] init]); | 132 [[AcceleratedTestView alloc] init]); |
127 compositor_.reset(new ui::Compositor(view)); | 133 compositor_.reset(new ui::Compositor(view, context_factory_)); |
128 compositor_->SetScaleAndSize(1.0f, bounds_.size()); | 134 compositor_->SetScaleAndSize(1.0f, bounds_.size()); |
129 [view setCompositor:compositor_.get()]; | 135 [view setCompositor:compositor_.get()]; |
130 [window_ setContentView:view]; | 136 [window_ setContentView:view]; |
131 [window_ orderFront:nil]; | 137 [window_ orderFront:nil]; |
132 } | 138 } |
133 | 139 |
134 ui::Compositor* TestCompositorHostMac::GetCompositor() { | 140 ui::Compositor* TestCompositorHostMac::GetCompositor() { |
135 return compositor_.get(); | 141 return compositor_.get(); |
136 } | 142 } |
137 | 143 |
138 // static | 144 // static |
139 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { | 145 TestCompositorHost* TestCompositorHost::Create( |
140 return new TestCompositorHostMac(bounds); | 146 const gfx::Rect& bounds, |
| 147 ui::ContextFactory* context_factory) { |
| 148 return new TestCompositorHostMac(bounds, context_factory); |
141 } | 149 } |
142 | 150 |
143 } // namespace ui | 151 } // namespace ui |
OLD | NEW |