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

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

Issue 2008153002: Add initial implementation of cc::Surfaces backend for exo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 <utility> 10 #include <utility>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "cc/surfaces/surface_factory_client.h"
16 #include "third_party/skia/include/core/SkRegion.h" 18 #include "third_party/skia/include/core/SkRegion.h"
17 #include "third_party/skia/include/core/SkXfermode.h" 19 #include "third_party/skia/include/core/SkXfermode.h"
18 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
19 #include "ui/aura/window_observer.h" 21 #include "ui/aura/window_observer.h"
20 #include "ui/compositor/compositor_observer.h" 22 #include "ui/compositor/compositor_observer.h"
21 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
22 24
23 namespace base { 25 namespace base {
24 namespace trace_event { 26 namespace trace_event {
25 class TracedValue; 27 class TracedValue;
26 } 28 }
27 } 29 }
28 30
31 namespace cc {
32 class SurfaceFactory;
33 enum class SurfaceDrawStatus;
34 }
35
29 namespace gfx { 36 namespace gfx {
30 class Path; 37 class Path;
31 } 38 }
32 39
33 namespace exo { 40 namespace exo {
34 class Buffer; 41 class Buffer;
35 class SurfaceDelegate; 42 class SurfaceDelegate;
36 class SurfaceObserver; 43 class SurfaceObserver;
44 class Surface;
45
46 // This class owns the SurfaceFactory and keeps track of references to the
47 // contents of Buffers. It's keeped alive by references from
48 // release_callbacks_. It's destroyed when its owning Surface is destroyed and
49 // the last outstanding release callback is called.
50 class SurfaceFactoryOwner : public base::RefCounted<SurfaceFactoryOwner>,
51 public cc::SurfaceFactoryClient {
52 public:
53 SurfaceFactoryOwner();
54
55 // cc::SurfaceFactoryClient implementation.
reveman 2016/05/27 06:18:40 nit: we've been using "// Overridden from cc::Surf
56 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
57 void WillDrawSurface(cc::SurfaceId id, const gfx::Rect& damage_rect) override;
58 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override;
59
60 private:
61 friend class base::RefCounted<SurfaceFactoryOwner>;
62 friend class Surface;
63 ~SurfaceFactoryOwner() override;
64
65 std::map<int,
66 std::pair<scoped_refptr<SurfaceFactoryOwner>,
67 std::unique_ptr<cc::SingleReleaseCallback>>>
68 release_callbacks_;
69 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_;
70 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
71 Surface* surface_;
72 };
37 73
38 // This class represents a rectangular area that is displayed on the screen. 74 // This class represents a rectangular area that is displayed on the screen.
39 // It has a location, size and pixel contents. 75 // It has a location, size and pixel contents.
40 class Surface : public aura::Window, 76 class Surface : public aura::Window,
41 public aura::WindowObserver, 77 public aura::WindowObserver,
42 public ui::CompositorObserver { 78 public ui::CompositorObserver {
43 public: 79 public:
44 Surface(); 80 Surface();
45 ~Surface() override; 81 ~Surface() override;
46 82
47 // Type-checking downcast routine. 83 // Type-checking downcast routine.
48 static Surface* AsSurface(const aura::Window* window); 84 static Surface* AsSurface(const aura::Window* window);
49 85
86 // Sets whether to put the contents in a SurfaceLayer or a TextureLayer.
87 static void SetUseSurfaceLayer(bool use_surface_layer);
88
50 // Set a buffer as the content of this surface. A buffer can only be attached 89 // Set a buffer as the content of this surface. A buffer can only be attached
51 // to one surface at a time. 90 // to one surface at a time.
52 void Attach(Buffer* buffer); 91 void Attach(Buffer* buffer);
53 92
54 // Describe the regions where the pending buffer is different from the 93 // Describe the regions where the pending buffer is different from the
55 // current surface contents, and where the surface therefore needs to be 94 // current surface contents, and where the surface therefore needs to be
56 // repainted. 95 // repainted.
57 void Damage(const gfx::Rect& rect); 96 void Damage(const gfx::Rect& rect);
58 97
59 // Request notification when the next frame is displayed. Useful for 98 // Request notification when the next frame is displayed. Useful for
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 193
155 // Overridden from ui::CompositorObserver: 194 // Overridden from ui::CompositorObserver:
156 void OnCompositingDidCommit(ui::Compositor* compositor) override; 195 void OnCompositingDidCommit(ui::Compositor* compositor) override;
157 void OnCompositingStarted(ui::Compositor* compositor, 196 void OnCompositingStarted(ui::Compositor* compositor,
158 base::TimeTicks start_time) override; 197 base::TimeTicks start_time) override;
159 void OnCompositingEnded(ui::Compositor* compositor) override; 198 void OnCompositingEnded(ui::Compositor* compositor) override;
160 void OnCompositingAborted(ui::Compositor* compositor) override; 199 void OnCompositingAborted(ui::Compositor* compositor) override;
161 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} 200 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {}
162 void OnCompositingShuttingDown(ui::Compositor* compositor) override; 201 void OnCompositingShuttingDown(ui::Compositor* compositor) override;
163 202
203 void WillDraw(cc::SurfaceId surface_id);
204
164 private: 205 private:
165 bool needs_commit_surface_hierarchy() const { 206 bool needs_commit_surface_hierarchy() const {
166 return needs_commit_surface_hierarchy_; 207 return needs_commit_surface_hierarchy_;
167 } 208 }
168 209
210 // Commit the current attached buffer to a TextureLayer.
211 void CommitLayerContents();
212
213 // Commit the current attached buffer to a SurfaceLayer.
214 void CommitSurfaceContents();
215
169 // This returns true when the surface has some contents assigned to it. 216 // This returns true when the surface has some contents assigned to it.
170 bool has_contents() const { return !!current_buffer_; } 217 bool has_contents() const { return !!current_buffer_; }
171 218
219 // This is true if the buffer contents should be put in a SurfaceLayer
220 // rather than a TextureLayer.
221 static bool use_surface_layer_;
222
172 // This is true when Attach() has been called and new contents should take 223 // This is true when Attach() has been called and new contents should take
173 // effect next time Commit() is called. 224 // effect next time Commit() is called.
174 bool has_pending_contents_; 225 bool has_pending_contents_;
175 226
176 // The buffer that will become the content of surface when Commit() is called. 227 // The buffer that will become the content of surface when Commit() is called.
177 base::WeakPtr<Buffer> pending_buffer_; 228 base::WeakPtr<Buffer> pending_buffer_;
178 229
230 cc::SurfaceManager* surface_manager_;
231
232 scoped_refptr<SurfaceFactoryOwner> factory_owner_;
233
234 // The Surface Id currently attached to the window.
235 cc::SurfaceId surface_id_;
236
237 // The next resource id the buffer will be attached to.
238 int next_resource_id_ = 0;
239
179 // The damage region to schedule paint for when Commit() is called. 240 // The damage region to schedule paint for when Commit() is called.
180 SkRegion pending_damage_; 241 SkRegion pending_damage_;
181 242
182 // These lists contains the callbacks to notify the client when it is a good 243 // These lists contains the callbacks to notify the client when it is a good
183 // time to start producing a new frame. These callbacks move to 244 // time to start producing a new frame. These callbacks move to
184 // |frame_callbacks_| when Commit() is called. Later they are moved to 245 // |frame_callbacks_| when Commit() is called. Later they are moved to
185 // |active_frame_callbacks_| when the effect of the Commit() is reflected in 246 // |active_frame_callbacks_| when the effect of the Commit() is reflected in
186 // the compositor's active layer tree. The callbacks fire once we're notified 247 // the compositor's active layer tree. The callbacks fire once we're notified
187 // that the compositor started drawing that active layer tree. 248 // that the compositor started drawing that active layer tree.
188 std::list<FrameCallback> pending_frame_callbacks_; 249 std::list<FrameCallback> pending_frame_callbacks_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 312
252 // Surface observer list. Surface does not own the observers. 313 // Surface observer list. Surface does not own the observers.
253 base::ObserverList<SurfaceObserver, true> observers_; 314 base::ObserverList<SurfaceObserver, true> observers_;
254 315
255 DISALLOW_COPY_AND_ASSIGN(Surface); 316 DISALLOW_COPY_AND_ASSIGN(Surface);
256 }; 317 };
257 318
258 } // namespace exo 319 } // namespace exo
259 320
260 #endif // COMPONENTS_EXO_SURFACE_H_ 321 #endif // COMPONENTS_EXO_SURFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698