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

Side by Side Diff: wm/foreign_window_client_view.cc

Issue 11485006: Add window manager component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Push gfx::AcceleratedWidget usage into platform specific code. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « wm/foreign_window_client_view.h ('k') | wm/foreign_window_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "wm/foreign_window_client_view.h"
6
7 #include "base/bind.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_delegate.h"
10 #include "ui/base/hit_test.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/widget/widget.h"
13 #include "wm/gpu/foreign_window_texture_factory.h"
14
15 namespace {
16
17 class ContentsViewImpl : public views::View {
18 public:
19 ContentsViewImpl() {}
20 virtual ~ContentsViewImpl() {}
21
22 // Overridden from views::View:
23 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
24 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY);
25 }
26
27 private:
28 DISALLOW_COPY_AND_ASSIGN(ContentsViewImpl);
29 };
30
31 class WindowDelegateImpl : public aura::WindowDelegate {
32 public:
33 WindowDelegateImpl() {}
34 virtual ~WindowDelegateImpl() {}
35
36 // Overridden from aura::WindowDelegate:
37 virtual gfx::Size GetMinimumSize() const OVERRIDE {
38 return gfx::Size();
39 }
40 virtual gfx::Size GetMaximumSize() const OVERRIDE {
41 return gfx::Size();
42 }
43 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
44 const gfx::Rect& new_bounds) OVERRIDE {}
45 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
46 return gfx::kNullCursor;
47 }
48 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
49 return HTCLIENT;
50 }
51 virtual bool ShouldDescendIntoChildForEventHandling(
52 aura::Window* child,
53 const gfx::Point& location) OVERRIDE {
54 return false;
55 }
56 virtual bool CanFocus() OVERRIDE {
57 return true;
58 }
59 virtual void OnCaptureLost() OVERRIDE {}
60 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {}
61 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
62 }
63 virtual void OnWindowDestroying() OVERRIDE {}
64 virtual void OnWindowDestroyed() OVERRIDE {
65 delete this;
66 }
67 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
68 virtual bool HasHitTestMask() const OVERRIDE {
69 return false;
70 }
71 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
72 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE {
73 NOTIMPLEMENTED();
74 return scoped_refptr<ui::Texture>();
75 }
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl);
79 };
80
81 } // namespace
82
83 namespace wm {
84
85 ForeignWindowClientView::ForeignWindowClientView(
86 gfx::PluginWindowHandle window_handle,
87 gfx::Size preferred_size)
88 : views::ClientView(NULL, NULL),
89 window_handle_(window_handle),
90 preferred_size_(preferred_size),
91 window_visible_(false),
92 window_destroyed_(false),
93 pending_texture_created_count_(0) {
94 ForeignWindowTextureFactory::GetInstance()->AddObserver(this);
95 contents_view_.reset(new ContentsViewImpl);
96 set_contents_view(contents_view_.get());
97 window_.reset(new aura::Window(new WindowDelegateImpl));
98 window_->set_owned_by_parent(false);
99 window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
100 window_->SetTransparent(false);
101 window_->Init(ui::LAYER_TEXTURED);
102 window_->layer()->SetMasksToBounds(true);
103 window_->SetName("ForeignWindowClientView");
104 }
105
106 ForeignWindowClientView::~ForeignWindowClientView() {
107 ForeignWindowTextureFactory::GetInstance()->RemoveObserver(this);
108 }
109
110 gfx::Size ForeignWindowClientView::GetPreferredSize() {
111 return preferred_size_;
112 }
113
114 gfx::Size ForeignWindowClientView::GetMinimumSize() {
115 return gfx::Size(1, 1);
116 }
117
118 void ForeignWindowClientView::OnBoundsChanged(
119 const gfx::Rect& previous_bounds) {
120 window_->SetBounds(bounds());
121 }
122
123 void ForeignWindowClientView::OnLostResources() {
124 // ForeignWindowTextureFactory guarantees that it's safe to keep the
125 // existing |texture_| reference around until we have a new texture. By
126 // not resetting |texture_| here we verify this behavior. The compositor
127 // however doesn't like using this texture so we reset the external
128 // texture here to make sure that doesn't happen.
129 window_->SetExternalTexture(NULL);
130
131 if (window_visible_)
132 CreateTexture();
133 }
134
135 gfx::NativeView ForeignWindowClientView::GetNativeView() const {
136 return window_.get();
137 }
138
139 void ForeignWindowClientView::OnWindowContentsChanged() {
140 if (pending_texture_created_count_)
141 return;
142
143 if (texture_) {
144 texture_->OnContentsChanged();
145
146 GetNativeView()->SchedulePaintInRect(
147 gfx::Rect(GetNativeView()->bounds().size()));
148 } else {
149 CreateTexture();
150 }
151 }
152
153 void ForeignWindowClientView::OnWindowSizeChanged(const gfx::Size& size) {
154 if (window_size_ == size)
155 return;
156
157 window_size_ = size;
158
159 if (window_visible_)
160 CreateTexture();
161 }
162
163 void ForeignWindowClientView::OnWindowVisibilityChanged(bool visible) {
164 window_visible_ = visible;
165
166 // Drop |texture_| reference when invisible to make sure texture is
167 // destroyed when no longer used by the compositor. Don't reset external
168 // texture for |window_| as that would prevent the compositor from
169 // drawing using this texture.
170 if (!visible)
171 texture_ = NULL;
172 }
173
174 void ForeignWindowClientView::OnWindowDestroyed() {
175 window_destroyed_ = true;
176 }
177
178 void ForeignWindowClientView::CreateTexture() {
179 ++pending_texture_created_count_;
180
181 DCHECK(!window_destroyed_);
182 ForeignWindowTextureFactory* factory =
183 ForeignWindowTextureFactory::GetInstance();
184 factory->CreateTextureForForeignWindow(
185 window_handle_,
186 false,
187 1.0,
188 base::Bind(&ForeignWindowClientView::OnTextureCreated, AsWeakPtr()));
189 }
190
191 void ForeignWindowClientView::OnTextureCreated(
192 scoped_refptr<ForeignWindowTexture> texture) {
193 --pending_texture_created_count_;
194
195 if (!texture)
196 return;
197
198 texture_ = texture;
199 window_->SetExternalTexture(texture);
200 }
201
202 } // namespace wm
OLDNEW
« no previous file with comments | « wm/foreign_window_client_view.h ('k') | wm/foreign_window_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698