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" |
30 #include "ui/base/cursor/cursor.h" | 31 #include "ui/base/cursor/cursor.h" |
31 #include "ui/base/hit_test.h" | 32 #include "ui/base/hit_test.h" |
32 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
33 #include "ui/events/event.h" | 34 #include "ui/events/event.h" |
34 #include "ui/gfx/buffer_format_util.h" | 35 #include "ui/gfx/buffer_format_util.h" |
35 #include "ui/gfx/geometry/safe_integer_conversions.h" | 36 #include "ui/gfx/geometry/safe_integer_conversions.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/gfx/gpu_memory_buffer.h" | 38 #include "ui/gfx/gpu_memory_buffer.h" |
38 #include "ui/gfx/path.h" | 39 #include "ui/gfx/path.h" |
39 #include "ui/gfx/skia_util.h" | 40 #include "ui/gfx/skia_util.h" |
40 #include "ui/gfx/transform_util.h" | 41 #include "ui/gfx/transform_util.h" |
41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
42 | 43 |
43 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); | 44 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); |
44 | 45 |
45 namespace exo { | 46 namespace exo { |
46 namespace { | 47 namespace { |
47 | 48 |
| 49 class SurfaceReferenceFactory : public cc::SequenceSurfaceReferenceFactory { |
| 50 public: |
| 51 explicit SurfaceReferenceFactory( |
| 52 scoped_refptr<CompositorFrameSinkHolder> sink_holder) |
| 53 : sink_holder_(std::move(sink_holder)) {} |
| 54 |
| 55 private: |
| 56 ~SurfaceReferenceFactory() override = default; |
| 57 |
| 58 // cc::SequenceSurfaceReferenceFactory implementation: |
| 59 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { |
| 60 sink_holder_->Satisfy(sequence); |
| 61 } |
| 62 |
| 63 void RequireSequence(const cc::SurfaceId& surface_id, |
| 64 const cc::SurfaceSequence& sequence) const override { |
| 65 sink_holder_->Require(surface_id, sequence); |
| 66 } |
| 67 |
| 68 scoped_refptr<CompositorFrameSinkHolder> sink_holder_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(SurfaceReferenceFactory); |
| 71 }; |
| 72 |
48 // A property key containing the surface that is associated with | 73 // A property key containing the surface that is associated with |
49 // window. If unset, no surface is associated with window. | 74 // window. If unset, no surface is associated with window. |
50 DEFINE_WINDOW_PROPERTY_KEY(Surface*, kSurfaceKey, nullptr); | 75 DEFINE_WINDOW_PROPERTY_KEY(Surface*, kSurfaceKey, nullptr); |
51 | 76 |
52 // Helper function that returns an iterator to the first entry in |list| | 77 // Helper function that returns an iterator to the first entry in |list| |
53 // with |key|. | 78 // with |key|. |
54 template <typename T, typename U> | 79 template <typename T, typename U> |
55 typename T::iterator FindListEntry(T& list, U key) { | 80 typename T::iterator FindListEntry(T& list, U key) { |
56 return std::find_if(list.begin(), list.end(), | 81 return std::find_if(list.begin(), list.end(), |
57 [key](const typename T::value_type& entry) { | 82 [key](const typename T::value_type& entry) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()) { | 175 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()) { |
151 cc::mojom::MojoCompositorFrameSinkClientPtr frame_sink_holder_ptr; | 176 cc::mojom::MojoCompositorFrameSinkClientPtr frame_sink_holder_ptr; |
152 cc::mojom::MojoCompositorFrameSinkClientRequest frame_sink_client_request = | 177 cc::mojom::MojoCompositorFrameSinkClientRequest frame_sink_client_request = |
153 mojo::GetProxy(&frame_sink_holder_ptr); | 178 mojo::GetProxy(&frame_sink_holder_ptr); |
154 std::unique_ptr<CompositorFrameSink> frame_sink(new CompositorFrameSink( | 179 std::unique_ptr<CompositorFrameSink> frame_sink(new CompositorFrameSink( |
155 frame_sink_id_, | 180 frame_sink_id_, |
156 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(), | 181 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(), |
157 std::move(frame_sink_holder_ptr))); | 182 std::move(frame_sink_holder_ptr))); |
158 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder( | 183 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder( |
159 this, std::move(frame_sink), std::move(frame_sink_client_request)); | 184 this, std::move(frame_sink), std::move(frame_sink_client_request)); |
| 185 ref_factory_ = new SurfaceReferenceFactory(compositor_frame_sink_holder_); |
160 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 186 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
161 window_->SetName("ExoSurface"); | 187 window_->SetName("ExoSurface"); |
162 window_->SetProperty(kSurfaceKey, this); | 188 window_->SetProperty(kSurfaceKey, this); |
163 window_->Init(ui::LAYER_SOLID_COLOR); | 189 window_->Init(ui::LAYER_SOLID_COLOR); |
164 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 190 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
165 window_->set_owned_by_parent(false); | 191 window_->set_owned_by_parent(false); |
166 window_->AddObserver(this); | 192 window_->AddObserver(this); |
167 aura::Env::GetInstance()->context_factory()->AddObserver(this); | 193 aura::Env::GetInstance()->context_factory()->AddObserver(this); |
168 } | 194 } |
169 | 195 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 436 |
411 UpdateSurface(false); | 437 UpdateSurface(false); |
412 | 438 |
413 if (old_local_frame_id != local_frame_id_) { | 439 if (old_local_frame_id != local_frame_id_) { |
414 float contents_surface_to_layer_scale = 1.0; | 440 float contents_surface_to_layer_scale = 1.0; |
415 // The bounds must be updated before switching to the new surface, because | 441 // The bounds must be updated before switching to the new surface, because |
416 // the layer may be mirrored, in which case a surface change causes the | 442 // the layer may be mirrored, in which case a surface change causes the |
417 // mirror layer to update its surface using the latest bounds. | 443 // mirror layer to update its surface using the latest bounds. |
418 window_->layer()->SetBounds( | 444 window_->layer()->SetBounds( |
419 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | 445 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
| 446 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); |
420 window_->layer()->SetShowSurface( | 447 window_->layer()->SetShowSurface( |
421 cc::SurfaceId(frame_sink_id_, local_frame_id_), | 448 cc::SurfaceInfo(surface_id, contents_surface_to_layer_scale, |
422 base::Bind(&CompositorFrameSinkHolder::Satisfy, | 449 content_size_), |
423 compositor_frame_sink_holder_), | 450 ref_factory_, content_size_); |
424 base::Bind(&CompositorFrameSinkHolder::Require, | |
425 compositor_frame_sink_holder_), | |
426 content_size_, contents_surface_to_layer_scale, content_size_); | |
427 window_->layer()->SetFillsBoundsOpaquely( | 451 window_->layer()->SetFillsBoundsOpaquely( |
428 state_.blend_mode == SkBlendMode::kSrc || | 452 state_.blend_mode == SkBlendMode::kSrc || |
429 state_.opaque_region.contains( | 453 state_.opaque_region.contains( |
430 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 454 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
431 } | 455 } |
432 | 456 |
433 // Reset damage. | 457 // Reset damage. |
434 pending_damage_.setEmpty(); | 458 pending_damage_.setEmpty(); |
435 | 459 |
436 DCHECK(!current_resource_.id || | 460 DCHECK(!current_resource_.id || |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 | 789 |
766 int64_t Surface::GetPropertyInternal(const void* key, | 790 int64_t Surface::GetPropertyInternal(const void* key, |
767 int64_t default_value) const { | 791 int64_t default_value) const { |
768 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 792 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
769 if (iter == prop_map_.end()) | 793 if (iter == prop_map_.end()) |
770 return default_value; | 794 return default_value; |
771 return iter->second.value; | 795 return iter->second.value; |
772 } | 796 } |
773 | 797 |
774 } // namespace exo | 798 } // namespace exo |
OLD | NEW |