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

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: 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 bool StaticTabSceneLayer::ShouldShowBackground() {
27 scoped_refptr<cc::Layer> parent = layer_->parent();
28 return parent.get() && parent->bounds() != layer_->bounds();
29 }
30
31 SkColor StaticTabSceneLayer::GetBackgroundColor() {
32 return background_color_;
33 }
34
35 void StaticTabSceneLayer::UpdateTabLayer(JNIEnv* env,
36 jobject jobj,
37 jfloat content_viewport_x,
38 jfloat content_viewport_y,
39 jfloat content_viewport_width,
40 jfloat content_viewport_height,
41 jobject jtab_content_manager,
42 jint id,
43 jint toolbar_resource_id,
44 jboolean can_use_live_layer,
45 jboolean can_use_ntp_fallback,
46 jint default_background_color,
47 jfloat x,
48 jfloat y,
49 jfloat width,
50 jfloat height,
51 jfloat content_offset_y,
52 jfloat static_to_view_blend,
53 jfloat saturation) {
54 background_color_ = default_background_color;
55 gfx::Size content_viewport_size(content_viewport_width,
56 content_viewport_height);
57 gfx::Point content_viewport_offset(content_viewport_x, content_viewport_y);
58 if (!content_layer_.get()) {
59 chrome::android::TabContentManager* tab_content_manager =
60 chrome::android::TabContentManager::FromJavaObject(
61 jtab_content_manager);
62 content_layer_ = chrome::android::ContentLayer::Create(tab_content_manager);
63 }
64
65 // Only override the alpha of content layers when the static tab is first
66 // assigned to the layer tree.
67 float content_alpha_override = 1.f;
68 bool should_override_content_alpha = last_set_tab_id_ != id;
69 last_set_tab_id_ = id;
70
71 // Set up the content layer and move it to the proper position.
72 content_layer_->layer()->SetBounds(gfx::Size(width, height));
73 content_layer_->layer()->SetPosition(gfx::Point(x, y));
74 content_layer_->SetProperties(
75 id, can_use_live_layer, can_use_ntp_fallback, static_to_view_blend,
76 should_override_content_alpha, content_alpha_override, saturation,
77 gfx::Rect(content_viewport_size), content_viewport_size);
78
79 gfx::Size content_bounds(0, 0);
80 content_bounds = content_layer_->layer()->bounds();
81
82 gfx::Size actual_content_size(content_layer_->GetContentSize());
83
84 bool view_and_content_have_same_orientation =
85 (content_viewport_size.width() > content_viewport_size.height()) ==
86 (actual_content_size.width() > actual_content_size.height()) &&
87 actual_content_size.width() > 0 && actual_content_size.height() > 0 &&
88 content_viewport_size.width() > 0 && content_viewport_size.height() > 0;
89
90 // This may not be true for frames during rotation.
91 bool content_has_consistent_width =
92 actual_content_size.width() == content_bounds.width() &&
93 actual_content_size.width() == content_viewport_size.width();
94
95 if (view_and_content_have_same_orientation ||
96 (content_has_consistent_width && content_layer_->ShowingLiveLayer())) {
97 y += content_offset_y;
98 } else {
99 // If our orientations are off and we have a static texture, or if we have
100 // a live layer of an unexpected width, move the texture in by the
101 // appropriate amount.
102 x += content_viewport_offset.x();
103 y += content_viewport_offset.y();
104 }
105
106 content_layer_->layer()->SetPosition(gfx::Point(x, y));
107 content_layer_->layer()->SetIsDrawable(true);
108
109 layer_->AddChild(content_layer_->layer());
110 }
111
112 void StaticTabSceneLayer::SetContentSceneLayer(JNIEnv* env,
113 jobject jobj,
114 jobject jcontent_scene_layer) {
115 SceneLayer* content_scene_layer = FromJavaObject(env, jcontent_scene_layer);
116 if (content_scene_layer && content_scene_layer->layer()) {
117 content_scene_layer_ = content_scene_layer->layer();
118 if (content_scene_layer_.get())
119 layer_->AddChild(content_scene_layer_);
120 } else if (content_scene_layer_) {
121 content_scene_layer_->RemoveFromParent();
122 content_scene_layer_ = 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
« no previous file with comments | « chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698