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

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

Issue 2736753006: exo: Cleanup and make buffer release code more robust. (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | components/exo/buffer.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_BUFFER_H_ 5 #ifndef COMPONENTS_EXO_BUFFER_H_
6 #define COMPONENTS_EXO_BUFFER_H_ 6 #define COMPONENTS_EXO_BUFFER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/cancelable_callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "cc/resources/transferable_resource.h" 14 #include "cc/resources/transferable_resource.h"
14 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
15 16
16 namespace base { 17 namespace base {
17 namespace trace_event { 18 namespace trace_event {
18 class TracedValue; 19 class TracedValue;
19 } 20 }
20 } 21 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 67
67 // Returns the size of the buffer. 68 // Returns the size of the buffer.
68 gfx::Size GetSize() const; 69 gfx::Size GetSize() const;
69 70
70 // Returns a trace value representing the state of the buffer. 71 // Returns a trace value representing the state of the buffer.
71 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; 72 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const;
72 73
73 private: 74 private:
74 class Texture; 75 class Texture;
75 76
76 // Decrements the use count of buffer and notifies the client that buffer 77 // This should be called when buffer is released and will notify the
77 // as been released if it reached 0. 78 // client that buffer has been released.
78 void Release(); 79 void Release();
79 80
80 // Runs the release callback if the buffer isn't attached or in use.
81 void CheckReleaseCallback();
82
83 // This is used by ProduceTextureMailbox() to produce a release callback 81 // This is used by ProduceTextureMailbox() to produce a release callback
84 // that releases a texture so it can be destroyed or reused. 82 // that releases a texture so it can be destroyed or reused.
85 void ReleaseTexture(std::unique_ptr<Texture> texture); 83 void ReleaseTexture(std::unique_ptr<Texture> texture);
86 84
87 // This is used by ProduceTextureMailbox() to produce a release callback 85 // This is used by ProduceTextureMailbox() to produce a release callback
88 // that releases the buffer contents referenced by a texture before the 86 // that releases the buffer contents referenced by a texture before the
89 // texture is destroyed or reused. 87 // texture is destroyed or reused.
90 void ReleaseContentsTexture(std::unique_ptr<Texture> texture); 88 void ReleaseContentsTexture(std::unique_ptr<Texture> texture,
89 const base::Closure& callback);
90
91 // Notifies the client that buffer has been released if no longer attached
92 // to a surface.
93 void ReleaseContents();
91 94
92 // The GPU memory buffer that contains the contents of this buffer. 95 // The GPU memory buffer that contains the contents of this buffer.
93 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; 96 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
94 97
95 // Texture target that must be used when creating a texture for buffer. 98 // Texture target that must be used when creating a texture for buffer.
96 const unsigned texture_target_; 99 const unsigned texture_target_;
97 100
98 // Query type that must be used when releasing buffer from a texture. 101 // Query type that must be used when releasing buffer from a texture.
99 const unsigned query_type_; 102 const unsigned query_type_;
100 103
101 // True if zero copy is used when producing a texture mailbox for buffer. 104 // True if zero copy is used when producing a texture mailbox for buffer.
102 const bool use_zero_copy_; 105 const bool use_zero_copy_;
103 106
104 // True if this buffer is an overlay candidate. 107 // True if this buffer is an overlay candidate.
105 const bool is_overlay_candidate_; 108 const bool is_overlay_candidate_;
106 109
107 // This is incremented when a transferable resource is produced and
108 // decremented when a transferable resource is released. It is used to
109 // determine when we should notify the client that buffer has been released.
110 unsigned use_count_ = 0;
111
112 // This keeps track of how many Surfaces the buffer is attached to. 110 // This keeps track of how many Surfaces the buffer is attached to.
113 unsigned attach_count_ = 0; 111 unsigned attach_count_ = 0;
114 112
115 // The last used texture. ProduceTransferableResource() will use this 113 // The last used texture. ProduceTransferableResource() will use this
116 // instead of creating a new texture when possible. 114 // instead of creating a new texture when possible.
117 std::unique_ptr<Texture> texture_; 115 std::unique_ptr<Texture> texture_;
118 116
119 // The last used contents texture. ProduceTransferableResource() will use this 117 // The last used contents texture. ProduceTransferableResource() will use this
120 // instead of creating a new texture when possible. 118 // instead of creating a new texture when possible.
121 std::unique_ptr<Texture> contents_texture_; 119 std::unique_ptr<Texture> contents_texture_;
122 120
123 // The client release callback. 121 // The client release callback.
124 base::Closure release_callback_; 122 base::Closure release_callback_;
125 123
126 // CompositorFrameSinkHolder instance that needs to be kept alive to receive 124 // CompositorFrameSinkHolder instance that needs to be kept alive to receive
127 // a release callback when the last produced transferable resource is no 125 // a release callback when the last produced transferable resource is no
128 // longer in use. 126 // longer in use.
129 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_; 127 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_;
130 128
129 // Cancelable release contents callback. This is set when a release callback
130 // is pending.
131 base::CancelableClosure release_contents_callback_;
132
131 DISALLOW_COPY_AND_ASSIGN(Buffer); 133 DISALLOW_COPY_AND_ASSIGN(Buffer);
132 }; 134 };
133 135
134 } // namespace exo 136 } // namespace exo
135 137
136 #endif // COMPONENTS_EXO_BUFFER_H_ 138 #endif // COMPONENTS_EXO_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | components/exo/buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698