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

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 nits 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
« no previous file with comments | « components/exo/buffer_unittest.cc ('k') | components/exo/surface.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 BufferAttachment& operator=(BufferAttachment&& buffer);
263
264 base::WeakPtr<Buffer>& buffer();
265 const base::WeakPtr<Buffer>& buffer() const;
266 void Reset(base::WeakPtr<Buffer> buffer);
267
268 private:
269 base::WeakPtr<Buffer> buffer_;
270
271 DISALLOW_COPY_AND_ASSIGN(BufferAttachment);
250 }; 272 };
251 273
252 friend class subtle::PropertyHelper; 274 friend class subtle::PropertyHelper;
253 275
254 bool needs_commit_surface_hierarchy() const { 276 bool needs_commit_surface_hierarchy() const {
255 return needs_commit_surface_hierarchy_; 277 return needs_commit_surface_hierarchy_;
256 } 278 }
257 279
258 // Returns true if this surface or any child surface needs a commit and has 280 // Returns true if this surface or any child surface needs a commit and has
259 // has_pending_layer_changes_ true. 281 // has_pending_layer_changes_ true.
260 bool HasLayerHierarchyChanged() const; 282 bool HasLayerHierarchyChanged() const;
261 283
262 // Sets that all children must create new cc::SurfaceIds for their contents. 284 // Sets that all children must create new cc::SurfaceIds for their contents.
263 void SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 285 void SetSurfaceHierarchyNeedsCommitToNewSurfaces();
264 286
265 // Set SurfaceLayer contents to the current buffer. 287 // Set SurfaceLayer contents to the current buffer.
266 void SetSurfaceLayerContents(ui::Layer* layer); 288 void SetSurfaceLayerContents(ui::Layer* layer);
267 289
290 // Updates current_resource_ with a new resource id corresponding to the
291 // contents of the attached buffer (or id 0, if no buffer is attached).
292 // UpdateSurface must be called afterwards to ensure the release callback
293 // will be called.
294 void UpdateResource(bool client_usage);
295
296 // Updates the current Surface with a new frame referring to the resource in
297 // current_resource_.
298 void UpdateSurface(bool full_damage);
299
268 int64_t SetPropertyInternal(const void* key, 300 int64_t SetPropertyInternal(const void* key,
269 const char* name, 301 const char* name,
270 PropertyDeallocator deallocator, 302 PropertyDeallocator deallocator,
271 int64_t value, 303 int64_t value,
272 int64_t default_value); 304 int64_t default_value);
273 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; 305 int64_t GetPropertyInternal(const void* key, int64_t default_value) const;
274 306
275 // This returns true when the surface has some contents assigned to it. 307 // This returns true when the surface has some contents assigned to it.
276 bool has_contents() const { return !!current_buffer_; } 308 bool has_contents() const { return !!current_buffer_.buffer(); }
277 309
278 // This window has the layer which contains the Surface contents. 310 // This window has the layer which contains the Surface contents.
279 std::unique_ptr<aura::Window> window_; 311 std::unique_ptr<aura::Window> window_;
280 312
281 // This is true if it's possible that the layer properties (size, opacity, 313 // 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 314 // 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. 315 // buffer with the same size as the old shouldn't set this to true.
284 bool has_pending_layer_changes_ = true; 316 bool has_pending_layer_changes_ = true;
285 317
286 // This is true if the next commit to this surface should put its contents 318 // 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 319 // into a new cc::SurfaceId. This allows for synchronization between Surface
288 // and layer changes. 320 // and layer changes.
289 bool needs_commit_to_new_surface_ = true; 321 bool needs_commit_to_new_surface_ = true;
290 322
291 // This is the size of the last committed contents. 323 // This is the size of the last committed contents.
292 gfx::Size content_size_; 324 gfx::Size content_size_;
293 325
294 // This is true when Attach() has been called and new contents should take 326 // This is true when Attach() has been called and new contents should take
295 // effect next time Commit() is called. 327 // effect next time Commit() is called.
296 bool has_pending_contents_; 328 bool has_pending_contents_;
297 329
298 // The buffer that will become the content of surface when Commit() is called. 330 // The buffer that will become the content of surface when Commit() is called.
299 base::WeakPtr<Buffer> pending_buffer_; 331 BufferAttachment pending_buffer_;
300 332
301 cc::SurfaceManager* surface_manager_; 333 cc::SurfaceManager* surface_manager_;
302 334
303 scoped_refptr<SurfaceFactoryOwner> factory_owner_; 335 scoped_refptr<SurfaceFactoryOwner> factory_owner_;
304 336
305 // The Surface Id currently attached to the window. 337 // The Surface Id currently attached to the window.
306 cc::SurfaceId surface_id_; 338 cc::SurfaceId surface_id_;
307 339
308 // The next resource id the buffer will be attached to. 340 // The next resource id the buffer will be attached to.
309 int next_resource_id_ = 1; 341 int next_resource_id_ = 1;
(...skipping 18 matching lines...) Expand all
328 State state_; 360 State state_;
329 361
330 // The stack of sub-surfaces to take effect when Commit() is called. 362 // 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 363 // Bottom-most sub-surface at the front of the list and top-most sub-surface
332 // at the back. 364 // at the back.
333 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; 365 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>;
334 using SubSurfaceEntryList = std::list<SubSurfaceEntry>; 366 using SubSurfaceEntryList = std::list<SubSurfaceEntry>;
335 SubSurfaceEntryList pending_sub_surfaces_; 367 SubSurfaceEntryList pending_sub_surfaces_;
336 368
337 // The buffer that is currently set as content of surface. 369 // The buffer that is currently set as content of surface.
338 base::WeakPtr<Buffer> current_buffer_; 370 BufferAttachment current_buffer_;
339 371
340 // The last resource that was sent to a surface. 372 // The last resource that was sent to a surface.
341 cc::TransferableResource current_resource_; 373 cc::TransferableResource current_resource_;
342 374
343 // This is true if a call to Commit() as been made but 375 // This is true if a call to Commit() as been made but
344 // CommitSurfaceHierarchy() has not yet been called. 376 // CommitSurfaceHierarchy() has not yet been called.
345 bool needs_commit_surface_hierarchy_; 377 bool needs_commit_surface_hierarchy_;
346 378
347 // This is set when the compositing starts and passed to active frame 379 // This is set when the compositing starts and passed to active frame
348 // callbacks when compositing successfully ends. 380 // callbacks when compositing successfully ends.
(...skipping 17 matching lines...) Expand all
366 398
367 // Surface observer list. Surface does not own the observers. 399 // Surface observer list. Surface does not own the observers.
368 base::ObserverList<SurfaceObserver, true> observers_; 400 base::ObserverList<SurfaceObserver, true> observers_;
369 401
370 DISALLOW_COPY_AND_ASSIGN(Surface); 402 DISALLOW_COPY_AND_ASSIGN(Surface);
371 }; 403 };
372 404
373 } // namespace exo 405 } // namespace exo
374 406
375 #endif // COMPONENTS_EXO_SURFACE_H_ 407 #endif // COMPONENTS_EXO_SURFACE_H_
OLDNEW
« no previous file with comments | « components/exo/buffer_unittest.cc ('k') | components/exo/surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698