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 "ui/gfx/geometry/size_conversions.h"
15 scoped_refptr
<ThumbnailLayer
> ThumbnailLayer::Create() {
16 return make_scoped_refptr(new ThumbnailLayer());
19 void ThumbnailLayer::SetThumbnail(Thumbnail
* thumbnail
) {
20 layer_
->SetUIResourceId(thumbnail
->ui_resource_id());
21 UpdateSizes(thumbnail
->scaled_content_size(), thumbnail
->scaled_data_size());
24 void ThumbnailLayer::Clip(const gfx::Rect
& clipping
) {
25 last_clipping_
= clipping
;
26 gfx::Size clipped_content
=
27 gfx::ToCeiledSize(gfx::Size(content_size_
.width() - clipping
.x(),
28 content_size_
.height() - clipping
.y()));
29 clipped_content
.SetToMin(clipping
.size());
30 layer_
->SetBounds(clipped_content
);
33 gfx::PointF(clipping
.x() / resource_size_
.width(),
34 clipping
.y() / resource_size_
.height()),
36 (clipping
.x() + clipped_content
.width()) / resource_size_
.width(),
37 (clipping
.y() + clipped_content
.height()) / resource_size_
.height()));
40 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr
<cc::Layer
> parent
,
42 if (index
>= parent
->children().size())
43 parent
->AddChild(layer_
);
44 else if (parent
->child_at(index
)->id() != layer_
->id())
45 parent
->ReplaceChild(parent
->child_at(index
), layer_
);
48 scoped_refptr
<cc::Layer
> ThumbnailLayer::layer() {
52 ThumbnailLayer::ThumbnailLayer() : layer_(cc::UIResourceLayer::Create()) {
53 layer_
->SetIsDrawable(true);
56 ThumbnailLayer::~ThumbnailLayer() {
59 void ThumbnailLayer::UpdateSizes(const gfx::SizeF
& content_size
,
60 const gfx::SizeF
& resource_size
) {
61 if (content_size
!= content_size_
|| resource_size
!= resource_size_
) {
62 content_size_
= content_size
;
63 resource_size_
= resource_size
;
68 } // namespace android