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"
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
);
34 gfx::PointF(clipping
.x() / resource_size_
.width(),
35 clipping
.y() / resource_size_
.height()),
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
,
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() {
53 ThumbnailLayer::ThumbnailLayer()
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
;
71 } // namespace android