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