| 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 #include "cc/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/base/simple_enclosed_region.h" | 13 #include "cc/base/simple_enclosed_region.h" |
| 13 #include "cc/layers/texture_layer_client.h" | 14 #include "cc/layers/texture_layer_client.h" |
| 14 #include "cc/layers/texture_layer_impl.h" | 15 #include "cc/layers/texture_layer_impl.h" |
| 15 #include "cc/resources/single_release_callback.h" | 16 #include "cc/resources/single_release_callback.h" |
| 16 #include "cc/resources/single_release_callback_impl.h" | 17 #include "cc/resources/single_release_callback_impl.h" |
| 17 #include "cc/trees/blocking_task_runner.h" | 18 #include "cc/trees/blocking_task_runner.h" |
| 18 #include "cc/trees/layer_tree_host.h" | 19 #include "cc/trees/layer_tree_host.h" |
| 19 | 20 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 void TextureLayer::ClearClient() { | 46 void TextureLayer::ClearClient() { |
| 46 client_ = nullptr; | 47 client_ = nullptr; |
| 47 ClearTexture(); | 48 ClearTexture(); |
| 48 UpdateDrawsContent(HasDrawableContent()); | 49 UpdateDrawsContent(HasDrawableContent()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void TextureLayer::ClearTexture() { | 52 void TextureLayer::ClearTexture() { |
| 52 SetTextureMailbox(TextureMailbox(), nullptr); | 53 SetTextureMailbox(TextureMailbox(), nullptr); |
| 53 } | 54 } |
| 54 | 55 |
| 55 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 56 std::unique_ptr<LayerImpl> TextureLayer::CreateLayerImpl( |
| 57 LayerTreeImpl* tree_impl) { |
| 56 return TextureLayerImpl::Create(tree_impl, id()); | 58 return TextureLayerImpl::Create(tree_impl, id()); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void TextureLayer::SetFlipped(bool flipped) { | 61 void TextureLayer::SetFlipped(bool flipped) { |
| 60 if (flipped_ == flipped) | 62 if (flipped_ == flipped) |
| 61 return; | 63 return; |
| 62 flipped_ = flipped; | 64 flipped_ = flipped; |
| 63 SetNeedsCommit(); | 65 SetNeedsCommit(); |
| 64 } | 66 } |
| 65 | 67 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 110 |
| 109 void TextureLayer::SetBlendBackgroundColor(bool blend) { | 111 void TextureLayer::SetBlendBackgroundColor(bool blend) { |
| 110 if (blend_background_color_ == blend) | 112 if (blend_background_color_ == blend) |
| 111 return; | 113 return; |
| 112 blend_background_color_ = blend; | 114 blend_background_color_ = blend; |
| 113 SetNeedsCommit(); | 115 SetNeedsCommit(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void TextureLayer::SetTextureMailboxInternal( | 118 void TextureLayer::SetTextureMailboxInternal( |
| 117 const TextureMailbox& mailbox, | 119 const TextureMailbox& mailbox, |
| 118 scoped_ptr<SingleReleaseCallback> release_callback, | 120 std::unique_ptr<SingleReleaseCallback> release_callback, |
| 119 bool requires_commit, | 121 bool requires_commit, |
| 120 bool allow_mailbox_reuse) { | 122 bool allow_mailbox_reuse) { |
| 121 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 123 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 122 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 124 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
| 123 allow_mailbox_reuse); | 125 allow_mailbox_reuse); |
| 124 DCHECK_EQ(mailbox.IsValid(), !!release_callback); | 126 DCHECK_EQ(mailbox.IsValid(), !!release_callback); |
| 125 | 127 |
| 126 // If we never commited the mailbox, we need to release it here. | 128 // If we never commited the mailbox, we need to release it here. |
| 127 if (mailbox.IsValid()) { | 129 if (mailbox.IsValid()) { |
| 128 holder_ref_ = | 130 holder_ref_ = |
| 129 TextureMailboxHolder::Create(mailbox, std::move(release_callback)); | 131 TextureMailboxHolder::Create(mailbox, std::move(release_callback)); |
| 130 } else { | 132 } else { |
| 131 holder_ref_ = nullptr; | 133 holder_ref_ = nullptr; |
| 132 } | 134 } |
| 133 needs_set_mailbox_ = true; | 135 needs_set_mailbox_ = true; |
| 134 // If we are within a commit, no need to do it again immediately after. | 136 // If we are within a commit, no need to do it again immediately after. |
| 135 if (requires_commit) | 137 if (requires_commit) |
| 136 SetNeedsCommit(); | 138 SetNeedsCommit(); |
| 137 else | 139 else |
| 138 SetNeedsPushProperties(); | 140 SetNeedsPushProperties(); |
| 139 | 141 |
| 140 UpdateDrawsContent(HasDrawableContent()); | 142 UpdateDrawsContent(HasDrawableContent()); |
| 141 // The active frame needs to be replaced and the mailbox returned before the | 143 // The active frame needs to be replaced and the mailbox returned before the |
| 142 // commit is called complete. | 144 // commit is called complete. |
| 143 SetNextCommitWaitsForActivation(); | 145 SetNextCommitWaitsForActivation(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 void TextureLayer::SetTextureMailbox( | 148 void TextureLayer::SetTextureMailbox( |
| 147 const TextureMailbox& mailbox, | 149 const TextureMailbox& mailbox, |
| 148 scoped_ptr<SingleReleaseCallback> release_callback) { | 150 std::unique_ptr<SingleReleaseCallback> release_callback) { |
| 149 bool requires_commit = true; | 151 bool requires_commit = true; |
| 150 bool allow_mailbox_reuse = false; | 152 bool allow_mailbox_reuse = false; |
| 151 SetTextureMailboxInternal(mailbox, std::move(release_callback), | 153 SetTextureMailboxInternal(mailbox, std::move(release_callback), |
| 152 requires_commit, allow_mailbox_reuse); | 154 requires_commit, allow_mailbox_reuse); |
| 153 } | 155 } |
| 154 | 156 |
| 155 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { | 157 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { |
| 156 } | 158 } |
| 157 | 159 |
| 158 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( | 160 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( |
| 159 const TextureMailbox& mailbox) { | 161 const TextureMailbox& mailbox) { |
| 160 // We allow reuse of the mailbox if there is a new sync point signalling new | 162 // We allow reuse of the mailbox if there is a new sync point signalling new |
| 161 // content, and the release callback goes nowhere since we'll be calling it | 163 // content, and the release callback goes nowhere since we'll be calling it |
| 162 // multiple times for the same mailbox. | 164 // multiple times for the same mailbox. |
| 163 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 165 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 164 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 166 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
| 165 mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); | 167 mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); |
| 166 scoped_ptr<SingleReleaseCallback> release; | 168 std::unique_ptr<SingleReleaseCallback> release; |
| 167 bool requires_commit = true; | 169 bool requires_commit = true; |
| 168 bool allow_mailbox_reuse = true; | 170 bool allow_mailbox_reuse = true; |
| 169 if (mailbox.IsValid()) | 171 if (mailbox.IsValid()) |
| 170 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); | 172 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); |
| 171 SetTextureMailboxInternal(mailbox, std::move(release), requires_commit, | 173 SetTextureMailboxInternal(mailbox, std::move(release), requires_commit, |
| 172 allow_mailbox_reuse); | 174 allow_mailbox_reuse); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { | 177 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { |
| 176 Layer::SetNeedsDisplayRect(dirty_rect); | 178 Layer::SetNeedsDisplayRect(dirty_rect); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 } | 197 } |
| 196 | 198 |
| 197 bool TextureLayer::HasDrawableContent() const { | 199 bool TextureLayer::HasDrawableContent() const { |
| 198 return (client_ || holder_ref_) && Layer::HasDrawableContent(); | 200 return (client_ || holder_ref_) && Layer::HasDrawableContent(); |
| 199 } | 201 } |
| 200 | 202 |
| 201 bool TextureLayer::Update() { | 203 bool TextureLayer::Update() { |
| 202 bool updated = Layer::Update(); | 204 bool updated = Layer::Update(); |
| 203 if (client_) { | 205 if (client_) { |
| 204 TextureMailbox mailbox; | 206 TextureMailbox mailbox; |
| 205 scoped_ptr<SingleReleaseCallback> release_callback; | 207 std::unique_ptr<SingleReleaseCallback> release_callback; |
| 206 if (client_->PrepareTextureMailbox( | 208 if (client_->PrepareTextureMailbox( |
| 207 &mailbox, | 209 &mailbox, |
| 208 &release_callback, | 210 &release_callback, |
| 209 layer_tree_host()->UsingSharedMemoryResources())) { | 211 layer_tree_host()->UsingSharedMemoryResources())) { |
| 210 // Already within a commit, no need to do another one immediately. | 212 // Already within a commit, no need to do another one immediately. |
| 211 bool requires_commit = false; | 213 bool requires_commit = false; |
| 212 bool allow_mailbox_reuse = false; | 214 bool allow_mailbox_reuse = false; |
| 213 SetTextureMailboxInternal(mailbox, std::move(release_callback), | 215 SetTextureMailboxInternal(mailbox, std::move(release_callback), |
| 214 requires_commit, allow_mailbox_reuse); | 216 requires_commit, allow_mailbox_reuse); |
| 215 updated = true; | 217 updated = true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 229 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 231 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
| 230 texture_layer->SetFlipped(flipped_); | 232 texture_layer->SetFlipped(flipped_); |
| 231 texture_layer->SetNearestNeighbor(nearest_neighbor_); | 233 texture_layer->SetNearestNeighbor(nearest_neighbor_); |
| 232 texture_layer->SetUVTopLeft(uv_top_left_); | 234 texture_layer->SetUVTopLeft(uv_top_left_); |
| 233 texture_layer->SetUVBottomRight(uv_bottom_right_); | 235 texture_layer->SetUVBottomRight(uv_bottom_right_); |
| 234 texture_layer->SetVertexOpacity(vertex_opacity_); | 236 texture_layer->SetVertexOpacity(vertex_opacity_); |
| 235 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); | 237 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); |
| 236 texture_layer->SetBlendBackgroundColor(blend_background_color_); | 238 texture_layer->SetBlendBackgroundColor(blend_background_color_); |
| 237 if (needs_set_mailbox_) { | 239 if (needs_set_mailbox_) { |
| 238 TextureMailbox texture_mailbox; | 240 TextureMailbox texture_mailbox; |
| 239 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl; | 241 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl; |
| 240 if (holder_ref_) { | 242 if (holder_ref_) { |
| 241 TextureMailboxHolder* holder = holder_ref_->holder(); | 243 TextureMailboxHolder* holder = holder_ref_->holder(); |
| 242 texture_mailbox = holder->mailbox(); | 244 texture_mailbox = holder->mailbox(); |
| 243 release_callback_impl = holder->GetCallbackForImplThread(); | 245 release_callback_impl = holder->GetCallbackForImplThread(); |
| 244 } | 246 } |
| 245 texture_layer->SetTextureMailbox(texture_mailbox, | 247 texture_layer->SetTextureMailbox(texture_mailbox, |
| 246 std::move(release_callback_impl)); | 248 std::move(release_callback_impl)); |
| 247 needs_set_mailbox_ = false; | 249 needs_set_mailbox_ = false; |
| 248 } | 250 } |
| 249 } | 251 } |
| 250 | 252 |
| 251 TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( | 253 TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( |
| 252 TextureMailboxHolder* holder) | 254 TextureMailboxHolder* holder) |
| 253 : holder_(holder) { | 255 : holder_(holder) { |
| 254 holder_->InternalAddRef(); | 256 holder_->InternalAddRef(); |
| 255 } | 257 } |
| 256 | 258 |
| 257 TextureLayer::TextureMailboxHolder::MainThreadReference:: | 259 TextureLayer::TextureMailboxHolder::MainThreadReference:: |
| 258 ~MainThreadReference() { | 260 ~MainThreadReference() { |
| 259 holder_->InternalRelease(); | 261 holder_->InternalRelease(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( | 264 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( |
| 263 const TextureMailbox& mailbox, | 265 const TextureMailbox& mailbox, |
| 264 scoped_ptr<SingleReleaseCallback> release_callback) | 266 std::unique_ptr<SingleReleaseCallback> release_callback) |
| 265 : internal_references_(0), | 267 : internal_references_(0), |
| 266 mailbox_(mailbox), | 268 mailbox_(mailbox), |
| 267 release_callback_(std::move(release_callback)), | 269 release_callback_(std::move(release_callback)), |
| 268 sync_token_(mailbox.sync_token()), | 270 sync_token_(mailbox.sync_token()), |
| 269 is_lost_(false) {} | 271 is_lost_(false) {} |
| 270 | 272 |
| 271 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { | 273 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { |
| 272 DCHECK_EQ(0u, internal_references_); | 274 DCHECK_EQ(0u, internal_references_); |
| 273 } | 275 } |
| 274 | 276 |
| 275 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> | 277 std::unique_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> |
| 276 TextureLayer::TextureMailboxHolder::Create( | 278 TextureLayer::TextureMailboxHolder::Create( |
| 277 const TextureMailbox& mailbox, | 279 const TextureMailbox& mailbox, |
| 278 scoped_ptr<SingleReleaseCallback> release_callback) { | 280 std::unique_ptr<SingleReleaseCallback> release_callback) { |
| 279 return make_scoped_ptr(new MainThreadReference( | 281 return base::WrapUnique(new MainThreadReference( |
| 280 new TextureMailboxHolder(mailbox, std::move(release_callback)))); | 282 new TextureMailboxHolder(mailbox, std::move(release_callback)))); |
| 281 } | 283 } |
| 282 | 284 |
| 283 void TextureLayer::TextureMailboxHolder::Return( | 285 void TextureLayer::TextureMailboxHolder::Return( |
| 284 const gpu::SyncToken& sync_token, | 286 const gpu::SyncToken& sync_token, |
| 285 bool is_lost) { | 287 bool is_lost) { |
| 286 base::AutoLock lock(arguments_lock_); | 288 base::AutoLock lock(arguments_lock_); |
| 287 sync_token_ = sync_token; | 289 sync_token_ = sync_token; |
| 288 is_lost_ = is_lost; | 290 is_lost_ = is_lost; |
| 289 } | 291 } |
| 290 | 292 |
| 291 scoped_ptr<SingleReleaseCallbackImpl> | 293 std::unique_ptr<SingleReleaseCallbackImpl> |
| 292 TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { | 294 TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { |
| 293 // We can't call GetCallbackForImplThread if we released the main thread | 295 // We can't call GetCallbackForImplThread if we released the main thread |
| 294 // reference. | 296 // reference. |
| 295 DCHECK_GT(internal_references_, 0u); | 297 DCHECK_GT(internal_references_, 0u); |
| 296 InternalAddRef(); | 298 InternalAddRef(); |
| 297 return SingleReleaseCallbackImpl::Create( | 299 return SingleReleaseCallbackImpl::Create( |
| 298 base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); | 300 base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void TextureLayer::TextureMailboxHolder::InternalAddRef() { | 303 void TextureLayer::TextureMailboxHolder::InternalAddRef() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 314 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( | 316 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( |
| 315 const gpu::SyncToken& sync_token, | 317 const gpu::SyncToken& sync_token, |
| 316 bool is_lost, | 318 bool is_lost, |
| 317 BlockingTaskRunner* main_thread_task_runner) { | 319 BlockingTaskRunner* main_thread_task_runner) { |
| 318 Return(sync_token, is_lost); | 320 Return(sync_token, is_lost); |
| 319 main_thread_task_runner->PostTask( | 321 main_thread_task_runner->PostTask( |
| 320 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); | 322 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); |
| 321 } | 323 } |
| 322 | 324 |
| 323 } // namespace cc | 325 } // namespace cc |
| OLD | NEW |