| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/android/compositor/layer/thumbnail_layer.h" | 5 #include "chrome/browser/android/compositor/layer/thumbnail_layer.h" |
| 6 | 6 |
| 7 #include "cc/layers/ui_resource_layer.h" | 7 #include "cc/layers/ui_resource_layer.h" |
| 8 #include "chrome/browser/android/thumbnail/thumbnail.h" | 8 #include "chrome/browser/android/thumbnail/thumbnail.h" |
| 9 #include "content/public/browser/android/compositor.h" | 9 #include "content/public/browser/android/compositor.h" |
| 10 #include "ui/gfx/geometry/size_conversions.h" | 10 #include "ui/gfx/geometry/size_conversions.h" |
| 11 | 11 |
| 12 namespace android { | 12 namespace android { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 scoped_refptr<ThumbnailLayer> ThumbnailLayer::Create() { | 15 scoped_refptr<ThumbnailLayer> ThumbnailLayer::Create() { |
| 16 return make_scoped_refptr(new ThumbnailLayer()); | 16 return make_scoped_refptr(new ThumbnailLayer()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void ThumbnailLayer::SetThumbnail(Thumbnail* thumbnail) { | 19 void ThumbnailLayer::SetThumbnail(Thumbnail* thumbnail) { |
| 20 layer_->SetUIResourceId(thumbnail->ui_resource_id()); | 20 layer_->SetUIResourceId(thumbnail->ui_resource_id()); |
| 21 UpdateSizes(thumbnail->scaled_content_size(), thumbnail->scaled_data_size()); | 21 UpdateSizes(thumbnail->scaled_content_size(), thumbnail->scaled_data_size()); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ThumbnailLayer::Clip(const gfx::Rect& clipping) { | 24 void ThumbnailLayer::Clip(const gfx::Rect& clipping) { |
| 25 last_clipping_ = clipping; | 25 last_clipping_ = clipping; |
| 26 clipped_ = true; |
| 27 |
| 26 gfx::Size clipped_content = gfx::Size(content_size_.width() - clipping.x(), | 28 gfx::Size clipped_content = gfx::Size(content_size_.width() - clipping.x(), |
| 27 content_size_.height() - clipping.y()); | 29 content_size_.height() - clipping.y()); |
| 28 clipped_content.SetToMin(clipping.size()); | 30 clipped_content.SetToMin(clipping.size()); |
| 29 layer_->SetBounds(clipped_content); | 31 layer_->SetBounds(clipped_content); |
| 30 | 32 |
| 31 layer_->SetUV( | 33 layer_->SetUV( |
| 32 gfx::PointF(clipping.x() / resource_size_.width(), | 34 gfx::PointF(clipping.x() / resource_size_.width(), |
| 33 clipping.y() / resource_size_.height()), | 35 clipping.y() / resource_size_.height()), |
| 34 gfx::PointF( | 36 gfx::PointF( |
| 35 (clipping.x() + clipped_content.width()) / resource_size_.width(), | 37 (clipping.x() + clipped_content.width()) / resource_size_.width(), |
| 36 (clipping.y() + clipped_content.height()) / resource_size_.height())); | 38 (clipping.y() + clipped_content.height()) / resource_size_.height())); |
| 37 } | 39 } |
| 38 | 40 |
| 41 void ThumbnailLayer::ClearClip() { |
| 42 layer_->SetUV(gfx::PointF(0.f, 0.f), gfx::PointF(1.f, 1.f)); |
| 43 layer_->SetBounds(gfx::Size(content_size_.width(), content_size_.height())); |
| 44 clipped_ = false; |
| 45 } |
| 46 |
| 39 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent, | 47 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent, |
| 40 size_t index) { | 48 size_t index) { |
| 41 if (index >= parent->children().size()) | 49 if (index >= parent->children().size()) |
| 42 parent->AddChild(layer_); | 50 parent->AddChild(layer_); |
| 43 else if (parent->child_at(index)->id() != layer_->id()) | 51 else if (parent->child_at(index)->id() != layer_->id()) |
| 44 parent->ReplaceChild(parent->child_at(index), layer_); | 52 parent->ReplaceChild(parent->child_at(index), layer_); |
| 45 } | 53 } |
| 46 | 54 |
| 47 scoped_refptr<cc::Layer> ThumbnailLayer::layer() { | 55 scoped_refptr<cc::Layer> ThumbnailLayer::layer() { |
| 48 return layer_; | 56 return layer_; |
| 49 } | 57 } |
| 50 | 58 |
| 51 ThumbnailLayer::ThumbnailLayer() : layer_(cc::UIResourceLayer::Create()) { | 59 ThumbnailLayer::ThumbnailLayer() : layer_(cc::UIResourceLayer::Create()) { |
| 52 layer_->SetIsDrawable(true); | 60 layer_->SetIsDrawable(true); |
| 53 } | 61 } |
| 54 | 62 |
| 55 ThumbnailLayer::~ThumbnailLayer() { | 63 ThumbnailLayer::~ThumbnailLayer() { |
| 56 } | 64 } |
| 57 | 65 |
| 58 void ThumbnailLayer::UpdateSizes(const gfx::SizeF& content_size, | 66 void ThumbnailLayer::UpdateSizes(const gfx::SizeF& content_size, |
| 59 const gfx::SizeF& resource_size) { | 67 const gfx::SizeF& resource_size) { |
| 60 if (content_size != content_size_ || resource_size != resource_size_) { | 68 if (content_size != content_size_ || resource_size != resource_size_) { |
| 61 content_size_ = content_size; | 69 content_size_ = content_size; |
| 62 resource_size_ = resource_size; | 70 resource_size_ = resource_size; |
| 63 Clip(last_clipping_); | 71 if (clipped_) |
| 72 Clip(last_clipping_); |
| 73 else |
| 74 ClearClip(); |
| 64 } | 75 } |
| 65 } | 76 } |
| 66 | 77 |
| 67 } // namespace android | 78 } // namespace android |
| OLD | NEW |