Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/callback_helpers.h" | |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 18 #include "cc/resources/transferable_resource.h" | 19 #include "cc/resources/transferable_resource.h" |
| 19 #include "cc/surfaces/surface_factory_client.h" | 20 #include "cc/surfaces/surface_factory_client.h" |
| 20 #include "third_party/skia/include/core/SkRegion.h" | 21 #include "third_party/skia/include/core/SkRegion.h" |
| 21 #include "third_party/skia/include/core/SkXfermode.h" | 22 #include "third_party/skia/include/core/SkXfermode.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 24 #include "ui/compositor/compositor.h" | |
| 23 #include "ui/compositor/layer_owner_delegate.h" | 25 #include "ui/compositor/layer_owner_delegate.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 namespace trace_event { | 29 namespace trace_event { |
| 28 class TracedValue; | 30 class TracedValue; |
| 29 } | 31 } |
| 30 } | 32 } |
| 31 | 33 |
| 32 namespace cc { | 34 namespace cc { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 std::pair<scoped_refptr<SurfaceFactoryOwner>, | 81 std::pair<scoped_refptr<SurfaceFactoryOwner>, |
| 80 std::unique_ptr<cc::SingleReleaseCallback>>> | 82 std::unique_ptr<cc::SingleReleaseCallback>>> |
| 81 release_callbacks_; | 83 release_callbacks_; |
| 82 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; | 84 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; |
| 83 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 85 std::unique_ptr<cc::SurfaceFactory> surface_factory_; |
| 84 Surface* surface_; | 86 Surface* surface_; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 // This class represents a rectangular area that is displayed on the screen. | 89 // This class represents a rectangular area that is displayed on the screen. |
| 88 // It has a location, size and pixel contents. | 90 // It has a location, size and pixel contents. |
| 89 class Surface : public ui::LayerOwnerDelegate { | 91 class Surface : public ui::LayerOwnerDelegate, |
| 92 public ui::ContextFactoryObserver { | |
| 90 public: | 93 public: |
| 91 typedef void (*PropertyDeallocator)(int64_t value); | 94 typedef void (*PropertyDeallocator)(int64_t value); |
| 92 | 95 |
| 93 Surface(); | 96 Surface(); |
| 94 ~Surface() override; | 97 ~Surface() override; |
| 95 | 98 |
| 96 // Type-checking downcast routine. | 99 // Type-checking downcast routine. |
| 97 static Surface* AsSurface(const aura::Window* window); | 100 static Surface* AsSurface(const aura::Window* window); |
| 98 | 101 |
| 99 aura::Window* window() { return window_.get(); } | 102 aura::Window* window() { return window_.get(); } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // Returns a trace value representing the state of the surface. | 202 // Returns a trace value representing the state of the surface. |
| 200 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; | 203 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
| 201 | 204 |
| 202 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { | 205 bool HasPendingDamageForTesting(const gfx::Rect& damage) const { |
| 203 return pending_damage_.contains(gfx::RectToSkIRect(damage)); | 206 return pending_damage_.contains(gfx::RectToSkIRect(damage)); |
| 204 } | 207 } |
| 205 | 208 |
| 206 // Overridden from ui::LayerOwnerDelegate: | 209 // Overridden from ui::LayerOwnerDelegate: |
| 207 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; | 210 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; |
| 208 | 211 |
| 212 // Overridden from ui::ContextFactoryObserver. | |
| 213 void OnLostResources() override; | |
| 214 | |
| 209 void WillDraw(cc::SurfaceId surface_id); | 215 void WillDraw(cc::SurfaceId surface_id); |
| 210 | 216 |
| 211 // Check whether this Surface and its children need to create new cc::Surface | 217 // 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. | 218 // IDs for their contents next time they get new buffer contents. |
| 213 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 219 void CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 214 | 220 |
| 215 gfx::Size content_size() const { return content_size_; } | 221 gfx::Size content_size() const { return content_size_; } |
| 216 | 222 |
| 217 // Sets the |value| of the given surface |property|. Setting to the default | 223 // 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 | 224 // value (e.g., NULL) removes the property. The caller is responsible for the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 // Returns true if this surface or any child surface needs a commit and has | 264 // Returns true if this surface or any child surface needs a commit and has |
| 259 // has_pending_layer_changes_ true. | 265 // has_pending_layer_changes_ true. |
| 260 bool HasLayerHierarchyChanged() const; | 266 bool HasLayerHierarchyChanged() const; |
| 261 | 267 |
| 262 // Sets that all children must create new cc::SurfaceIds for their contents. | 268 // Sets that all children must create new cc::SurfaceIds for their contents. |
| 263 void SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 269 void SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 264 | 270 |
| 265 // Set SurfaceLayer contents to the current buffer. | 271 // Set SurfaceLayer contents to the current buffer. |
| 266 void SetSurfaceLayerContents(ui::Layer* layer); | 272 void SetSurfaceLayerContents(ui::Layer* layer); |
| 267 | 273 |
| 274 // Updates current_resource_ with a new resource id corresponding to the | |
| 275 // contents of the attached buffer (or id 0, if no buffer is attached). | |
| 276 // UpdateSurface must be called afterwards to ensure the release callback | |
| 277 // will be called. | |
| 278 void CreateResource(bool for_commit); | |
|
reveman
2016/06/22 17:15:26
nit: UpdateResource?
jbauman
2016/06/22 23:45:48
Done.
| |
| 279 | |
| 280 // Updates the current Surface with a new frame referring to the resource in | |
| 281 // current_resource_. | |
| 282 void UpdateSurface(bool for_commit); | |
| 283 | |
| 268 int64_t SetPropertyInternal(const void* key, | 284 int64_t SetPropertyInternal(const void* key, |
| 269 const char* name, | 285 const char* name, |
| 270 PropertyDeallocator deallocator, | 286 PropertyDeallocator deallocator, |
| 271 int64_t value, | 287 int64_t value, |
| 272 int64_t default_value); | 288 int64_t default_value); |
| 273 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; | 289 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; |
| 274 | 290 |
| 275 // This returns true when the surface has some contents assigned to it. | 291 // This returns true when the surface has some contents assigned to it. |
| 276 bool has_contents() const { return !!current_buffer_; } | 292 bool has_contents() const { return !!current_buffer_; } |
| 277 | 293 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 // The stack of sub-surfaces to take effect when Commit() is called. | 346 // 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 | 347 // Bottom-most sub-surface at the front of the list and top-most sub-surface |
| 332 // at the back. | 348 // at the back. |
| 333 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; | 349 using SubSurfaceEntry = std::pair<Surface*, gfx::Point>; |
| 334 using SubSurfaceEntryList = std::list<SubSurfaceEntry>; | 350 using SubSurfaceEntryList = std::list<SubSurfaceEntry>; |
| 335 SubSurfaceEntryList pending_sub_surfaces_; | 351 SubSurfaceEntryList pending_sub_surfaces_; |
| 336 | 352 |
| 337 // The buffer that is currently set as content of surface. | 353 // The buffer that is currently set as content of surface. |
| 338 base::WeakPtr<Buffer> current_buffer_; | 354 base::WeakPtr<Buffer> current_buffer_; |
| 339 | 355 |
| 356 bool frame_is_opaque_ = false; | |
| 357 | |
| 340 // The last resource that was sent to a surface. | 358 // The last resource that was sent to a surface. |
| 341 cc::TransferableResource current_resource_; | 359 cc::TransferableResource current_resource_; |
| 342 | 360 |
| 361 // This holds onto the release callback for the current buffer. | |
| 362 base::ScopedClosureRunner current_buffer_release_runner_; | |
| 363 | |
| 343 // This is true if a call to Commit() as been made but | 364 // This is true if a call to Commit() as been made but |
| 344 // CommitSurfaceHierarchy() has not yet been called. | 365 // CommitSurfaceHierarchy() has not yet been called. |
| 345 bool needs_commit_surface_hierarchy_; | 366 bool needs_commit_surface_hierarchy_; |
| 346 | 367 |
| 347 // This is set when the compositing starts and passed to active frame | 368 // This is set when the compositing starts and passed to active frame |
| 348 // callbacks when compositing successfully ends. | 369 // callbacks when compositing successfully ends. |
| 349 base::TimeTicks last_compositing_start_time_; | 370 base::TimeTicks last_compositing_start_time_; |
| 350 | 371 |
| 351 // Cursor providers. Surface does not own the cursor providers. | 372 // Cursor providers. Surface does not own the cursor providers. |
| 352 std::set<CursorProvider*> cursor_providers_; | 373 std::set<CursorProvider*> cursor_providers_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 366 | 387 |
| 367 // Surface observer list. Surface does not own the observers. | 388 // Surface observer list. Surface does not own the observers. |
| 368 base::ObserverList<SurfaceObserver, true> observers_; | 389 base::ObserverList<SurfaceObserver, true> observers_; |
| 369 | 390 |
| 370 DISALLOW_COPY_AND_ASSIGN(Surface); | 391 DISALLOW_COPY_AND_ASSIGN(Surface); |
| 371 }; | 392 }; |
| 372 | 393 |
| 373 } // namespace exo | 394 } // namespace exo |
| 374 | 395 |
| 375 #endif // COMPONENTS_EXO_SURFACE_H_ | 396 #endif // COMPONENTS_EXO_SURFACE_H_ |
| OLD | NEW |