Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: chrome/browser/android/compositor/layer/thumbnail_layer.cc

Issue 2499863002: Simplify content_layer attachment and viewporting logic. (Closed)
Patch Set: Fix clang error Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 clipped_ = false;
44 }
45
39 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent, 46 void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent,
40 size_t index) { 47 size_t index) {
41 if (index >= parent->children().size()) 48 if (index >= parent->children().size())
42 parent->AddChild(layer_); 49 parent->AddChild(layer_);
43 else if (parent->child_at(index)->id() != layer_->id()) 50 else if (parent->child_at(index)->id() != layer_->id())
44 parent->ReplaceChild(parent->child_at(index), layer_); 51 parent->ReplaceChild(parent->child_at(index), layer_);
45 } 52 }
46 53
47 scoped_refptr<cc::Layer> ThumbnailLayer::layer() { 54 scoped_refptr<cc::Layer> ThumbnailLayer::layer() {
48 return layer_; 55 return layer_;
49 } 56 }
50 57
51 ThumbnailLayer::ThumbnailLayer() : layer_(cc::UIResourceLayer::Create()) { 58 ThumbnailLayer::ThumbnailLayer() : layer_(cc::UIResourceLayer::Create()) {
52 layer_->SetIsDrawable(true); 59 layer_->SetIsDrawable(true);
53 } 60 }
54 61
55 ThumbnailLayer::~ThumbnailLayer() { 62 ThumbnailLayer::~ThumbnailLayer() {
56 } 63 }
57 64
58 void ThumbnailLayer::UpdateSizes(const gfx::SizeF& content_size, 65 void ThumbnailLayer::UpdateSizes(const gfx::SizeF& content_size,
59 const gfx::SizeF& resource_size) { 66 const gfx::SizeF& resource_size) {
60 if (content_size != content_size_ || resource_size != resource_size_) { 67 if (content_size != content_size_ || resource_size != resource_size_) {
61 content_size_ = content_size; 68 content_size_ = content_size;
62 resource_size_ = resource_size; 69 resource_size_ = resource_size;
63 Clip(last_clipping_); 70 if (clipped_)
71 Clip(last_clipping_);
64 } 72 }
65 } 73 }
66 74
67 } // namespace android 75 } // namespace android
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698