Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / compositor / layer / thumbnail_layer.cc
blobb18555ac593fe9416546bf2e670d1fc9d5b93d0d
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/compositor/layer/thumbnail_layer.h"
7 #include "cc/layers/ui_resource_layer.h"
8 #include "chrome/browser/android/thumbnail/thumbnail.h"
9 #include "content/public/browser/android/compositor.h"
10 #include "ui/gfx/geometry/size_conversions.h"
12 namespace chrome {
13 namespace android {
15 // static
16 scoped_refptr<ThumbnailLayer> ThumbnailLayer::Create() {
17 return make_scoped_refptr(new ThumbnailLayer());
20 void ThumbnailLayer::SetThumbnail(Thumbnail* thumbnail) {
21 layer_->SetUIResourceId(thumbnail->ui_resource_id());
22 UpdateSizes(thumbnail->scaled_content_size(), thumbnail->scaled_data_size());
25 void ThumbnailLayer::Clip(const gfx::Rect& clipping) {
26 last_clipping_ = clipping;
27 gfx::Size clipped_content =
28 gfx::ToCeiledSize(gfx::Size(content_size_.width() - clipping.x(),
29 content_size_.height() - clipping.y()));
30 clipped_content.SetToMin(clipping.size());
31 layer_->SetBounds(clipped_content);
33 layer_->SetUV(
34 gfx::PointF(clipping.x() / resource_size_.width(),
35 clipping.y() / resource_size_.height()),
36 gfx::PointF(
37 (clipping.x() + clipped_content.width()) / resource_size_.width(),
38 (clipping.y() + clipped_content.height()) / resource_size_.height()));
41 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent,
42 size_t index) {
43 if (index >= parent->children().size())
44 parent->AddChild(layer_);
45 else if (parent->child_at(index)->id() != layer_->id())
46 parent->ReplaceChild(parent->child_at(index), layer_);
49 scoped_refptr<cc::Layer> ThumbnailLayer::layer() {
50 return layer_;
53 ThumbnailLayer::ThumbnailLayer()
54 : layer_(
55 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())) {
56 layer_->SetIsDrawable(true);
59 ThumbnailLayer::~ThumbnailLayer() {
62 void ThumbnailLayer::UpdateSizes(const gfx::SizeF& content_size,
63 const gfx::SizeF& resource_size) {
64 if (content_size != content_size_ || resource_size != resource_size_) {
65 content_size_ = content_size;
66 resource_size_ = resource_size;
67 Clip(last_clipping_);
71 } // namespace android
72 } // namespace chrome