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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 texture_layer->set_vertex_opacity(vertex_opacity_); | 56 texture_layer->set_vertex_opacity(vertex_opacity_); |
57 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); | 57 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); |
58 if (uses_mailbox_ && own_mailbox_) { | 58 if (uses_mailbox_ && own_mailbox_) { |
59 texture_layer->SetTextureMailbox(texture_mailbox_); | 59 texture_layer->SetTextureMailbox(texture_mailbox_); |
60 own_mailbox_ = false; | 60 own_mailbox_ = false; |
61 } else { | 61 } else { |
62 texture_layer->set_texture_id(texture_id_); | 62 texture_layer->set_texture_id(texture_id_); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void TextureLayerImpl::WillDraw(ResourceProvider* resource_provider) { | 66 bool TextureLayerImpl::WillDraw(DrawMode draw_mode, |
67 if (uses_mailbox_ || !texture_id_) | 67 ResourceProvider* resource_provider) { |
68 return; | 68 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
69 DCHECK(!external_texture_resource_); | 69 return false; |
70 external_texture_resource_ = | 70 |
71 resource_provider->CreateResourceFromExternalTexture( | 71 if (!uses_mailbox_ && texture_id_) { |
72 GL_TEXTURE_2D, | 72 DCHECK(!external_texture_resource_); |
73 texture_id_); | 73 external_texture_resource_ = |
| 74 resource_provider->CreateResourceFromExternalTexture( |
| 75 GL_TEXTURE_2D, |
| 76 texture_id_); |
| 77 } |
| 78 return external_texture_resource_ && |
| 79 LayerImpl::WillDraw(draw_mode, resource_provider); |
74 } | 80 } |
75 | 81 |
76 void TextureLayerImpl::AppendQuads(QuadSink* quad_sink, | 82 void TextureLayerImpl::AppendQuads(QuadSink* quad_sink, |
77 AppendQuadsData* append_quads_data) { | 83 AppendQuadsData* append_quads_data) { |
78 if (!external_texture_resource_) | 84 DCHECK(external_texture_resource_); |
79 return; | |
80 | 85 |
81 SharedQuadState* shared_quad_state = | 86 SharedQuadState* shared_quad_state = |
82 quad_sink->UseSharedQuadState(CreateSharedQuadState()); | 87 quad_sink->UseSharedQuadState(CreateSharedQuadState()); |
83 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 88 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
84 | 89 |
85 gfx::Rect quad_rect(content_bounds()); | 90 gfx::Rect quad_rect(content_bounds()); |
86 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | 91 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
87 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 92 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
88 quad->SetNew(shared_quad_state, | 93 quad->SetNew(shared_quad_state, |
89 quad_rect, | 94 quad_rect, |
90 opaque_rect, | 95 opaque_rect, |
91 external_texture_resource_, | 96 external_texture_resource_, |
92 premultiplied_alpha_, | 97 premultiplied_alpha_, |
93 uv_top_left_, | 98 uv_top_left_, |
94 uv_bottom_right_, | 99 uv_bottom_right_, |
95 vertex_opacity_, | 100 vertex_opacity_, |
96 flipped_); | 101 flipped_); |
97 | 102 |
98 // Perform explicit clipping on a quad to avoid setting a scissor later. | 103 // Perform explicit clipping on a quad to avoid setting a scissor later. |
99 if (shared_quad_state->is_clipped && quad->PerformClipping()) | 104 if (shared_quad_state->is_clipped && quad->PerformClipping()) |
100 shared_quad_state->is_clipped = false; | 105 shared_quad_state->is_clipped = false; |
101 if (!quad->rect.IsEmpty()) | 106 if (!quad->rect.IsEmpty()) |
102 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 107 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
103 } | 108 } |
104 | 109 |
105 void TextureLayerImpl::DidDraw(ResourceProvider* resource_provider) { | 110 void TextureLayerImpl::DidDraw(ResourceProvider* resource_provider) { |
| 111 LayerImpl::DidDraw(resource_provider); |
106 if (uses_mailbox_ || !external_texture_resource_) | 112 if (uses_mailbox_ || !external_texture_resource_) |
107 return; | 113 return; |
108 // FIXME: the following assert will not be true when sending resources to a | 114 // FIXME: the following assert will not be true when sending resources to a |
109 // parent compositor. A synchronization scheme (double-buffering or | 115 // parent compositor. A synchronization scheme (double-buffering or |
110 // pipelining of updates) for the client will need to exist to solve this. | 116 // pipelining of updates) for the client will need to exist to solve this. |
111 DCHECK(!resource_provider->InUseByConsumer(external_texture_resource_)); | 117 DCHECK(!resource_provider->InUseByConsumer(external_texture_resource_)); |
112 resource_provider->DeleteResource(external_texture_resource_); | 118 resource_provider->DeleteResource(external_texture_resource_); |
113 external_texture_resource_ = 0; | 119 external_texture_resource_ = 0; |
114 } | 120 } |
115 | 121 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } else if (external_texture_resource_) { | 162 } else if (external_texture_resource_) { |
157 DCHECK(!own_mailbox_); | 163 DCHECK(!own_mailbox_); |
158 ResourceProvider* resource_provider = | 164 ResourceProvider* resource_provider = |
159 layer_tree_impl()->resource_provider(); | 165 layer_tree_impl()->resource_provider(); |
160 resource_provider->DeleteResource(external_texture_resource_); | 166 resource_provider->DeleteResource(external_texture_resource_); |
161 external_texture_resource_ = 0; | 167 external_texture_resource_ = 0; |
162 } | 168 } |
163 } | 169 } |
164 | 170 |
165 } // namespace cc | 171 } // namespace cc |
OLD | NEW |