| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/nine_patch_layer_impl.h" | 5 #include "cc/layers/nine_patch_layer_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/quad_sink.h" | |
| 11 #include "cc/quads/texture_draw_quad.h" | 10 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
| 12 #include "cc/trees/occlusion_tracker.h" |
| 13 #include "ui/gfx/rect_f.h" | 13 #include "ui/gfx/rect_f.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) | 17 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 18 : UIResourceLayerImpl(tree_impl, id), | 18 : UIResourceLayerImpl(tree_impl, id), |
| 19 fill_center_(false) {} | 19 fill_center_(false) {} |
| 20 | 20 |
| 21 NinePatchLayerImpl::~NinePatchLayerImpl() {} | 21 NinePatchLayerImpl::~NinePatchLayerImpl() {} |
| 22 | 22 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 DCHECK_GE(border_.x(), 0); | 73 DCHECK_GE(border_.x(), 0); |
| 74 DCHECK_GE(border_.y(), 0); | 74 DCHECK_GE(border_.y(), 0); |
| 75 | 75 |
| 76 // |aperture| is in image space. It cannot exceed the bounds of the bitmap. | 76 // |aperture| is in image space. It cannot exceed the bounds of the bitmap. |
| 77 DCHECK(!image_aperture_.size().IsEmpty()); | 77 DCHECK(!image_aperture_.size().IsEmpty()); |
| 78 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) | 78 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) |
| 79 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() | 79 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() |
| 80 << " image_aperture_ " << image_aperture_.ToString(); | 80 << " image_aperture_ " << image_aperture_.ToString(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink, | 83 void NinePatchLayerImpl::AppendQuads( |
| 84 AppendQuadsData* append_quads_data) { | 84 RenderPass* render_pass, |
| 85 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 86 AppendQuadsData* append_quads_data) { |
| 85 CheckGeometryLimitations(); | 87 CheckGeometryLimitations(); |
| 86 SharedQuadState* shared_quad_state = quad_sink->CreateSharedQuadState(); | 88 SharedQuadState* shared_quad_state = |
| 89 render_pass->CreateAndAppendSharedQuadState(); |
| 87 PopulateSharedQuadState(shared_quad_state); | 90 PopulateSharedQuadState(shared_quad_state); |
| 88 | 91 |
| 89 AppendDebugBorderQuad( | 92 AppendDebugBorderQuad( |
| 90 quad_sink, content_bounds(), shared_quad_state, append_quads_data); | 93 render_pass, content_bounds(), shared_quad_state, append_quads_data); |
| 91 | 94 |
| 92 if (!ui_resource_id_) | 95 if (!ui_resource_id_) |
| 93 return; | 96 return; |
| 94 | 97 |
| 95 ResourceProvider::ResourceId resource = | 98 ResourceProvider::ResourceId resource = |
| 96 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | 99 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
| 97 | 100 |
| 98 if (!resource) | 101 if (!resource) |
| 99 return; | 102 return; |
| 100 | 103 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 uv_left.height()); | 208 uv_left.height()); |
| 206 | 209 |
| 207 // Nothing is opaque here. | 210 // Nothing is opaque here. |
| 208 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? | 211 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? |
| 209 gfx::Rect opaque_rect; | 212 gfx::Rect opaque_rect; |
| 210 gfx::Rect visible_rect; | 213 gfx::Rect visible_rect; |
| 211 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 214 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 212 scoped_ptr<TextureDrawQuad> quad; | 215 scoped_ptr<TextureDrawQuad> quad; |
| 213 | 216 |
| 214 visible_rect = | 217 visible_rect = |
| 215 quad_sink->UnoccludedContentRect(layer_top_left, draw_transform()); | 218 occlusion_tracker.UnoccludedContentRect(layer_top_left, draw_transform()); |
| 216 if (!visible_rect.IsEmpty()) { | 219 if (!visible_rect.IsEmpty()) { |
| 217 quad = TextureDrawQuad::Create(); | 220 quad = TextureDrawQuad::Create(); |
| 218 quad->SetNew(shared_quad_state, | 221 quad->SetNew(shared_quad_state, |
| 219 layer_top_left, | 222 layer_top_left, |
| 220 opaque_rect, | 223 opaque_rect, |
| 221 visible_rect, | 224 visible_rect, |
| 222 resource, | 225 resource, |
| 223 premultiplied_alpha, | 226 premultiplied_alpha, |
| 224 uv_top_left.origin(), | 227 uv_top_left.origin(), |
| 225 uv_top_left.bottom_right(), | 228 uv_top_left.bottom_right(), |
| 226 SK_ColorTRANSPARENT, | 229 SK_ColorTRANSPARENT, |
| 227 vertex_opacity, | 230 vertex_opacity, |
| 228 flipped); | 231 flipped); |
| 229 quad_sink->Append(quad.PassAs<DrawQuad>()); | 232 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 230 } | 233 } |
| 231 | 234 |
| 232 visible_rect = | 235 visible_rect = occlusion_tracker.UnoccludedContentRect(layer_top_right, |
| 233 quad_sink->UnoccludedContentRect(layer_top_right, draw_transform()); | 236 draw_transform()); |
| 234 if (!visible_rect.IsEmpty()) { | 237 if (!visible_rect.IsEmpty()) { |
| 235 quad = TextureDrawQuad::Create(); | 238 quad = TextureDrawQuad::Create(); |
| 236 quad->SetNew(shared_quad_state, | 239 quad->SetNew(shared_quad_state, |
| 237 layer_top_right, | 240 layer_top_right, |
| 238 opaque_rect, | 241 opaque_rect, |
| 239 visible_rect, | 242 visible_rect, |
| 240 resource, | 243 resource, |
| 241 premultiplied_alpha, | 244 premultiplied_alpha, |
| 242 uv_top_right.origin(), | 245 uv_top_right.origin(), |
| 243 uv_top_right.bottom_right(), | 246 uv_top_right.bottom_right(), |
| 244 SK_ColorTRANSPARENT, | 247 SK_ColorTRANSPARENT, |
| 245 vertex_opacity, | 248 vertex_opacity, |
| 246 flipped); | 249 flipped); |
| 247 quad_sink->Append(quad.PassAs<DrawQuad>()); | 250 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 248 } | 251 } |
| 249 | 252 |
| 250 visible_rect = | 253 visible_rect = occlusion_tracker.UnoccludedContentRect(layer_bottom_left, |
| 251 quad_sink->UnoccludedContentRect(layer_bottom_left, draw_transform()); | 254 draw_transform()); |
| 252 if (!visible_rect.IsEmpty()) { | 255 if (!visible_rect.IsEmpty()) { |
| 253 quad = TextureDrawQuad::Create(); | 256 quad = TextureDrawQuad::Create(); |
| 254 quad->SetNew(shared_quad_state, | 257 quad->SetNew(shared_quad_state, |
| 255 layer_bottom_left, | 258 layer_bottom_left, |
| 256 opaque_rect, | 259 opaque_rect, |
| 257 visible_rect, | 260 visible_rect, |
| 258 resource, | 261 resource, |
| 259 premultiplied_alpha, | 262 premultiplied_alpha, |
| 260 uv_bottom_left.origin(), | 263 uv_bottom_left.origin(), |
| 261 uv_bottom_left.bottom_right(), | 264 uv_bottom_left.bottom_right(), |
| 262 SK_ColorTRANSPARENT, | 265 SK_ColorTRANSPARENT, |
| 263 vertex_opacity, | 266 vertex_opacity, |
| 264 flipped); | 267 flipped); |
| 265 quad_sink->Append(quad.PassAs<DrawQuad>()); | 268 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 266 } | 269 } |
| 267 | 270 |
| 268 visible_rect = | 271 visible_rect = occlusion_tracker.UnoccludedContentRect(layer_bottom_right, |
| 269 quad_sink->UnoccludedContentRect(layer_bottom_right, draw_transform()); | 272 draw_transform()); |
| 270 if (!visible_rect.IsEmpty()) { | 273 if (!visible_rect.IsEmpty()) { |
| 271 quad = TextureDrawQuad::Create(); | 274 quad = TextureDrawQuad::Create(); |
| 272 quad->SetNew(shared_quad_state, | 275 quad->SetNew(shared_quad_state, |
| 273 layer_bottom_right, | 276 layer_bottom_right, |
| 274 opaque_rect, | 277 opaque_rect, |
| 275 visible_rect, | 278 visible_rect, |
| 276 resource, | 279 resource, |
| 277 premultiplied_alpha, | 280 premultiplied_alpha, |
| 278 uv_bottom_right.origin(), | 281 uv_bottom_right.origin(), |
| 279 uv_bottom_right.bottom_right(), | 282 uv_bottom_right.bottom_right(), |
| 280 SK_ColorTRANSPARENT, | 283 SK_ColorTRANSPARENT, |
| 281 vertex_opacity, | 284 vertex_opacity, |
| 282 flipped); | 285 flipped); |
| 283 quad_sink->Append(quad.PassAs<DrawQuad>()); | 286 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 284 } | 287 } |
| 285 | 288 |
| 286 visible_rect = quad_sink->UnoccludedContentRect(layer_top, draw_transform()); | 289 visible_rect = |
| 290 occlusion_tracker.UnoccludedContentRect(layer_top, draw_transform()); |
| 287 if (!visible_rect.IsEmpty()) { | 291 if (!visible_rect.IsEmpty()) { |
| 288 quad = TextureDrawQuad::Create(); | 292 quad = TextureDrawQuad::Create(); |
| 289 quad->SetNew(shared_quad_state, | 293 quad->SetNew(shared_quad_state, |
| 290 layer_top, | 294 layer_top, |
| 291 opaque_rect, | 295 opaque_rect, |
| 292 visible_rect, | 296 visible_rect, |
| 293 resource, | 297 resource, |
| 294 premultiplied_alpha, | 298 premultiplied_alpha, |
| 295 uv_top.origin(), | 299 uv_top.origin(), |
| 296 uv_top.bottom_right(), | 300 uv_top.bottom_right(), |
| 297 SK_ColorTRANSPARENT, | 301 SK_ColorTRANSPARENT, |
| 298 vertex_opacity, | 302 vertex_opacity, |
| 299 flipped); | 303 flipped); |
| 300 quad_sink->Append(quad.PassAs<DrawQuad>()); | 304 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 301 } | 305 } |
| 302 | 306 |
| 303 visible_rect = quad_sink->UnoccludedContentRect(layer_left, draw_transform()); | 307 visible_rect = |
| 308 occlusion_tracker.UnoccludedContentRect(layer_left, draw_transform()); |
| 304 if (!visible_rect.IsEmpty()) { | 309 if (!visible_rect.IsEmpty()) { |
| 305 quad = TextureDrawQuad::Create(); | 310 quad = TextureDrawQuad::Create(); |
| 306 quad->SetNew(shared_quad_state, | 311 quad->SetNew(shared_quad_state, |
| 307 layer_left, | 312 layer_left, |
| 308 opaque_rect, | 313 opaque_rect, |
| 309 visible_rect, | 314 visible_rect, |
| 310 resource, | 315 resource, |
| 311 premultiplied_alpha, | 316 premultiplied_alpha, |
| 312 uv_left.origin(), | 317 uv_left.origin(), |
| 313 uv_left.bottom_right(), | 318 uv_left.bottom_right(), |
| 314 SK_ColorTRANSPARENT, | 319 SK_ColorTRANSPARENT, |
| 315 vertex_opacity, | 320 vertex_opacity, |
| 316 flipped); | 321 flipped); |
| 317 quad_sink->Append(quad.PassAs<DrawQuad>()); | 322 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 318 } | 323 } |
| 319 | 324 |
| 320 visible_rect = | 325 visible_rect = |
| 321 quad_sink->UnoccludedContentRect(layer_right, draw_transform()); | 326 occlusion_tracker.UnoccludedContentRect(layer_right, draw_transform()); |
| 322 if (!visible_rect.IsEmpty()) { | 327 if (!visible_rect.IsEmpty()) { |
| 323 quad = TextureDrawQuad::Create(); | 328 quad = TextureDrawQuad::Create(); |
| 324 quad->SetNew(shared_quad_state, | 329 quad->SetNew(shared_quad_state, |
| 325 layer_right, | 330 layer_right, |
| 326 opaque_rect, | 331 opaque_rect, |
| 327 layer_right, | 332 layer_right, |
| 328 resource, | 333 resource, |
| 329 premultiplied_alpha, | 334 premultiplied_alpha, |
| 330 uv_right.origin(), | 335 uv_right.origin(), |
| 331 uv_right.bottom_right(), | 336 uv_right.bottom_right(), |
| 332 SK_ColorTRANSPARENT, | 337 SK_ColorTRANSPARENT, |
| 333 vertex_opacity, | 338 vertex_opacity, |
| 334 flipped); | 339 flipped); |
| 335 quad_sink->Append(quad.PassAs<DrawQuad>()); | 340 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 336 } | 341 } |
| 337 | 342 |
| 338 visible_rect = | 343 visible_rect = |
| 339 quad_sink->UnoccludedContentRect(layer_bottom, draw_transform()); | 344 occlusion_tracker.UnoccludedContentRect(layer_bottom, draw_transform()); |
| 340 if (!visible_rect.IsEmpty()) { | 345 if (!visible_rect.IsEmpty()) { |
| 341 quad = TextureDrawQuad::Create(); | 346 quad = TextureDrawQuad::Create(); |
| 342 quad->SetNew(shared_quad_state, | 347 quad->SetNew(shared_quad_state, |
| 343 layer_bottom, | 348 layer_bottom, |
| 344 opaque_rect, | 349 opaque_rect, |
| 345 visible_rect, | 350 visible_rect, |
| 346 resource, | 351 resource, |
| 347 premultiplied_alpha, | 352 premultiplied_alpha, |
| 348 uv_bottom.origin(), | 353 uv_bottom.origin(), |
| 349 uv_bottom.bottom_right(), | 354 uv_bottom.bottom_right(), |
| 350 SK_ColorTRANSPARENT, | 355 SK_ColorTRANSPARENT, |
| 351 vertex_opacity, | 356 vertex_opacity, |
| 352 flipped); | 357 flipped); |
| 353 quad_sink->Append(quad.PassAs<DrawQuad>()); | 358 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 354 } | 359 } |
| 355 | 360 |
| 356 if (fill_center_) { | 361 if (fill_center_) { |
| 357 visible_rect = | 362 visible_rect = |
| 358 quad_sink->UnoccludedContentRect(layer_center, draw_transform()); | 363 occlusion_tracker.UnoccludedContentRect(layer_center, draw_transform()); |
| 359 if (!visible_rect.IsEmpty()) { | 364 if (!visible_rect.IsEmpty()) { |
| 360 quad = TextureDrawQuad::Create(); | 365 quad = TextureDrawQuad::Create(); |
| 361 quad->SetNew(shared_quad_state, | 366 quad->SetNew(shared_quad_state, |
| 362 layer_center, | 367 layer_center, |
| 363 opaque_rect, | 368 opaque_rect, |
| 364 visible_rect, | 369 visible_rect, |
| 365 resource, | 370 resource, |
| 366 premultiplied_alpha, | 371 premultiplied_alpha, |
| 367 uv_center.origin(), | 372 uv_center.origin(), |
| 368 uv_center.bottom_right(), | 373 uv_center.bottom_right(), |
| 369 SK_ColorTRANSPARENT, | 374 SK_ColorTRANSPARENT, |
| 370 vertex_opacity, | 375 vertex_opacity, |
| 371 flipped); | 376 flipped); |
| 372 quad_sink->Append(quad.PassAs<DrawQuad>()); | 377 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 373 } | 378 } |
| 374 } | 379 } |
| 375 } | 380 } |
| 376 | 381 |
| 377 const char* NinePatchLayerImpl::LayerTypeAsString() const { | 382 const char* NinePatchLayerImpl::LayerTypeAsString() const { |
| 378 return "cc::NinePatchLayerImpl"; | 383 return "cc::NinePatchLayerImpl"; |
| 379 } | 384 } |
| 380 | 385 |
| 381 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { | 386 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { |
| 382 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); | 387 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 396 result->Set("Border", MathUtil::AsValue(border_).release()); | 401 result->Set("Border", MathUtil::AsValue(border_).release()); |
| 397 | 402 |
| 398 base::FundamentalValue* fill_center = | 403 base::FundamentalValue* fill_center = |
| 399 base::Value::CreateBooleanValue(fill_center_); | 404 base::Value::CreateBooleanValue(fill_center_); |
| 400 result->Set("FillCenter", fill_center); | 405 result->Set("FillCenter", fill_center); |
| 401 | 406 |
| 402 return result; | 407 return result; |
| 403 } | 408 } |
| 404 | 409 |
| 405 } // namespace cc | 410 } // namespace cc |
| OLD | NEW |