| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_impl.h" | 5 #include "cc/layers/texture_layer_impl.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 8 #include "cc/layers/quad_sink.h" | 10 #include "cc/layers/quad_sink.h" |
| 9 #include "cc/output/renderer.h" | 11 #include "cc/output/renderer.h" |
| 10 #include "cc/quads/texture_draw_quad.h" | 12 #include "cc/quads/texture_draw_quad.h" |
| 11 #include "cc/resources/platform_color.h" | 13 #include "cc/resources/platform_color.h" |
| 12 #include "cc/resources/scoped_resource.h" | 14 #include "cc/resources/scoped_resource.h" |
| 13 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
| 14 | 16 |
| 15 namespace cc { | 17 namespace cc { |
| 16 | 18 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 29 own_mailbox_(false), | 31 own_mailbox_(false), |
| 30 valid_texture_copy_(false) { | 32 valid_texture_copy_(false) { |
| 31 vertex_opacity_[0] = 1.0f; | 33 vertex_opacity_[0] = 1.0f; |
| 32 vertex_opacity_[1] = 1.0f; | 34 vertex_opacity_[1] = 1.0f; |
| 33 vertex_opacity_[2] = 1.0f; | 35 vertex_opacity_[2] = 1.0f; |
| 34 vertex_opacity_[3] = 1.0f; | 36 vertex_opacity_[3] = 1.0f; |
| 35 } | 37 } |
| 36 | 38 |
| 37 TextureLayerImpl::~TextureLayerImpl() { FreeTextureMailbox(); } | 39 TextureLayerImpl::~TextureLayerImpl() { FreeTextureMailbox(); } |
| 38 | 40 |
| 39 void TextureLayerImpl::SetTextureMailbox(const TextureMailbox& mailbox) { | 41 void TextureLayerImpl::SetTextureMailbox( |
| 42 const TextureMailbox& mailbox, |
| 43 ScopedReleaseCallback release_callback) { |
| 40 DCHECK(uses_mailbox_); | 44 DCHECK(uses_mailbox_); |
| 45 DCHECK_EQ(mailbox.IsValid(), !release_callback.IsEmpty()); |
| 41 FreeTextureMailbox(); | 46 FreeTextureMailbox(); |
| 42 texture_mailbox_ = mailbox; | 47 texture_mailbox_ = mailbox; |
| 48 release_callback_ = release_callback.Pass(); |
| 43 own_mailbox_ = true; | 49 own_mailbox_ = true; |
| 44 valid_texture_copy_ = false; | 50 valid_texture_copy_ = false; |
| 45 } | 51 } |
| 46 | 52 |
| 47 scoped_ptr<LayerImpl> TextureLayerImpl::CreateLayerImpl( | 53 scoped_ptr<LayerImpl> TextureLayerImpl::CreateLayerImpl( |
| 48 LayerTreeImpl* tree_impl) { | 54 LayerTreeImpl* tree_impl) { |
| 49 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). | 55 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). |
| 50 PassAs<LayerImpl>(); | 56 PassAs<LayerImpl>(); |
| 51 } | 57 } |
| 52 | 58 |
| 53 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 59 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 54 LayerImpl::PushPropertiesTo(layer); | 60 LayerImpl::PushPropertiesTo(layer); |
| 55 | 61 |
| 56 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 62 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
| 57 texture_layer->set_flipped(flipped_); | 63 texture_layer->set_flipped(flipped_); |
| 58 texture_layer->set_uv_top_left(uv_top_left_); | 64 texture_layer->set_uv_top_left(uv_top_left_); |
| 59 texture_layer->set_uv_bottom_right(uv_bottom_right_); | 65 texture_layer->set_uv_bottom_right(uv_bottom_right_); |
| 60 texture_layer->set_vertex_opacity(vertex_opacity_); | 66 texture_layer->set_vertex_opacity(vertex_opacity_); |
| 61 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); | 67 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); |
| 62 if (uses_mailbox_ && own_mailbox_) { | 68 if (uses_mailbox_ && own_mailbox_) { |
| 63 texture_layer->SetTextureMailbox(texture_mailbox_); | 69 texture_layer->SetTextureMailbox(texture_mailbox_, |
| 70 release_callback_.Pass()); |
| 64 own_mailbox_ = false; | 71 own_mailbox_ = false; |
| 65 } else { | 72 } else { |
| 66 texture_layer->set_texture_id(texture_id_); | 73 texture_layer->set_texture_id(texture_id_); |
| 67 } | 74 } |
| 68 } | 75 } |
| 69 | 76 |
| 70 bool TextureLayerImpl::WillDraw(DrawMode draw_mode, | 77 bool TextureLayerImpl::WillDraw(DrawMode draw_mode, |
| 71 ResourceProvider* resource_provider) { | 78 ResourceProvider* resource_provider) { |
| 72 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 79 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| 73 return false; | 80 return false; |
| 74 | 81 |
| 75 if (uses_mailbox_) { | 82 if (uses_mailbox_) { |
| 76 if (own_mailbox_) { | 83 if (own_mailbox_) { |
| 77 DCHECK(!external_texture_resource_); | 84 DCHECK(!external_texture_resource_); |
| 78 if ((draw_mode == DRAW_MODE_HARDWARE && texture_mailbox_.IsTexture()) || | 85 if ((draw_mode == DRAW_MODE_HARDWARE && texture_mailbox_.IsTexture()) || |
| 79 (draw_mode == DRAW_MODE_SOFTWARE && | 86 (draw_mode == DRAW_MODE_SOFTWARE && |
| 80 texture_mailbox_.IsSharedMemory())) { | 87 texture_mailbox_.IsSharedMemory())) { |
| 81 external_texture_resource_ = | 88 external_texture_resource_ = |
| 82 resource_provider->CreateResourceFromTextureMailbox( | 89 resource_provider->CreateResourceFromTextureMailbox( |
| 83 texture_mailbox_); | 90 texture_mailbox_, |
| 91 release_callback_.Pass()); |
| 84 DCHECK(external_texture_resource_); | 92 DCHECK(external_texture_resource_); |
| 85 texture_copy_.reset(); | 93 texture_copy_.reset(); |
| 86 valid_texture_copy_ = false; | 94 valid_texture_copy_ = false; |
| 87 } | 95 } |
| 88 if (external_texture_resource_) | 96 if (external_texture_resource_) |
| 89 own_mailbox_ = false; | 97 own_mailbox_ = false; |
| 90 } | 98 } |
| 91 | 99 |
| 92 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && | 100 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && |
| 93 texture_mailbox_.IsSharedMemory()) { | 101 texture_mailbox_.IsSharedMemory()) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 230 |
| 223 bool TextureLayerImpl::CanClipSelf() const { | 231 bool TextureLayerImpl::CanClipSelf() const { |
| 224 return true; | 232 return true; |
| 225 } | 233 } |
| 226 | 234 |
| 227 void TextureLayerImpl::FreeTextureMailbox() { | 235 void TextureLayerImpl::FreeTextureMailbox() { |
| 228 if (!uses_mailbox_) | 236 if (!uses_mailbox_) |
| 229 return; | 237 return; |
| 230 if (own_mailbox_) { | 238 if (own_mailbox_) { |
| 231 DCHECK(!external_texture_resource_); | 239 DCHECK(!external_texture_resource_); |
| 232 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); | 240 if (!release_callback_.IsEmpty()) |
| 241 release_callback_.RunAndReset(texture_mailbox_.sync_point(), false); |
| 233 } else if (external_texture_resource_) { | 242 } else if (external_texture_resource_) { |
| 234 DCHECK(!own_mailbox_); | 243 DCHECK(!own_mailbox_); |
| 235 ResourceProvider* resource_provider = | 244 ResourceProvider* resource_provider = |
| 236 layer_tree_impl()->resource_provider(); | 245 layer_tree_impl()->resource_provider(); |
| 237 resource_provider->DeleteResource(external_texture_resource_); | 246 resource_provider->DeleteResource(external_texture_resource_); |
| 238 external_texture_resource_ = 0; | 247 external_texture_resource_ = 0; |
| 239 } | 248 } |
| 240 } | 249 } |
| 241 | 250 |
| 242 } // namespace cc | 251 } // namespace cc |
| OLD | NEW |