OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/surface.h" | 5 #include "components/exo/surface.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
11 #include "cc/resources/single_release_callback.h" | 11 #include "cc/resources/single_release_callback.h" |
12 #include "components/exo/buffer.h" | 12 #include "components/exo/buffer.h" |
13 #include "components/exo/surface_delegate.h" | 13 #include "components/exo/surface_delegate.h" |
14 #include "components/exo/surface_observer.h" | 14 #include "components/exo/surface_observer.h" |
15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
16 #include "ui/aura/window_property.h" | 16 #include "ui/aura/window_property.h" |
17 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
18 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
19 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
20 #include "ui/gfx/buffer_format_util.h" | 20 #include "ui/gfx/buffer_format_util.h" |
21 #include "ui/gfx/gpu_memory_buffer.h" | 21 #include "ui/gfx/gpu_memory_buffer.h" |
22 #include "ui/gfx/transform_util.h" | |
22 | 23 |
23 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); | 24 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); |
24 | 25 |
25 namespace exo { | 26 namespace exo { |
26 namespace { | 27 namespace { |
27 | 28 |
28 // A property key containing the surface that is associated with | 29 // A property key containing the surface that is associated with |
29 // window. If unset, no surface is associated with window. | 30 // window. If unset, no surface is associated with window. |
30 DEFINE_WINDOW_PROPERTY_KEY(Surface*, kSurfaceKey, nullptr); | 31 DEFINE_WINDOW_PROPERTY_KEY(Surface*, kSurfaceKey, nullptr); |
31 | 32 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 }; | 84 }; |
84 | 85 |
85 } // namespace | 86 } // namespace |
86 | 87 |
87 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
88 // Surface, public: | 89 // Surface, public: |
89 | 90 |
90 Surface::Surface() | 91 Surface::Surface() |
91 : aura::Window(new EmptyWindowDelegate), | 92 : aura::Window(new EmptyWindowDelegate), |
92 has_pending_contents_(false), | 93 has_pending_contents_(false), |
94 pending_buffer_scale_(1.0f), | |
93 needs_commit_surface_hierarchy_(false), | 95 needs_commit_surface_hierarchy_(false), |
94 update_contents_after_successful_compositing_(false), | 96 update_contents_after_successful_compositing_(false), |
95 compositor_(nullptr), | 97 compositor_(nullptr), |
96 delegate_(nullptr) { | 98 delegate_(nullptr) { |
97 SetType(ui::wm::WINDOW_TYPE_CONTROL); | 99 SetType(ui::wm::WINDOW_TYPE_CONTROL); |
98 SetName("ExoSurface"); | 100 SetName("ExoSurface"); |
99 Init(ui::LAYER_SOLID_COLOR); | 101 Init(ui::LAYER_SOLID_COLOR); |
100 SetProperty(kSurfaceKey, this); | 102 SetProperty(kSurfaceKey, this); |
101 set_owned_by_parent(false); | 103 set_owned_by_parent(false); |
102 } | 104 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 pending_frame_callbacks_.push_back(callback); | 144 pending_frame_callbacks_.push_back(callback); |
143 } | 145 } |
144 | 146 |
145 void Surface::SetOpaqueRegion(const SkRegion& region) { | 147 void Surface::SetOpaqueRegion(const SkRegion& region) { |
146 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", | 148 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", |
147 gfx::SkIRectToRect(region.getBounds()).ToString()); | 149 gfx::SkIRectToRect(region.getBounds()).ToString()); |
148 | 150 |
149 pending_opaque_region_ = region; | 151 pending_opaque_region_ = region; |
150 } | 152 } |
151 | 153 |
154 void Surface::SetBufferScale(float scale) { | |
155 TRACE_EVENT1("exo", "Surface::SetBufferScale", "scale", scale); | |
156 | |
157 pending_buffer_scale_ = scale; | |
158 } | |
159 | |
152 void Surface::AddSubSurface(Surface* sub_surface) { | 160 void Surface::AddSubSurface(Surface* sub_surface) { |
153 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", | 161 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", |
154 sub_surface->AsTracedValue()); | 162 sub_surface->AsTracedValue()); |
155 | 163 |
156 DCHECK(!sub_surface->parent()); | 164 DCHECK(!sub_surface->parent()); |
157 DCHECK(!sub_surface->IsVisible()); | 165 DCHECK(!sub_surface->IsVisible()); |
158 DCHECK(sub_surface->bounds().origin() == gfx::Point()); | 166 DCHECK(sub_surface->bounds().origin() == gfx::Point()); |
159 AddChild(sub_surface); | 167 AddChild(sub_surface); |
160 | 168 |
161 DCHECK(!ListContainsEntry(pending_sub_surfaces_, sub_surface)); | 169 DCHECK(!ListContainsEntry(pending_sub_surfaces_, sub_surface)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 texture_mailbox_release_callback = | 272 texture_mailbox_release_callback = |
265 current_buffer_->ProduceTextureMailbox(&texture_mailbox); | 273 current_buffer_->ProduceTextureMailbox(&texture_mailbox); |
266 } | 274 } |
267 | 275 |
268 if (texture_mailbox_release_callback) { | 276 if (texture_mailbox_release_callback) { |
269 // Update layer with the new contents. | 277 // Update layer with the new contents. |
270 layer()->SetTextureMailbox(texture_mailbox, | 278 layer()->SetTextureMailbox(texture_mailbox, |
271 texture_mailbox_release_callback.Pass(), | 279 texture_mailbox_release_callback.Pass(), |
272 texture_mailbox.size_in_pixels()); | 280 texture_mailbox.size_in_pixels()); |
273 layer()->SetTextureFlipped(false); | 281 layer()->SetTextureFlipped(false); |
274 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), | 282 gfx::Size contents_size(gfx::ScaleToFlooredSize( |
275 texture_mailbox.size_in_pixels())); | 283 texture_mailbox.size_in_pixels(), 1.0f / pending_buffer_scale_)); |
284 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size)); | |
276 layer()->SetFillsBoundsOpaquely(pending_opaque_region_.contains( | 285 layer()->SetFillsBoundsOpaquely(pending_opaque_region_.contains( |
277 gfx::RectToSkIRect(gfx::Rect(texture_mailbox.size_in_pixels())))); | 286 gfx::RectToSkIRect(gfx::Rect(contents_size)))); |
287 layer()->SetTransform(gfx::GetScaleTransform( | |
288 gfx::Rect(texture_mailbox.size_in_pixels()).CenterPoint(), | |
289 1.0f / pending_buffer_scale_)); | |
lpique
2016/01/04 19:36:20
The call to ScaleToFlooredSize() includes (as the
reveman
2016/01/05 09:02:48
Good point. Done.
| |
278 } else { | 290 } else { |
279 // Show solid color content if no buffer is attached or we failed | 291 // Show solid color content if no buffer is attached or we failed |
280 // to produce a texture mailbox for the currently attached buffer. | 292 // to produce a texture mailbox for the currently attached buffer. |
281 layer()->SetShowSolidColorContent(); | 293 layer()->SetShowSolidColorContent(); |
282 layer()->SetColor(SK_ColorBLACK); | 294 layer()->SetColor(SK_ColorBLACK); |
283 } | 295 } |
284 | 296 |
285 // Schedule redraw of the damage region. | 297 // Schedule redraw of the damage region. |
286 layer()->SchedulePaint(pending_damage_); | 298 layer()->SchedulePaint(pending_damage_); |
287 pending_damage_ = gfx::Rect(); | 299 pending_damage_ = gfx::Rect(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // Stack next sub-surface above this sub-surface. | 336 // Stack next sub-surface above this sub-surface. |
325 stacking_target = sub_surface; | 337 stacking_target = sub_surface; |
326 | 338 |
327 // Update sub-surface position relative to surface origin. | 339 // Update sub-surface position relative to surface origin. |
328 sub_surface->SetBounds( | 340 sub_surface->SetBounds( |
329 gfx::Rect(sub_surface_entry.second, sub_surface->layer()->size())); | 341 gfx::Rect(sub_surface_entry.second, sub_surface->layer()->size())); |
330 } | 342 } |
331 } | 343 } |
332 | 344 |
333 gfx::Size Surface::GetPreferredSize() const { | 345 gfx::Size Surface::GetPreferredSize() const { |
334 return pending_buffer_ ? pending_buffer_->GetSize() : layer()->size(); | 346 return pending_buffer_ ? gfx::ScaleToFlooredSize(pending_buffer_->GetSize(), |
347 1.0f / pending_buffer_scale_) | |
348 : layer()->size(); | |
335 } | 349 } |
336 | 350 |
337 bool Surface::IsSynchronized() const { | 351 bool Surface::IsSynchronized() const { |
338 return delegate_ ? delegate_->IsSurfaceSynchronized() : false; | 352 return delegate_ ? delegate_->IsSurfaceSynchronized() : false; |
339 } | 353 } |
340 | 354 |
341 void Surface::SetSurfaceDelegate(SurfaceDelegate* delegate) { | 355 void Surface::SetSurfaceDelegate(SurfaceDelegate* delegate) { |
342 DCHECK(!delegate_ || !delegate); | 356 DCHECK(!delegate_ || !delegate); |
343 delegate_ = delegate; | 357 delegate_ = delegate; |
344 } | 358 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 // of the surface next time the compositor successfully ends compositing. | 428 // of the surface next time the compositor successfully ends compositing. |
415 update_contents_after_successful_compositing_ = true; | 429 update_contents_after_successful_compositing_ = true; |
416 } | 430 } |
417 | 431 |
418 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { | 432 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
419 compositor->RemoveObserver(this); | 433 compositor->RemoveObserver(this); |
420 compositor_ = nullptr; | 434 compositor_ = nullptr; |
421 } | 435 } |
422 | 436 |
423 } // namespace exo | 437 } // namespace exo |
OLD | NEW |