Chromium Code Reviews| 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" |
| 11 #include "cc/quads/texture_draw_quad.h" | 11 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/resources/platform_color.h" | 12 #include "cc/resources/platform_color.h" |
| 13 #include "cc/resources/scoped_resource.h" | 13 #include "cc/resources/scoped_resource.h" |
| 14 #include "cc/resources/single_release_callback_impl.h" | 14 #include "cc/resources/single_release_callback_impl.h" |
| 15 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
| 16 #include "cc/trees/occlusion.h" | 16 #include "cc/trees/occlusion.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, int id) | 20 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 21 : LayerImpl(tree_impl, id), | 21 : LayerImpl(tree_impl, id), |
| 22 external_texture_resource_(0), | 22 external_texture_resource_(0), |
| 23 external_texture_allow_overlay_(false), | |
| 23 premultiplied_alpha_(true), | 24 premultiplied_alpha_(true), |
| 24 blend_background_color_(false), | 25 blend_background_color_(false), |
| 25 flipped_(true), | 26 flipped_(true), |
| 26 nearest_neighbor_(false), | 27 nearest_neighbor_(false), |
| 27 uv_top_left_(0.f, 0.f), | 28 uv_top_left_(0.f, 0.f), |
| 28 uv_bottom_right_(1.f, 1.f), | 29 uv_bottom_right_(1.f, 1.f), |
| 29 own_mailbox_(false), | 30 own_mailbox_(false), |
| 30 valid_texture_copy_(false) { | 31 valid_texture_copy_(false) { |
| 31 vertex_opacity_[0] = 1.0f; | 32 vertex_opacity_[0] = 1.0f; |
| 32 vertex_opacity_[1] = 1.0f; | 33 vertex_opacity_[1] = 1.0f; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 return false; | 78 return false; |
| 78 | 79 |
| 79 if (own_mailbox_) { | 80 if (own_mailbox_) { |
| 80 DCHECK(!external_texture_resource_); | 81 DCHECK(!external_texture_resource_); |
| 81 if ((draw_mode == DRAW_MODE_HARDWARE && texture_mailbox_.IsTexture()) || | 82 if ((draw_mode == DRAW_MODE_HARDWARE && texture_mailbox_.IsTexture()) || |
| 82 (draw_mode == DRAW_MODE_SOFTWARE && | 83 (draw_mode == DRAW_MODE_SOFTWARE && |
| 83 texture_mailbox_.IsSharedMemory())) { | 84 texture_mailbox_.IsSharedMemory())) { |
| 84 external_texture_resource_ = | 85 external_texture_resource_ = |
| 85 resource_provider->CreateResourceFromTextureMailbox( | 86 resource_provider->CreateResourceFromTextureMailbox( |
| 86 texture_mailbox_, release_callback_.Pass()); | 87 texture_mailbox_, release_callback_.Pass()); |
| 88 external_texture_resource_size_ = texture_mailbox_.size(); | |
| 89 external_texture_allow_overlay_ = texture_mailbox_.allow_overlay(); | |
| 87 DCHECK(external_texture_resource_); | 90 DCHECK(external_texture_resource_); |
| 88 texture_copy_ = nullptr; | 91 texture_copy_ = nullptr; |
| 89 valid_texture_copy_ = false; | 92 valid_texture_copy_ = false; |
| 90 } | 93 } |
| 91 if (external_texture_resource_) | 94 if (external_texture_resource_) |
| 92 own_mailbox_ = false; | 95 own_mailbox_ = false; |
| 93 } | 96 } |
| 94 | 97 |
| 95 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && | 98 if (!valid_texture_copy_ && draw_mode == DRAW_MODE_HARDWARE && |
| 96 texture_mailbox_.IsSharedMemory()) { | 99 texture_mailbox_.IsSharedMemory()) { |
| 97 DCHECK(!external_texture_resource_); | 100 DCHECK(!external_texture_resource_); |
| 98 // Have to upload a copy to a texture for it to be used in a | 101 // Have to upload a copy to a texture for it to be used in a |
| 99 // hardware draw. | 102 // hardware draw. |
| 100 if (!texture_copy_) | 103 if (!texture_copy_) |
| 101 texture_copy_ = ScopedResource::Create(resource_provider); | 104 texture_copy_ = ScopedResource::Create(resource_provider); |
| 102 if (texture_copy_->size() != texture_mailbox_.shared_memory_size() || | 105 if (texture_copy_->size() != texture_mailbox_.size() || |
| 103 resource_provider->InUseByConsumer(texture_copy_->id())) | 106 resource_provider->InUseByConsumer(texture_copy_->id())) |
| 104 texture_copy_->Free(); | 107 texture_copy_->Free(); |
| 105 | 108 |
| 106 if (!texture_copy_->id()) { | 109 if (!texture_copy_->id()) { |
| 107 texture_copy_->Allocate(texture_mailbox_.shared_memory_size(), | 110 texture_copy_->Allocate(texture_mailbox_.size(), |
| 108 ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 111 ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 109 resource_provider->best_texture_format()); | 112 resource_provider->best_texture_format()); |
| 110 } | 113 } |
| 111 | 114 |
| 112 if (texture_copy_->id()) { | 115 if (texture_copy_->id()) { |
| 113 std::vector<uint8> swizzled; | 116 std::vector<uint8> swizzled; |
| 114 uint8* pixels = texture_mailbox_.shared_bitmap()->pixels(); | 117 uint8* pixels = texture_mailbox_.shared_bitmap()->pixels(); |
| 115 | 118 |
| 116 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { | 119 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { |
| 117 // Swizzle colors. This is slow, but should be really uncommon. | 120 // Swizzle colors. This is slow, but should be really uncommon. |
| 118 size_t bytes = texture_mailbox_.SharedMemorySizeInBytes(); | 121 size_t bytes = texture_mailbox_.SharedMemorySizeInBytes(); |
| 119 swizzled.resize(bytes); | 122 swizzled.resize(bytes); |
| 120 for (size_t i = 0; i < bytes; i += 4) { | 123 for (size_t i = 0; i < bytes; i += 4) { |
| 121 swizzled[i] = pixels[i + 2]; | 124 swizzled[i] = pixels[i + 2]; |
| 122 swizzled[i + 1] = pixels[i + 1]; | 125 swizzled[i + 1] = pixels[i + 1]; |
| 123 swizzled[i + 2] = pixels[i]; | 126 swizzled[i + 2] = pixels[i]; |
| 124 swizzled[i + 3] = pixels[i + 3]; | 127 swizzled[i + 3] = pixels[i + 3]; |
| 125 } | 128 } |
| 126 pixels = &swizzled[0]; | 129 pixels = &swizzled[0]; |
| 127 } | 130 } |
| 128 | 131 |
| 129 resource_provider->SetPixels( | 132 resource_provider->SetPixels( |
| 130 texture_copy_->id(), | 133 texture_copy_->id(), pixels, gfx::Rect(texture_mailbox_.size()), |
| 131 pixels, | 134 gfx::Rect(texture_mailbox_.size()), gfx::Vector2d()); |
| 132 gfx::Rect(texture_mailbox_.shared_memory_size()), | |
| 133 gfx::Rect(texture_mailbox_.shared_memory_size()), | |
| 134 gfx::Vector2d()); | |
| 135 | 135 |
| 136 valid_texture_copy_ = true; | 136 valid_texture_copy_ = true; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 return (external_texture_resource_ || valid_texture_copy_) && | 139 return (external_texture_resource_ || valid_texture_copy_) && |
| 140 LayerImpl::WillDraw(draw_mode, resource_provider); | 140 LayerImpl::WillDraw(draw_mode, resource_provider); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, | 143 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, |
| 144 AppendQuadsData* append_quads_data) { | 144 AppendQuadsData* append_quads_data) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 opaque_rect, | 172 opaque_rect, |
| 173 visible_quad_rect, | 173 visible_quad_rect, |
| 174 id, | 174 id, |
| 175 premultiplied_alpha_, | 175 premultiplied_alpha_, |
| 176 uv_top_left_, | 176 uv_top_left_, |
| 177 uv_bottom_right_, | 177 uv_bottom_right_, |
| 178 bg_color, | 178 bg_color, |
| 179 vertex_opacity_, | 179 vertex_opacity_, |
| 180 flipped_, | 180 flipped_, |
| 181 nearest_neighbor_); | 181 nearest_neighbor_); |
| 182 if (!valid_texture_copy_) { | |
| 183 quad->resource_size = external_texture_resource_size_; | |
|
danakj
2015/05/29 20:04:14
could you just pull these from the texture_mailbox
achaulk
2015/06/01 15:43:10
Done.
| |
| 184 quad->allow_overlay = external_texture_allow_overlay_; | |
| 185 } | |
| 182 ValidateQuadResources(quad); | 186 ValidateQuadResources(quad); |
| 183 } | 187 } |
| 184 | 188 |
| 185 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { | 189 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { |
| 186 if (contents_opaque()) | 190 if (contents_opaque()) |
| 187 return SimpleEnclosedRegion(visible_content_rect()); | 191 return SimpleEnclosedRegion(visible_content_rect()); |
| 188 | 192 |
| 189 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 193 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
| 190 return SimpleEnclosedRegion(visible_content_rect()); | 194 return SimpleEnclosedRegion(visible_content_rect()); |
| 191 | 195 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 } else if (external_texture_resource_) { | 261 } else if (external_texture_resource_) { |
| 258 DCHECK(!own_mailbox_); | 262 DCHECK(!own_mailbox_); |
| 259 ResourceProvider* resource_provider = | 263 ResourceProvider* resource_provider = |
| 260 layer_tree_impl()->resource_provider(); | 264 layer_tree_impl()->resource_provider(); |
| 261 resource_provider->DeleteResource(external_texture_resource_); | 265 resource_provider->DeleteResource(external_texture_resource_); |
| 262 external_texture_resource_ = 0; | 266 external_texture_resource_ = 0; |
| 263 } | 267 } |
| 264 } | 268 } |
| 265 | 269 |
| 266 } // namespace cc | 270 } // namespace cc |
| OLD | NEW |