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/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/scheduler/begin_frame_source.h" | 19 #include "cc/scheduler/begin_frame_source.h" |
| 20 #include "cc/surfaces/surface_factory.h" |
20 #include "cc/surfaces/surface_factory_client.h" | 21 #include "cc/surfaces/surface_factory_client.h" |
| 22 #include "cc/surfaces/surface_id.h" |
| 23 #include "components/exo/exo_compositor_frame_sink.h" |
21 #include "third_party/skia/include/core/SkRegion.h" | 24 #include "third_party/skia/include/core/SkRegion.h" |
22 #include "third_party/skia/include/core/SkXfermode.h" | 25 #include "third_party/skia/include/core/SkXfermode.h" |
23 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
24 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
25 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
26 | 29 |
27 namespace base { | 30 namespace base { |
28 namespace trace_event { | 31 namespace trace_event { |
29 class TracedValue; | 32 class TracedValue; |
30 } | 33 } |
31 } | 34 } |
32 | 35 |
33 namespace cc { | |
34 class SurfaceFactory; | |
35 } | |
36 | |
37 namespace gfx { | 36 namespace gfx { |
38 class Path; | 37 class Path; |
39 } | 38 } |
40 | 39 |
41 namespace exo { | 40 namespace exo { |
42 class Buffer; | 41 class Buffer; |
43 class Pointer; | 42 class Pointer; |
44 class SurfaceDelegate; | 43 class SurfaceDelegate; |
45 class SurfaceObserver; | 44 class SurfaceObserver; |
46 class Surface; | 45 class Surface; |
47 | 46 |
48 template <typename T> | 47 template <typename T> |
49 struct SurfaceProperty; | 48 struct SurfaceProperty; |
50 | 49 |
51 namespace subtle { | 50 namespace subtle { |
52 class PropertyHelper; | 51 class PropertyHelper; |
53 } | 52 } |
54 | 53 |
55 // The pointer class is currently the only cursor provider class but this can | 54 // The pointer class is currently the only cursor provider class but this can |
56 // change in the future when better hardware cursor support is added. | 55 // change in the future when better hardware cursor support is added. |
57 using CursorProvider = Pointer; | 56 using CursorProvider = Pointer; |
58 | 57 |
59 // This class owns the SurfaceFactory and keeps track of references to the | |
60 // contents of Buffers. It's keeped alive by references from | |
61 // release_callbacks_. It's destroyed when its owning Surface is destroyed and | |
62 // the last outstanding release callback is called. | |
63 class SurfaceFactoryOwner : public base::RefCounted<SurfaceFactoryOwner>, | |
64 public cc::SurfaceFactoryClient { | |
65 public: | |
66 SurfaceFactoryOwner(); | |
67 | |
68 // Overridden from cc::SurfaceFactoryClient: | |
69 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
70 void WillDrawSurface(const cc::LocalFrameId& id, | |
71 const gfx::Rect& damage_rect) override; | |
72 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; | |
73 | |
74 private: | |
75 friend class base::RefCounted<SurfaceFactoryOwner>; | |
76 friend class Surface; | |
77 | |
78 ~SurfaceFactoryOwner() override; | |
79 | |
80 std::map<int, | |
81 std::pair<scoped_refptr<SurfaceFactoryOwner>, | |
82 std::unique_ptr<cc::SingleReleaseCallback>>> | |
83 release_callbacks_; | |
84 cc::FrameSinkId frame_sink_id_; | |
85 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; | |
86 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | |
87 Surface* surface_ = nullptr; | |
88 }; | |
89 | |
90 // This class represents a rectangular area that is displayed on the screen. | 58 // This class represents a rectangular area that is displayed on the screen. |
91 // It has a location, size and pixel contents. | 59 // It has a location, size and pixel contents. |
92 class Surface : public ui::ContextFactoryObserver, | 60 class Surface : public ui::ContextFactoryObserver, |
93 public aura::WindowObserver, | 61 public aura::WindowObserver, |
94 public cc::BeginFrameObserver { | 62 public cc::BeginFrameObserver { |
95 public: | 63 public: |
96 using PropertyDeallocator = void (*)(int64_t value); | 64 using PropertyDeallocator = void (*)(int64_t value); |
97 | 65 |
98 Surface(); | 66 Surface(); |
99 ~Surface() override; | 67 ~Surface() override; |
100 | 68 |
101 // Type-checking downcast routine. | 69 // Type-checking downcast routine. |
102 static Surface* AsSurface(const aura::Window* window); | 70 static Surface* AsSurface(const aura::Window* window); |
103 | 71 |
104 aura::Window* window() { return window_.get(); } | 72 aura::Window* window() { return window_.get(); } |
105 | 73 |
106 const cc::LocalFrameId& local_frame_id() const { return local_frame_id_; } | 74 const cc::LocalFrameId& local_frame_id() const { |
| 75 return surface_id_.local_frame_id(); |
| 76 } |
| 77 |
107 cc::SurfaceId GetSurfaceId() const; | 78 cc::SurfaceId GetSurfaceId() const; |
108 | 79 |
109 // Set a buffer as the content of this surface. A buffer can only be attached | 80 // Set a buffer as the content of this surface. A buffer can only be attached |
110 // to one surface at a time. | 81 // to one surface at a time. |
111 void Attach(Buffer* buffer); | 82 void Attach(Buffer* buffer); |
112 | 83 |
113 // Describe the regions where the pending buffer is different from the | 84 // Describe the regions where the pending buffer is different from the |
114 // current surface contents, and where the surface therefore needs to be | 85 // current surface contents, and where the surface therefore needs to be |
115 // repainted. | 86 // repainted. |
116 void Damage(const gfx::Rect& rect); | 87 void Damage(const gfx::Rect& rect); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 315 |
345 // This is true when Attach() has been called and new contents should take | 316 // This is true when Attach() has been called and new contents should take |
346 // effect next time Commit() is called. | 317 // effect next time Commit() is called. |
347 bool has_pending_contents_ = false; | 318 bool has_pending_contents_ = false; |
348 | 319 |
349 // The buffer that will become the content of surface when Commit() is called. | 320 // The buffer that will become the content of surface when Commit() is called. |
350 BufferAttachment pending_buffer_; | 321 BufferAttachment pending_buffer_; |
351 | 322 |
352 cc::SurfaceManager* surface_manager_; | 323 cc::SurfaceManager* surface_manager_; |
353 | 324 |
354 scoped_refptr<SurfaceFactoryOwner> factory_owner_; | 325 scoped_refptr<ExoCompositorFrameSink> compositor_frame_sink_; |
355 | |
356 // The Surface Id currently attached to the window. | |
357 cc::LocalFrameId local_frame_id_; | |
358 | 326 |
359 // The next resource id the buffer will be attached to. | 327 // The next resource id the buffer will be attached to. |
360 int next_resource_id_ = 1; | 328 int next_resource_id_ = 1; |
361 | 329 |
362 // The damage region to schedule paint for when Commit() is called. | 330 // The damage region to schedule paint for when Commit() is called. |
363 SkRegion pending_damage_; | 331 SkRegion pending_damage_; |
364 | 332 |
365 // These lists contains the callbacks to notify the client when it is a good | 333 // These lists contains the callbacks to notify the client when it is a good |
366 // time to start producing a new frame. These callbacks move to | 334 // time to start producing a new frame. These callbacks move to |
367 // |frame_callbacks_| when Commit() is called. Later they are moved to | 335 // |frame_callbacks_| when Commit() is called. Later they are moved to |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 const char* name; | 383 const char* name; |
416 int64_t value; | 384 int64_t value; |
417 PropertyDeallocator deallocator; | 385 PropertyDeallocator deallocator; |
418 }; | 386 }; |
419 | 387 |
420 std::map<const void*, Value> prop_map_; | 388 std::map<const void*, Value> prop_map_; |
421 | 389 |
422 // Surface observer list. Surface does not own the observers. | 390 // Surface observer list. Surface does not own the observers. |
423 base::ObserverList<SurfaceObserver, true> observers_; | 391 base::ObserverList<SurfaceObserver, true> observers_; |
424 | 392 |
| 393 cc::SurfaceId surface_id_; |
| 394 |
425 DISALLOW_COPY_AND_ASSIGN(Surface); | 395 DISALLOW_COPY_AND_ASSIGN(Surface); |
426 }; | 396 }; |
427 | 397 |
428 } // namespace exo | 398 } // namespace exo |
429 | 399 |
430 #endif // COMPONENTS_EXO_SURFACE_H_ | 400 #endif // COMPONENTS_EXO_SURFACE_H_ |
OLD | NEW |