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

Side by Side Diff: chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.cc

Issue 852433002: [Android] Upstream scene layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 11 months 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
(Empty)
1 // Copyright 2015 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.
4
5 #include "chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h "
6
7 #include "cc/layers/layer.h"
8 #include "chrome/browser/android/compositor/layer/content_layer.h"
9 #include "chrome/browser/android/compositor/layer_title_cache.h"
10 #include "chrome/browser/android/compositor/tab_content_manager.h"
11 #include "jni/StaticTabSceneLayer_jni.h"
12 #include "third_party/skia/include/core/SkColor.h"
13
14 namespace chrome {
15 namespace android {
16
17 StaticTabSceneLayer::StaticTabSceneLayer(JNIEnv* env, jobject jobj)
18 : SceneLayer(env, jobj),
19 last_set_tab_id_(-1),
20 background_color_(SK_ColorWHITE) {
21 }
22
23 StaticTabSceneLayer::~StaticTabSceneLayer() {
24 }
25
26 void StaticTabSceneLayer::UpdateTabLayer(JNIEnv* env,
27 jobject jobj,
28 jfloat content_viewport_x,
29 jfloat content_viewport_y,
30 jfloat content_viewport_width,
31 jfloat content_viewport_height,
32 jobject jtab_content_manager,
33 jint id,
34 jint toolbar_resource_id,
35 jboolean can_use_live_layer,
36 jboolean can_use_ntp_fallback,
37 jint default_background_color,
38 jfloat x,
39 jfloat y,
40 jfloat width,
41 jfloat height,
42 jfloat content_offset_y,
43 jfloat static_to_view_blend,
44 jfloat saturation) {
45 background_color_ = default_background_color;
46 gfx::Size content_viewport_size(content_viewport_width,
47 content_viewport_height);
48 gfx::Point content_viewport_offset(content_viewport_x, content_viewport_y);
49 if (!content_layer_.get()) {
50 chrome::android::TabContentManager* tab_content_manager =
51 chrome::android::TabContentManager::FromJavaObject(
52 jtab_content_manager);
53 content_layer_ = chrome::android::ContentLayer::Create(tab_content_manager);
54 }
55
56 // Only override the alpha of content layers when the static tab is first
57 // assigned to the layer tree.
58 float content_alpha_override = 1.f;
59 bool should_override_content_alpha = last_set_tab_id_ != id;
60 last_set_tab_id_ = id;
61
62 // Set up the content layer and move it to the proper position.
63 content_layer_->layer()->SetBounds(gfx::Size(width, height));
64 content_layer_->layer()->SetPosition(gfx::Point(x, y));
65 content_layer_->SetProperties(
66 id, can_use_live_layer, can_use_ntp_fallback, static_to_view_blend,
67 should_override_content_alpha, content_alpha_override, saturation,
68 gfx::Rect(content_viewport_size), content_viewport_size);
69
70 gfx::Size content_bounds(0, 0);
71 content_bounds = content_layer_->layer()->bounds();
72
73 gfx::Size actual_content_size(content_layer_->GetContentSize());
74
75 bool view_and_content_have_same_orientation =
76 (content_viewport_size.width() > content_viewport_size.height()) ==
77 (actual_content_size.width() > actual_content_size.height()) &&
78 actual_content_size.width() > 0 && actual_content_size.height() > 0 &&
79 content_viewport_size.width() > 0 && content_viewport_size.height() > 0;
80
81 // This may not be true for frames during rotation.
82 bool content_has_consistent_width =
83 actual_content_size.width() == content_bounds.width() &&
84 actual_content_size.width() == content_viewport_size.width();
85
86 if (view_and_content_have_same_orientation ||
87 (content_has_consistent_width && content_layer_->ShowingLiveLayer())) {
88 y += content_offset_y;
89 } else {
90 // If our orientations are off and we have a static texture, or if we have
91 // a live layer of an unexpected width, move the texture in by the
92 // appropriate amount.
93 x += content_viewport_offset.x();
94 y += content_viewport_offset.y();
95 }
96
97 content_layer_->layer()->SetPosition(gfx::Point(x, y));
98 content_layer_->layer()->SetIsDrawable(true);
99
100 layer_->AddChild(content_layer_->layer());
101 }
102
103 bool StaticTabSceneLayer::ShouldShowBackground() {
104 scoped_refptr<cc::Layer> parent = layer_->parent();
105 return parent.get() && parent->bounds() != layer_->bounds();
106 }
107
108 SkColor StaticTabSceneLayer::GetBackgroundColor() {
109 return background_color_;
110 }
111
112 void StaticTabSceneLayer::SetContentTree(JNIEnv* env,
113 jobject jobj,
114 jobject jcontent_tree) {
115 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree);
116 if (content_tree && content_tree->layer()) {
117 contextual_content_tree_ = content_tree->layer();
118 if (contextual_content_tree_.get())
119 layer_->AddChild(contextual_content_tree_);
120 } else if (contextual_content_tree_) {
121 contextual_content_tree_->RemoveFromParent();
122 contextual_content_tree_ = nullptr;
123 }
124 }
125
126 static jlong Init(JNIEnv* env, jobject jobj) {
127 // This will automatically bind to the Java object and pass ownership there.
128 StaticTabSceneLayer* scene_layer = new StaticTabSceneLayer(env, jobj);
129 return reinterpret_cast<intptr_t>(scene_layer);
130 }
131
132 bool RegisterStaticTabSceneLayer(JNIEnv* env) {
133 return RegisterNativesImpl(env);
134 }
135
136 } // namespace android
137 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698