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

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

Issue 2083853002: exo: Recreate Surface resources on context lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_EXO_SURFACE_H_ 5 #ifndef COMPONENTS_EXO_SURFACE_H_
6 #define COMPONENTS_EXO_SURFACE_H_ 6 #define COMPONENTS_EXO_SURFACE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "cc/resources/transferable_resource.h" 18 #include "cc/resources/transferable_resource.h"
19 #include "cc/surfaces/surface_factory_client.h" 19 #include "cc/surfaces/surface_factory_client.h"
20 #include "third_party/skia/include/core/SkRegion.h" 20 #include "third_party/skia/include/core/SkRegion.h"
21 #include "third_party/skia/include/core/SkXfermode.h" 21 #include "third_party/skia/include/core/SkXfermode.h"
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/compositor/compositor.h"
23 #include "ui/compositor/layer_owner_delegate.h" 24 #include "ui/compositor/layer_owner_delegate.h"
24 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
25 26
26 namespace base { 27 namespace base {
27 namespace trace_event { 28 namespace trace_event {
28 class TracedValue; 29 class TracedValue;
29 } 30 }
30 } 31 }
31 32
32 namespace cc { 33 namespace cc {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 std::pair<scoped_refptr<SurfaceFactoryOwner>, 80 std::pair<scoped_refptr<SurfaceFactoryOwner>,
80 std::unique_ptr<cc::SingleReleaseCallback>>> 81 std::unique_ptr<cc::SingleReleaseCallback>>>
81 release_callbacks_; 82 release_callbacks_;
82 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; 83 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_;
83 std::unique_ptr<cc::SurfaceFactory> surface_factory_; 84 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
84 Surface* surface_; 85 Surface* surface_;
85 }; 86 };
86 87
87 // This class represents a rectangular area that is displayed on the screen. 88 // This class represents a rectangular area that is displayed on the screen.
88 // It has a location, size and pixel contents. 89 // It has a location, size and pixel contents.
89 class Surface : public ui::LayerOwnerDelegate { 90 class Surface : public ui::LayerOwnerDelegate,
91 public ui::ContextFactoryObserver {
90 public: 92 public:
91 typedef void (*PropertyDeallocator)(int64_t value); 93 typedef void (*PropertyDeallocator)(int64_t value);
92 94
93 Surface(); 95 Surface();
94 ~Surface() override; 96 ~Surface() override;
95 97
96 // Type-checking downcast routine. 98 // Type-checking downcast routine.
97 static Surface* AsSurface(const aura::Window* window); 99 static Surface* AsSurface(const aura::Window* window);
98 100
99 aura::Window* window() { return window_.get(); } 101 aura::Window* window() { return window_.get(); }
100 102
103 cc::SurfaceId surface_id() const { return surface_id_; }
104
101 // Set a buffer as the content of this surface. A buffer can only be attached 105 // Set a buffer as the content of this surface. A buffer can only be attached
102 // to one surface at a time. 106 // to one surface at a time.
103 void Attach(Buffer* buffer); 107 void Attach(Buffer* buffer);
104 108
105 // Describe the regions where the pending buffer is different from the 109 // Describe the regions where the pending buffer is different from the
106 // current surface contents, and where the surface therefore needs to be 110 // current surface contents, and where the surface therefore needs to be
107 // repainted. 111 // repainted.
108 void Damage(const gfx::Rect& rect); 112 void Damage(const gfx::Rect& rect);
109 113
110 // Request notification when the next frame is displayed. Useful for 114 // Request notification when the next frame is displayed. Useful for
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // Returns a trace value representing the state of the surface. 203 // Returns a trace value representing the state of the surface.
200 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; 204 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const;
201 205
202 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { 206 bool HasPendingDamageForTesting(const gfx::Rect& damage) const {
203 return pending_damage_.contains(gfx::RectToSkIRect(damage)); 207 return pending_damage_.contains(gfx::RectToSkIRect(damage));
204 } 208 }
205 209
206 // Overridden from ui::LayerOwnerDelegate: 210 // Overridden from ui::LayerOwnerDelegate:
207 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; 211 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override;
208 212
213 // Overridden from ui::ContextFactoryObserver.
214 void OnLostResources() override;
215
209 void WillDraw(cc::SurfaceId surface_id); 216 void WillDraw(cc::SurfaceId surface_id);
210 217
211 // Check whether this Surface and its children need to create new cc::Surface 218 // Check whether this Surface and its children need to create new cc::Surface
212 // IDs for their contents next time they get new buffer contents. 219 // IDs for their contents next time they get new buffer contents.
213 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 220 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
214 221
215 gfx::Size content_size() const { return content_size_; } 222 gfx::Size content_size() const { return content_size_; }
216 223
217 // Sets the |value| of the given surface |property|. Setting to the default 224 // Sets the |value| of the given surface |property|. Setting to the default
218 // value (e.g., NULL) removes the property. The caller is responsible for the 225 // value (e.g., NULL) removes the property. The caller is responsible for the
(...skipping 20 matching lines...) Expand all
239 bool operator!=(const State& other) { return !(*this == other); } 246 bool operator!=(const State& other) { return !(*this == other); }
240 247
241 SkRegion opaque_region; 248 SkRegion opaque_region;
242 SkRegion input_region; 249 SkRegion input_region;
243 float buffer_scale = 1.f; 250 float buffer_scale = 1.f;
244 gfx::Size viewport; 251 gfx::Size viewport;
245 gfx::RectF crop; 252 gfx::RectF crop;
246 bool only_visible_on_secure_output = false; 253 bool only_visible_on_secure_output = false;
247 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode; 254 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
248 float alpha = 1.0f; 255 float alpha = 1.0f;
249 ; 256 };
257 class BufferAttachment {
258 public:
259 BufferAttachment();
260 ~BufferAttachment();
261
262 base::WeakPtr<Buffer>& buffer();
263 const base::WeakPtr<Buffer>& buffer() const;
264 void Reset(base::WeakPtr<Buffer> buffer);
265
266 private:
267 base::WeakPtr<Buffer> buffer_;
268 DISALLOW_COPY_AND_ASSIGN(BufferAttachment);
reveman 2016/06/23 00:44:39 nit: blank line before this
250 }; 269 };
251 270
252 friend class subtle::PropertyHelper; 271 friend class subtle::PropertyHelper;
253 272
254 bool needs_commit_surface_hierarchy() const { 273 bool needs_commit_surface_hierarchy() const {
255 return needs_commit_surface_hierarchy_; 274 return needs_commit_surface_hierarchy_;
256 } 275 }
257 276
258 // Returns true if this surface or any child surface needs a commit and has 277 // Returns true if this surface or any child surface needs a commit and has
259 // has_pending_layer_changes_ true. 278 // has_pending_layer_changes_ true.
260 bool HasLayerHierarchyChanged() const; 279 bool HasLayerHierarchyChanged() const;
261 280
262 // Sets that all children must create new cc::SurfaceIds for their contents. 281 // Sets that all children must create new cc::SurfaceIds for their contents.
263 void SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 282 void SetSurfaceHierarchyNeedsCommitToNewSurfaces();
264 283
265 // Set SurfaceLayer contents to the current buffer. 284 // Set SurfaceLayer contents to the current buffer.
266 void SetSurfaceLayerContents(ui::Layer* layer); 285 void SetSurfaceLayerContents(ui::Layer* layer);
267 286
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.
291 void UpdateResource(bool client_usage);
292
293 // Updates the current Surface with a new frame referring to the resource in
294 // current_resource_.
295 void UpdateSurface(bool for_commit);
reveman 2016/06/23 00:44:39 nit: s/for_commit/full_damage/
296
268 int64_t SetPropertyInternal(const void* key, 297 int64_t SetPropertyInternal(const void* key,
269 const char* name, 298 const char* name,
270 PropertyDeallocator deallocator, 299 PropertyDeallocator deallocator,
271 int64_t value, 300 int64_t value,
272 int64_t default_value); 301 int64_t default_value);
273 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; 302 int64_t GetPropertyInternal(const void* key, int64_t default_value) const;
274 303
275 // This returns true when the surface has some contents assigned to it. 304 // This returns true when the surface has some contents assigned to it.
276 bool has_contents() const { return !!current_buffer_; } 305 bool has_contents() const { return !!current_buffer_.buffer(); }
277 306
278 // This window has the layer which contains the Surface contents. 307 // This window has the layer which contains the Surface contents.
279 std::unique_ptr<aura::Window> window_; 308 std::unique_ptr<aura::Window> window_;
280 309
281 // This is true if it's possible that the layer properties (size, opacity, 310 // This is true if it's possible that the layer properties (size, opacity,
282 // etc.) may have been modified since the last commit. Attaching a new 311 // etc.) may have been modified since the last commit. Attaching a new
283 // buffer with the same size as the old shouldn't set this to true. 312 // buffer with the same size as the old shouldn't set this to true.
284 bool has_pending_layer_changes_ = true; 313 bool has_pending_layer_changes_ = true;
285 314
286 // This is true if the next commit to this surface should put its contents 315 // This is true if the next commit to this surface should put its contents
287 // into a new cc::SurfaceId. This allows for synchronization between Surface 316 // into a new cc::SurfaceId. This allows for synchronization between Surface
288 // and layer changes. 317 // and layer changes.
289 bool needs_commit_to_new_surface_ = true; 318 bool needs_commit_to_new_surface_ = true;
290 319
291 // This is the size of the last committed contents. 320 // This is the size of the last committed contents.
292 gfx::Size content_size_; 321 gfx::Size content_size_;
293 322
294 // This is true when Attach() has been called and new contents should take 323 // This is true when Attach() has been called and new contents should take
295 // effect next time Commit() is called. 324 // effect next time Commit() is called.
296 bool has_pending_contents_; 325 bool has_pending_contents_;
297 326
298 // The buffer that will become the content of surface when Commit() is called. 327 // The buffer that will become the content of surface when Commit() is called.
299 base::WeakPtr<Buffer> pending_buffer_; 328 BufferAttachment pending_buffer_;
300 329
301 cc::SurfaceManager* surface_manager_; 330 cc::SurfaceManager* surface_manager_;
302 331
303 scoped_refptr<SurfaceFactoryOwner> factory_owner_; 332 scoped_refptr<SurfaceFactoryOwner> factory_owner_;
304 333
305 // The Surface Id currently attached to the window. 334 // The Surface Id currently attached to the window.
306 cc::SurfaceId surface_id_; 335 cc::SurfaceId surface_id_;
307 336
308 // The next resource id the buffer will be attached to. 337 // The next resource id the buffer will be attached to.
309 int next_resource_id_ = 1; 338 int next_resource_id_ = 1;
(...skipping 18 matching lines...) Expand all
328 State state_; 357 State state_;
329 358
330 // The stack of sub-surfaces to take effect when Commit() is called. 359 // The stack of sub-surfaces to take effect when Commit() is called.
331 // Bottom-most sub-surface at the front of the list and top-most sub-surface 360 // Bottom-most sub-surface at the front of the list and top-most sub-surface
332 // at the back. 361 // at the back.
333 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; 362 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>;
334 using SubSurfaceEntryList = std::list<SubSurfaceEntry>; 363 using SubSurfaceEntryList = std::list<SubSurfaceEntry>;
335 SubSurfaceEntryList pending_sub_surfaces_; 364 SubSurfaceEntryList pending_sub_surfaces_;
336 365
337 // The buffer that is currently set as content of surface. 366 // The buffer that is currently set as content of surface.
338 base::WeakPtr<Buffer> current_buffer_; 367 BufferAttachment current_buffer_;
339 368
340 // The last resource that was sent to a surface. 369 // The last resource that was sent to a surface.
341 cc::TransferableResource current_resource_; 370 cc::TransferableResource current_resource_;
342 371
343 // This is true if a call to Commit() as been made but 372 // This is true if a call to Commit() as been made but
344 // CommitSurfaceHierarchy() has not yet been called. 373 // CommitSurfaceHierarchy() has not yet been called.
345 bool needs_commit_surface_hierarchy_; 374 bool needs_commit_surface_hierarchy_;
346 375
347 // This is set when the compositing starts and passed to active frame 376 // This is set when the compositing starts and passed to active frame
348 // callbacks when compositing successfully ends. 377 // callbacks when compositing successfully ends.
(...skipping 17 matching lines...) Expand all
366 395
367 // Surface observer list. Surface does not own the observers. 396 // Surface observer list. Surface does not own the observers.
368 base::ObserverList<SurfaceObserver, true> observers_; 397 base::ObserverList<SurfaceObserver, true> observers_;
369 398
370 DISALLOW_COPY_AND_ASSIGN(Surface); 399 DISALLOW_COPY_AND_ASSIGN(Surface);
371 }; 400 };
372 401
373 } // namespace exo 402 } // namespace exo
374 403
375 #endif // COMPONENTS_EXO_SURFACE_H_ 404 #endif // COMPONENTS_EXO_SURFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698