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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
15 #include "cc/quads/render_pass.h" | 15 #include "cc/quads/render_pass.h" |
16 #include "cc/quads/shared_quad_state.h" | 16 #include "cc/quads/shared_quad_state.h" |
17 #include "cc/quads/solid_color_draw_quad.h" | 17 #include "cc/quads/solid_color_draw_quad.h" |
18 #include "cc/quads/texture_draw_quad.h" | 18 #include "cc/quads/texture_draw_quad.h" |
19 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
| 20 #include "cc/surfaces/sequence_surface_reference_factory.h" |
20 #include "cc/surfaces/surface.h" | 21 #include "cc/surfaces/surface.h" |
21 #include "cc/surfaces/surface_id_allocator.h" | 22 #include "cc/surfaces/surface_id_allocator.h" |
22 #include "components/exo/buffer.h" | 23 #include "components/exo/buffer.h" |
23 #include "components/exo/surface_delegate.h" | 24 #include "components/exo/surface_delegate.h" |
24 #include "components/exo/surface_observer.h" | 25 #include "components/exo/surface_observer.h" |
25 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
26 #include "ui/aura/env.h" | 27 #include "ui/aura/env.h" |
27 #include "ui/aura/window_delegate.h" | 28 #include "ui/aura/window_delegate.h" |
28 #include "ui/aura/window_property.h" | 29 #include "ui/aura/window_property.h" |
29 #include "ui/aura/window_targeter.h" | 30 #include "ui/aura/window_targeter.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (window->parent()) | 133 if (window->parent()) |
133 aura::Window::ConvertPointToTarget(window->parent(), window, | 134 aura::Window::ConvertPointToTarget(window->parent(), window, |
134 &local_point); | 135 &local_point); |
135 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); | 136 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); |
136 } | 137 } |
137 | 138 |
138 private: | 139 private: |
139 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); | 140 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); |
140 }; | 141 }; |
141 | 142 |
| 143 class CustomSurfaceReferenceFactory |
| 144 : public cc::SequenceSurfaceReferenceFactory { |
| 145 public: |
| 146 explicit CustomSurfaceReferenceFactory(CompositorFrameSinkHolder* sink_holder) |
| 147 : sink_holder_(sink_holder) {} |
| 148 |
| 149 private: |
| 150 ~CustomSurfaceReferenceFactory() override = default; |
| 151 |
| 152 // Overridden from cc::SequenceSurfaceReferenceFactory: |
| 153 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { |
| 154 sink_holder_->Satisfy(sequence); |
| 155 } |
| 156 |
| 157 void RequireSequence(const cc::SurfaceId& surface_id, |
| 158 const cc::SurfaceSequence& sequence) const override { |
| 159 sink_holder_->Require(surface_id, sequence); |
| 160 } |
| 161 |
| 162 scoped_refptr<CompositorFrameSinkHolder> sink_holder_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(CustomSurfaceReferenceFactory); |
| 165 }; |
| 166 |
142 } // namespace | 167 } // namespace |
143 | 168 |
144 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
145 // Surface, public: | 170 // Surface, public: |
146 | 171 |
147 // TODO(fsamuel): exo should not use context_factory_private. Instead, we should | 172 // TODO(fsamuel): exo should not use context_factory_private. Instead, we should |
148 // request a CompositorFrameSink from the aura::Window. Setting up the | 173 // request a CompositorFrameSink from the aura::Window. Setting up the |
149 // BeginFrame hierarchy should be an internal implementation detail of aura or | 174 // BeginFrame hierarchy should be an internal implementation detail of aura or |
150 // mus in aura-mus. | 175 // mus in aura-mus. |
151 Surface::Surface() | 176 Surface::Surface() |
152 : window_(new aura::Window(new CustomWindowDelegate(this))), | 177 : window_(new aura::Window(new CustomWindowDelegate(this))), |
153 frame_sink_id_(aura::Env::GetInstance() | 178 frame_sink_id_(aura::Env::GetInstance() |
154 ->context_factory_private() | 179 ->context_factory_private() |
155 ->AllocateFrameSinkId()) { | 180 ->AllocateFrameSinkId()) { |
156 cc::mojom::MojoCompositorFrameSinkClientPtr frame_sink_holder_ptr; | 181 cc::mojom::MojoCompositorFrameSinkClientPtr frame_sink_holder_ptr; |
157 cc::mojom::MojoCompositorFrameSinkClientRequest frame_sink_client_request = | 182 cc::mojom::MojoCompositorFrameSinkClientRequest frame_sink_client_request = |
158 mojo::GetProxy(&frame_sink_holder_ptr); | 183 mojo::GetProxy(&frame_sink_holder_ptr); |
159 std::unique_ptr<CompositorFrameSink> frame_sink(new CompositorFrameSink( | 184 std::unique_ptr<CompositorFrameSink> frame_sink(new CompositorFrameSink( |
160 frame_sink_id_, | 185 frame_sink_id_, |
161 aura::Env::GetInstance()->context_factory_private()->GetSurfaceManager(), | 186 aura::Env::GetInstance()->context_factory_private()->GetSurfaceManager(), |
162 std::move(frame_sink_holder_ptr))); | 187 std::move(frame_sink_holder_ptr))); |
163 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder( | 188 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder( |
164 this, std::move(frame_sink), std::move(frame_sink_client_request)); | 189 this, std::move(frame_sink), std::move(frame_sink_client_request)); |
| 190 surface_reference_factory_ = |
| 191 new CustomSurfaceReferenceFactory(compositor_frame_sink_holder_.get()); |
165 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 192 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
166 window_->SetName("ExoSurface"); | 193 window_->SetName("ExoSurface"); |
167 window_->SetProperty(kSurfaceKey, this); | 194 window_->SetProperty(kSurfaceKey, this); |
168 window_->Init(ui::LAYER_SOLID_COLOR); | 195 window_->Init(ui::LAYER_SOLID_COLOR); |
169 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 196 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
170 window_->set_owned_by_parent(false); | 197 window_->set_owned_by_parent(false); |
171 window_->AddObserver(this); | 198 window_->AddObserver(this); |
172 aura::Env::GetInstance()->context_factory()->AddObserver(this); | 199 aura::Env::GetInstance()->context_factory()->AddObserver(this); |
173 } | 200 } |
174 | 201 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 442 |
416 UpdateSurface(false); | 443 UpdateSurface(false); |
417 | 444 |
418 if (old_local_frame_id != local_frame_id_) { | 445 if (old_local_frame_id != local_frame_id_) { |
419 float contents_surface_to_layer_scale = 1.0; | 446 float contents_surface_to_layer_scale = 1.0; |
420 // The bounds must be updated before switching to the new surface, because | 447 // The bounds must be updated before switching to the new surface, because |
421 // the layer may be mirrored, in which case a surface change causes the | 448 // the layer may be mirrored, in which case a surface change causes the |
422 // mirror layer to update its surface using the latest bounds. | 449 // mirror layer to update its surface using the latest bounds. |
423 window_->layer()->SetBounds( | 450 window_->layer()->SetBounds( |
424 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | 451 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
| 452 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); |
425 window_->layer()->SetShowSurface( | 453 window_->layer()->SetShowSurface( |
426 cc::SurfaceId(frame_sink_id_, local_frame_id_), | 454 cc::SurfaceInfo(surface_id, contents_surface_to_layer_scale, |
427 base::Bind(&CompositorFrameSinkHolder::Satisfy, | 455 content_size_), |
428 compositor_frame_sink_holder_), | 456 surface_reference_factory_); |
429 base::Bind(&CompositorFrameSinkHolder::Require, | |
430 compositor_frame_sink_holder_), | |
431 content_size_, contents_surface_to_layer_scale); | |
432 window_->layer()->SetFillsBoundsOpaquely( | 457 window_->layer()->SetFillsBoundsOpaquely( |
433 state_.blend_mode == SkBlendMode::kSrc || | 458 state_.blend_mode == SkBlendMode::kSrc || |
434 state_.opaque_region.contains( | 459 state_.opaque_region.contains( |
435 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 460 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
436 } | 461 } |
437 | 462 |
438 // Reset damage. | 463 // Reset damage. |
439 pending_damage_.setEmpty(); | 464 pending_damage_.setEmpty(); |
440 | 465 |
441 DCHECK(!current_resource_.id || | 466 DCHECK(!current_resource_.id || |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 795 |
771 int64_t Surface::GetPropertyInternal(const void* key, | 796 int64_t Surface::GetPropertyInternal(const void* key, |
772 int64_t default_value) const { | 797 int64_t default_value) const { |
773 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 798 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
774 if (iter == prop_map_.end()) | 799 if (iter == prop_map_.end()) |
775 return default_value; | 800 return default_value; |
776 return iter->second.value; | 801 return iter->second.value; |
777 } | 802 } |
778 | 803 |
779 } // namespace exo | 804 } // namespace exo |
OLD | NEW |