| 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 "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "cc/layers/quad_sink.h" | 8 #include "cc/layers/quad_sink.h" |
| 9 #include "cc/output/renderer.h" | 9 #include "cc/output/renderer.h" |
| 10 #include "cc/quads/texture_draw_quad.h" | 10 #include "cc/quads/texture_draw_quad.h" |
| 11 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, | 15 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, |
| 16 int id, | 16 int id, |
| 17 bool uses_mailbox) | 17 bool uses_mailbox) |
| 18 : LayerImpl(tree_impl, id), | 18 : LayerImpl(tree_impl, id), |
| 19 uses_mailbox_(uses_mailbox), |
| 19 texture_id_(0), | 20 texture_id_(0), |
| 20 external_texture_resource_(0), | 21 external_texture_resource_(0), |
| 21 premultiplied_alpha_(true), | 22 premultiplied_alpha_(true), |
| 22 flipped_(true), | 23 flipped_(true), |
| 23 uv_top_left_(0.f, 0.f), | 24 uv_top_left_(0.f, 0.f), |
| 24 uv_bottom_right_(1.f, 1.f), | 25 uv_bottom_right_(1.f, 1.f), |
| 25 uses_mailbox_(uses_mailbox), | |
| 26 own_mailbox_(false) { | 26 own_mailbox_(false) { |
| 27 vertex_opacity_[0] = 1.0f; | 27 vertex_opacity_[0] = 1.0f; |
| 28 vertex_opacity_[1] = 1.0f; | 28 vertex_opacity_[1] = 1.0f; |
| 29 vertex_opacity_[2] = 1.0f; | 29 vertex_opacity_[2] = 1.0f; |
| 30 vertex_opacity_[3] = 1.0f; | 30 vertex_opacity_[3] = 1.0f; |
| 31 } | 31 } |
| 32 | 32 |
| 33 TextureLayerImpl::~TextureLayerImpl() { FreeTextureMailbox(); } | 33 TextureLayerImpl::~TextureLayerImpl() { |
| 34 FreeMailbox(); |
| 35 } |
| 34 | 36 |
| 35 void TextureLayerImpl::SetTextureMailbox(const TextureMailbox& mailbox) { | 37 void TextureLayerImpl::SetTextureMailbox(const TextureMailbox& mailbox) { |
| 36 DCHECK(uses_mailbox_); | 38 DCHECK(uses_mailbox_); |
| 37 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(texture_mailbox_)); | 39 DCHECK(!mailbox.IsValid() || !mailbox.Equals(mailbox_)); |
| 38 FreeTextureMailbox(); | 40 FreeMailbox(); |
| 39 texture_mailbox_ = mailbox; | 41 mailbox_ = mailbox; |
| 40 own_mailbox_ = true; | 42 own_mailbox_ = true; |
| 41 } | 43 } |
| 42 | 44 |
| 43 scoped_ptr<LayerImpl> TextureLayerImpl::CreateLayerImpl( | 45 scoped_ptr<LayerImpl> TextureLayerImpl::CreateLayerImpl( |
| 44 LayerTreeImpl* tree_impl) { | 46 LayerTreeImpl* tree_impl) { |
| 45 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). | 47 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). |
| 46 PassAs<LayerImpl>(); | 48 PassAs<LayerImpl>(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 51 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 50 LayerImpl::PushPropertiesTo(layer); | 52 LayerImpl::PushPropertiesTo(layer); |
| 51 | 53 |
| 52 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 54 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
| 53 texture_layer->set_flipped(flipped_); | 55 texture_layer->set_flipped(flipped_); |
| 54 texture_layer->set_uv_top_left(uv_top_left_); | 56 texture_layer->set_uv_top_left(uv_top_left_); |
| 55 texture_layer->set_uv_bottom_right(uv_bottom_right_); | 57 texture_layer->set_uv_bottom_right(uv_bottom_right_); |
| 56 texture_layer->set_vertex_opacity(vertex_opacity_); | 58 texture_layer->set_vertex_opacity(vertex_opacity_); |
| 57 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); | 59 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); |
| 58 if (uses_mailbox_ && own_mailbox_) { | 60 if (uses_mailbox_ && own_mailbox_) { |
| 59 texture_layer->SetTextureMailbox(texture_mailbox_); | 61 texture_layer->SetTextureMailbox(mailbox_); |
| 60 own_mailbox_ = false; | 62 own_mailbox_ = false; |
| 61 } else { | 63 } else { |
| 62 texture_layer->set_texture_id(texture_id_); | 64 texture_layer->set_texture_id(texture_id_); |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 | 67 |
| 66 void TextureLayerImpl::WillDraw(ResourceProvider* resource_provider) { | 68 void TextureLayerImpl::WillDraw(ResourceProvider* resource_provider) { |
| 67 if (uses_mailbox_ || !texture_id_) | 69 if (uses_mailbox_ || !texture_id_) |
| 68 return; | 70 return; |
| 69 DCHECK(!external_texture_resource_); | 71 DCHECK(!external_texture_resource_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 135 |
| 134 bool TextureLayerImpl::CanClipSelf() const { | 136 bool TextureLayerImpl::CanClipSelf() const { |
| 135 return true; | 137 return true; |
| 136 } | 138 } |
| 137 | 139 |
| 138 void TextureLayerImpl::DidBecomeActive() { | 140 void TextureLayerImpl::DidBecomeActive() { |
| 139 if (!own_mailbox_) | 141 if (!own_mailbox_) |
| 140 return; | 142 return; |
| 141 DCHECK(!external_texture_resource_); | 143 DCHECK(!external_texture_resource_); |
| 142 ResourceProvider* resource_provider = layer_tree_impl()->resource_provider(); | 144 ResourceProvider* resource_provider = layer_tree_impl()->resource_provider(); |
| 143 if (!texture_mailbox_.IsEmpty()) { | 145 if (mailbox_.IsValid()) { |
| 144 external_texture_resource_ = | 146 external_texture_resource_ = |
| 145 resource_provider->CreateResourceFromTextureMailbox(texture_mailbox_); | 147 resource_provider->CreateResourceFromTextureMailbox(mailbox_); |
| 146 } | 148 } |
| 147 own_mailbox_ = false; | 149 own_mailbox_ = false; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void TextureLayerImpl::FreeTextureMailbox() { | 152 void TextureLayerImpl::FreeMailbox() { |
| 151 if (!uses_mailbox_) | 153 if (!uses_mailbox_) |
| 152 return; | 154 return; |
| 153 if (own_mailbox_) { | 155 if (own_mailbox_) { |
| 154 DCHECK(!external_texture_resource_); | 156 DCHECK(!external_texture_resource_); |
| 155 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); | 157 mailbox_.RunReleaseCallback(mailbox_.sync_point(), false); |
| 156 } else if (external_texture_resource_) { | 158 } else if (external_texture_resource_) { |
| 157 DCHECK(!own_mailbox_); | 159 DCHECK(!own_mailbox_); |
| 158 ResourceProvider* resource_provider = | 160 ResourceProvider* resource_provider = |
| 159 layer_tree_impl()->resource_provider(); | 161 layer_tree_impl()->resource_provider(); |
| 160 resource_provider->DeleteResource(external_texture_resource_); | 162 resource_provider->DeleteResource(external_texture_resource_); |
| 161 external_texture_resource_ = 0; | 163 external_texture_resource_ = 0; |
| 162 } | 164 } |
| 163 } | 165 } |
| 164 | 166 |
| 165 } // namespace cc | 167 } // namespace cc |
| OLD | NEW |