blob: 4b7d1d32d3a44a201ddb62dca3290034df18cea5 [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);
jbaumanb362a892016-06-17 03:30:5669
revemanb195f41d2015-11-19 22:16:4870 Surface();
Ahmed Fakhry32f3c452019-08-01 16:36:3471 ~Surface() override;
revemanb195f41d2015-11-19 22:16:4872
reveman39b32c872015-12-08 05:34:0573 // Type-checking downcast routine.
kinabad14ca03e2016-02-23 04:43:3574 static Surface* AsSurface(const aura::Window* window);
reveman39b32c872015-12-08 05:34:0575
jbaumane3526252016-06-09 18:43:0576 aura::Window* window() { return window_.get(); }
77
revemanb195f41d2015-11-19 22:16:4878 // Set a buffer as the content of this surface. A buffer can only be attached
79 // to one surface at a time.
80 void Attach(Buffer* buffer);
Fergus Dalla4293852019-07-26 07:13:4781 void Attach(Buffer* buffer, gfx::Vector2d offset);
82
83 gfx::Vector2d GetBufferOffset();
84
Alexandros Frantzis4ee9da52019-03-11 15:29:2385 // Returns whether the surface has an uncommitted attached buffer.
86 bool HasPendingAttachedBuffer() const;
revemanb195f41d2015-11-19 22:16:4887
88 // Describe the regions where the pending buffer is different from the
89 // current surface contents, and where the surface therefore needs to be
90 // repainted.
91 void Damage(const gfx::Rect& rect);
92
reveman211cf802017-01-10 00:30:5993 // Request notification when it's a good time to produce a new frame. Useful
94 // for throttling redrawing operations, and driving animations.
Ken Rockote3cd25a2019-12-21 22:28:0495 using FrameCallback =
96 base::RepeatingCallback<void(base::TimeTicks frame_time)>;
revemanb195f41d2015-11-19 22:16:4897 void RequestFrameCallback(const FrameCallback& callback);
98
reveman211cf802017-01-10 00:30:5999 // Request notification when the next frame is displayed. Useful for
100 // throttling redrawing operations, and driving animations.
101 using PresentationCallback =
Ken Rockote3cd25a2019-12-21 22:28:04102 base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
reveman211cf802017-01-10 00:30:59103 void RequestPresentationCallback(const PresentationCallback& callback);
104
revemanb195f41d2015-11-19 22:16:48105 // This sets the region of the surface that contains opaque content.
Dominik Laskowski0dcf91352017-11-29 19:21:35106 void SetOpaqueRegion(const cc::Region& region);
revemanb195f41d2015-11-19 22:16:48107
reveman2966d7702016-02-12 02:09:54108 // This sets the region of the surface that can receive pointer and touch
Dominik Laskowski57064702017-11-30 10:31:41109 // events. The region is clipped to the surface bounds.
Dominik Laskowski0dcf91352017-11-29 19:21:35110 void SetInputRegion(const cc::Region& region);
Scott Violetdb1f0682018-08-30 19:19:46111 const cc::Region& hit_test_region() const { return hit_test_region_; }
reveman2966d7702016-02-12 02:09:54112
Mike Reed2c570fa2018-01-11 21:59:22113 // This resets the region of the surface that can receive pointer and touch
114 // events to be wide-open. This will be clipped to the surface bounds.
115 void ResetInputRegion();
116
Dominik Laskowski2d4316412017-12-13 19:14:44117 // This overrides the input region to the surface bounds with an outset.
118 // TODO(domlaskowski): Remove this once client-driven resizing is removed.
119 void SetInputOutset(int outset);
120
reveman7efa4b02016-01-06 08:29:54121 // This sets the scaling factor used to interpret the contents of the buffer
122 // attached to the surface. Note that if the scale is larger than 1, then you
123 // have to attach a buffer that is larger (by a factor of scale in each
124 // dimension) than the desired surface size.
125 void SetBufferScale(float scale);
126
David Revemanfca309b2017-08-24 18:18:11127 // This sets the transformation used to interpret the contents of the buffer
128 // attached to the surface.
129 void SetBufferTransform(Transform transform);
130
reveman27fe2642015-11-20 06:33:39131 // Functions that control sub-surface state. All sub-surface state is
132 // double-buffered and will be applied when Commit() is called.
133 void AddSubSurface(Surface* sub_surface);
134 void RemoveSubSurface(Surface* sub_surface);
135 void SetSubSurfacePosition(Surface* sub_surface, const gfx::Point& position);
136 void PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference);
137 void PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling);
David Reveman8b43b352017-11-03 15:24:51138 void OnSubSurfaceCommit();
reveman27fe2642015-11-20 06:33:39139
reveman642d8c332016-02-19 19:55:44140 // This sets the surface viewport for scaling.
141 void SetViewport(const gfx::Size& viewport);
142
reveman8e323902016-05-23 21:55:36143 // This sets the surface crop rectangle.
144 void SetCrop(const gfx::RectF& crop);
145
reveman85b7a562016-03-17 23:27:32146 // This sets the only visible on secure output flag, preventing it from
147 // appearing in screenshots or from being viewed on non-secure displays.
148 void SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output);
149
revemanfca687e2016-05-10 21:44:48150 // This sets the blend mode that will be used when drawing the surface.
reedcc9c70f2016-11-22 04:26:01151 void SetBlendMode(SkBlendMode blend_mode);
revemanfca687e2016-05-10 21:44:48152
153 // This sets the alpha value that will be applied to the whole surface.
154 void SetAlpha(float alpha);
155
David Reveman93f67c02017-09-06 03:23:08156 // Request that surface should have the specified frame type.
157 void SetFrame(SurfaceFrameType type);
158
David Reveman786d3182017-12-20 22:04:33159 // Request that surface should use a specific set of frame colors.
160 void SetFrameColors(SkColor active_color, SkColor inactive_color);
161
David Reveman21e2236d2018-04-12 06:01:10162 // Request that surface should have a specific startup ID string.
Tim Zheng08df5662018-04-04 05:08:15163 void SetStartupId(const char* startup_id);
164
David Reveman21e2236d2018-04-12 06:01:10165 // Request that surface should have a specific application ID string.
166 void SetApplicationId(const char* application_id);
167
Jeffrey Kardatzke0d7b8312019-12-09 19:40:01168 // This sets the color space for the buffer for this surface.
169 void SetColorSpace(gfx::ColorSpace color_space);
170
David Reveman32715092017-12-05 18:24:11171 // Request "parent" for surface.
172 void SetParent(Surface* parent, const gfx::Point& position);
173
Ryo Hashimoto8f10c882018-11-28 17:43:52174 // Request that surface should have a specific ID assigned by client.
175 void SetClientSurfaceId(int32_t client_surface_id);
176 int32_t GetClientSurfaceId() const;
177
Albert Chaulkfd08f9842019-10-11 15:26:14178 // Enable embedding of an arbitrary viz surface in this exo surface.
179 // If the callback is valid, a SurfaceDrawQuad will be emitted targeting
180 // the returned SurfaceId each frame.
181 void SetEmbeddedSurfaceId(
182 base::RepeatingCallback<viz::SurfaceId()> surface_id_callback);
183
Albert Chaulk77191cc2019-12-19 21:57:50184 // Set the size of the embedded surface, to allow proper scaling.
185 void SetEmbeddedSurfaceSize(const gfx::Size& size);
186
Alexandros Frantzis4ee9da52019-03-11 15:29:23187 // Request that the attached surface buffer at the next commit is associated
188 // with a gpu fence to be signaled when the buffer is ready for use.
189 void SetAcquireFence(std::unique_ptr<gfx::GpuFence> gpu_fence);
190 // Returns whether the surface has an uncommitted acquire fence.
191 bool HasPendingAcquireFence() const;
192
revemanb195f41d2015-11-19 22:16:48193 // Surface state (damage regions, attached buffers, etc.) is double-buffered.
194 // A Commit() call atomically applies all pending state, replacing the
reveman27fe2642015-11-20 06:33:39195 // current state. Commit() is not guaranteed to be synchronous. See
196 // CommitSurfaceHierarchy() below.
revemanb195f41d2015-11-19 22:16:48197 void Commit();
198
David Reveman8b43b352017-11-03 15:24:51199 // This will commit all pending state of the surface and its descendants by
David Reveman7a126ba2017-11-09 17:17:41200 // recursively calling CommitSurfaceHierarchy() for each sub-surface.
201 // If |synchronized| is set to false, then synchronized surfaces should not
202 // commit pending state.
David Revemanef1cb082017-11-09 21:14:40203 void CommitSurfaceHierarchy(bool synchronized);
reveman27fe2642015-11-20 06:33:39204
David Revemanef1cb082017-11-09 21:14:40205 // This will append current callbacks for surface and its descendants to
206 // |frame_callbacks| and |presentation_callbacks|.
207 void AppendSurfaceHierarchyCallbacks(
208 std::list<FrameCallback>* frame_callbacks,
209 std::list<PresentationCallback>* presentation_callbacks);
210
211 // This will append contents for surface and its descendants to frame.
Peng Huang76f5fd02017-09-01 00:59:39212 void AppendSurfaceHierarchyContentsToFrame(
213 const gfx::Point& origin,
214 float device_scale_factor,
Albert Chaulk56e96582019-01-30 19:33:18215 FrameSinkResourceManager* resource_manager,
danakj5e0a12b2017-09-25 17:26:49216 viz::CompositorFrame* frame);
Peng Huang76f5fd02017-09-01 00:59:39217
reveman27fe2642015-11-20 06:33:39218 // Returns true if surface is in synchronized mode.
219 bool IsSynchronized() const;
220
Dominik Laskowski14a163772018-02-09 19:25:18221 // Returns true if surface should receive input events.
222 bool IsInputEnabled(Surface* surface) const;
Dominik Laskowski3e2f94792017-12-15 00:27:10223
Dominik Laskowski57064702017-11-30 10:31:41224 // Returns false if the hit test region is empty.
225 bool HasHitTestRegion() const;
reveman2966d7702016-02-12 02:09:54226
Dominik Laskowski57064702017-11-30 10:31:41227 // Returns true if |point| is inside the surface.
228 bool HitTest(const gfx::Point& point) const;
reveman2966d7702016-02-12 02:09:54229
Dominik Laskowski57064702017-11-30 10:31:41230 // Sets |mask| to the path that delineates the hit test region of the surface.
Raul Tambre038e96d2019-01-07 21:47:44231 void GetHitTestMask(SkPath* mask) const;
reveman4c94cf962015-12-03 06:49:43232
revemanb195f41d2015-11-19 22:16:48233 // Set the surface delegate.
234 void SetSurfaceDelegate(SurfaceDelegate* delegate);
235
reveman27fe2642015-11-20 06:33:39236 // Returns true if surface has been assigned a surface delegate.
237 bool HasSurfaceDelegate() const;
238
239 // Surface does not own observers. It is the responsibility of the observer
240 // to remove itself when it is done observing.
241 void AddSurfaceObserver(SurfaceObserver* observer);
242 void RemoveSurfaceObserver(SurfaceObserver* observer);
243 bool HasSurfaceObserver(const SurfaceObserver* observer) const;
244
revemanb195f41d2015-11-19 22:16:48245 // Returns a trace value representing the state of the surface.
dcheng31759da2016-04-21 01:26:31246 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const;
revemanb195f41d2015-11-19 22:16:48247
eseckler599d86bb2017-03-15 09:02:55248 // Called when the begin frame source has changed.
Fady Samuelc645ffe2017-07-24 17:28:20249 void SetBeginFrameSource(viz::BeginFrameSource* begin_frame_source);
jbaumanbd9586a92016-05-28 01:09:03250
David Reveman7a126ba2017-11-09 17:17:41251 // Returns the active content size.
Peng Huangb07b0652017-06-27 17:25:22252 const gfx::Size& content_size() const { return content_size_; }
jbaumanb362a892016-06-17 03:30:56253
David Reveman7a126ba2017-11-09 17:17:41254 // Returns the active content bounds for surface hierarchy. ie. the bounding
255 // box of the surface and its descendants, in the local coordinate space of
256 // the surface.
257 const gfx::Rect& surface_hierarchy_content_bounds() const {
258 return surface_hierarchy_content_bounds_;
259 }
260
kaznacheev8e270592017-05-25 06:13:26261 // Returns true if the associated window is in 'stylus-only' mode.
262 bool IsStylusOnly();
263
264 // Enables 'stylus-only' mode for the associated window.
265 void SetStylusOnly();
266
Peng Huangc51f7aba2017-09-05 16:00:39267 // Notify surface that resources and subsurfaces' resources have been lost.
268 void SurfaceHierarchyResourcesLost();
reveman15aee282016-11-04 19:09:20269
Peng Huang583c9dc62017-07-27 23:38:28270 // Returns true if the surface's bounds should be filled opaquely.
271 bool FillsBoundsOpaquely() const;
reveman211cf802017-01-10 00:30:59272
reveman15aee282016-11-04 19:09:20273 bool HasPendingDamageForTesting(const gfx::Rect& damage) const {
Dominik Laskowski0dcf91352017-11-29 19:21:35274 return pending_damage_.Contains(damage);
reveman15aee282016-11-04 19:09:20275 }
276
Eliot Courtneybb051d12018-12-15 02:41:31277 // Set occlusion tracking region for surface.
278 void SetOcclusionTracking(bool tracking);
279
280 // Triggers sending an occlusion update to observers.
281 void OnWindowOcclusionChanged();
282
Eliot Courtney99f3e9fc2019-04-03 09:07:20283 // True if the window for this surface has its occlusion tracked.
284 bool is_tracking_occlusion() const { return is_tracking_occlusion_; }
285
[email protected]93855732019-06-24 19:49:30286 // Sets the |surface_hierarchy_content_bounds_|.
287 void SetSurfaceHierarchyContentBoundsForTest(const gfx::Rect& content_bounds);
288
Nicholas Hollingumbad8a05f62019-12-05 05:56:21289 // Requests that this surface should be made active (i.e. foregrounded).
290 void RequestActivation();
291
revemanb195f41d2015-11-19 22:16:48292 private:
jbaumanf4c3f292016-06-11 00:57:33293 struct State {
294 State();
295 ~State();
296
Lei Zhang1c9963ba2018-05-15 04:50:21297 bool operator==(const State& other) const;
298 bool operator!=(const State& other) const { return !(*this == other); }
jbaumanf4c3f292016-06-11 00:57:33299
Dominik Laskowski0dcf91352017-11-29 19:21:35300 cc::Region opaque_region;
Mike Reed2c570fa2018-01-11 21:59:22301 base::Optional<cc::Region> input_region;
Dominik Laskowski2d4316412017-12-13 19:14:44302 int input_outset = 0;
reveman2d3815d2016-06-26 20:13:25303 float buffer_scale = 1.0f;
David Revemanfca309b2017-08-24 18:18:11304 Transform buffer_transform = Transform::NORMAL;
jbaumanf4c3f292016-06-11 00:57:33305 gfx::Size viewport;
306 gfx::RectF crop;
307 bool only_visible_on_secure_output = false;
reedcc9c70f2016-11-22 04:26:01308 SkBlendMode blend_mode = SkBlendMode::kSrcOver;
jbaumanf4c3f292016-06-11 00:57:33309 float alpha = 1.0f;
Fergus Dalla4293852019-07-26 07:13:47310 gfx::Vector2d offset;
Jeffrey Kardatzke0d7b8312019-12-09 19:40:01311 gfx::ColorSpace color_space;
jbauman45c06862016-06-23 19:35:02312 };
313 class BufferAttachment {
314 public:
315 BufferAttachment();
316 ~BufferAttachment();
317
318 BufferAttachment& operator=(BufferAttachment&& buffer);
319
320 base::WeakPtr<Buffer>& buffer();
321 const base::WeakPtr<Buffer>& buffer() const;
David Revemane6e23342017-11-07 06:18:06322 const gfx::Size& size() const;
jbauman45c06862016-06-23 19:35:02323 void Reset(base::WeakPtr<Buffer> buffer);
324
325 private:
326 base::WeakPtr<Buffer> buffer_;
David Revemane6e23342017-11-07 06:18:06327 gfx::Size size_;
jbauman45c06862016-06-23 19:35:02328
329 DISALLOW_COPY_AND_ASSIGN(BufferAttachment);
jbaumanf4c3f292016-06-11 00:57:33330 };
331
jbaumanb362a892016-06-17 03:30:56332 friend class subtle::PropertyHelper;
333
jbauman45c06862016-06-23 19:35:02334 // Updates current_resource_ with a new resource id corresponding to the
335 // contents of the attached buffer (or id 0, if no buffer is attached).
336 // UpdateSurface must be called afterwards to ensure the release callback
337 // will be called.
Albert Chaulk56e96582019-01-30 19:33:18338 void UpdateResource(FrameSinkResourceManager* resource_manager);
jbauman45c06862016-06-23 19:35:02339
Lloyd Pique0a3045f2017-09-15 23:34:12340 // Updates buffer_transform_ to match the current buffer parameters.
Zach Reizner8bcce6e2018-10-31 00:04:37341 void UpdateBufferTransform(bool y_invert);
Lloyd Pique0a3045f2017-09-15 23:34:12342
Peng Huang583c9dc62017-07-27 23:38:28343 // Puts the current surface into a draw quad, and appends the draw quads into
344 // the |frame|.
345 void AppendContentsToFrame(const gfx::Point& origin,
Peng Huang76f5fd02017-09-01 00:59:39346 float device_scale_factor,
danakj5e0a12b2017-09-25 17:26:49347 viz::CompositorFrame* frame);
jbauman45c06862016-06-23 19:35:02348
Peng Huangc51f7aba2017-09-05 16:00:39349 // Update surface content size base on current buffer size.
Peng Huang583c9dc62017-07-27 23:38:28350 void UpdateContentSize();
eseckler599d86bb2017-03-15 09:02:55351
revemanced21f862015-11-24 00:42:49352 // This returns true when the surface has some contents assigned to it.
David Revemane6e23342017-11-07 06:18:06353 bool has_contents() const { return !current_buffer_.size().IsEmpty(); }
revemanced21f862015-11-24 00:42:49354
jbaumane3526252016-06-09 18:43:05355 // This window has the layer which contains the Surface contents.
356 std::unique_ptr<aura::Window> window_;
357
Peng Huang583c9dc62017-07-27 23:38:28358 // This true, if sub_surfaces_ has changes (order, position, etc).
359 bool sub_surfaces_changed_ = false;
jbaumanf4c3f292016-06-11 00:57:33360
jbaumanb362a892016-06-17 03:30:56361 // This is the size of the last committed contents.
362 gfx::Size content_size_;
363
David Reveman7a126ba2017-11-09 17:17:41364 // This is the bounds of the last committed surface hierarchy contents.
365 gfx::Rect surface_hierarchy_content_bounds_;
366
revemanced21f862015-11-24 00:42:49367 // This is true when Attach() has been called and new contents should take
368 // effect next time Commit() is called.
reveman2d3815d2016-06-26 20:13:25369 bool has_pending_contents_ = false;
reveman27fe2642015-11-20 06:33:39370
revemanb195f41d2015-11-19 22:16:48371 // The buffer that will become the content of surface when Commit() is called.
jbauman45c06862016-06-23 19:35:02372 BufferAttachment pending_buffer_;
revemanb195f41d2015-11-19 22:16:48373
374 // The damage region to schedule paint for when Commit() is called.
Dominik Laskowski0dcf91352017-11-29 19:21:35375 cc::Region pending_damage_;
revemanb195f41d2015-11-19 22:16:48376
Peng Huang76f5fd02017-09-01 00:59:39377 // The damage region which will be used by
378 // AppendSurfaceHierarchyContentsToFrame() to generate frame.
Dominik Laskowski0dcf91352017-11-29 19:21:35379 cc::Region damage_;
Peng Huang76f5fd02017-09-01 00:59:39380
revemanb195f41d2015-11-19 22:16:48381 // These lists contains the callbacks to notify the client when it is a good
382 // time to start producing a new frame. These callbacks move to
383 // |frame_callbacks_| when Commit() is called. Later they are moved to
reveman15aee282016-11-04 19:09:20384 // |active_frame_callbacks_| when the effect of the Commit() is scheduled to
385 // be drawn. They fire at the first begin frame notification after this.
revemanb195f41d2015-11-19 22:16:48386 std::list<FrameCallback> pending_frame_callbacks_;
David Revemanef1cb082017-11-09 21:14:40387 std::list<FrameCallback> frame_callbacks_;
reveman211cf802017-01-10 00:30:59388
389 // These lists contains the callbacks to notify the client when surface
390 // contents have been presented. These callbacks move to
391 // |presentation_callbacks_| when Commit() is called. Later they are moved to
392 // |swapping_presentation_callbacks_| when the effect of the Commit() is
393 // scheduled to be drawn and then moved to |swapped_presentation_callbacks_|
394 // after receiving VSync parameters update for the previous frame. They fire
395 // at the next VSync parameters update after that.
396 std::list<PresentationCallback> pending_presentation_callbacks_;
David Revemanef1cb082017-11-09 21:14:40397 std::list<PresentationCallback> presentation_callbacks_;
revemanb195f41d2015-11-19 22:16:48398
jbaumanf4c3f292016-06-11 00:57:33399 // This is the state that has yet to be committed.
400 State pending_state_;
revemanb195f41d2015-11-19 22:16:48401
jbaumanf4c3f292016-06-11 00:57:33402 // This is the state that has been committed.
403 State state_;
reveman7efa4b02016-01-06 08:29:54404
Dominik Laskowski57064702017-11-30 10:31:41405 // Cumulative input region of surface and its sub-surfaces.
406 cc::Region hit_test_region_;
407
reveman27fe2642015-11-20 06:33:39408 // The stack of sub-surfaces to take effect when Commit() is called.
409 // Bottom-most sub-surface at the front of the list and top-most sub-surface
410 // at the back.
411 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>;
412 using SubSurfaceEntryList = std::list<SubSurfaceEntry>;
413 SubSurfaceEntryList pending_sub_surfaces_;
Peng Huang583c9dc62017-07-27 23:38:28414 SubSurfaceEntryList sub_surfaces_;
reveman27fe2642015-11-20 06:33:39415
revemanced21f862015-11-24 00:42:49416 // The buffer that is currently set as content of surface.
jbauman45c06862016-06-23 19:35:02417 BufferAttachment current_buffer_;
revemanced21f862015-11-24 00:42:49418
jbauman2fdc0732016-06-07 00:55:36419 // The last resource that was sent to a surface.
Fady Samuel4f7f0fb32017-07-28 15:33:37420 viz::TransferableResource current_resource_;
jbauman2fdc0732016-06-07 00:55:36421
revemanca132dc2017-01-31 22:35:54422 // Whether the last resource that was sent to a surface has an alpha channel.
423 bool current_resource_has_alpha_ = false;
424
Alexandros Frantzis4ee9da52019-03-11 15:29:23425 // The acquire gpu fence to associate with the surface buffer when Commit()
426 // is called.
427 std::unique_ptr<gfx::GpuFence> pending_acquire_fence_;
428 // The acquire gpu fence that is currently associated with the surface buffer.
429 std::unique_ptr<gfx::GpuFence> acquire_fence_;
430
reveman27fe2642015-11-20 06:33:39431 // This is true if a call to Commit() as been made but
432 // CommitSurfaceHierarchy() has not yet been called.
Peng Huang76f5fd02017-09-01 00:59:39433 bool needs_commit_surface_ = false;
reveman27fe2642015-11-20 06:33:39434
Peng Huangc51f7aba2017-09-05 16:00:39435 // This is true if UpdateResources() should be called.
436 bool needs_update_resource_ = true;
437
Lloyd Pique0a3045f2017-09-15 23:34:12438 // The current buffer transform matrix. It specifies the transformation from
439 // normalized buffer coordinates to post-tranform buffer coordinates.
440 gfx::Transform buffer_transform_;
441
reveman7cadea42016-02-05 20:14:38442 // This is set when the compositing starts and passed to active frame
443 // callbacks when compositing successfully ends.
444 base::TimeTicks last_compositing_start_time_;
445
revemanb195f41d2015-11-19 22:16:48446 // This can be set to have some functions delegated. E.g. ShellSurface class
447 // can set this to handle Commit() and apply any double buffered state it
448 // maintains.
reveman2d3815d2016-06-26 20:13:25449 SurfaceDelegate* delegate_ = nullptr;
revemanb195f41d2015-11-19 22:16:48450
reveman27fe2642015-11-20 06:33:39451 // Surface observer list. Surface does not own the observers.
Trent Apteda250ec3ab2018-08-19 08:52:19452 base::ObserverList<SurfaceObserver, true>::Unchecked observers_;
reveman27fe2642015-11-20 06:33:39453
Eliot Courtneybb051d12018-12-15 02:41:31454 // Whether this surface is tracking occlusion for the client.
455 bool is_tracking_occlusion_ = false;
456
Dominik Laskowski638b1632019-06-28 20:59:02457#if defined(OS_CHROMEOS)
458 std::unique_ptr<ash::OutputProtectionDelegate> output_protection_;
459#endif // defined(OS_CHROMEOS)
460
Albert Chaulkfd08f9842019-10-11 15:26:14461 viz::SurfaceId first_embedded_surface_id_;
Albert Chaulk0adb8b8d2019-11-06 20:06:27462 viz::SurfaceId latest_embedded_surface_id_;
Albert Chaulkfd08f9842019-10-11 15:26:14463 base::RepeatingCallback<viz::SurfaceId()> get_current_surface_id_;
464
Albert Chaulk77191cc2019-12-19 21:57:50465 // The embedded surface is actually |embedded_surface_size_|. This is used
466 // for calculating clipping and scaling.
467 gfx::SizeF embedded_surface_size_;
468
revemanb195f41d2015-11-19 22:16:48469 DISALLOW_COPY_AND_ASSIGN(Surface);
470};
471
Fergus Dalla4293852019-07-26 07:13:47472class ScopedSurface {
473 public:
474 ScopedSurface(Surface* surface, SurfaceObserver* observer);
475 ~ScopedSurface();
476 Surface* get() { return surface_; }
477
478 private:
479 Surface* const surface_;
480 SurfaceObserver* const observer_;
481
482 DISALLOW_COPY_AND_ASSIGN(ScopedSurface);
483};
484
revemanb195f41d2015-11-19 22:16:48485} // namespace exo
486
487#endif // COMPONENTS_EXO_SURFACE_H_