OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 CC_LAYERS_TEXTURE_LAYER_H_ | 5 #ifndef CC_LAYERS_TEXTURE_LAYER_H_ |
6 #define CC_LAYERS_TEXTURE_LAYER_H_ | 6 #define CC_LAYERS_TEXTURE_LAYER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 private: | 40 private: |
41 scoped_refptr<TextureMailboxHolder> holder_; | 41 scoped_refptr<TextureMailboxHolder> holder_; |
42 DISALLOW_COPY_AND_ASSIGN(MainThreadReference); | 42 DISALLOW_COPY_AND_ASSIGN(MainThreadReference); |
43 }; | 43 }; |
44 | 44 |
45 const TextureMailbox& mailbox() const { return mailbox_; } | 45 const TextureMailbox& mailbox() const { return mailbox_; } |
46 void Return(const gpu::SyncToken& sync_token, bool is_lost); | 46 void Return(const gpu::SyncToken& sync_token, bool is_lost); |
47 | 47 |
48 // Gets a ReleaseCallback that can be called from another thread. Note: the | 48 // Gets a ReleaseCallback that can be called from another thread. Note: the |
49 // caller must ensure the callback is called. | 49 // caller must ensure the callback is called. |
50 scoped_ptr<SingleReleaseCallbackImpl> GetCallbackForImplThread(); | 50 std::unique_ptr<SingleReleaseCallbackImpl> GetCallbackForImplThread(); |
51 | 51 |
52 protected: | 52 protected: |
53 friend class TextureLayer; | 53 friend class TextureLayer; |
54 | 54 |
55 // Protected visiblity so only TextureLayer and unit tests can create these. | 55 // Protected visiblity so only TextureLayer and unit tests can create these. |
56 static scoped_ptr<MainThreadReference> Create( | 56 static std::unique_ptr<MainThreadReference> Create( |
57 const TextureMailbox& mailbox, | 57 const TextureMailbox& mailbox, |
58 scoped_ptr<SingleReleaseCallback> release_callback); | 58 std::unique_ptr<SingleReleaseCallback> release_callback); |
59 virtual ~TextureMailboxHolder(); | 59 virtual ~TextureMailboxHolder(); |
60 | 60 |
61 private: | 61 private: |
62 friend class base::RefCountedThreadSafe<TextureMailboxHolder>; | 62 friend class base::RefCountedThreadSafe<TextureMailboxHolder>; |
63 friend class MainThreadReference; | 63 friend class MainThreadReference; |
64 explicit TextureMailboxHolder( | 64 explicit TextureMailboxHolder( |
65 const TextureMailbox& mailbox, | 65 const TextureMailbox& mailbox, |
66 scoped_ptr<SingleReleaseCallback> release_callback); | 66 std::unique_ptr<SingleReleaseCallback> release_callback); |
67 | 67 |
68 void InternalAddRef(); | 68 void InternalAddRef(); |
69 void InternalRelease(); | 69 void InternalRelease(); |
70 void ReturnAndReleaseOnImplThread( | 70 void ReturnAndReleaseOnImplThread( |
71 const gpu::SyncToken& sync_token, | 71 const gpu::SyncToken& sync_token, |
72 bool is_lost, | 72 bool is_lost, |
73 BlockingTaskRunner* main_thread_task_runner); | 73 BlockingTaskRunner* main_thread_task_runner); |
74 | 74 |
75 // These members are only accessed on the main thread, or on the impl thread | 75 // These members are only accessed on the main thread, or on the impl thread |
76 // during commit where the main thread is blocked. | 76 // during commit where the main thread is blocked. |
77 unsigned internal_references_; | 77 unsigned internal_references_; |
78 TextureMailbox mailbox_; | 78 TextureMailbox mailbox_; |
79 scoped_ptr<SingleReleaseCallback> release_callback_; | 79 std::unique_ptr<SingleReleaseCallback> release_callback_; |
80 | 80 |
81 // This lock guards the sync_token_ and is_lost_ fields because they can be | 81 // This lock guards the sync_token_ and is_lost_ fields because they can be |
82 // accessed on both the impl and main thread. We do this to ensure that the | 82 // accessed on both the impl and main thread. We do this to ensure that the |
83 // values of these fields are well-ordered such that the last call to | 83 // values of these fields are well-ordered such that the last call to |
84 // ReturnAndReleaseOnImplThread() defines their values. | 84 // ReturnAndReleaseOnImplThread() defines their values. |
85 base::Lock arguments_lock_; | 85 base::Lock arguments_lock_; |
86 gpu::SyncToken sync_token_; | 86 gpu::SyncToken sync_token_; |
87 bool is_lost_; | 87 bool is_lost_; |
88 base::ThreadChecker main_thread_checker_; | 88 base::ThreadChecker main_thread_checker_; |
89 DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder); | 89 DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder); |
90 }; | 90 }; |
91 | 91 |
92 // Used when mailbox names are specified instead of texture IDs. | 92 // Used when mailbox names are specified instead of texture IDs. |
93 static scoped_refptr<TextureLayer> CreateForMailbox( | 93 static scoped_refptr<TextureLayer> CreateForMailbox( |
94 TextureLayerClient* client); | 94 TextureLayerClient* client); |
95 | 95 |
96 // Resets the client, which also resets the texture. | 96 // Resets the client, which also resets the texture. |
97 void ClearClient(); | 97 void ClearClient(); |
98 | 98 |
99 // Resets the texture. | 99 // Resets the texture. |
100 void ClearTexture(); | 100 void ClearTexture(); |
101 | 101 |
102 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; | 102 std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; |
103 | 103 |
104 // Sets whether this texture should be Y-flipped at draw time. Defaults to | 104 // Sets whether this texture should be Y-flipped at draw time. Defaults to |
105 // true. | 105 // true. |
106 void SetFlipped(bool flipped); | 106 void SetFlipped(bool flipped); |
107 bool flipped() const { return flipped_; } | 107 bool flipped() const { return flipped_; } |
108 | 108 |
109 // Sets whether this texture should use nearest neighbor interpolation as | 109 // Sets whether this texture should use nearest neighbor interpolation as |
110 // opposed to bilinear. Defaults to false. | 110 // opposed to bilinear. Defaults to false. |
111 void SetNearestNeighbor(bool nearest_neighbor); | 111 void SetNearestNeighbor(bool nearest_neighbor); |
112 | 112 |
113 // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). | 113 // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). |
114 void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right); | 114 void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right); |
115 | 115 |
116 // Sets an opacity value per vertex. It will be multiplied by the layer | 116 // Sets an opacity value per vertex. It will be multiplied by the layer |
117 // opacity value. | 117 // opacity value. |
118 void SetVertexOpacity(float bottom_left, | 118 void SetVertexOpacity(float bottom_left, |
119 float top_left, | 119 float top_left, |
120 float top_right, | 120 float top_right, |
121 float bottom_right); | 121 float bottom_right); |
122 | 122 |
123 // Sets whether the alpha channel is premultiplied or unpremultiplied. | 123 // Sets whether the alpha channel is premultiplied or unpremultiplied. |
124 // Defaults to true. | 124 // Defaults to true. |
125 void SetPremultipliedAlpha(bool premultiplied_alpha); | 125 void SetPremultipliedAlpha(bool premultiplied_alpha); |
126 | 126 |
127 // Sets whether the texture should be blended with the background color | 127 // Sets whether the texture should be blended with the background color |
128 // at draw time. Defaults to false. | 128 // at draw time. Defaults to false. |
129 void SetBlendBackgroundColor(bool blend); | 129 void SetBlendBackgroundColor(bool blend); |
130 | 130 |
131 // Code path for plugins which supply their own mailbox. | 131 // Code path for plugins which supply their own mailbox. |
132 void SetTextureMailbox(const TextureMailbox& mailbox, | 132 void SetTextureMailbox( |
133 scoped_ptr<SingleReleaseCallback> release_callback); | 133 const TextureMailbox& mailbox, |
| 134 std::unique_ptr<SingleReleaseCallback> release_callback); |
134 | 135 |
135 // Use this for special cases where the same texture is used to back the | 136 // Use this for special cases where the same texture is used to back the |
136 // TextureLayer across all frames. | 137 // TextureLayer across all frames. |
137 // WARNING: DON'T ACTUALLY USE THIS WHAT YOU ARE DOING IS WRONG. | 138 // WARNING: DON'T ACTUALLY USE THIS WHAT YOU ARE DOING IS WRONG. |
138 // TODO(danakj): Remove this when pepper doesn't need it. crbug.com/350204 | 139 // TODO(danakj): Remove this when pepper doesn't need it. crbug.com/350204 |
139 void SetTextureMailboxWithoutReleaseCallback(const TextureMailbox& mailbox); | 140 void SetTextureMailboxWithoutReleaseCallback(const TextureMailbox& mailbox); |
140 | 141 |
141 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override; | 142 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override; |
142 | 143 |
143 void SetLayerTreeHost(LayerTreeHost* layer_tree_host) override; | 144 void SetLayerTreeHost(LayerTreeHost* layer_tree_host) override; |
144 bool Update() override; | 145 bool Update() override; |
145 void PushPropertiesTo(LayerImpl* layer) override; | 146 void PushPropertiesTo(LayerImpl* layer) override; |
146 | 147 |
147 protected: | 148 protected: |
148 explicit TextureLayer(TextureLayerClient* client); | 149 explicit TextureLayer(TextureLayerClient* client); |
149 ~TextureLayer() override; | 150 ~TextureLayer() override; |
150 bool HasDrawableContent() const override; | 151 bool HasDrawableContent() const override; |
151 | 152 |
152 private: | 153 private: |
153 void SetTextureMailboxInternal( | 154 void SetTextureMailboxInternal( |
154 const TextureMailbox& mailbox, | 155 const TextureMailbox& mailbox, |
155 scoped_ptr<SingleReleaseCallback> release_callback, | 156 std::unique_ptr<SingleReleaseCallback> release_callback, |
156 bool requires_commit, | 157 bool requires_commit, |
157 bool allow_mailbox_reuse); | 158 bool allow_mailbox_reuse); |
158 | 159 |
159 TextureLayerClient* client_; | 160 TextureLayerClient* client_; |
160 | 161 |
161 bool flipped_; | 162 bool flipped_; |
162 bool nearest_neighbor_; | 163 bool nearest_neighbor_; |
163 gfx::PointF uv_top_left_; | 164 gfx::PointF uv_top_left_; |
164 gfx::PointF uv_bottom_right_; | 165 gfx::PointF uv_bottom_right_; |
165 // [bottom left, top left, top right, bottom right] | 166 // [bottom left, top left, top right, bottom right] |
166 float vertex_opacity_[4]; | 167 float vertex_opacity_[4]; |
167 bool premultiplied_alpha_; | 168 bool premultiplied_alpha_; |
168 bool blend_background_color_; | 169 bool blend_background_color_; |
169 | 170 |
170 scoped_ptr<TextureMailboxHolder::MainThreadReference> holder_ref_; | 171 std::unique_ptr<TextureMailboxHolder::MainThreadReference> holder_ref_; |
171 bool needs_set_mailbox_; | 172 bool needs_set_mailbox_; |
172 | 173 |
173 DISALLOW_COPY_AND_ASSIGN(TextureLayer); | 174 DISALLOW_COPY_AND_ASSIGN(TextureLayer); |
174 }; | 175 }; |
175 | 176 |
176 } // namespace cc | 177 } // namespace cc |
177 #endif // CC_LAYERS_TEXTURE_LAYER_H_ | 178 #endif // CC_LAYERS_TEXTURE_LAYER_H_ |
OLD | NEW |