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 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 30 | namespace base { |
| 31 | namespace trace_event { |
| 32 | class TracedValue; |
| 33 | } |
| 34 | } |
| 35 | |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 36 | namespace viz { |
| 37 | class CompositorFrame; |
| 38 | } |
| 39 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 40 | namespace exo { |
| 41 | class Buffer; |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 42 | class LayerTreeFrameSinkHolder; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 43 | class SurfaceObserver; |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 44 | class Surface; |
| 45 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 46 | namespace subtle { |
| 47 | class PropertyHelper; |
| 48 | } |
| 49 | |
David Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 50 | // Counter-clockwise rotations. |
| 51 | enum class Transform { NORMAL, ROTATE_90, ROTATE_180, ROTATE_270 }; |
| 52 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 53 | // This class represents a rectangular area that is displayed on the screen. |
| 54 | // It has a location, size and pixel contents. |
Hans Wennborg | af90ff1 | 2017-09-04 19:46:02 | [diff] [blame] | 55 | class Surface final : public ui::PropertyHandler { |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 56 | public: |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 57 | using PropertyDeallocator = void (*)(int64_t value); |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 58 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 59 | Surface(); |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 60 | ~Surface(); |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 61 | |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 62 | // Type-checking downcast routine. |
kinaba | d14ca03e | 2016-02-23 04:43:35 | [diff] [blame] | 63 | static Surface* AsSurface(const aura::Window* window); |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 64 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 65 | aura::Window* window() { return window_.get(); } |
| 66 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 67 | // Set a buffer as the content of this surface. A buffer can only be attached |
| 68 | // to one surface at a time. |
| 69 | void Attach(Buffer* buffer); |
| 70 | |
| 71 | // Describe the regions where the pending buffer is different from the |
| 72 | // current surface contents, and where the surface therefore needs to be |
| 73 | // repainted. |
| 74 | void Damage(const gfx::Rect& rect); |
| 75 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 76 | // Request notification when it's a good time to produce a new frame. Useful |
| 77 | // for throttling redrawing operations, and driving animations. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 78 | using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>; |
| 79 | void RequestFrameCallback(const FrameCallback& callback); |
| 80 | |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 81 | // Request notification when the next frame is displayed. Useful for |
| 82 | // throttling redrawing operations, and driving animations. |
| 83 | using PresentationCallback = |
Sadrul Habib Chowdhury | b62a9730 | 2018-06-06 03:33:48 | [diff] [blame] | 84 | base::Callback<void(const gfx::PresentationFeedback&)>; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 85 | void RequestPresentationCallback(const PresentationCallback& callback); |
| 86 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 87 | // This sets the region of the surface that contains opaque content. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 88 | void SetOpaqueRegion(const cc::Region& region); |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 89 | |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 90 | // This sets the region of the surface that can receive pointer and touch |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 91 | // events. The region is clipped to the surface bounds. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 92 | void SetInputRegion(const cc::Region& region); |
Scott Violet | db1f068 | 2018-08-30 19:19:46 | [diff] [blame] | 93 | const cc::Region& hit_test_region() const { return hit_test_region_; } |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 94 | |
Mike Reed | 2c570fa | 2018-01-11 21:59:22 | [diff] [blame] | 95 | // This resets the region of the surface that can receive pointer and touch |
| 96 | // events to be wide-open. This will be clipped to the surface bounds. |
| 97 | void ResetInputRegion(); |
| 98 | |
Dominik Laskowski | 2d431641 | 2017-12-13 19:14:44 | [diff] [blame] | 99 | // This overrides the input region to the surface bounds with an outset. |
| 100 | // TODO(domlaskowski): Remove this once client-driven resizing is removed. |
| 101 | void SetInputOutset(int outset); |
| 102 | |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 103 | // This sets the scaling factor used to interpret the contents of the buffer |
| 104 | // attached to the surface. Note that if the scale is larger than 1, then you |
| 105 | // have to attach a buffer that is larger (by a factor of scale in each |
| 106 | // dimension) than the desired surface size. |
| 107 | void SetBufferScale(float scale); |
| 108 | |
David Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 109 | // This sets the transformation used to interpret the contents of the buffer |
| 110 | // attached to the surface. |
| 111 | void SetBufferTransform(Transform transform); |
| 112 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 113 | // Functions that control sub-surface state. All sub-surface state is |
| 114 | // double-buffered and will be applied when Commit() is called. |
| 115 | void AddSubSurface(Surface* sub_surface); |
| 116 | void RemoveSubSurface(Surface* sub_surface); |
| 117 | void SetSubSurfacePosition(Surface* sub_surface, const gfx::Point& position); |
| 118 | void PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference); |
| 119 | void PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling); |
David Reveman | 8b43b35 | 2017-11-03 15:24:51 | [diff] [blame] | 120 | void OnSubSurfaceCommit(); |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 121 | |
reveman | 642d8c33 | 2016-02-19 19:55:44 | [diff] [blame] | 122 | // This sets the surface viewport for scaling. |
| 123 | void SetViewport(const gfx::Size& viewport); |
| 124 | |
reveman | 8e32390 | 2016-05-23 21:55:36 | [diff] [blame] | 125 | // This sets the surface crop rectangle. |
| 126 | void SetCrop(const gfx::RectF& crop); |
| 127 | |
reveman | 85b7a56 | 2016-03-17 23:27:32 | [diff] [blame] | 128 | // This sets the only visible on secure output flag, preventing it from |
| 129 | // appearing in screenshots or from being viewed on non-secure displays. |
| 130 | void SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output); |
| 131 | |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 132 | // This sets the blend mode that will be used when drawing the surface. |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 133 | void SetBlendMode(SkBlendMode blend_mode); |
reveman | fca687e | 2016-05-10 21:44:48 | [diff] [blame] | 134 | |
| 135 | // This sets the alpha value that will be applied to the whole surface. |
| 136 | void SetAlpha(float alpha); |
| 137 | |
David Reveman | 93f67c0 | 2017-09-06 03:23:08 | [diff] [blame] | 138 | // Request that surface should have the specified frame type. |
| 139 | void SetFrame(SurfaceFrameType type); |
| 140 | |
David Reveman | 786d318 | 2017-12-20 22:04:33 | [diff] [blame] | 141 | // Request that surface should use a specific set of frame colors. |
| 142 | void SetFrameColors(SkColor active_color, SkColor inactive_color); |
| 143 | |
David Reveman | 21e2236d | 2018-04-12 06:01:10 | [diff] [blame] | 144 | // Request that surface should have a specific startup ID string. |
Tim Zheng | 08df566 | 2018-04-04 05:08:15 | [diff] [blame] | 145 | void SetStartupId(const char* startup_id); |
| 146 | |
David Reveman | 21e2236d | 2018-04-12 06:01:10 | [diff] [blame] | 147 | // Request that surface should have a specific application ID string. |
| 148 | void SetApplicationId(const char* application_id); |
| 149 | |
David Reveman | 3271509 | 2017-12-05 18:24:11 | [diff] [blame] | 150 | // Request "parent" for surface. |
| 151 | void SetParent(Surface* parent, const gfx::Point& position); |
| 152 | |
Ryo Hashimoto | 8f10c88 | 2018-11-28 17:43:52 | [diff] [blame] | 153 | // Request that surface should have a specific ID assigned by client. |
| 154 | void SetClientSurfaceId(int32_t client_surface_id); |
| 155 | int32_t GetClientSurfaceId() const; |
| 156 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 157 | // Surface state (damage regions, attached buffers, etc.) is double-buffered. |
| 158 | // A Commit() call atomically applies all pending state, replacing the |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 159 | // current state. Commit() is not guaranteed to be synchronous. See |
| 160 | // CommitSurfaceHierarchy() below. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 161 | void Commit(); |
| 162 | |
David Reveman | 8b43b35 | 2017-11-03 15:24:51 | [diff] [blame] | 163 | // This will commit all pending state of the surface and its descendants by |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 164 | // recursively calling CommitSurfaceHierarchy() for each sub-surface. |
| 165 | // If |synchronized| is set to false, then synchronized surfaces should not |
| 166 | // commit pending state. |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 167 | void CommitSurfaceHierarchy(bool synchronized); |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 168 | |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 169 | // This will append current callbacks for surface and its descendants to |
| 170 | // |frame_callbacks| and |presentation_callbacks|. |
| 171 | void AppendSurfaceHierarchyCallbacks( |
| 172 | std::list<FrameCallback>* frame_callbacks, |
| 173 | std::list<PresentationCallback>* presentation_callbacks); |
| 174 | |
| 175 | // This will append contents for surface and its descendants to frame. |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 176 | void AppendSurfaceHierarchyContentsToFrame( |
| 177 | const gfx::Point& origin, |
| 178 | float device_scale_factor, |
| 179 | LayerTreeFrameSinkHolder* frame_sink_holder, |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 180 | viz::CompositorFrame* frame); |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 181 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 182 | // Returns true if surface is in synchronized mode. |
| 183 | bool IsSynchronized() const; |
| 184 | |
Dominik Laskowski | 14a16377 | 2018-02-09 19:25:18 | [diff] [blame] | 185 | // Returns true if surface should receive input events. |
| 186 | bool IsInputEnabled(Surface* surface) const; |
Dominik Laskowski | 3e2f9479 | 2017-12-15 00:27:10 | [diff] [blame] | 187 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 188 | // Returns false if the hit test region is empty. |
| 189 | bool HasHitTestRegion() const; |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 190 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 191 | // Returns true if |point| is inside the surface. |
| 192 | bool HitTest(const gfx::Point& point) const; |
reveman | 2966d770 | 2016-02-12 02:09:54 | [diff] [blame] | 193 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 194 | // 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^] | 195 | void GetHitTestMask(SkPath* mask) const; |
reveman | 4c94cf96 | 2015-12-03 06:49:43 | [diff] [blame] | 196 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 197 | // Set the surface delegate. |
| 198 | void SetSurfaceDelegate(SurfaceDelegate* delegate); |
| 199 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 200 | // Returns true if surface has been assigned a surface delegate. |
| 201 | bool HasSurfaceDelegate() const; |
| 202 | |
| 203 | // Surface does not own observers. It is the responsibility of the observer |
| 204 | // to remove itself when it is done observing. |
| 205 | void AddSurfaceObserver(SurfaceObserver* observer); |
| 206 | void RemoveSurfaceObserver(SurfaceObserver* observer); |
| 207 | bool HasSurfaceObserver(const SurfaceObserver* observer) const; |
| 208 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 209 | // Returns a trace value representing the state of the surface. |
dcheng | 31759da | 2016-04-21 01:26:31 | [diff] [blame] | 210 | std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 211 | |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame] | 212 | // Called when the begin frame source has changed. |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 213 | void SetBeginFrameSource(viz::BeginFrameSource* begin_frame_source); |
jbauman | bd9586a9 | 2016-05-28 01:09:03 | [diff] [blame] | 214 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 215 | // Returns the active content size. |
Peng Huang | b07b065 | 2017-06-27 17:25:22 | [diff] [blame] | 216 | const gfx::Size& content_size() const { return content_size_; } |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 217 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 218 | // Returns the active content bounds for surface hierarchy. ie. the bounding |
| 219 | // box of the surface and its descendants, in the local coordinate space of |
| 220 | // the surface. |
| 221 | const gfx::Rect& surface_hierarchy_content_bounds() const { |
| 222 | return surface_hierarchy_content_bounds_; |
| 223 | } |
| 224 | |
kaznacheev | 8e27059 | 2017-05-25 06:13:26 | [diff] [blame] | 225 | // Returns true if the associated window is in 'stylus-only' mode. |
| 226 | bool IsStylusOnly(); |
| 227 | |
| 228 | // Enables 'stylus-only' mode for the associated window. |
| 229 | void SetStylusOnly(); |
| 230 | |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 231 | // Notify surface that resources and subsurfaces' resources have been lost. |
| 232 | void SurfaceHierarchyResourcesLost(); |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 233 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 234 | // Returns true if the surface's bounds should be filled opaquely. |
| 235 | bool FillsBoundsOpaquely() const; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 236 | |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 237 | bool HasPendingDamageForTesting(const gfx::Rect& damage) const { |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 238 | return pending_damage_.Contains(damage); |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 239 | } |
| 240 | |
Eliot Courtney | bb051d1 | 2018-12-15 02:41:31 | [diff] [blame] | 241 | // Set occlusion tracking region for surface. |
| 242 | void SetOcclusionTracking(bool tracking); |
| 243 | |
| 244 | // Triggers sending an occlusion update to observers. |
| 245 | void OnWindowOcclusionChanged(); |
| 246 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 247 | private: |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 248 | struct State { |
| 249 | State(); |
| 250 | ~State(); |
| 251 | |
Lei Zhang | 1c9963ba | 2018-05-15 04:50:21 | [diff] [blame] | 252 | bool operator==(const State& other) const; |
| 253 | bool operator!=(const State& other) const { return !(*this == other); } |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 254 | |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 255 | cc::Region opaque_region; |
Mike Reed | 2c570fa | 2018-01-11 21:59:22 | [diff] [blame] | 256 | base::Optional<cc::Region> input_region; |
Dominik Laskowski | 2d431641 | 2017-12-13 19:14:44 | [diff] [blame] | 257 | int input_outset = 0; |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 258 | float buffer_scale = 1.0f; |
David Reveman | fca309b | 2017-08-24 18:18:11 | [diff] [blame] | 259 | Transform buffer_transform = Transform::NORMAL; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 260 | gfx::Size viewport; |
| 261 | gfx::RectF crop; |
| 262 | bool only_visible_on_secure_output = false; |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 263 | SkBlendMode blend_mode = SkBlendMode::kSrcOver; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 264 | float alpha = 1.0f; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 265 | }; |
| 266 | class BufferAttachment { |
| 267 | public: |
| 268 | BufferAttachment(); |
| 269 | ~BufferAttachment(); |
| 270 | |
| 271 | BufferAttachment& operator=(BufferAttachment&& buffer); |
| 272 | |
| 273 | base::WeakPtr<Buffer>& buffer(); |
| 274 | const base::WeakPtr<Buffer>& buffer() const; |
David Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 275 | const gfx::Size& size() const; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 276 | void Reset(base::WeakPtr<Buffer> buffer); |
| 277 | |
| 278 | private: |
| 279 | base::WeakPtr<Buffer> buffer_; |
David Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 280 | gfx::Size size_; |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 281 | |
| 282 | DISALLOW_COPY_AND_ASSIGN(BufferAttachment); |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 283 | }; |
| 284 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 285 | friend class subtle::PropertyHelper; |
| 286 | |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 287 | // Updates current_resource_ with a new resource id corresponding to the |
| 288 | // contents of the attached buffer (or id 0, if no buffer is attached). |
| 289 | // UpdateSurface must be called afterwards to ensure the release callback |
| 290 | // will be called. |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 291 | void UpdateResource(LayerTreeFrameSinkHolder* frame_sink_holder); |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 292 | |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 293 | // Updates buffer_transform_ to match the current buffer parameters. |
Zach Reizner | 8bcce6e | 2018-10-31 00:04:37 | [diff] [blame] | 294 | void UpdateBufferTransform(bool y_invert); |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 295 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 296 | // Puts the current surface into a draw quad, and appends the draw quads into |
| 297 | // the |frame|. |
| 298 | void AppendContentsToFrame(const gfx::Point& origin, |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 299 | float device_scale_factor, |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 300 | viz::CompositorFrame* frame); |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 301 | |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 302 | // Update surface content size base on current buffer size. |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 303 | void UpdateContentSize(); |
eseckler | 599d86bb | 2017-03-15 09:02:55 | [diff] [blame] | 304 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 305 | // This returns true when the surface has some contents assigned to it. |
David Reveman | e6e2334 | 2017-11-07 06:18:06 | [diff] [blame] | 306 | bool has_contents() const { return !current_buffer_.size().IsEmpty(); } |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 307 | |
jbauman | e352625 | 2016-06-09 18:43:05 | [diff] [blame] | 308 | // This window has the layer which contains the Surface contents. |
| 309 | std::unique_ptr<aura::Window> window_; |
| 310 | |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 311 | // This true, if sub_surfaces_ has changes (order, position, etc). |
| 312 | bool sub_surfaces_changed_ = false; |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 313 | |
jbauman | b362a89 | 2016-06-17 03:30:56 | [diff] [blame] | 314 | // This is the size of the last committed contents. |
| 315 | gfx::Size content_size_; |
| 316 | |
David Reveman | 7a126ba | 2017-11-09 17:17:41 | [diff] [blame] | 317 | // This is the bounds of the last committed surface hierarchy contents. |
| 318 | gfx::Rect surface_hierarchy_content_bounds_; |
| 319 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 320 | // This is true when Attach() has been called and new contents should take |
| 321 | // effect next time Commit() is called. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 322 | bool has_pending_contents_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 323 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 324 | // The buffer that will become the content of surface when Commit() is called. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 325 | BufferAttachment pending_buffer_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 326 | |
| 327 | // The damage region to schedule paint for when Commit() is called. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 328 | cc::Region pending_damage_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 329 | |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 330 | // The damage region which will be used by |
| 331 | // AppendSurfaceHierarchyContentsToFrame() to generate frame. |
Dominik Laskowski | 0dcf9135 | 2017-11-29 19:21:35 | [diff] [blame] | 332 | cc::Region damage_; |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 333 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 334 | // These lists contains the callbacks to notify the client when it is a good |
| 335 | // time to start producing a new frame. These callbacks move to |
| 336 | // |frame_callbacks_| when Commit() is called. Later they are moved to |
reveman | 15aee28 | 2016-11-04 19:09:20 | [diff] [blame] | 337 | // |active_frame_callbacks_| when the effect of the Commit() is scheduled to |
| 338 | // be drawn. They fire at the first begin frame notification after this. |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 339 | std::list<FrameCallback> pending_frame_callbacks_; |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 340 | std::list<FrameCallback> frame_callbacks_; |
reveman | 211cf80 | 2017-01-10 00:30:59 | [diff] [blame] | 341 | |
| 342 | // These lists contains the callbacks to notify the client when surface |
| 343 | // contents have been presented. These callbacks move to |
| 344 | // |presentation_callbacks_| when Commit() is called. Later they are moved to |
| 345 | // |swapping_presentation_callbacks_| when the effect of the Commit() is |
| 346 | // scheduled to be drawn and then moved to |swapped_presentation_callbacks_| |
| 347 | // after receiving VSync parameters update for the previous frame. They fire |
| 348 | // at the next VSync parameters update after that. |
| 349 | std::list<PresentationCallback> pending_presentation_callbacks_; |
David Reveman | ef1cb08 | 2017-11-09 21:14:40 | [diff] [blame] | 350 | std::list<PresentationCallback> presentation_callbacks_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 351 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 352 | // This is the state that has yet to be committed. |
| 353 | State pending_state_; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 354 | |
jbauman | f4c3f29 | 2016-06-11 00:57:33 | [diff] [blame] | 355 | // This is the state that has been committed. |
| 356 | State state_; |
reveman | 7efa4b0 | 2016-01-06 08:29:54 | [diff] [blame] | 357 | |
Dominik Laskowski | 5706470 | 2017-11-30 10:31:41 | [diff] [blame] | 358 | // Cumulative input region of surface and its sub-surfaces. |
| 359 | cc::Region hit_test_region_; |
| 360 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 361 | // The stack of sub-surfaces to take effect when Commit() is called. |
| 362 | // Bottom-most sub-surface at the front of the list and top-most sub-surface |
| 363 | // at the back. |
| 364 | using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; |
| 365 | using SubSurfaceEntryList = std::list<SubSurfaceEntry>; |
| 366 | SubSurfaceEntryList pending_sub_surfaces_; |
Peng Huang | 583c9dc6 | 2017-07-27 23:38:28 | [diff] [blame] | 367 | SubSurfaceEntryList sub_surfaces_; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 368 | |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 369 | // The buffer that is currently set as content of surface. |
jbauman | 45c0686 | 2016-06-23 19:35:02 | [diff] [blame] | 370 | BufferAttachment current_buffer_; |
reveman | ced21f8 | 2015-11-24 00:42:49 | [diff] [blame] | 371 | |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 372 | // The last resource that was sent to a surface. |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 373 | viz::TransferableResource current_resource_; |
jbauman | 2fdc073 | 2016-06-07 00:55:36 | [diff] [blame] | 374 | |
reveman | ca132dc | 2017-01-31 22:35:54 | [diff] [blame] | 375 | // Whether the last resource that was sent to a surface has an alpha channel. |
| 376 | bool current_resource_has_alpha_ = false; |
| 377 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 378 | // This is true if a call to Commit() as been made but |
| 379 | // CommitSurfaceHierarchy() has not yet been called. |
Peng Huang | 76f5fd0 | 2017-09-01 00:59:39 | [diff] [blame] | 380 | bool needs_commit_surface_ = false; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 381 | |
Peng Huang | c51f7aba | 2017-09-05 16:00:39 | [diff] [blame] | 382 | // This is true if UpdateResources() should be called. |
| 383 | bool needs_update_resource_ = true; |
| 384 | |
Lloyd Pique | 0a3045f | 2017-09-15 23:34:12 | [diff] [blame] | 385 | // The current buffer transform matrix. It specifies the transformation from |
| 386 | // normalized buffer coordinates to post-tranform buffer coordinates. |
| 387 | gfx::Transform buffer_transform_; |
| 388 | |
reveman | 7cadea4 | 2016-02-05 20:14:38 | [diff] [blame] | 389 | // This is set when the compositing starts and passed to active frame |
| 390 | // callbacks when compositing successfully ends. |
| 391 | base::TimeTicks last_compositing_start_time_; |
| 392 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 393 | // This can be set to have some functions delegated. E.g. ShellSurface class |
| 394 | // can set this to handle Commit() and apply any double buffered state it |
| 395 | // maintains. |
reveman | 2d3815d | 2016-06-26 20:13:25 | [diff] [blame] | 396 | SurfaceDelegate* delegate_ = nullptr; |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 397 | |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 398 | // Surface observer list. Surface does not own the observers. |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 399 | base::ObserverList<SurfaceObserver, true>::Unchecked observers_; |
reveman | 27fe264 | 2015-11-20 06:33:39 | [diff] [blame] | 400 | |
Eliot Courtney | bb051d1 | 2018-12-15 02:41:31 | [diff] [blame] | 401 | // Whether this surface is tracking occlusion for the client. |
| 402 | bool is_tracking_occlusion_ = false; |
| 403 | |
reveman | b195f41d | 2015-11-19 22:16:48 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(Surface); |
| 405 | }; |
| 406 | |
| 407 | } // namespace exo |
| 408 | |
| 409 | #endif // COMPONENTS_EXO_SURFACE_H_ |