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/picture_layer_tiling.h" | 5 #include "cc/picture_layer_tiling.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "cc/math_util.h" | 8 #include "cc/math_util.h" |
9 #include "ui/gfx/point_conversions.h" | 9 #include "ui/gfx/point_conversions.h" |
10 #include "ui/gfx/rect_conversions.h" | 10 #include "ui/gfx/rect_conversions.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 gfx::SizeF PictureLayerTiling::ContentSizeF() const { | 45 gfx::SizeF PictureLayerTiling::ContentSizeF() const { |
46 return gfx::ScaleSize(layer_bounds_, contents_scale_); | 46 return gfx::ScaleSize(layer_bounds_, contents_scale_); |
47 } | 47 } |
48 | 48 |
49 Tile* PictureLayerTiling::TileAt(int i, int j) const { | 49 Tile* PictureLayerTiling::TileAt(int i, int j) const { |
50 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 50 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
51 if (iter == tiles_.end()) | 51 if (iter == tiles_.end()) |
52 return NULL; | 52 return NULL; |
53 return iter->second.get(); | 53 return iter->second.tile(); |
54 } | 54 } |
55 | 55 |
56 void PictureLayerTiling::CreateTile(int i, int j) { | 56 void PictureLayerTiling::CreateTile(int i, int j) { |
57 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); | 57 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); |
58 tile_rect.set_size(tiling_data_.max_texture_size()); | 58 tile_rect.set_size(tiling_data_.max_texture_size()); |
59 TileMapKey key(i, j); | 59 TileMapKey key(i, j); |
60 DCHECK(tiles_.find(key) == tiles_.end()); | 60 DCHECK(tiles_.find(key) == tiles_.end()); |
61 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 61 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); |
62 if (tile) | 62 if (tile) |
63 tiles_[key] = tile; | 63 tiles_.insert(make_pair(key, TileHandle(tile))); |
64 } | 64 } |
65 | 65 |
66 Region PictureLayerTiling::OpaqueRegionInContentRect( | 66 Region PictureLayerTiling::OpaqueRegionInContentRect( |
67 const gfx::Rect& content_rect) const { | 67 const gfx::Rect& content_rect) const { |
68 Region opaque_region; | 68 Region opaque_region; |
69 // TODO(enne): implement me | 69 // TODO(enne): implement me |
70 return opaque_region; | 70 return opaque_region; |
71 } | 71 } |
72 | 72 |
73 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { | 73 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 last_prioritized_rect_, | 407 last_prioritized_rect_, |
408 inflated_rect); | 408 inflated_rect); |
409 iter; | 409 iter; |
410 ++iter) { | 410 ++iter) { |
411 TileMap::iterator find = tiles_.find(iter.index()); | 411 TileMap::iterator find = tiles_.find(iter.index()); |
412 if (find == tiles_.end()) | 412 if (find == tiles_.end()) |
413 continue; | 413 continue; |
414 | 414 |
415 TilePriority priority; | 415 TilePriority priority; |
416 DCHECK(!priority.is_live); | 416 DCHECK(!priority.is_live); |
417 Tile* tile = find->second.get(); | 417 TileHandle* tile_handle = &find->second; |
| 418 Tile* tile = tile_handle->tile(); |
418 tile->set_priority(tree, priority); | 419 tile->set_priority(tree, priority); |
419 } | 420 } |
420 last_prioritized_rect_ = inflated_rect; | 421 last_prioritized_rect_ = inflated_rect; |
421 | 422 |
422 gfx::Rect view_rect(device_viewport); | 423 gfx::Rect view_rect(device_viewport); |
423 float current_scale = current_layer_contents_scale / contents_scale_; | 424 float current_scale = current_layer_contents_scale / contents_scale_; |
424 float last_scale = last_layer_contents_scale / contents_scale_; | 425 float last_scale = last_layer_contents_scale / contents_scale_; |
425 | 426 |
426 // Fast path tile priority calculation when both transforms are translations. | 427 // Fast path tile priority calculation when both transforms are translations. |
427 if (last_screen_transform.IsIdentityOrTranslation() && | 428 if (last_screen_transform.IsIdentityOrTranslation() && |
428 current_screen_transform.IsIdentityOrTranslation()) | 429 current_screen_transform.IsIdentityOrTranslation()) |
429 { | 430 { |
430 gfx::Vector2dF current_offset( | 431 gfx::Vector2dF current_offset( |
431 current_screen_transform.matrix().get(0, 3), | 432 current_screen_transform.matrix().get(0, 3), |
432 current_screen_transform.matrix().get(1, 3)); | 433 current_screen_transform.matrix().get(1, 3)); |
433 gfx::Vector2dF last_offset( | 434 gfx::Vector2dF last_offset( |
434 last_screen_transform.matrix().get(0, 3), | 435 last_screen_transform.matrix().get(0, 3), |
435 last_screen_transform.matrix().get(1, 3)); | 436 last_screen_transform.matrix().get(1, 3)); |
436 | 437 |
437 for (TilingData::Iterator iter(&tiling_data_, inflated_rect); | 438 for (TilingData::Iterator iter(&tiling_data_, inflated_rect); |
438 iter; ++iter) { | 439 iter; ++iter) { |
439 TileMap::iterator find = tiles_.find(iter.index()); | 440 TileMap::iterator find = tiles_.find(iter.index()); |
440 if (find == tiles_.end()) | 441 if (find == tiles_.end()) |
441 continue; | 442 continue; |
442 Tile* tile = find->second.get(); | 443 TileHandle* tile_handle = &find->second; |
| 444 Tile* tile = tile_handle->tile(); |
443 | 445 |
444 gfx::Rect tile_bounds = | 446 gfx::Rect tile_bounds = |
445 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 447 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
446 gfx::RectF current_screen_rect = gfx::ScaleRect( | 448 gfx::RectF current_screen_rect = gfx::ScaleRect( |
447 tile_bounds, | 449 tile_bounds, |
448 current_scale, | 450 current_scale, |
449 current_scale) + current_offset; | 451 current_scale) + current_offset; |
450 gfx::RectF last_screen_rect = gfx::ScaleRect( | 452 gfx::RectF last_screen_rect = gfx::ScaleRect( |
451 tile_bounds, | 453 tile_bounds, |
452 last_scale, | 454 last_scale, |
(...skipping 12 matching lines...) Expand all Loading... |
465 if (store_screen_space_quads_on_tiles) | 467 if (store_screen_space_quads_on_tiles) |
466 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect)); | 468 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect)); |
467 tile->set_priority(tree, priority); | 469 tile->set_priority(tree, priority); |
468 } | 470 } |
469 } else { | 471 } else { |
470 for (TilingData::Iterator iter(&tiling_data_, inflated_rect); | 472 for (TilingData::Iterator iter(&tiling_data_, inflated_rect); |
471 iter; ++iter) { | 473 iter; ++iter) { |
472 TileMap::iterator find = tiles_.find(iter.index()); | 474 TileMap::iterator find = tiles_.find(iter.index()); |
473 if (find == tiles_.end()) | 475 if (find == tiles_.end()) |
474 continue; | 476 continue; |
475 Tile* tile = find->second.get(); | 477 TileHandle* tile_handle = &find->second; |
| 478 Tile* tile = tile_handle->tile(); |
476 | 479 |
477 gfx::Rect tile_bounds = | 480 gfx::Rect tile_bounds = |
478 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 481 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
479 gfx::RectF current_layer_content_rect = gfx::ScaleRect( | 482 gfx::RectF current_layer_content_rect = gfx::ScaleRect( |
480 tile_bounds, | 483 tile_bounds, |
481 current_scale, | 484 current_scale, |
482 current_scale); | 485 current_scale); |
483 gfx::RectF current_screen_rect = MathUtil::mapClippedRect( | 486 gfx::RectF current_screen_rect = MathUtil::mapClippedRect( |
484 current_screen_transform, current_layer_content_rect); | 487 current_screen_transform, current_layer_content_rect); |
485 gfx::RectF last_layer_content_rect = gfx::ScaleRect( | 488 gfx::RectF last_layer_content_rect = gfx::ScaleRect( |
(...skipping 24 matching lines...) Expand all Loading... |
510 tile->set_priority(tree, priority); | 513 tile->set_priority(tree, priority); |
511 } | 514 } |
512 } | 515 } |
513 | 516 |
514 last_source_frame_number_ = current_source_frame_number; | 517 last_source_frame_number_ = current_source_frame_number; |
515 last_impl_frame_time_ = current_frame_time; | 518 last_impl_frame_time_ = current_frame_time; |
516 } | 519 } |
517 | 520 |
518 void PictureLayerTiling::DidBecomeActive() { | 521 void PictureLayerTiling::DidBecomeActive() { |
519 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 522 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
520 it->second->set_priority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); | 523 Tile* tile = it->second.tile(); |
521 it->second->set_priority(PENDING_TREE, TilePriority()); | 524 tile->set_priority(ACTIVE_TREE, tile->priority(PENDING_TREE)); |
| 525 tile->set_priority(PENDING_TREE, TilePriority()); |
522 | 526 |
523 // Tile holds a ref onto a picture pile. If the tile never gets invalidated | 527 // Tile holds a ref onto a picture pile. If the tile never gets invalidated |
524 // and recreated, then that picture pile ref could exist indefinitely. To | 528 // and recreated, then that picture pile ref could exist indefinitely. To |
525 // prevent this, ask the client to update the pile to its own ref. This | 529 // prevent this, ask the client to update the pile to its own ref. This |
526 // will cause PicturePileImpls and their clones to get deleted once the | 530 // will cause PicturePileImpls and their clones to get deleted once the |
527 // corresponding PictureLayerImpl and any in flight raster jobs go out of | 531 // corresponding PictureLayerImpl and any in flight raster jobs go out of |
528 // scope. | 532 // scope. |
529 client_->UpdatePile(it->second); | 533 client_->UpdatePile(tile); |
530 } | 534 } |
531 } | 535 } |
532 | 536 |
533 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { | 537 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { |
534 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 538 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
535 state->SetInteger("num_tiles", tiles_.size()); | 539 state->SetInteger("num_tiles", tiles_.size()); |
536 state->SetDouble("content_scale", contents_scale_); | 540 state->SetDouble("content_scale", contents_scale_); |
537 state->Set("content_bounds", | 541 state->Set("content_bounds", |
538 MathUtil::asValue(ContentRect().size()).release()); | 542 MathUtil::asValue(ContentRect().size()).release()); |
539 return state.PassAs<base::Value>(); | 543 return state.PassAs<base::Value>(); |
540 } | 544 } |
541 | 545 |
| 546 TileHandle::TileHandle(scoped_refptr<Tile> tile) |
| 547 : tile_(tile), |
| 548 managed_tile_state_(tile_->tile_manager()->RegisterTile(tile_)) { |
| 549 } |
| 550 |
| 551 TileHandle::~TileHandle() { |
| 552 } |
| 553 |
542 } // namespace cc | 554 } // namespace cc |
OLD | NEW |