reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 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 | #ifndef COMPONENTS_EXO_SURFACE_H_ |
| 6 | #define COMPONENTS_EXO_SURFACE_H_ |
| 7 | |
| 8 | #include <list> |
reveman | 70baca1 | 2016-05-31 20:35:30 | [diff] [blame] | 9 | #include <set> |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 10 | #include <utility> |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 11 | |
| 12 | #include "base/callback.h" |
| 13 | #include "base/macros.h" |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 16 | #include "base/observer_list.h" |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 17 | #include "cc/base/region.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 18 | #include "components/exo/layer_tree_frame_sink_holder.h" |
David Reveman | 93f67c0 | 2017-09-06 03:23:08 | [diff] [blame] | 19 | #include "components/exo/surface_delegate.h" |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 20 | #include "components/viz/common/frame_sinks/begin_frame_source.h" |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 21 | #include "components/viz/common/resources/transferable_resource.h" |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 22 | #include "third_party/skia/include/core/SkBlendMode.h" |
reveman | 4c94cf96 | 2015-12-03 06:49:43 | [diff] [blame] | 23 | #include "ui/aura/window.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 24 | #include "ui/gfx/geometry/rect.h" |
reveman | e295c66 | 2017-01-30 23:01:21 | [diff] [blame] | 25 | #include "ui/gfx/native_widget_types.h" |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 26 | #include "ui/gfx/transform.h" |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 27 | |
Raul Tambre | 038e96d | 2019-01-07 21:47:44 | [diff] [blame] | 28 | class SkPath; |
| 29 | |
Dominik Laskowski | 638b163 | 2019-06-28 20:59:02 | [diff] [blame] | 30 | namespace ash { |
| 31 | class OutputProtectionDelegate; |
| 32 | } |
| 33 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 34 | namespace base { |
| 35 | namespace trace_event { |
| 36 | class TracedValue; |
| 37 | } |
Nicholas Hollingum | bad8a05f6 | 2019-12-05 05:56:21 | [diff] [blame] | 38 | } // namespace base |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 39 | |
Alexandros Frantzis | 4ee9da5 | 2019-03-11 15:29:23 | [diff] [blame] | 40 | namespace gfx { |
Jeffrey Kardatzke | 0d7b831 | 2019-12-09 19:40:01 | [diff] [blame] | 41 | class ColorSpace; |
Alexandros Frantzis | 4ee9da5 | 2019-03-11 15:29:23 | [diff] [blame] | 42 | class GpuFence; |
| 43 | } |
| 44 | |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 45 | namespace viz { |
| 46 | class CompositorFrame; |
| 47 | } |
| 48 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 49 | namespace exo { |
| 50 | class Buffer; |
Albert Chaulk | 56e9658 | 2019-01-30 19:33:18 | [diff] [blame] | 51 | class FrameSinkResourceManager; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 52 | class SurfaceObserver; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 53 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 54 | namespace subtle { |
| 55 | class PropertyHelper; |
| 56 | } |
| 57 | |
David Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 58 | // Counter-clockwise rotations. |
| 59 | enum class Transform { NORMAL, ROTATE_90, ROTATE_180, ROTATE_270 }; |
| 60 | |
Ryo Hashimoto | 4e7c572f | 2019-04-18 05:55:56 | [diff] [blame] | 61 | // A property key to store the surface Id set by the client. |
| 62 | extern const ui::ClassProperty<int32_t>* const kClientSurfaceIdKey; |
| 63 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 64 | // This class represents a rectangular area that is displayed on the screen. |
| 65 | // It has a location, size and pixel contents. |
Hans Wennborg | af90ff1 | 2017-09-04 19:46:02 | [diff] [blame] | 66 | class Surface final : public ui::PropertyHandler { |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 67 | public: |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 68 | using PropertyDeallocator = void (*)(int64_t value); |
Mitsuru Oshima | 91322d5 | 2020-08-03 22:43:33 | [diff] [blame] | 69 | using LeaveEnterCallback = base::RepeatingCallback<void(int64_t, int64_t)>; |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 70 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 71 | Surface(); |
Ahmed Fakhry | 32f3c45 | 2019-08-01 16:36:34 | [diff] [blame] | 72 | ~Surface() override; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 73 | |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 74 | // Type-checking downcast routine. |
kinaba | d14ca03e | 2016-02-23 04:43:35 | [diff] [blame] | 75 | static Surface* AsSurface(const aura::Window* window); |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 76 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 77 | aura::Window* window() { return window_.get(); } |
| 78 | |
Mitsuru Oshima | 91322d5 | 2020-08-03 22:43:33 | [diff] [blame] | 79 | 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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 89 | // 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 Dall | a429385 | 2019-07-26 07:13:47 | [diff] [blame] | 92 | void Attach(Buffer* buffer, gfx::Vector2d offset); |
| 93 | |
| 94 | gfx::Vector2d GetBufferOffset(); |
| 95 | |
Alexandros Frantzis | 4ee9da5 | 2019-03-11 15:29:23 | [diff] [blame] | 96 | // Returns whether the surface has an uncommitted attached buffer. |
| 97 | bool HasPendingAttachedBuffer() const; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 98 | |
| 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 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 104 | // Request notification when it's a good time to produce a new frame. Useful |
| 105 | // for throttling redrawing operations, and driving animations. |
Ken Rockot | e3cd25a | 2019-12-21 22:28:04 | [diff] [blame] | 106 | using FrameCallback = |
| 107 | base::RepeatingCallback<void(base::TimeTicks frame_time)>; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 108 | void RequestFrameCallback(const FrameCallback& callback); |
| 109 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 110 | // Request notification when the next frame is displayed. Useful for |
| 111 | // throttling redrawing operations, and driving animations. |
| 112 | using PresentationCallback = |
Ken Rockot | e3cd25a | 2019-12-21 22:28:04 | [diff] [blame] | 113 | base::RepeatingCallback<void(const gfx::PresentationFeedback&)>; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 114 | void RequestPresentationCallback(const PresentationCallback& callback); |
| 115 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 116 | // This sets the region of the surface that contains opaque content. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 117 | void SetOpaqueRegion(const cc::Region& region); |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 118 | |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 119 | // This sets the region of the surface that can receive pointer and touch |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 120 | // events. The region is clipped to the surface bounds. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 121 | void SetInputRegion(const cc::Region& region); |
Scott Violet | db1f068 | 2018-08-30 19:19:46 | [diff] [blame] | 122 | const cc::Region& hit_test_region() const { return hit_test_region_; } |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 123 | |
Mike Reed | 2c570fa | 2018-01-11 21:59:22 | [diff] [blame] | 124 | // 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 Laskowski | 2d431641 | 2017-12-13 19:14:44 | [diff] [blame] | 128 | // 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 | |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 132 | // 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 Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 138 | // This sets the transformation used to interpret the contents of the buffer |
| 139 | // attached to the surface. |
| 140 | void SetBufferTransform(Transform transform); |
| 141 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 142 | // 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 Reveman | 8b43b35 | 2017-11-03 15:24:51 | [diff] [blame] | 149 | void OnSubSurfaceCommit(); |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 150 | |
reveman | 642d8c33 | 2016-02-19 19:55:44 | [diff] [blame] | 151 | // This sets the surface viewport for scaling. |
| 152 | void SetViewport(const gfx::Size& viewport); |
| 153 | |
reveman | 8e32390 | 2016-05-23 21:55:36 | [diff] [blame] | 154 | // This sets the surface crop rectangle. |
| 155 | void SetCrop(const gfx::RectF& crop); |
| 156 | |
reveman | 85b7a56 | 2016-03-17 23:27:32 | [diff] [blame] | 157 | // 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 | |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 161 | // This sets the blend mode that will be used when drawing the surface. |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 162 | void SetBlendMode(SkBlendMode blend_mode); |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 163 | |
| 164 | // This sets the alpha value that will be applied to the whole surface. |
| 165 | void SetAlpha(float alpha); |
| 166 | |
David Reveman | 93f67c0 | 2017-09-06 03:23:08 | [diff] [blame] | 167 | // Request that surface should have the specified frame type. |
| 168 | void SetFrame(SurfaceFrameType type); |
| 169 | |
David Reveman | 786d318 | 2017-12-20 22:04:33 | [diff] [blame] | 170 | // Request that surface should use a specific set of frame colors. |
| 171 | void SetFrameColors(SkColor active_color, SkColor inactive_color); |
| 172 | |
David Reveman | 21e2236d | 2018-04-12 06:01:10 | [diff] [blame] | 173 | // Request that surface should have a specific startup ID string. |
Tim Zheng | 08df566 | 2018-04-04 05:08:15 | [diff] [blame] | 174 | void SetStartupId(const char* startup_id); |
| 175 | |
David Reveman | 21e2236d | 2018-04-12 06:01:10 | [diff] [blame] | 176 | // Request that surface should have a specific application ID string. |
| 177 | void SetApplicationId(const char* application_id); |
| 178 | |
Chloe Pelling | 8a8acdeb | 2020-07-07 10:45:20 | [diff] [blame] | 179 | // 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 Kardatzke | 0d7b831 | 2019-12-09 19:40:01 | [diff] [blame] | 184 | // This sets the color space for the buffer for this surface. |
| 185 | void SetColorSpace(gfx::ColorSpace color_space); |
| 186 | |
David Reveman | 3271509 | 2017-12-05 18:24:11 | [diff] [blame] | 187 | // Request "parent" for surface. |
| 188 | void SetParent(Surface* parent, const gfx::Point& position); |
| 189 | |
Ryo Hashimoto | 8f10c88 | 2018-11-28 17:43:52 | [diff] [blame] | 190 | // 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 Chaulk | fd08f984 | 2019-10-11 15:26:14 | [diff] [blame] | 194 | // 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 Chaulk | 77191cc | 2019-12-19 21:57:50 | [diff] [blame] | 200 | // Set the size of the embedded surface, to allow proper scaling. |
| 201 | void SetEmbeddedSurfaceSize(const gfx::Size& size); |
| 202 | |
Alexandros Frantzis | 4ee9da5 | 2019-03-11 15:29:23 | [diff] [blame] | 203 | // 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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 209 | // Surface state (damage regions, attached buffers, etc.) is double-buffered. |
| 210 | // A Commit() call atomically applies all pending state, replacing the |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 211 | // current state. Commit() is not guaranteed to be synchronous. See |
| 212 | // CommitSurfaceHierarchy() below. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 213 | void Commit(); |
| 214 | |
David Reveman | 8b43b35 | 2017-11-03 15:24:51 | [diff] [blame] | 215 | // This will commit all pending state of the surface and its descendants by |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 216 | // recursively calling CommitSurfaceHierarchy() for each sub-surface. |
| 217 | // If |synchronized| is set to false, then synchronized surfaces should not |
| 218 | // commit pending state. |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 219 | void CommitSurfaceHierarchy(bool synchronized); |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 220 | |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 221 | // 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 Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 228 | void AppendSurfaceHierarchyContentsToFrame( |
| 229 | const gfx::Point& origin, |
| 230 | float device_scale_factor, |
Albert Chaulk | 56e9658 | 2019-01-30 19:33:18 | [diff] [blame] | 231 | FrameSinkResourceManager* resource_manager, |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 232 | viz::CompositorFrame* frame); |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 233 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 234 | // Returns true if surface is in synchronized mode. |
| 235 | bool IsSynchronized() const; |
| 236 | |
Dominik Laskowski | 14a16377 | 2018-02-09 19:25:18 | [diff] [blame] | 237 | // Returns true if surface should receive input events. |
| 238 | bool IsInputEnabled(Surface* surface) const; |
Dominik Laskowski | 3e2f9479 | 2017-12-15 00:27:10 | [diff] [blame] | 239 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 240 | // Returns false if the hit test region is empty. |
| 241 | bool HasHitTestRegion() const; |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 242 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 243 | // Returns true if |point| is inside the surface. |
| 244 | bool HitTest(const gfx::Point& point) const; |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 245 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 246 | // Sets |mask| to the path that delineates the hit test region of the surface. |
Raul Tambre | 038e96d | 2019-01-07 21:47:44 | [diff] [blame] | 247 | void GetHitTestMask(SkPath* mask) const; |
reveman | 4c94cf96 | 2015-12-03 06:49:43 | [diff] [blame] | 248 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 249 | // Set the surface delegate. |
| 250 | void SetSurfaceDelegate(SurfaceDelegate* delegate); |
| 251 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 252 | // 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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 261 | // Returns a trace value representing the state of the surface. |
dcheng | 31759da | 2016-04-21 01:26:31 | [diff] [blame] | 262 | std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 263 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame] | 264 | // Called when the begin frame source has changed. |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 265 | void SetBeginFrameSource(viz::BeginFrameSource* begin_frame_source); |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 266 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 267 | // Returns the active content size. |
Peng Huang | b07b065 | 2017-06-27 17:25:22 | [diff] [blame] | 268 | const gfx::Size& content_size() const { return content_size_; } |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 269 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 270 | // 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 | |
kaznacheev | 8e27059 | 2017-05-25 06:13:26 | [diff] [blame] | 277 | // 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 Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 283 | // Notify surface that resources and subsurfaces' resources have been lost. |
| 284 | void SurfaceHierarchyResourcesLost(); |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 285 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 286 | // Returns true if the surface's bounds should be filled opaquely. |
| 287 | bool FillsBoundsOpaquely() const; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 288 | |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 289 | bool HasPendingDamageForTesting(const gfx::Rect& damage) const { |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 290 | return pending_damage_.Contains(damage); |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 291 | } |
| 292 | |
Eliot Courtney | bb051d1 | 2018-12-15 02:41:31 | [diff] [blame] | 293 | // 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 Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 299 | // True if the window for this surface has its occlusion tracked. |
[email protected] | 82d399b0 | 2020-05-26 17:00:23 | [diff] [blame] | 300 | bool IsTrackingOcclusion(); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 301 | |
[email protected] | 9385573 | 2019-06-24 19:49:30 | [diff] [blame] | 302 | // Sets the |surface_hierarchy_content_bounds_|. |
| 303 | void SetSurfaceHierarchyContentBoundsForTest(const gfx::Rect& content_bounds); |
| 304 | |
Nicholas Hollingum | bad8a05f6 | 2019-12-05 05:56:21 | [diff] [blame] | 305 | // Requests that this surface should be made active (i.e. foregrounded). |
| 306 | void RequestActivation(); |
| 307 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 308 | private: |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 309 | struct State { |
| 310 | State(); |
| 311 | ~State(); |
| 312 | |
Lei Zhang | 1c9963ba | 2018-05-15 04:50:21 | [diff] [blame] | 313 | bool operator==(const State& other) const; |
| 314 | bool operator!=(const State& other) const { return !(*this == other); } |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 315 | |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 316 | cc::Region opaque_region; |
Mike Reed | 2c570fa | 2018-01-11 21:59:22 | [diff] [blame] | 317 | base::Optional<cc::Region> input_region; |
Dominik Laskowski | 2d431641 | 2017-12-13 19:14:44 | [diff] [blame] | 318 | int input_outset = 0; |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 319 | float buffer_scale = 1.0f; |
David Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 320 | Transform buffer_transform = Transform::NORMAL; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 321 | gfx::Size viewport; |
| 322 | gfx::RectF crop; |
| 323 | bool only_visible_on_secure_output = false; |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 324 | SkBlendMode blend_mode = SkBlendMode::kSrcOver; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 325 | float alpha = 1.0f; |
Fergus Dall | a429385 | 2019-07-26 07:13:47 | [diff] [blame] | 326 | gfx::Vector2d offset; |
Jeffrey Kardatzke | 0d7b831 | 2019-12-09 19:40:01 | [diff] [blame] | 327 | gfx::ColorSpace color_space; |
[email protected] | 82d399b0 | 2020-05-26 17:00:23 | [diff] [blame] | 328 | bool is_tracking_occlusion = false; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 329 | }; |
| 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 Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 339 | const gfx::Size& size() const; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 340 | void Reset(base::WeakPtr<Buffer> buffer); |
| 341 | |
| 342 | private: |
| 343 | base::WeakPtr<Buffer> buffer_; |
David Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 344 | gfx::Size size_; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 345 | |
| 346 | DISALLOW_COPY_AND_ASSIGN(BufferAttachment); |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 347 | }; |
| 348 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 349 | friend class subtle::PropertyHelper; |
| 350 | |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 351 | // 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 Chaulk | 56e9658 | 2019-01-30 19:33:18 | [diff] [blame] | 355 | void UpdateResource(FrameSinkResourceManager* resource_manager); |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 356 | |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 357 | // Updates buffer_transform_ to match the current buffer parameters. |
Zach Reizner | 8bcce6e | 2018-10-31 00:04:37 | [diff] [blame] | 358 | void UpdateBufferTransform(bool y_invert); |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 359 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 360 | // 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 Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 363 | float device_scale_factor, |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 364 | viz::CompositorFrame* frame); |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 365 | |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 366 | // Update surface content size base on current buffer size. |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 367 | void UpdateContentSize(); |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame] | 368 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 369 | // This returns true when the surface has some contents assigned to it. |
David Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 370 | bool has_contents() const { return !current_buffer_.size().IsEmpty(); } |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 371 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 372 | // This window has the layer which contains the Surface contents. |
| 373 | std::unique_ptr<aura::Window> window_; |
| 374 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 375 | // This true, if sub_surfaces_ has changes (order, position, etc). |
| 376 | bool sub_surfaces_changed_ = false; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 377 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 378 | // This is the size of the last committed contents. |
| 379 | gfx::Size content_size_; |
| 380 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 381 | // This is the bounds of the last committed surface hierarchy contents. |
| 382 | gfx::Rect surface_hierarchy_content_bounds_; |
| 383 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 384 | // This is true when Attach() has been called and new contents should take |
| 385 | // effect next time Commit() is called. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 386 | bool has_pending_contents_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 387 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 388 | // The buffer that will become the content of surface when Commit() is called. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 389 | BufferAttachment pending_buffer_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 390 | |
| 391 | // The damage region to schedule paint for when Commit() is called. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 392 | cc::Region pending_damage_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 393 | |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 394 | // The damage region which will be used by |
| 395 | // AppendSurfaceHierarchyContentsToFrame() to generate frame. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 396 | cc::Region damage_; |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 397 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 398 | // 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 |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 401 | // |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. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 403 | std::list<FrameCallback> pending_frame_callbacks_; |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 404 | std::list<FrameCallback> frame_callbacks_; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 405 | |
| 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 Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 414 | std::list<PresentationCallback> presentation_callbacks_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 415 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 416 | // This is the state that has yet to be committed. |
| 417 | State pending_state_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 418 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 419 | // This is the state that has been committed. |
| 420 | State state_; |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 421 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 422 | // Cumulative input region of surface and its sub-surfaces. |
| 423 | cc::Region hit_test_region_; |
| 424 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 425 | // 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 Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 431 | SubSurfaceEntryList sub_surfaces_; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 432 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 433 | // The buffer that is currently set as content of surface. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 434 | BufferAttachment current_buffer_; |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 435 | |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 436 | // The last resource that was sent to a surface. |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 437 | viz::TransferableResource current_resource_; |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 438 | |
reveman | ca132dc | 2017-01-31 22:35:54 | [diff] [blame] | 439 | // Whether the last resource that was sent to a surface has an alpha channel. |
| 440 | bool current_resource_has_alpha_ = false; |
| 441 | |
Alexandros Frantzis | 4ee9da5 | 2019-03-11 15:29:23 | [diff] [blame] | 442 | // 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 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 448 | // This is true if a call to Commit() as been made but |
| 449 | // CommitSurfaceHierarchy() has not yet been called. |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 450 | bool needs_commit_surface_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 451 | |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 452 | // This is true if UpdateResources() should be called. |
| 453 | bool needs_update_resource_ = true; |
| 454 | |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 455 | // 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 | |
reveman | 7cadea4 | 2016-02-05 20:14:38 | [diff] [blame] | 459 | // 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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 463 | // 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. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 466 | SurfaceDelegate* delegate_ = nullptr; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 467 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 468 | // Surface observer list. Surface does not own the observers. |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 469 | base::ObserverList<SurfaceObserver, true>::Unchecked observers_; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 470 | |
Dominik Laskowski | 638b163 | 2019-06-28 20:59:02 | [diff] [blame] | 471 | #if defined(OS_CHROMEOS) |
| 472 | std::unique_ptr<ash::OutputProtectionDelegate> output_protection_; |
| 473 | #endif // defined(OS_CHROMEOS) |
| 474 | |
Albert Chaulk | fd08f984 | 2019-10-11 15:26:14 | [diff] [blame] | 475 | viz::SurfaceId first_embedded_surface_id_; |
Albert Chaulk | 0adb8b8d | 2019-11-06 20:06:27 | [diff] [blame] | 476 | viz::SurfaceId latest_embedded_surface_id_; |
Albert Chaulk | fd08f984 | 2019-10-11 15:26:14 | [diff] [blame] | 477 | base::RepeatingCallback<viz::SurfaceId()> get_current_surface_id_; |
| 478 | |
Albert Chaulk | 77191cc | 2019-12-19 21:57:50 | [diff] [blame] | 479 | // The embedded surface is actually |embedded_surface_size_|. This is used |
| 480 | // for calculating clipping and scaling. |
Albert Chaulk | fbbbe23 | 2020-01-14 00:16:04 | [diff] [blame] | 481 | gfx::Size embedded_surface_size_; |
Albert Chaulk | 77191cc | 2019-12-19 21:57:50 | [diff] [blame] | 482 | |
Mitsuru Oshima | 91322d5 | 2020-08-03 22:43:33 | [diff] [blame] | 483 | LeaveEnterCallback leave_enter_callback_; |
| 484 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(Surface); |
| 486 | }; |
| 487 | |
Fergus Dall | a429385 | 2019-07-26 07:13:47 | [diff] [blame] | 488 | class 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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 501 | } // namespace exo |
| 502 | |
| 503 | #endif // COMPONENTS_EXO_SURFACE_H_ |