| 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(quad_sink, shared_quad_state, append_quads_data); | 92 AppendDebugBorderQuad(render_pass, shared_quad_state, append_quads_data); |
| 90 | 93 |
| 91 if (!ui_resource_id_) | 94 if (!ui_resource_id_) |
| 92 return; | 95 return; |
| 93 | 96 |
| 94 ResourceProvider::ResourceId resource = | 97 ResourceProvider::ResourceId resource = |
| 95 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | 98 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
| 96 | 99 |
| 97 if (!resource) | 100 if (!resource) |
| 98 return; | 101 return; |
| 99 | 102 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 uv_top.width(), | 206 uv_top.width(), |
| 204 uv_left.height()); | 207 uv_left.height()); |
| 205 | 208 |
| 206 // Nothing is opaque here. | 209 // Nothing is opaque here. |
| 207 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? | 210 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? |
| 208 gfx::Rect opaque_rect; | 211 gfx::Rect opaque_rect; |
| 209 gfx::Rect visible_rect; | 212 gfx::Rect visible_rect; |
| 210 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 213 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 211 scoped_ptr<TextureDrawQuad> quad; | 214 scoped_ptr<TextureDrawQuad> quad; |
| 212 | 215 |
| 213 visible_rect = | 216 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 214 quad_sink->UnoccludedContentRect(this, layer_top_left, draw_transform()); | 217 this->render_target(), layer_top_left, draw_transform()); |
| 215 if (!visible_rect.IsEmpty()) { | 218 if (!visible_rect.IsEmpty()) { |
| 216 quad = TextureDrawQuad::Create(); | 219 quad = TextureDrawQuad::Create(); |
| 217 quad->SetNew(shared_quad_state, | 220 quad->SetNew(shared_quad_state, |
| 218 layer_top_left, | 221 layer_top_left, |
| 219 opaque_rect, | 222 opaque_rect, |
| 220 visible_rect, | 223 visible_rect, |
| 221 resource, | 224 resource, |
| 222 premultiplied_alpha, | 225 premultiplied_alpha, |
| 223 uv_top_left.origin(), | 226 uv_top_left.origin(), |
| 224 uv_top_left.bottom_right(), | 227 uv_top_left.bottom_right(), |
| 225 SK_ColorTRANSPARENT, | 228 SK_ColorTRANSPARENT, |
| 226 vertex_opacity, | 229 vertex_opacity, |
| 227 flipped); | 230 flipped); |
| 228 quad_sink->Append(quad.PassAs<DrawQuad>()); | 231 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 229 } | 232 } |
| 230 | 233 |
| 231 visible_rect = | 234 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 232 quad_sink->UnoccludedContentRect(this, layer_top_right, draw_transform()); | 235 this->render_target(), layer_top_right, draw_transform()); |
| 233 if (!visible_rect.IsEmpty()) { | 236 if (!visible_rect.IsEmpty()) { |
| 234 quad = TextureDrawQuad::Create(); | 237 quad = TextureDrawQuad::Create(); |
| 235 quad->SetNew(shared_quad_state, | 238 quad->SetNew(shared_quad_state, |
| 236 layer_top_right, | 239 layer_top_right, |
| 237 opaque_rect, | 240 opaque_rect, |
| 238 visible_rect, | 241 visible_rect, |
| 239 resource, | 242 resource, |
| 240 premultiplied_alpha, | 243 premultiplied_alpha, |
| 241 uv_top_right.origin(), | 244 uv_top_right.origin(), |
| 242 uv_top_right.bottom_right(), | 245 uv_top_right.bottom_right(), |
| 243 SK_ColorTRANSPARENT, | 246 SK_ColorTRANSPARENT, |
| 244 vertex_opacity, | 247 vertex_opacity, |
| 245 flipped); | 248 flipped); |
| 246 quad_sink->Append(quad.PassAs<DrawQuad>()); | 249 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 247 } | 250 } |
| 248 | 251 |
| 249 visible_rect = quad_sink->UnoccludedContentRect( | 252 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 250 this, layer_bottom_left, draw_transform()); | 253 this->render_target(), layer_bottom_left, draw_transform()); |
| 251 if (!visible_rect.IsEmpty()) { | 254 if (!visible_rect.IsEmpty()) { |
| 252 quad = TextureDrawQuad::Create(); | 255 quad = TextureDrawQuad::Create(); |
| 253 quad->SetNew(shared_quad_state, | 256 quad->SetNew(shared_quad_state, |
| 254 layer_bottom_left, | 257 layer_bottom_left, |
| 255 opaque_rect, | 258 opaque_rect, |
| 256 visible_rect, | 259 visible_rect, |
| 257 resource, | 260 resource, |
| 258 premultiplied_alpha, | 261 premultiplied_alpha, |
| 259 uv_bottom_left.origin(), | 262 uv_bottom_left.origin(), |
| 260 uv_bottom_left.bottom_right(), | 263 uv_bottom_left.bottom_right(), |
| 261 SK_ColorTRANSPARENT, | 264 SK_ColorTRANSPARENT, |
| 262 vertex_opacity, | 265 vertex_opacity, |
| 263 flipped); | 266 flipped); |
| 264 quad_sink->Append(quad.PassAs<DrawQuad>()); | 267 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 265 } | 268 } |
| 266 | 269 |
| 267 visible_rect = quad_sink->UnoccludedContentRect( | 270 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 268 this, layer_bottom_right, draw_transform()); | 271 this->render_target(), layer_bottom_right, draw_transform()); |
| 269 if (!visible_rect.IsEmpty()) { | 272 if (!visible_rect.IsEmpty()) { |
| 270 quad = TextureDrawQuad::Create(); | 273 quad = TextureDrawQuad::Create(); |
| 271 quad->SetNew(shared_quad_state, | 274 quad->SetNew(shared_quad_state, |
| 272 layer_bottom_right, | 275 layer_bottom_right, |
| 273 opaque_rect, | 276 opaque_rect, |
| 274 visible_rect, | 277 visible_rect, |
| 275 resource, | 278 resource, |
| 276 premultiplied_alpha, | 279 premultiplied_alpha, |
| 277 uv_bottom_right.origin(), | 280 uv_bottom_right.origin(), |
| 278 uv_bottom_right.bottom_right(), | 281 uv_bottom_right.bottom_right(), |
| 279 SK_ColorTRANSPARENT, | 282 SK_ColorTRANSPARENT, |
| 280 vertex_opacity, | 283 vertex_opacity, |
| 281 flipped); | 284 flipped); |
| 282 quad_sink->Append(quad.PassAs<DrawQuad>()); | 285 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 283 } | 286 } |
| 284 | 287 |
| 285 visible_rect = | 288 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 286 quad_sink->UnoccludedContentRect(this, layer_top, draw_transform()); | 289 this->render_target(), layer_top, draw_transform()); |
| 287 if (!visible_rect.IsEmpty()) { | 290 if (!visible_rect.IsEmpty()) { |
| 288 quad = TextureDrawQuad::Create(); | 291 quad = TextureDrawQuad::Create(); |
| 289 quad->SetNew(shared_quad_state, | 292 quad->SetNew(shared_quad_state, |
| 290 layer_top, | 293 layer_top, |
| 291 opaque_rect, | 294 opaque_rect, |
| 292 visible_rect, | 295 visible_rect, |
| 293 resource, | 296 resource, |
| 294 premultiplied_alpha, | 297 premultiplied_alpha, |
| 295 uv_top.origin(), | 298 uv_top.origin(), |
| 296 uv_top.bottom_right(), | 299 uv_top.bottom_right(), |
| 297 SK_ColorTRANSPARENT, | 300 SK_ColorTRANSPARENT, |
| 298 vertex_opacity, | 301 vertex_opacity, |
| 299 flipped); | 302 flipped); |
| 300 quad_sink->Append(quad.PassAs<DrawQuad>()); | 303 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 301 } | 304 } |
| 302 | 305 |
| 303 visible_rect = | 306 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 304 quad_sink->UnoccludedContentRect(this, layer_left, draw_transform()); | 307 this->render_target(), layer_left, draw_transform()); |
| 305 if (!visible_rect.IsEmpty()) { | 308 if (!visible_rect.IsEmpty()) { |
| 306 quad = TextureDrawQuad::Create(); | 309 quad = TextureDrawQuad::Create(); |
| 307 quad->SetNew(shared_quad_state, | 310 quad->SetNew(shared_quad_state, |
| 308 layer_left, | 311 layer_left, |
| 309 opaque_rect, | 312 opaque_rect, |
| 310 visible_rect, | 313 visible_rect, |
| 311 resource, | 314 resource, |
| 312 premultiplied_alpha, | 315 premultiplied_alpha, |
| 313 uv_left.origin(), | 316 uv_left.origin(), |
| 314 uv_left.bottom_right(), | 317 uv_left.bottom_right(), |
| 315 SK_ColorTRANSPARENT, | 318 SK_ColorTRANSPARENT, |
| 316 vertex_opacity, | 319 vertex_opacity, |
| 317 flipped); | 320 flipped); |
| 318 quad_sink->Append(quad.PassAs<DrawQuad>()); | 321 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 319 } | 322 } |
| 320 | 323 |
| 321 visible_rect = | 324 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 322 quad_sink->UnoccludedContentRect(this, layer_right, draw_transform()); | 325 this->render_target(), layer_right, draw_transform()); |
| 323 if (!visible_rect.IsEmpty()) { | 326 if (!visible_rect.IsEmpty()) { |
| 324 quad = TextureDrawQuad::Create(); | 327 quad = TextureDrawQuad::Create(); |
| 325 quad->SetNew(shared_quad_state, | 328 quad->SetNew(shared_quad_state, |
| 326 layer_right, | 329 layer_right, |
| 327 opaque_rect, | 330 opaque_rect, |
| 328 layer_right, | 331 layer_right, |
| 329 resource, | 332 resource, |
| 330 premultiplied_alpha, | 333 premultiplied_alpha, |
| 331 uv_right.origin(), | 334 uv_right.origin(), |
| 332 uv_right.bottom_right(), | 335 uv_right.bottom_right(), |
| 333 SK_ColorTRANSPARENT, | 336 SK_ColorTRANSPARENT, |
| 334 vertex_opacity, | 337 vertex_opacity, |
| 335 flipped); | 338 flipped); |
| 336 quad_sink->Append(quad.PassAs<DrawQuad>()); | 339 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 337 } | 340 } |
| 338 | 341 |
| 339 visible_rect = | 342 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 340 quad_sink->UnoccludedContentRect(this, layer_bottom, draw_transform()); | 343 this->render_target(), layer_bottom, draw_transform()); |
| 341 if (!visible_rect.IsEmpty()) { | 344 if (!visible_rect.IsEmpty()) { |
| 342 quad = TextureDrawQuad::Create(); | 345 quad = TextureDrawQuad::Create(); |
| 343 quad->SetNew(shared_quad_state, | 346 quad->SetNew(shared_quad_state, |
| 344 layer_bottom, | 347 layer_bottom, |
| 345 opaque_rect, | 348 opaque_rect, |
| 346 visible_rect, | 349 visible_rect, |
| 347 resource, | 350 resource, |
| 348 premultiplied_alpha, | 351 premultiplied_alpha, |
| 349 uv_bottom.origin(), | 352 uv_bottom.origin(), |
| 350 uv_bottom.bottom_right(), | 353 uv_bottom.bottom_right(), |
| 351 SK_ColorTRANSPARENT, | 354 SK_ColorTRANSPARENT, |
| 352 vertex_opacity, | 355 vertex_opacity, |
| 353 flipped); | 356 flipped); |
| 354 quad_sink->Append(quad.PassAs<DrawQuad>()); | 357 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 355 } | 358 } |
| 356 | 359 |
| 357 if (fill_center_) { | 360 if (fill_center_) { |
| 358 visible_rect = | 361 visible_rect = occlusion_tracker.UnoccludedContentRect( |
| 359 quad_sink->UnoccludedContentRect(this, layer_center, draw_transform()); | 362 this->render_target(), layer_center, draw_transform()); |
| 360 if (!visible_rect.IsEmpty()) { | 363 if (!visible_rect.IsEmpty()) { |
| 361 quad = TextureDrawQuad::Create(); | 364 quad = TextureDrawQuad::Create(); |
| 362 quad->SetNew(shared_quad_state, | 365 quad->SetNew(shared_quad_state, |
| 363 layer_center, | 366 layer_center, |
| 364 opaque_rect, | 367 opaque_rect, |
| 365 visible_rect, | 368 visible_rect, |
| 366 resource, | 369 resource, |
| 367 premultiplied_alpha, | 370 premultiplied_alpha, |
| 368 uv_center.origin(), | 371 uv_center.origin(), |
| 369 uv_center.bottom_right(), | 372 uv_center.bottom_right(), |
| 370 SK_ColorTRANSPARENT, | 373 SK_ColorTRANSPARENT, |
| 371 vertex_opacity, | 374 vertex_opacity, |
| 372 flipped); | 375 flipped); |
| 373 quad_sink->Append(quad.PassAs<DrawQuad>()); | 376 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 374 } | 377 } |
| 375 } | 378 } |
| 376 } | 379 } |
| 377 | 380 |
| 378 const char* NinePatchLayerImpl::LayerTypeAsString() const { | 381 const char* NinePatchLayerImpl::LayerTypeAsString() const { |
| 379 return "cc::NinePatchLayerImpl"; | 382 return "cc::NinePatchLayerImpl"; |
| 380 } | 383 } |
| 381 | 384 |
| 382 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { | 385 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { |
| 383 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); | 386 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 397 result->Set("Border", MathUtil::AsValue(border_).release()); | 400 result->Set("Border", MathUtil::AsValue(border_).release()); |
| 398 | 401 |
| 399 base::FundamentalValue* fill_center = | 402 base::FundamentalValue* fill_center = |
| 400 base::Value::CreateBooleanValue(fill_center_); | 403 base::Value::CreateBooleanValue(fill_center_); |
| 401 result->Set("FillCenter", fill_center); | 404 result->Set("FillCenter", fill_center); |
| 402 | 405 |
| 403 return result; | 406 return result; |
| 404 } | 407 } |
| 405 | 408 |
| 406 } // namespace cc | 409 } // namespace cc |
| OLD | NEW |