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

Side by Side Diff: components/exo/surface.cc

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build issues and remove wayland_bindings.h Created 5 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/exo/surface.h"
6
7 #include "base/callback_helpers.h"
8 #include "base/logging.h"
9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/resources/single_release_callback.h"
12 #include "components/exo/buffer.h"
13 #include "components/exo/surface_delegate.h"
14 #include "ui/compositor/layer.h"
15 #include "ui/gfx/buffer_format_util.h"
16 #include "ui/gfx/gpu_memory_buffer.h"
17
18 namespace exo {
19
20 ////////////////////////////////////////////////////////////////////////////////
21 // Surface, public:
22
23 Surface::Surface() : compositor_(nullptr), delegate_(nullptr) {
24 SetLayer(new ui::Layer(ui::LAYER_SOLID_COLOR));
25 set_owned_by_client();
26 }
27
28 Surface::~Surface() {
29 if (delegate_)
30 delegate_->OnSurfaceDestroying();
31
32 layer()->SetShowSolidColorContent();
33
34 if (compositor_)
35 compositor_->RemoveObserver(this);
36
37 // Call pending frame callbacks with a null frame time to indicate that they
38 // have been cancelled.
39 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
40 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
41 frame_callbacks_);
42 for (const auto& frame_callback : active_frame_callbacks_)
43 frame_callback.Run(base::TimeTicks());
44 }
45
46 void Surface::Attach(Buffer* buffer) {
47 TRACE_EVENT1("exo", "Surface::Attach", "buffer", buffer->AsTracedValue());
48
49 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>();
50 }
51
52 void Surface::Damage(const gfx::Rect& damage) {
53 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString());
54
55 pending_damage_.Union(damage);
56 }
57
58 void Surface::RequestFrameCallback(const FrameCallback& callback) {
59 TRACE_EVENT0("exo", "Surface::RequestFrameCallback");
60
61 pending_frame_callbacks_.push_back(callback);
62 }
63
64 void Surface::SetOpaqueRegion(const cc::Region& region) {
65 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", region.ToString());
66
67 pending_opaque_region_ = region;
68 }
69
70 void Surface::Commit() {
71 TRACE_EVENT0("exo", "Surface::Commit");
72
73 if (delegate_)
74 delegate_->OnSurfaceCommit();
75
76 cc::TextureMailbox texture_mailbox;
77 scoped_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback;
78 if (pending_buffer_) {
79 texture_mailbox_release_callback =
80 pending_buffer_->AcquireTextureMailbox(&texture_mailbox);
81 pending_buffer_.reset();
82 }
83
84 if (texture_mailbox_release_callback) {
85 // Update layer with the new contents.
86 layer()->SetTextureMailbox(texture_mailbox,
87 texture_mailbox_release_callback.Pass(),
88 texture_mailbox.size_in_pixels());
89 layer()->SetTextureFlipped(false);
90 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(),
91 texture_mailbox.size_in_pixels()));
92 layer()->SetFillsBoundsOpaquely(pending_opaque_region_.Contains(
93 gfx::Rect(texture_mailbox.size_in_pixels())));
94 } else {
95 // Show solid color content if there is no pending buffer.
96 layer()->SetShowSolidColorContent();
97 }
98
99 if (texture_mailbox_release_callback) {
100 // Update layer with the new contents.
101 layer()->SetTextureMailbox(texture_mailbox,
102 texture_mailbox_release_callback.Pass(),
103 texture_mailbox.size_in_pixels());
104 layer()->SetTextureFlipped(false);
105 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(),
106 texture_mailbox.size_in_pixels()));
107 layer()->SetFillsBoundsOpaquely(pending_opaque_region_.Contains(
108 gfx::Rect(texture_mailbox.size_in_pixels())));
109 }
110
111 // Schedule redraw of the damage region.
112 layer()->SchedulePaint(pending_damage_);
113 pending_damage_ = gfx::Rect();
114
115 ui::Compositor* compositor = layer()->GetCompositor();
116 if (compositor && !pending_frame_callbacks_.empty()) {
117 // Start observing the compositor for frame callbacks.
118 if (!compositor_) {
119 compositor->AddObserver(this);
120 compositor_ = compositor;
121 }
122
123 // Move pending frame callbacks to the end of |frame_callbacks_|.
124 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
125 }
126 }
127
128 void Surface::SetSurfaceDelegate(SurfaceDelegate* delegate) {
129 DCHECK(!delegate_ || !delegate);
130 delegate_ = delegate;
131 }
132
133 scoped_refptr<base::trace_event::TracedValue> Surface::AsTracedValue() const {
134 scoped_refptr<base::trace_event::TracedValue> value =
135 new base::trace_event::TracedValue;
136 value->SetString("name", layer()->name());
137 return value;
138 }
139
140 ////////////////////////////////////////////////////////////////////////////////
141 // views::Views overrides:
142
143 gfx::Size Surface::GetPreferredSize() const {
144 return pending_buffer_ ? pending_buffer_->GetSize() : layer()->size();
145 }
146
147 ////////////////////////////////////////////////////////////////////////////////
148 // ui::CompositorObserver overrides:
149
150 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) {
151 // Move frame callbacks to the end of |active_frame_callbacks_|.
152 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
153 frame_callbacks_);
154 }
155
156 void Surface::OnCompositingStarted(ui::Compositor* compositor,
157 base::TimeTicks start_time) {
158 // Run all frame callbacks associated with the compositor's active tree.
159 while (!active_frame_callbacks_.empty()) {
160 active_frame_callbacks_.front().Run(start_time);
161 active_frame_callbacks_.pop_front();
162 }
163 }
164
165 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) {
166 compositor->RemoveObserver(this);
167 compositor_ = nullptr;
168 }
169
170 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698