| 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_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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 // Returns the format of the buffer. | 71 // Returns the format of the buffer. |
| 71 gfx::BufferFormat GetFormat() const; | 72 gfx::BufferFormat GetFormat() const; |
| 72 | 73 |
| 73 // Returns a trace value representing the state of the buffer. | 74 // Returns a trace value representing the state of the buffer. |
| 74 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; | 75 std::unique_ptr<base::trace_event::TracedValue> AsTracedValue() const; |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 class Texture; | 78 class Texture; |
| 78 | 79 |
| 79 // Decrements the use count of buffer and notifies the client that buffer | 80 // This should be called when buffer is released and will notify the |
| 80 // as been released if it reached 0. | 81 // client that buffer has been released. |
| 81 void Release(); | 82 void Release(); |
| 82 | 83 |
| 83 // Runs the release callback if the buffer isn't attached or in use. | |
| 84 void CheckReleaseCallback(); | |
| 85 | |
| 86 // This is used by ProduceTextureMailbox() to produce a release callback | 84 // This is used by ProduceTextureMailbox() to produce a release callback |
| 87 // that releases a texture so it can be destroyed or reused. | 85 // that releases a texture so it can be destroyed or reused. |
| 88 void ReleaseTexture(std::unique_ptr<Texture> texture); | 86 void ReleaseTexture(std::unique_ptr<Texture> texture); |
| 89 | 87 |
| 90 // This is used by ProduceTextureMailbox() to produce a release callback | 88 // This is used by ProduceTextureMailbox() to produce a release callback |
| 91 // that releases the buffer contents referenced by a texture before the | 89 // that releases the buffer contents referenced by a texture before the |
| 92 // texture is destroyed or reused. | 90 // texture is destroyed or reused. |
| 93 void ReleaseContentsTexture(std::unique_ptr<Texture> texture); | 91 void ReleaseContentsTexture(std::unique_ptr<Texture> texture, |
| 92 const base::Closure& callback); |
| 93 |
| 94 // Notifies the client that buffer has been released if no longer attached |
| 95 // to a surface. |
| 96 void ReleaseContents(); |
| 94 | 97 |
| 95 // The GPU memory buffer that contains the contents of this buffer. | 98 // The GPU memory buffer that contains the contents of this buffer. |
| 96 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; | 99 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
| 97 | 100 |
| 98 // Texture target that must be used when creating a texture for buffer. | 101 // Texture target that must be used when creating a texture for buffer. |
| 99 const unsigned texture_target_; | 102 const unsigned texture_target_; |
| 100 | 103 |
| 101 // Query type that must be used when releasing buffer from a texture. | 104 // Query type that must be used when releasing buffer from a texture. |
| 102 const unsigned query_type_; | 105 const unsigned query_type_; |
| 103 | 106 |
| 104 // True if zero copy is used when producing a texture mailbox for buffer. | 107 // True if zero copy is used when producing a texture mailbox for buffer. |
| 105 const bool use_zero_copy_; | 108 const bool use_zero_copy_; |
| 106 | 109 |
| 107 // True if this buffer is an overlay candidate. | 110 // True if this buffer is an overlay candidate. |
| 108 const bool is_overlay_candidate_; | 111 const bool is_overlay_candidate_; |
| 109 | 112 |
| 110 // This is incremented when a transferable resource is produced and | |
| 111 // decremented when a transferable resource is released. It is used to | |
| 112 // determine when we should notify the client that buffer has been released. | |
| 113 unsigned use_count_ = 0; | |
| 114 | |
| 115 // This keeps track of how many Surfaces the buffer is attached to. | 113 // This keeps track of how many Surfaces the buffer is attached to. |
| 116 unsigned attach_count_ = 0; | 114 unsigned attach_count_ = 0; |
| 117 | 115 |
| 118 // The last used texture. ProduceTransferableResource() will use this | 116 // The last used texture. ProduceTransferableResource() will use this |
| 119 // instead of creating a new texture when possible. | 117 // instead of creating a new texture when possible. |
| 120 std::unique_ptr<Texture> texture_; | 118 std::unique_ptr<Texture> texture_; |
| 121 | 119 |
| 122 // The last used contents texture. ProduceTransferableResource() will use this | 120 // The last used contents texture. ProduceTransferableResource() will use this |
| 123 // instead of creating a new texture when possible. | 121 // instead of creating a new texture when possible. |
| 124 std::unique_ptr<Texture> contents_texture_; | 122 std::unique_ptr<Texture> contents_texture_; |
| 125 | 123 |
| 126 // The client release callback. | 124 // The client release callback. |
| 127 base::Closure release_callback_; | 125 base::Closure release_callback_; |
| 128 | 126 |
| 129 // CompositorFrameSinkHolder instance that needs to be kept alive to receive | 127 // CompositorFrameSinkHolder instance that needs to be kept alive to receive |
| 130 // a release callback when the last produced transferable resource is no | 128 // a release callback when the last produced transferable resource is no |
| 131 // longer in use. | 129 // longer in use. |
| 132 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_; | 130 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder_; |
| 133 | 131 |
| 132 // Cancelable release contents callback. This is set when a release callback |
| 133 // is pending. |
| 134 base::CancelableClosure release_contents_callback_; |
| 135 |
| 134 DISALLOW_COPY_AND_ASSIGN(Buffer); | 136 DISALLOW_COPY_AND_ASSIGN(Buffer); |
| 135 }; | 137 }; |
| 136 | 138 |
| 137 } // namespace exo | 139 } // namespace exo |
| 138 | 140 |
| 139 #endif // COMPONENTS_EXO_BUFFER_H_ | 141 #endif // COMPONENTS_EXO_BUFFER_H_ |
| OLD | NEW |