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 premultiplied_alpha_(true), | 23 premultiplied_alpha_(true), |
| 24 blend_background_color_(false), | 24 blend_background_color_(false), |
| 25 flipped_(true), | 25 flipped_(true), |
| 26 nearest_neighbor_(false), | |
| 26 uv_top_left_(0.f, 0.f), | 27 uv_top_left_(0.f, 0.f), |
| 27 uv_bottom_right_(1.f, 1.f), | 28 uv_bottom_right_(1.f, 1.f), |
| 28 own_mailbox_(false), | 29 own_mailbox_(false), |
| 29 valid_texture_copy_(false) { | 30 valid_texture_copy_(false) { |
| 30 vertex_opacity_[0] = 1.0f; | 31 vertex_opacity_[0] = 1.0f; |
| 31 vertex_opacity_[1] = 1.0f; | 32 vertex_opacity_[1] = 1.0f; |
| 32 vertex_opacity_[2] = 1.0f; | 33 vertex_opacity_[2] = 1.0f; |
| 33 vertex_opacity_[3] = 1.0f; | 34 vertex_opacity_[3] = 1.0f; |
| 34 } | 35 } |
| 35 | 36 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 55 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 56 void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 56 LayerImpl::PushPropertiesTo(layer); | 57 LayerImpl::PushPropertiesTo(layer); |
| 57 | 58 |
| 58 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 59 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
| 59 texture_layer->SetFlipped(flipped_); | 60 texture_layer->SetFlipped(flipped_); |
| 60 texture_layer->SetUVTopLeft(uv_top_left_); | 61 texture_layer->SetUVTopLeft(uv_top_left_); |
| 61 texture_layer->SetUVBottomRight(uv_bottom_right_); | 62 texture_layer->SetUVBottomRight(uv_bottom_right_); |
| 62 texture_layer->SetVertexOpacity(vertex_opacity_); | 63 texture_layer->SetVertexOpacity(vertex_opacity_); |
| 63 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); | 64 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); |
| 64 texture_layer->SetBlendBackgroundColor(blend_background_color_); | 65 texture_layer->SetBlendBackgroundColor(blend_background_color_); |
| 66 texture_layer->SetNearestNeighbor(nearest_neighbor_); | |
| 65 if (own_mailbox_) { | 67 if (own_mailbox_) { |
| 66 texture_layer->SetTextureMailbox(texture_mailbox_, | 68 texture_layer->SetTextureMailbox(texture_mailbox_, |
| 67 release_callback_.Pass()); | 69 release_callback_.Pass()); |
| 68 own_mailbox_ = false; | 70 own_mailbox_ = false; |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool TextureLayerImpl::WillDraw(DrawMode draw_mode, | 74 bool TextureLayerImpl::WillDraw(DrawMode draw_mode, |
| 73 ResourceProvider* resource_provider) { | 75 ResourceProvider* resource_provider) { |
| 74 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 76 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 94 texture_mailbox_.IsSharedMemory()) { | 96 texture_mailbox_.IsSharedMemory()) { |
| 95 DCHECK(!external_texture_resource_); | 97 DCHECK(!external_texture_resource_); |
| 96 // 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 |
| 97 // hardware draw. | 99 // hardware draw. |
| 98 if (!texture_copy_) | 100 if (!texture_copy_) |
| 99 texture_copy_ = ScopedResource::Create(resource_provider); | 101 texture_copy_ = ScopedResource::Create(resource_provider); |
| 100 if (texture_copy_->size() != texture_mailbox_.shared_memory_size() || | 102 if (texture_copy_->size() != texture_mailbox_.shared_memory_size() || |
| 101 resource_provider->InUseByConsumer(texture_copy_->id())) | 103 resource_provider->InUseByConsumer(texture_copy_->id())) |
| 102 texture_copy_->Free(); | 104 texture_copy_->Free(); |
| 103 | 105 |
| 106 //if (nearest_neighbor_) | |
| 107 //texture_copy_->filter = GL_NEAREST; | |
| 108 | |
| 104 if (!texture_copy_->id()) { | 109 if (!texture_copy_->id()) { |
| 105 texture_copy_->Allocate(texture_mailbox_.shared_memory_size(), | 110 texture_copy_->Allocate(texture_mailbox_.shared_memory_size(), |
| 106 ResourceProvider::TextureHintImmutable, | 111 ResourceProvider::TextureHintDefault, |
|
piman
2014/10/28 05:09:50
Why changing this? (and other places)
Immutability
jackhou1
2014/10/29 00:12:25
Oops, I wasn't sure if this mattered. Removed.
| |
| 107 resource_provider->best_texture_format()); | 112 resource_provider->best_texture_format()); |
| 108 } | 113 } |
| 109 | 114 |
| 110 if (texture_copy_->id()) { | 115 if (texture_copy_->id()) { |
| 111 std::vector<uint8> swizzled; | 116 std::vector<uint8> swizzled; |
| 112 uint8* pixels = | 117 uint8* pixels = |
| 113 static_cast<uint8*>(texture_mailbox_.shared_memory()->memory()); | 118 static_cast<uint8*>(texture_mailbox_.shared_memory()->memory()); |
| 114 | 119 |
| 115 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { | 120 if (!PlatformColor::SameComponentOrder(texture_copy_->format())) { |
| 116 // Swizzle colors. This is slow, but should be really uncommon. | 121 // Swizzle colors. This is slow, but should be really uncommon. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 128 resource_provider->SetPixels( | 133 resource_provider->SetPixels( |
| 129 texture_copy_->id(), | 134 texture_copy_->id(), |
| 130 pixels, | 135 pixels, |
| 131 gfx::Rect(texture_mailbox_.shared_memory_size()), | 136 gfx::Rect(texture_mailbox_.shared_memory_size()), |
| 132 gfx::Rect(texture_mailbox_.shared_memory_size()), | 137 gfx::Rect(texture_mailbox_.shared_memory_size()), |
| 133 gfx::Vector2d()); | 138 gfx::Vector2d()); |
| 134 | 139 |
| 135 valid_texture_copy_ = true; | 140 valid_texture_copy_ = true; |
| 136 } | 141 } |
| 137 } | 142 } |
| 138 return (external_texture_resource_ || valid_texture_copy_) && | 143 bool result = (external_texture_resource_ || valid_texture_copy_) && |
| 139 LayerImpl::WillDraw(draw_mode, resource_provider); | 144 LayerImpl::WillDraw(draw_mode, resource_provider); |
| 145 //printf("TextureLayerImpl::WillDraw %d %p\n", result, this); | |
| 146 return result; | |
| 140 } | 147 } |
| 141 | 148 |
| 142 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, | 149 void TextureLayerImpl::AppendQuads(RenderPass* render_pass, |
| 143 const Occlusion& occlusion_in_content_space, | 150 const Occlusion& occlusion_in_content_space, |
| 144 AppendQuadsData* append_quads_data) { | 151 AppendQuadsData* append_quads_data) { |
| 145 DCHECK(external_texture_resource_ || valid_texture_copy_); | 152 DCHECK(external_texture_resource_ || valid_texture_copy_); |
| 146 | 153 |
| 147 SharedQuadState* shared_quad_state = | 154 SharedQuadState* shared_quad_state = |
| 148 render_pass->CreateAndAppendSharedQuadState(); | 155 render_pass->CreateAndAppendSharedQuadState(); |
| 149 PopulateSharedQuadState(shared_quad_state); | 156 PopulateSharedQuadState(shared_quad_state); |
| 150 | 157 |
| 151 AppendDebugBorderQuad( | 158 AppendDebugBorderQuad( |
| 152 render_pass, content_bounds(), shared_quad_state, append_quads_data); | 159 render_pass, content_bounds(), shared_quad_state, append_quads_data); |
| 153 | 160 |
| 154 SkColor bg_color = blend_background_color_ ? | 161 SkColor bg_color = blend_background_color_ ? |
| 155 background_color() : SK_ColorTRANSPARENT; | 162 background_color() : SK_ColorTRANSPARENT; |
| 156 bool opaque = contents_opaque() || (SkColorGetA(bg_color) == 0xFF); | 163 bool opaque = contents_opaque() || (SkColorGetA(bg_color) == 0xFF); |
| 157 | 164 |
| 158 gfx::Rect quad_rect(content_bounds()); | 165 gfx::Rect quad_rect(content_bounds()); |
| 159 gfx::Rect opaque_rect = opaque ? quad_rect : gfx::Rect(); | 166 gfx::Rect opaque_rect = opaque ? quad_rect : gfx::Rect(); |
| 160 gfx::Rect visible_quad_rect = | 167 gfx::Rect visible_quad_rect = |
| 161 occlusion_in_content_space.GetUnoccludedContentRect(quad_rect); | 168 occlusion_in_content_space.GetUnoccludedContentRect(quad_rect); |
| 162 if (visible_quad_rect.IsEmpty()) | 169 if (visible_quad_rect.IsEmpty()) |
| 163 return; | 170 return; |
| 164 | 171 |
| 165 TextureDrawQuad* quad = | 172 TextureDrawQuad* quad = |
| 166 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 173 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 167 ResourceProvider::ResourceId id = | 174 ResourceProvider::ResourceId id = |
| 168 valid_texture_copy_ ? texture_copy_->id() : external_texture_resource_; | 175 valid_texture_copy_ ? texture_copy_->id() : external_texture_resource_; |
| 176 | |
| 177 //printf("TextureLayerImpl::AppendQuads %d %d %p\n", nearest_neighbor_, id, th is); | |
| 169 quad->SetNew(shared_quad_state, | 178 quad->SetNew(shared_quad_state, |
| 170 quad_rect, | 179 quad_rect, |
| 171 opaque_rect, | 180 opaque_rect, |
| 172 visible_quad_rect, | 181 visible_quad_rect, |
| 173 id, | 182 id, |
| 174 premultiplied_alpha_, | 183 premultiplied_alpha_, |
| 175 uv_top_left_, | 184 uv_top_left_, |
| 176 uv_bottom_right_, | 185 uv_bottom_right_, |
| 177 bg_color, | 186 bg_color, |
| 178 vertex_opacity_, | 187 vertex_opacity_, |
| 179 flipped_); | 188 flipped_, |
| 189 nearest_neighbor_); | |
| 180 } | 190 } |
| 181 | 191 |
| 182 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { | 192 SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const { |
| 183 if (contents_opaque()) | 193 if (contents_opaque()) |
| 184 return SimpleEnclosedRegion(visible_content_rect()); | 194 return SimpleEnclosedRegion(visible_content_rect()); |
| 185 | 195 |
| 186 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 196 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
| 187 return SimpleEnclosedRegion(visible_content_rect()); | 197 return SimpleEnclosedRegion(visible_content_rect()); |
| 188 | 198 |
| 189 return SimpleEnclosedRegion(); | 199 return SimpleEnclosedRegion(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 204 void TextureLayerImpl::SetBlendBackgroundColor(bool blend) { | 214 void TextureLayerImpl::SetBlendBackgroundColor(bool blend) { |
| 205 blend_background_color_ = blend; | 215 blend_background_color_ = blend; |
| 206 SetNeedsPushProperties(); | 216 SetNeedsPushProperties(); |
| 207 } | 217 } |
| 208 | 218 |
| 209 void TextureLayerImpl::SetFlipped(bool flipped) { | 219 void TextureLayerImpl::SetFlipped(bool flipped) { |
| 210 flipped_ = flipped; | 220 flipped_ = flipped; |
| 211 SetNeedsPushProperties(); | 221 SetNeedsPushProperties(); |
| 212 } | 222 } |
| 213 | 223 |
| 224 void TextureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { | |
| 225 //printf("TextureLayerImpl::SetNearestNeighbor %d %p\n", nearest_neighbor, thi s); | |
| 226 nearest_neighbor_ = nearest_neighbor; | |
| 227 SetNeedsPushProperties(); | |
| 228 } | |
| 229 | |
| 214 void TextureLayerImpl::SetUVTopLeft(const gfx::PointF top_left) { | 230 void TextureLayerImpl::SetUVTopLeft(const gfx::PointF top_left) { |
| 215 uv_top_left_ = top_left; | 231 uv_top_left_ = top_left; |
| 216 SetNeedsPushProperties(); | 232 SetNeedsPushProperties(); |
| 217 } | 233 } |
| 218 | 234 |
| 219 void TextureLayerImpl::SetUVBottomRight(const gfx::PointF bottom_right) { | 235 void TextureLayerImpl::SetUVBottomRight(const gfx::PointF bottom_right) { |
| 220 uv_bottom_right_ = bottom_right; | 236 uv_bottom_right_ = bottom_right; |
| 221 SetNeedsPushProperties(); | 237 SetNeedsPushProperties(); |
| 222 } | 238 } |
| 223 | 239 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 249 } else if (external_texture_resource_) { | 265 } else if (external_texture_resource_) { |
| 250 DCHECK(!own_mailbox_); | 266 DCHECK(!own_mailbox_); |
| 251 ResourceProvider* resource_provider = | 267 ResourceProvider* resource_provider = |
| 252 layer_tree_impl()->resource_provider(); | 268 layer_tree_impl()->resource_provider(); |
| 253 resource_provider->DeleteResource(external_texture_resource_); | 269 resource_provider->DeleteResource(external_texture_resource_); |
| 254 external_texture_resource_ = 0; | 270 external_texture_resource_ = 0; |
| 255 } | 271 } |
| 256 } | 272 } |
| 257 | 273 |
| 258 } // namespace cc | 274 } // namespace cc |
| OLD | NEW |