blob: a544f828bc2ccfa94967abde7af2435e11f662ef [file] [log] [blame]
revemanb195f41d2015-11-19 22:16:481// 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#ifndef COMPONENTS_EXO_SURFACE_H_
6#define COMPONENTS_EXO_SURFACE_H_
7
8#include <list>
reveman70baca12016-05-31 20:35:309#include <set>
reveman27fe2642015-11-20 06:33:3910#include <utility>
revemanb195f41d2015-11-19 22:16:4811
12#include "base/callback.h"
13#include "base/macros.h"
jbaumanbd9586a92016-05-28 01:09:0314#include "base/memory/ref_counted.h"
revemanb195f41d2015-11-19 22:16:4815#include "base/memory/weak_ptr.h"
reveman27fe2642015-11-20 06:33:3916#include "base/observer_list.h"
Dominik Laskowski0dcf91352017-11-29 19:21:3517#include "cc/base/region.h"
danakjc7afae52017-06-20 21:12:4118#include "components/exo/layer_tree_frame_sink_holder.h"
David Reveman93f67c02017-09-06 03:23:0819#include "components/exo/surface_delegate.h"
Fady Samuelc645ffe2017-07-24 17:28:2020#include "components/viz/common/frame_sinks/begin_frame_source.h"
Fady Samuel4f7f0fb32017-07-28 15:33:3721#include "components/viz/common/resources/transferable_resource.h"
reedcc9c70f2016-11-22 04:26:0122#include "third_party/skia/include/core/SkBlendMode.h"
reveman4c94cf962015-12-03 06:49:4323#include "ui/aura/window.h"
revemanb195f41d2015-11-19 22:16:4824#include "ui/gfx/geometry/rect.h"
revemane295c662017-01-30 23:01:2125#include "ui/gfx/native_widget_types.h"
Lloyd Pique0a3045f2017-09-15 23:34:1226#include "ui/gfx/transform.h"
revemanb195f41d2015-11-19 22:16:4827
Raul Tambre038e96d2019-01-07 21:47:4428class SkPath;
29
Dominik Laskowski638b1632019-06-28 20:59:0230namespace ash {
31class OutputProtectionDelegate;
32}
33
revemanb195f41d2015-11-19 22:16:4834namespace base {
35namespace trace_event {
36class TracedValue;
37}
Nicholas Hollingumbad8a05f62019-12-05 05:56:2138} // namespace base
revemanb195f41d2015-11-19 22:16:4839
Alexandros Frantzis4ee9da52019-03-11 15:29:2340namespace gfx {
Jeffrey Kardatzke0d7b8312019-12-09 19:40:0141class ColorSpace;
Alexandros Frantzis4ee9da52019-03-11 15:29:2342class GpuFence;
43}
44
danakj5e0a12b2017-09-25 17:26:4945namespace viz {
46class CompositorFrame;
47}
48
revemanb195f41d2015-11-19 22:16:4849namespace exo {
50class Buffer;
Albert Chaulk56e96582019-01-30 19:33:1851class FrameSinkResourceManager;
reveman27fe2642015-11-20 06:33:3952class SurfaceObserver;
jbaumanbd9586a92016-05-28 01:09:0353
jbaumanb362a892016-06-17 03:30:5654namespace subtle {
55class PropertyHelper;
56}
57
David Revemanfca309b2017-08-24 18:18:1158// Counter-clockwise rotations.
59enum class Transform { NORMAL, ROTATE_90, ROTATE_180, ROTATE_270 };
60
Ryo Hashimoto4e7c572f2019-04-18 05:55:5661// A property key to store the surface Id set by the client.
62extern const ui::ClassProperty<int32_t>* const kClientSurfaceIdKey;
63
revemanb195f41d2015-11-19 22:16:4864// This class represents a rectangular area that is displayed on the screen.
65// It has a location, size and pixel contents.
Hans Wennborgaf90ff12017-09-04 19:46:0266class Surface final : public ui::PropertyHandler {
revemanb195f41d2015-11-19 22:16:4867 public:
reveman2d3815d2016-06-26 20:13:2568 using PropertyDeallocator = void (*)(int64_t value);
Mitsuru Oshima91322d52020-08-03 22:43:3369 using LeaveEnterCallback = base::RepeatingCallback<void(int64_t, int64_t)>;
jbaumanb362a892016-06-17 03:30:5670
revemanb195f41d2015-11-19 22:16:4871 Surface();
Ahmed Fakhry32f3c452019-08-01 16:36:3472 ~Surface() override;
revemanb195f41d2015-11-19 22:16:4873
reveman39b32c872015-12-08 05:34:0574 // Type-checking downcast routine.
kinabad14ca03e2016-02-23 04:43:3575 static Surface* AsSurface(const aura::Window* window);
reveman39b32c872015-12-08 05:34:0576
jbaumane3526252016-06-09 18:43:0577 aura::Window* window() { return window_.get(); }
78
Mitsuru Oshima91322d52020-08-03 22:43:3379 void set_leave_enter_callback(LeaveEnterCallback callback) {
80 leave_enter_callback_ = callback;
81 }
82
83 // Called when the display the surface is on has changed.
84 void UpdateDisplay(int64_t old_id, int64_t new_id);
85
86 // Called when the output is added for new display.
87 void OnNewOutputAdded();
88
revemanb195f41d2015-11-19 22:16:4889 // Set a buffer as the content of this surface. A buffer can only be attached
90 // to one surface at a time.
91 void Attach(Buffer* buffer);
Fergus Dalla4293852019-07-26 07:13:4792 void Attach(Buffer* buffer, gfx::Vector2d offset);
93
94 gfx::Vector2d GetBufferOffset();
95
Alexandros Frantzis4ee9da52019-03-11 15:29:2396 // Returns whether the surface has an uncommitted attached buffer.
97 bool HasPendingAttachedBuffer() const;
revemanb195f41d2015-11-19 22:16:4898
99 // Describe the regions where the pending buffer is different from the
100 // current surface contents, and where the surface therefore needs to be
101 // repainted.
102 void Damage(const gfx::Rect& rect);
103
reveman211cf802017-01-10 00:30:59104 // Request notification when it's a good time to produce a new frame. Useful
105 // for throttling redrawing operations, and driving animations.
Ken Rockote3cd25a2019-12-21 22:28:04106 using FrameCallback =
107 base::RepeatingCallback<void(base::TimeTicks frame_time)>;
revemanb195f41d2015-11-19 22:16:48108 void RequestFrameCallback(const FrameCallback& callback);
109
reveman211cf802017-01-10 00:30:59110 // Request notification when the next frame is displayed. Useful for
111 // throttling redrawing operations, and driving animations.
112 using PresentationCallback =
Ken Rockote3cd25a2019-12-21 22:28:04113 base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
reveman211cf802017-01-10 00:30:59114 void RequestPresentationCallback(const PresentationCallback& callback);
115
revemanb195f41d2015-11-19 22:16:48116 // This sets the region of the surface that contains opaque content.
Dominik Laskowski0dcf91352017-11-29 19:21:35117 void SetOpaqueRegion(const cc::Region& region);
revemanb195f41d2015-11-19 22:16:48118
reveman2966d7702016-02-12 02:09:54119 // This sets the region of the surface that can receive pointer and touch
Dominik Laskowski57064702017-11-30 10:31:41120 // events. The region is clipped to the surface bounds.
Dominik Laskowski0dcf91352017-11-29 19:21:35121 void SetInputRegion(const cc::Region& region);
Scott Violetdb1f0682018-08-30 19:19:46122 const cc::Region& hit_test_region() const { return hit_test_region_; }
reveman2966d7702016-02-12 02:09:54123
Mike Reed2c570fa2018-01-11 21:59:22124 // This resets the region of the surface that can receive pointer and touch
125 // events to be wide-open. This will be clipped to the surface bounds.
126 void ResetInputRegion();
127
Dominik Laskowski2d4316412017-12-13 19:14:44128 // This overrides the input region to the surface bounds with an outset.
129 // TODO(domlaskowski): Remove this once client-driven resizing is removed.
130 void SetInputOutset(int outset);
131
reveman7efa4b02016-01-06 08:29:54132 // This sets the scaling factor used to interpret the contents of the buffer
133 // attached to the surface. Note that if the scale is larger than 1, then you
134 // have to attach a buffer that is larger (by a factor of scale in each
135 // dimension) than the desired surface size.
136 void SetBufferScale(float scale);
137
David Revemanfca309b2017-08-24 18:18:11138 // This sets the transformation used to interpret the contents of the buffer
139 // attached to the surface.
140 void SetBufferTransform(Transform transform);
141
reveman27fe2642015-11-20 06:33:39142 // Functions that control sub-surface state. All sub-surface state is
143 // double-buffered and will be applied when Commit() is called.
144 void AddSubSurface(Surface* sub_surface);
145 void RemoveSubSurface(Surface* sub_surface);
146 void SetSubSurfacePosition(Surface* sub_surface, const gfx::Point& position);
147 void PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference);
148 void PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling);
David Reveman8b43b352017-11-03 15:24:51149 void OnSubSurfaceCommit();
reveman27fe2642015-11-20 06:33:39150
reveman642d8c332016-02-19 19:55:44151 // This sets the surface viewport for scaling.
152 void SetViewport(const gfx::Size& viewport);
153
reveman8e323902016-05-23 21:55:36154 // This sets the surface crop rectangle.
155 void SetCrop(const gfx::RectF& crop);
156
reveman85b7a562016-03-17 23:27:32157 // This sets the only visible on secure output flag, preventing it from
158 // appearing in screenshots or from being viewed on non-secure displays.
159 void SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output);
160
revemanfca687e2016-05-10 21:44:48161 // This sets the blend mode that will be used when drawing the surface.
reedcc9c70f2016-11-22 04:26:01162 void SetBlendMode(SkBlendMode blend_mode);
revemanfca687e2016-05-10 21:44:48163
164 // This sets the alpha value that will be applied to the whole surface.
165 void SetAlpha(float alpha);
166
David Reveman93f67c02017-09-06 03:23:08167 // Request that surface should have the specified frame type.
168 void SetFrame(SurfaceFrameType type);
169
David Reveman786d3182017-12-20 22:04:33170 // Request that surface should use a specific set of frame colors.
171 void SetFrameColors(SkColor active_color, SkColor inactive_color);
172
David Reveman21e2236d2018-04-12 06:01:10173 // Request that surface should have a specific startup ID string.
Tim Zheng08df5662018-04-04 05:08:15174 void SetStartupId(const char* startup_id);
175
David Reveman21e2236d2018-04-12 06:01:10176 // Request that surface should have a specific application ID string.
177 void SetApplicationId(const char* application_id);
178
Chloe Pelling8a8acdeb2020-07-07 10:45:20179 // Whether to hide the shelf when fullscreen. If true, shelf is inaccessible
180 // (plain fullscreen). If false, shelf auto-hides and can be shown with a
181 // mouse gesture (immersive fullscreen).
182 void SetUseImmersiveForFullscreen(bool value);
183
Jeffrey Kardatzke0d7b8312019-12-09 19:40:01184 // This sets the color space for the buffer for this surface.
185 void SetColorSpace(gfx::ColorSpace color_space);
186
David Reveman32715092017-12-05 18:24:11187 // Request "parent" for surface.
188 void SetParent(Surface* parent, const gfx::Point& position);
189
Ryo Hashimoto8f10c882018-11-28 17:43:52190 // Request that surface should have a specific ID assigned by client.
191 void SetClientSurfaceId(int32_t client_surface_id);
192 int32_t GetClientSurfaceId() const;
193
Albert Chaulkfd08f9842019-10-11 15:26:14194 // Enable embedding of an arbitrary viz surface in this exo surface.
195 // If the callback is valid, a SurfaceDrawQuad will be emitted targeting
196 // the returned SurfaceId each frame.
197 void SetEmbeddedSurfaceId(
198 base::RepeatingCallback<viz::SurfaceId()> surface_id_callback);
199
Albert Chaulk77191cc2019-12-19 21:57:50200 // Set the size of the embedded surface, to allow proper scaling.
201 void SetEmbeddedSurfaceSize(const gfx::Size& size);
202
Alexandros Frantzis4ee9da52019-03-11 15:29:23203 // Request that the attached surface buffer at the next commit is associated
204 // with a gpu fence to be signaled when the buffer is ready for use.
205 void SetAcquireFence(std::unique_ptr<gfx::GpuFence> gpu_fence);
206 // Returns whether the surface has an uncommitted acquire fence.
207 bool HasPendingAcquireFence() const;
208
revemanb195f41d2015-11-19 22:16:48209 // Surface state (damage regions, attached buffers, etc.) is double-buffered.
210 // A Commit() call atomically applies all pending state, replacing the
reveman27fe2642015-11-20 06:33:39211 // current state. Commit() is not guaranteed to be synchronous. See
212 // CommitSurfaceHierarchy() below.
revemanb195f41d2015-11-19 22:16:48213 void Commit();
214
David Reveman8b43b352017-11-03 15:24:51215 // This will commit all pending state of the surface and its descendants by
David Reveman7a126ba2017-11-09 17:17:41216 // recursively calling CommitSurfaceHierarchy() for each sub-surface.
217 // If |synchronized| is set to false, then synchronized surfaces should not
218 // commit pending state.
David Revemanef1cb082017-11-09 21:14:40219 void CommitSurfaceHierarchy(bool synchronized);
reveman27fe2642015-11-20 06:33:39220
David Revemanef1cb082017-11-09 21:14:40221 // This will append current callbacks for surface and its descendants to
222 // |frame_callbacks| and |presentation_callbacks|.
223 void AppendSurfaceHierarchyCallbacks(
224 std::list<FrameCallback>* frame_callbacks,
225 std::list<PresentationCallback>* presentation_callbacks);
226
227 // This will append contents for surface and its descendants to frame.
Peng Huang76f5fd02017-09-01 00:59:39228 void AppendSurfaceHierarchyContentsToFrame(
229 const gfx::Point& origin,
230 float device_scale_factor,
Albert Chaulk56e96582019-01-30 19:33:18231 FrameSinkResourceManager* resource_manager,
danakj5e0a12b2017-09-25 17:26:49232 viz::CompositorFrame* frame);
Peng Huang76f5fd02017-09-01 00:59:39233
reveman27fe2642015-11-20 06:33:39234 // Returns true if surface is in synchronized mode.
235 bool IsSynchronized() const;
236
Dominik Laskowski14a163772018-02-09 19:25:18237 // Returns true if surface should receive input events.
238 bool IsInputEnabled(Surface* surface) const;
Dominik Laskowski3e2f94792017-12-15 00:27:10239
Dominik Laskowski57064702017-11-30 10:31:41240 // Returns false if the hit test region is empty.
241 bool HasHitTestRegion() const;
reveman2966d7702016-02-12 02:09:54242
Dominik Laskowski57064702017-11-30 10:31:41243 // Returns true if |point| is inside the surface.
244 bool HitTest(const gfx::Point& point) const;
reveman2966d7702016-02-12 02:09:54245
Dominik Laskowski57064702017-11-30 10:31:41246 // Sets |mask| to the path that delineates the hit test region of the surface.
Raul Tambre038e96d2019-01-07 21:47:44247 void GetHitTestMask(SkPath* mask) const;
reveman4c94cf962015-12-03 06:49:43248
revemanb195f41d2015-11-19 22:16:48249 // Set the surface delegate.
250 void SetSurfaceDelegate(SurfaceDelegate* delegate);
251
reveman27fe2642015-11-20 06:33:39252 // Returns true if surface has been assigned a surface delegate.
253 bool HasSurfaceDelegate() const;
254
255 // Surface does not own observers. It is the responsibility of the observer
256 // to remove itself when it is done observing.
257 void AddSurfaceObserver(SurfaceObserver* observer);
258 void RemoveSurfaceObserver(SurfaceObserver* observer);
259 bool HasSurfaceObserver(const SurfaceObserver* observer) const;
260
revemanb195f41d2015-11-19 22:16:48261 // Returns a trace value representing the state of the surface.
dcheng31759da2016-04-21 01:26:31262 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const;
revemanb195f41d2015-11-19 22:16:48263
eseckler599d86bb2017-03-15 09:02:55264 // Called when the begin frame source has changed.
Fady Samuelc645ffe2017-07-24 17:28:20265 void SetBeginFrameSource(viz::BeginFrameSource* begin_frame_source);
jbaumanbd9586a92016-05-28 01:09:03266
David Reveman7a126ba2017-11-09 17:17:41267 // Returns the active content size.
Peng Huangb07b0652017-06-27 17:25:22268 const gfx::Size& content_size() const { return content_size_; }
jbaumanb362a892016-06-17 03:30:56269
David Reveman7a126ba2017-11-09 17:17:41270 // Returns the active content bounds for surface hierarchy. ie. the bounding
271 // box of the surface and its descendants, in the local coordinate space of
272 // the surface.
273 const gfx::Rect& surface_hierarchy_content_bounds() const {
274 return surface_hierarchy_content_bounds_;
275 }
276
kaznacheev8e270592017-05-25 06:13:26277 // Returns true if the associated window is in 'stylus-only' mode.
278 bool IsStylusOnly();
279
280 // Enables 'stylus-only' mode for the associated window.
281 void SetStylusOnly();
282
Peng Huangc51f7aba2017-09-05 16:00:39283 // Notify surface that resources and subsurfaces' resources have been lost.
284 void SurfaceHierarchyResourcesLost();
reveman15aee282016-11-04 19:09:20285
Peng Huang583c9dc62017-07-27 23:38:28286 // Returns true if the surface's bounds should be filled opaquely.
287 bool FillsBoundsOpaquely() const;
reveman211cf802017-01-10 00:30:59288
reveman15aee282016-11-04 19:09:20289 bool HasPendingDamageForTesting(const gfx::Rect& damage) const {
Dominik Laskowski0dcf91352017-11-29 19:21:35290 return pending_damage_.Contains(damage);
reveman15aee282016-11-04 19:09:20291 }
292
Eliot Courtneybb051d12018-12-15 02:41:31293 // Set occlusion tracking region for surface.
294 void SetOcclusionTracking(bool tracking);
295
296 // Triggers sending an occlusion update to observers.
297 void OnWindowOcclusionChanged();
298
Eliot Courtney99f3e9fc2019-04-03 09:07:20299 // True if the window for this surface has its occlusion tracked.
[email protected]82d399b02020-05-26 17:00:23300 bool IsTrackingOcclusion();
Eliot Courtney99f3e9fc2019-04-03 09:07:20301
[email protected]93855732019-06-24 19:49:30302 // Sets the |surface_hierarchy_content_bounds_|.
303 void SetSurfaceHierarchyContentBoundsForTest(const gfx::Rect& content_bounds);
304
Nicholas Hollingumbad8a05f62019-12-05 05:56:21305 // Requests that this surface should be made active (i.e. foregrounded).
306 void RequestActivation();
307
revemanb195f41d2015-11-19 22:16:48308 private:
jbaumanf4c3f292016-06-11 00:57:33309 struct State {
310 State();
311 ~State();
312
Lei Zhang1c9963ba2018-05-15 04:50:21313 bool operator==(const State& other) const;
314 bool operator!=(const State& other) const { return !(*this == other); }
jbaumanf4c3f292016-06-11 00:57:33315
Dominik Laskowski0dcf91352017-11-29 19:21:35316 cc::Region opaque_region;
Mike Reed2c570fa2018-01-11 21:59:22317 base::Optional<cc::Region> input_region;
Dominik Laskowski2d4316412017-12-13 19:14:44318 int input_outset = 0;
reveman2d3815d2016-06-26 20:13:25319 float buffer_scale = 1.0f;
David Revemanfca309b2017-08-24 18:18:11320 Transform buffer_transform = Transform::NORMAL;
jbaumanf4c3f292016-06-11 00:57:33321 gfx::Size viewport;
322 gfx::RectF crop;
323 bool only_visible_on_secure_output = false;
reedcc9c70f2016-11-22 04:26:01324 SkBlendMode blend_mode = SkBlendMode::kSrcOver;
jbaumanf4c3f292016-06-11 00:57:33325 float alpha = 1.0f;
Fergus Dalla4293852019-07-26 07:13:47326 gfx::Vector2d offset;
Jeffrey Kardatzke0d7b8312019-12-09 19:40:01327 gfx::ColorSpace color_space;
[email protected]82d399b02020-05-26 17:00:23328 bool is_tracking_occlusion = false;
jbauman45c06862016-06-23 19:35:02329 };
330 class BufferAttachment {
331 public:
332 BufferAttachment();
333 ~BufferAttachment();
334
335 BufferAttachment& operator=(BufferAttachment&& buffer);
336
337 base::WeakPtr<Buffer>& buffer();
338 const base::WeakPtr<Buffer>& buffer() const;
David Revemane6e23342017-11-07 06:18:06339 const gfx::Size& size() const;
jbauman45c06862016-06-23 19:35:02340 void Reset(base::WeakPtr<Buffer> buffer);
341
342 private:
343 base::WeakPtr<Buffer> buffer_;
David Revemane6e23342017-11-07 06:18:06344 gfx::Size size_;
jbauman45c06862016-06-23 19:35:02345
346 DISALLOW_COPY_AND_ASSIGN(BufferAttachment);
jbaumanf4c3f292016-06-11 00:57:33347 };
348
jbaumanb362a892016-06-17 03:30:56349 friend class subtle::PropertyHelper;
350
jbauman45c06862016-06-23 19:35:02351 // Updates current_resource_ with a new resource id corresponding to the
352 // contents of the attached buffer (or id 0, if no buffer is attached).
353 // UpdateSurface must be called afterwards to ensure the release callback
354 // will be called.
Albert Chaulk56e96582019-01-30 19:33:18355 void UpdateResource(FrameSinkResourceManager* resource_manager);
jbauman45c06862016-06-23 19:35:02356
Lloyd Pique0a3045f2017-09-15 23:34:12357 // Updates buffer_transform_ to match the current buffer parameters.
Zach Reizner8bcce6e2018-10-31 00:04:37358 void UpdateBufferTransform(bool y_invert);
Lloyd Pique0a3045f2017-09-15 23:34:12359
Peng Huang583c9dc62017-07-27 23:38:28360 // Puts the current surface into a draw quad, and appends the draw quads into
361 // the |frame|.
362 void AppendContentsToFrame(const gfx::Point& origin,
Peng Huang76f5fd02017-09-01 00:59:39363 float device_scale_factor,
danakj5e0a12b2017-09-25 17:26:49364 viz::CompositorFrame* frame);
jbauman45c06862016-06-23 19:35:02365
Peng Huangc51f7aba2017-09-05 16:00:39366 // Update surface content size base on current buffer size.
Peng Huang583c9dc62017-07-27 23:38:28367 void UpdateContentSize();
eseckler599d86bb2017-03-15 09:02:55368
revemanced21f82015-11-24 00:42:49369 // This returns true when the surface has some contents assigned to it.
David Revemane6e23342017-11-07 06:18:06370 bool has_contents() const { return !current_buffer_.size().IsEmpty(); }
revemanced21f82015-11-24 00:42:49371
jbaumane3526252016-06-09 18:43:05372 // This window has the layer which contains the Surface contents.
373 std::unique_ptr<aura::Window> window_;
374
Peng Huang583c9dc62017-07-27 23:38:28375 // This true, if sub_surfaces_ has changes (order, position, etc).
376 bool sub_surfaces_changed_ = false;
jbaumanf4c3f292016-06-11 00:57:33377
jbaumanb362a892016-06-17 03:30:56378 // This is the size of the last committed contents.
379 gfx::Size content_size_;
380
David Reveman7a126ba2017-11-09 17:17:41381 // This is the bounds of the last committed surface hierarchy contents.
382 gfx::Rect surface_hierarchy_content_bounds_;
383
revemanced21f82015-11-24 00:42:49384 // This is true when Attach() has been called and new contents should take
385 // effect next time Commit() is called.
reveman2d3815d2016-06-26 20:13:25386 bool has_pending_contents_ = false;
reveman27fe2642015-11-20 06:33:39387
revemanb195f41d2015-11-19 22:16:48388 // The buffer that will become the content of surface when Commit() is called.
jbauman45c06862016-06-23 19:35:02389 BufferAttachment pending_buffer_;
revemanb195f41d2015-11-19 22:16:48390
391 // The damage region to schedule paint for when Commit() is called.
Dominik Laskowski0dcf91352017-11-29 19:21:35392 cc::Region pending_damage_;
revemanb195f41d2015-11-19 22:16:48393
Peng Huang76f5fd02017-09-01 00:59:39394 // The damage region which will be used by
395 // AppendSurfaceHierarchyContentsToFrame() to generate frame.
Dominik Laskowski0dcf91352017-11-29 19:21:35396 cc::Region damage_;
Peng Huang76f5fd02017-09-01 00:59:39397
revemanb195f41d2015-11-19 22:16:48398 // These lists contains the callbacks to notify the client when it is a good
399 // time to start producing a new frame. These callbacks move to
400 // |frame_callbacks_| when Commit() is called. Later they are moved to
reveman15aee282016-11-04 19:09:20401 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to
402 // be drawn. They fire at the first begin frame notification after this.
revemanb195f41d2015-11-19 22:16:48403 std::list<FrameCallback> pending_frame_callbacks_;
David Revemanef1cb082017-11-09 21:14:40404 std::list<FrameCallback> frame_callbacks_;
reveman211cf802017-01-10 00:30:59405
406 // These lists contains the callbacks to notify the client when surface
407 // contents have been presented. These callbacks move to
408 // |presentation_callbacks_| when Commit() is called. Later they are moved to
409 // |swapping_presentation_callbacks_| when the effect of the Commit() is
410 // scheduled to be drawn and then moved to |swapped_presentation_callbacks_|
411 // after receiving VSync parameters update for the previous frame. They fire
412 // at the next VSync parameters update after that.
413 std::list<PresentationCallback> pending_presentation_callbacks_;
David Revemanef1cb082017-11-09 21:14:40414 std::list<PresentationCallback> presentation_callbacks_;
revemanb195f41d2015-11-19 22:16:48415
jbaumanf4c3f292016-06-11 00:57:33416 // This is the state that has yet to be committed.
417 State pending_state_;
revemanb195f41d2015-11-19 22:16:48418
jbaumanf4c3f292016-06-11 00:57:33419 // This is the state that has been committed.
420 State state_;
reveman7efa4b02016-01-06 08:29:54421
Dominik Laskowski57064702017-11-30 10:31:41422 // Cumulative input region of surface and its sub-surfaces.
423 cc::Region hit_test_region_;
424
reveman27fe2642015-11-20 06:33:39425 // The stack of sub-surfaces to take effect when Commit() is called.
426 // Bottom-most sub-surface at the front of the list and top-most sub-surface
427 // at the back.
428 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>;
429 using SubSurfaceEntryList = std::list<SubSurfaceEntry>;
430 SubSurfaceEntryList pending_sub_surfaces_;
Peng Huang583c9dc62017-07-27 23:38:28431 SubSurfaceEntryList sub_surfaces_;
reveman27fe2642015-11-20 06:33:39432
revemanced21f82015-11-24 00:42:49433 // The buffer that is currently set as content of surface.
jbauman45c06862016-06-23 19:35:02434 BufferAttachment current_buffer_;
revemanced21f82015-11-24 00:42:49435
jbauman2fdc0732016-06-07 00:55:36436 // The last resource that was sent to a surface.
Fady Samuel4f7f0fb32017-07-28 15:33:37437 viz::TransferableResource current_resource_;
jbauman2fdc0732016-06-07 00:55:36438
revemanca132dc2017-01-31 22:35:54439 // Whether the last resource that was sent to a surface has an alpha channel.
440 bool current_resource_has_alpha_ = false;
441
Alexandros Frantzis4ee9da52019-03-11 15:29:23442 // The acquire gpu fence to associate with the surface buffer when Commit()
443 // is called.
444 std::unique_ptr<gfx::GpuFence> pending_acquire_fence_;
445 // The acquire gpu fence that is currently associated with the surface buffer.
446 std::unique_ptr<gfx::GpuFence> acquire_fence_;
447
reveman27fe2642015-11-20 06:33:39448 // This is true if a call to Commit() as been made but
449 // CommitSurfaceHierarchy() has not yet been called.
Peng Huang76f5fd02017-09-01 00:59:39450 bool needs_commit_surface_ = false;
reveman27fe2642015-11-20 06:33:39451
Peng Huangc51f7aba2017-09-05 16:00:39452 // This is true if UpdateResources() should be called.
453 bool needs_update_resource_ = true;
454
Lloyd Pique0a3045f2017-09-15 23:34:12455 // The current buffer transform matrix. It specifies the transformation from
456 // normalized buffer coordinates to post-tranform buffer coordinates.
457 gfx::Transform buffer_transform_;
458
reveman7cadea42016-02-05 20:14:38459 // This is set when the compositing starts and passed to active frame
460 // callbacks when compositing successfully ends.
461 base::TimeTicks last_compositing_start_time_;
462
revemanb195f41d2015-11-19 22:16:48463 // This can be set to have some functions delegated. E.g. ShellSurface class
464 // can set this to handle Commit() and apply any double buffered state it
465 // maintains.
reveman2d3815d2016-06-26 20:13:25466 SurfaceDelegate* delegate_ = nullptr;
revemanb195f41d2015-11-19 22:16:48467
reveman27fe2642015-11-20 06:33:39468 // Surface observer list. Surface does not own the observers.
Trent Apteda250ec3ab2018-08-19 08:52:19469 base::ObserverList<SurfaceObserver, true>::Unchecked observers_;
reveman27fe2642015-11-20 06:33:39470
Dominik Laskowski638b1632019-06-28 20:59:02471#if defined(OS_CHROMEOS)
472 std::unique_ptr<ash::OutputProtectionDelegate> output_protection_;
473#endif // defined(OS_CHROMEOS)
474
Albert Chaulkfd08f9842019-10-11 15:26:14475 viz::SurfaceId first_embedded_surface_id_;
Albert Chaulk0adb8b8d2019-11-06 20:06:27476 viz::SurfaceId latest_embedded_surface_id_;
Albert Chaulkfd08f9842019-10-11 15:26:14477 base::RepeatingCallback<viz::SurfaceId()> get_current_surface_id_;
478
Albert Chaulk77191cc2019-12-19 21:57:50479 // The embedded surface is actually |embedded_surface_size_|. This is used
480 // for calculating clipping and scaling.
Albert Chaulkfbbbe232020-01-14 00:16:04481 gfx::Size embedded_surface_size_;
Albert Chaulk77191cc2019-12-19 21:57:50482
Mitsuru Oshima91322d52020-08-03 22:43:33483 LeaveEnterCallback leave_enter_callback_;
484
revemanb195f41d2015-11-19 22:16:48485 DISALLOW_COPY_AND_ASSIGN(Surface);
486};
487
Fergus Dalla4293852019-07-26 07:13:47488class ScopedSurface {
489 public:
490 ScopedSurface(Surface* surface, SurfaceObserver* observer);
491 ~ScopedSurface();
492 Surface* get() { return surface_; }
493
494 private:
495 Surface* const surface_;
496 SurfaceObserver* const observer_;
497
498 DISALLOW_COPY_AND_ASSIGN(ScopedSurface);
499};
500
revemanb195f41d2015-11-19 22:16:48501} // namespace exo
502
503#endif // COMPONENTS_EXO_SURFACE_H_