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> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "cc/output/renderer.h" | 10 #include "cc/output/renderer.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 own_mailbox_ = false; | 92 own_mailbox_ = false; |
93 } | 93 } |
94 | 94 |
95 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && | 95 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && |
96 texture_mailbox_.IsSharedMemory()) { | 96 texture_mailbox_.IsSharedMemory()) { |
97 DCHECK(!external_texture_resource_); | 97 DCHECK(!external_texture_resource_); |
98 // Have to upload a copy to a texture for it to be used in a | 98 // Have to upload a copy to a texture for it to be used in a |
99 // hardware draw. | 99 // hardware draw. |
100 if (!texture_copy_) | 100 if (!texture_copy_) |
101 texture_copy_ = ScopedResource::Create(resource_provider); | 101 texture_copy_ = ScopedResource::Create(resource_provider); |
102 if (texture_copy_->size() != texture_mailbox_.shared_memory_size() || | 102 if (texture_copy_->size() != texture_mailbox_.size_in_pixels() || |
103 resource_provider->InUseByConsumer(texture_copy_->id())) | 103 resource_provider->InUseByConsumer(texture_copy_->id())) |
104 texture_copy_->Free(); | 104 texture_copy_->Free(); |
105 | 105 |
106 if (!texture_copy_->id()) { | 106 if (!texture_copy_->id()) { |
107 texture_copy_->Allocate(texture_mailbox_.shared_memory_size(), | 107 texture_copy_->Allocate(texture_mailbox_.size_in_pixels(), |
108 ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 108 ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
109 resource_provider->best_texture_format()); | 109 resource_provider->best_texture_format()); |
110 } | 110 } |
111 | 111 |
112 if (texture_copy_->id()) { | 112 if (texture_copy_->id()) { |
113 std::vector<uint8> swizzled; | 113 std::vector<uint8> swizzled; |
114 uint8* pixels = texture_mailbox_.shared_bitmap()->pixels(); | 114 uint8* pixels = texture_mailbox_.shared_bitmap()->pixels(); |
115 | 115 |
116 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { | 116 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { |
117 // Swizzle colors. This is slow, but should be really uncommon. | 117 // Swizzle colors. This is slow, but should be really uncommon. |
118 size_t bytes = texture_mailbox_.SharedMemorySizeInBytes(); | 118 size_t bytes = texture_mailbox_.SharedMemorySizeInBytes(); |
119 swizzled.resize(bytes); | 119 swizzled.resize(bytes); |
120 for (size_t i = 0; i < bytes; i += 4) { | 120 for (size_t i = 0; i < bytes; i += 4) { |
121 swizzled[i] = pixels[i + 2]; | 121 swizzled[i] = pixels[i + 2]; |
122 swizzled[i + 1] = pixels[i + 1]; | 122 swizzled[i + 1] = pixels[i + 1]; |
123 swizzled[i + 2] = pixels[i]; | 123 swizzled[i + 2] = pixels[i]; |
124 swizzled[i + 3] = pixels[i + 3]; | 124 swizzled[i + 3] = pixels[i + 3]; |
125 } | 125 } |
126 pixels = &swizzled[0]; | 126 pixels = &swizzled[0]; |
127 } | 127 } |
128 | 128 |
129 resource_provider->SetPixels( | 129 resource_provider->SetPixels(texture_copy_->id(), pixels, |
130 texture_copy_->id(), | 130 gfx::Rect(texture_mailbox_.size_in_pixels()), |
131 pixels, | 131 gfx::Rect(texture_mailbox_.size_in_pixels()), |
132 gfx::Rect(texture_mailbox_.shared_memory_size()), | 132 gfx::Vector2d()); |
133 gfx::Rect(texture_mailbox_.shared_memory_size()), | |
134 gfx::Vector2d()); | |
135 | 133 |
136 valid_texture_copy_ = true; | 134 valid_texture_copy_ = true; |
137 } | 135 } |
138 } | 136 } |
139 return (external_texture_resource_ || valid_texture_copy_) && | 137 return (external_texture_resource_ || valid_texture_copy_) && |
140 LayerImpl::WillDraw(draw_mode, resource_provider); | 138 LayerImpl::WillDraw(draw_mode, resource_provider); |
141 } | 139 } |
142 | 140 |
143 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, | 141 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, |
144 AppendQuadsData* append_quads_data) { | 142 AppendQuadsData* append_quads_data) { |
(...skipping 27 matching lines...) Expand all Loading... |
172 opaque_rect, | 170 opaque_rect, |
173 visible_quad_rect, | 171 visible_quad_rect, |
174 id, | 172 id, |
175 premultiplied_alpha_, | 173 premultiplied_alpha_, |
176 uv_top_left_, | 174 uv_top_left_, |
177 uv_bottom_right_, | 175 uv_bottom_right_, |
178 bg_color, | 176 bg_color, |
179 vertex_opacity_, | 177 vertex_opacity_, |
180 flipped_, | 178 flipped_, |
181 nearest_neighbor_); | 179 nearest_neighbor_); |
| 180 if (!valid_texture_copy_) { |
| 181 quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels()); |
| 182 quad->set_allow_overlay(texture_mailbox_.allow_overlay()); |
| 183 } |
182 ValidateQuadResources(quad); | 184 ValidateQuadResources(quad); |
183 } | 185 } |
184 | 186 |
185 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { | 187 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { |
186 if (contents_opaque()) | 188 if (contents_opaque()) |
187 return SimpleEnclosedRegion(visible_content_rect()); | 189 return SimpleEnclosedRegion(visible_content_rect()); |
188 | 190 |
189 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 191 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
190 return SimpleEnclosedRegion(visible_content_rect()); | 192 return SimpleEnclosedRegion(visible_content_rect()); |
191 | 193 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } else if (external_texture_resource_) { | 259 } else if (external_texture_resource_) { |
258 DCHECK(!own_mailbox_); | 260 DCHECK(!own_mailbox_); |
259 ResourceProvider* resource_provider = | 261 ResourceProvider* resource_provider = |
260 layer_tree_impl()->resource_provider(); | 262 layer_tree_impl()->resource_provider(); |
261 resource_provider->DeleteResource(external_texture_resource_); | 263 resource_provider->DeleteResource(external_texture_resource_); |
262 external_texture_resource_ = 0; | 264 external_texture_resource_ = 0; |
263 } | 265 } |
264 } | 266 } |
265 | 267 |
266 } // namespace cc | 268 } // namespace cc |
OLD | NEW |