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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "gpu/command_buffer/common/mailbox.h" | |
13 #include "gpu/command_buffer/common/sync_token.h" | |
14 #include "ui/gfx/buffer_types.h" | |
15 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
16 | 13 |
17 namespace base { | 14 namespace base { |
18 namespace trace_event { | 15 namespace trace_event { |
19 class TracedValue; | 16 class TracedValue; |
20 } | 17 } |
21 } | 18 } |
22 | 19 |
23 namespace cc { | 20 namespace cc { |
24 class SingleReleaseCallback; | 21 class SingleReleaseCallback; |
25 class TextureMailbox; | 22 class TextureMailbox; |
26 } | 23 } |
27 | 24 |
28 namespace gfx { | 25 namespace gfx { |
29 class GpuMemoryBuffer; | 26 class GpuMemoryBuffer; |
30 } | 27 } |
31 | 28 |
| 29 namespace gpu { |
| 30 struct SyncToken; |
| 31 } |
| 32 |
32 namespace exo { | 33 namespace exo { |
33 | 34 |
34 // This class provides the content for a Surface. The mechanism by which a | 35 // This class provides the content for a Surface. The mechanism by which a |
35 // client provides and updates the contents is the responsibility of the client | 36 // client provides and updates the contents is the responsibility of the client |
36 // and not defined as part of this class. | 37 // and not defined as part of this class. |
37 class Buffer : public base::SupportsWeakPtr<Buffer> { | 38 class Buffer : public base::SupportsWeakPtr<Buffer> { |
38 public: | 39 public: |
39 Buffer(scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer, | 40 Buffer(scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer, |
40 unsigned texture_target); | 41 unsigned texture_target); |
41 ~Buffer(); | 42 ~Buffer(); |
42 | 43 |
43 // Set the callback to run when the buffer is no longer used by the | 44 // Set the callback to run when the buffer is no longer used by the |
44 // compositor. The client is free to re-use or destroy this buffer and | 45 // compositor. The client is free to re-use or destroy this buffer and |
45 // its backing storage after this has been called. | 46 // its backing storage after this has been called. |
46 void set_release_callback(const base::Closure& release_callback) { | 47 void set_release_callback(const base::Closure& release_callback) { |
47 release_callback_ = release_callback; | 48 release_callback_ = release_callback; |
48 } | 49 } |
49 | 50 |
50 // This function can be used to acquire a texture mailbox that is bound to | 51 // This function can be used to acquire a texture mailbox that is bound to |
51 // the buffer. Returns a release callback on success. The release callback | 52 // the buffer. Returns a release callback on success. The release callback |
52 // must be called before a new texture mailbox can be acquired. | 53 // must be called before a new texture mailbox can be acquired. |
53 scoped_ptr<cc::SingleReleaseCallback> AcquireTextureMailbox( | 54 scoped_ptr<cc::SingleReleaseCallback> ProduceTextureMailbox( |
54 cc::TextureMailbox* mailbox); | 55 cc::TextureMailbox* mailbox); |
55 | 56 |
56 // Returns the size of the buffer. | 57 // Returns the size of the buffer. |
57 gfx::Size GetSize() const; | 58 gfx::Size GetSize() const; |
58 | 59 |
59 // Returns a trace value representing the state of the buffer. | 60 // Returns a trace value representing the state of the buffer. |
60 scoped_refptr<base::trace_event::TracedValue> AsTracedValue() const; | 61 scoped_refptr<base::trace_event::TracedValue> AsTracedValue() const; |
61 | 62 |
62 private: | 63 private: |
63 static void Release(base::WeakPtr<Buffer> buffer, | 64 class Texture; |
64 unsigned texture_target, | |
65 unsigned texture_id, | |
66 unsigned image_id, | |
67 const gpu::SyncToken& sync_token, | |
68 bool is_lost); | |
69 | 65 |
| 66 // Decrements the use count of buffer and notifies the client that buffer |
| 67 // as been released if it reached 0. |
| 68 void Release(); |
| 69 |
| 70 // This is used by ProduceTextureMailbox() to produce a release callback |
| 71 // that releases the buffer contents referenced by a texture before the |
| 72 // texture is destroyed or reused. |
| 73 // Note: This is a static function as it needs to run even if the buffer |
| 74 // has been destroyed. |
| 75 static void ReleaseTexture(base::WeakPtr<Buffer> buffer, |
| 76 scoped_ptr<Texture> texture, |
| 77 const gpu::SyncToken& sync_token, |
| 78 bool is_lost); |
| 79 |
| 80 // The GPU memory buffer that contains the contents of this buffer. |
70 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; | 81 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
| 82 |
| 83 // Texture target that must be used when creating a texture for buffer. |
71 const unsigned texture_target_; | 84 const unsigned texture_target_; |
72 unsigned texture_id_; | 85 |
73 unsigned image_id_; | 86 // This is incremented when a texture mailbox is produced and decremented |
74 gpu::Mailbox mailbox_; | 87 // when a texture mailbox is released. It is used to determine when we should |
| 88 // notify the client that buffer has been released. |
| 89 unsigned use_count_; |
| 90 |
| 91 // The last released texture instance. ProduceTextureMailbox() will use this |
| 92 // instead of creating a new texture when possible. |
| 93 scoped_ptr<Texture> last_texture_; |
| 94 |
| 95 // The client release callback. |
75 base::Closure release_callback_; | 96 base::Closure release_callback_; |
76 | 97 |
77 DISALLOW_COPY_AND_ASSIGN(Buffer); | 98 DISALLOW_COPY_AND_ASSIGN(Buffer); |
78 }; | 99 }; |
79 | 100 |
80 } // namespace exo | 101 } // namespace exo |
81 | 102 |
82 #endif // COMPONENTS_EXO_BUFFER_H_ | 103 #endif // COMPONENTS_EXO_BUFFER_H_ |
OLD | NEW |